Files
code-bang/frontend/miniapp/pages/demand/detail/index.js
T

750 lines
21 KiB
JavaScript
Raw Normal View History

2026-09-17 16:25:31 +08:00
// pages/demand/detail.js
import { fetchDemandDetail, joinDemandBidding, demandOperate } from '../../../services/demand/fetchDemand';
Page({
/**
* 页面的初始数据
*/
data: {
id: 0,
quotedPrice: '',
needDays: '',
remark: '',
actualAccount: 0,
2026-09-30 14:56:56 +08:00
activeValues: [0, 1, 2, 3, 4],
2026-09-30 18:19:25 +08:00
demandInfo: null,
copyUrl: '' // 剪贴板复制失败时,弹出可长按选择的链接
2026-09-17 16:25:31 +08:00
},
/**
* 获取需求详情
*/
/**
* 获取需求详情
* @param {number|string} id
* @returns {Promise} 详情渲染完成后 resolve
*/
2026-09-17 16:25:31 +08:00
loadDemandDetail(id) {
return new Promise((resolve) => {
fetchDemandDetail({ id: id }).then(
(res) => {
console.log(res);
const demandInfo = res.data;
this.setData({
demandInfo,
actualAccount: parseFloat(demandInfo?.myBidding?.quoted_price || demandInfo?.demand_contracts?.total_amount || 0) * 0.9
}, () => resolve()); // setData 回调:页面已重新渲染
},
() => {
//接口异常处理
resolve();
},
);
});
2026-09-17 16:25:31 +08:00
},
2026-09-30 18:19:25 +08:00
// 取文件扩展名对应的 openDocument 类型(默认 pdf)
getFileType(url) {
const ext = String(url || '').split('?')[0].split('#')[0].split('.').pop().toLowerCase();
const support = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf'];
return support.indexOf(ext) > -1 ? ext : 'pdf';
},
// 取域名,用于下载失败时提示配置合法域名
getUrlHost(url) {
const match = String(url || '').match(/^https?:\/\/([^/:?#]+)/);
return match ? match[1] : '';
},
2026-09-17 16:25:31 +08:00
//文件预览
fileView(e) {
const fileUrl = e.currentTarget.dataset.url;
2026-09-30 18:19:25 +08:00
if (!fileUrl) {
wx.showToast({
title: '文件链接为空',
icon: 'none'
});
return;
}
const fileType = this.getFileType(fileUrl);
// 指定带扩展名的保存路径:安卓/鸿蒙靠扩展名识别文件类型,
// downloadFile 默认的 tempFilePath 无扩展名,容易打开失败
const filePath = `${wx.env.USER_DATA_PATH}/demand_file_${Date.now()}.${fileType}`;
wx.showLoading({
title: '加载中...',
mask: true
});
2026-09-17 16:25:31 +08:00
wx.downloadFile({
url: fileUrl,
2026-09-30 18:19:25 +08:00
filePath: filePath,
success: (res) => {
wx.hideLoading();
if (res.statusCode !== 200) {
wx.showToast({
title: '文件加载失败(' + res.statusCode + ')',
icon: 'none'
});
return;
}
const openPath = res.filePath || res.tempFilePath || filePath;
console.log('openDocument', { openPath, fileType });
2026-09-17 16:25:31 +08:00
wx.openDocument({
2026-09-30 18:19:25 +08:00
filePath: openPath,
fileType: fileType,
showMenu: true, // 支持转发/用其他应用打开
success: () => {
console.log('打开文档成功');
},
fail: (err) => {
console.error('openDocument fail', err);
// 安卓/鸿蒙部分机型无法直接预览,降级为复制链接到浏览器打开
wx.showModal({
title: '预览失败',
content: '当前系统无法直接预览该文件,是否复制链接后在浏览器中打开?',
confirmText: '复制链接',
cancelText: '关闭',
success: (res2) => {
if (res2.confirm) {
this.copyUrlToClipboard(fileUrl);
}
}
});
2026-09-17 16:25:31 +08:00
}
});
},
2026-09-30 18:19:25 +08:00
fail: (err) => {
wx.hideLoading();
console.error('downloadFile fail', err);
// 真机/体验版常见原因:downloadFile 合法域名未配置(开发者工具可关闭校验,真机不行)
const host = this.getUrlHost(fileUrl);
wx.showModal({
title: '预览失败',
showCancel: false,
content: '文件下载失败(' + (err && err.errMsg ? err.errMsg : '未知错误') + '),请检查网络' + (host ? ';请确认已配置 downloadFile 合法域名:' + host : '')
2026-09-17 16:25:31 +08:00
});
}
});
},
2026-09-30 18:19:25 +08:00
// 复制链接(失败自动重试一次,仍失败则弹出可长按选择的链接供手动复制)
copyUrlToClipboard(url) {
if (!url) {
wx.showToast({
title: '文件链接为空',
icon: 'none'
});
return;
}
const doCopy = (retry) => {
wx.setClipboardData({
data: String(url),
success: () => {
wx.showToast({
title: '下载链接已复制',
icon: 'success'
});
},
fail: (err) => {
console.error('setClipboardData fail', err);
if (retry > 0) {
// 系统剪贴板偶发写入失败,短暂延迟后重试一次
setTimeout(() => doCopy(retry - 1), 200);
return;
}
// 降级:展示可长按选择的链接,用户手动复制
this.setData({ copyUrl: String(url) });
}
});
};
doCopy(1);
},
//文件复制
fileUrlCopy(e) {
this.copyUrlToClipboard(e.currentTarget.dataset.url);
},
// 关闭手动复制弹层
closeCopyModal() {
this.setData({ copyUrl: '' });
},
2026-09-17 16:25:31 +08:00
handleChange(e) {
console.log(e.detail.value);
this.setData({
activeValues: e.detail.value,
});
},
onInputChange(e) {
const field = e.currentTarget.dataset.field;
const value = e.detail.value;
if (field == 'quotedPrice') {
let actualAccount = parseInt(value * 0.9);
this.setData({ actualAccount });
}
this.setData({
[`${field}`]: value
});
},
//图片预览
onImageView(e) {
const { images, index } = e.currentTarget.dataset;
console.log('images', images);
console.log('index', index);
wx.previewImage({
current: images[index],
urls: images
});
},
2026-09-30 14:56:56 +08:00
//交付凭证截图预览
onDeliveryImagePreview(e) {
const { images, index } = e.currentTarget.dataset;
const urls = (images || []).map(item => item.url);
if (!urls.length) {
return;
}
wx.previewImage({
current: urls[index],
urls
});
},
//去发货(交付开发成果)
deliverGoods() {
wx.navigateTo({
url: `/pages/demand/deliver/index?demandId=${this.data.id}`,
});
},
2026-09-17 16:25:31 +08:00
//参与竞标
submitBidding() {
const { id, quotedPrice, needDays, remark } = this.data;
if (!quotedPrice) {
wx.showToast({
title: '报价不能为空',
icon: 'none'
});
return;
}
if (!needDays) {
wx.showToast({
title: '工期不能为空',
icon: 'none'
});
return;
}
let params = {
demand_id: id,
quoted_price: quotedPrice,
need_days: needDays,
remark: remark,
};
joinDemandBidding(params).then(
(res) => {
console.log(res);
if (res.code == 1) {
wx.setStorageSync('bidDemandId', this.data.id);
wx.requestSubscribeMessage({
2026-09-23 17:06:46 +08:00
tmplIds: ['JGQJ3a-enop3Jfrcb7av4e5bX8p0Cah_5txloDHhBNw', 'fuSe71gltzwYTjNrc6N2bWg4cuO4qlhYjgo-09D3Gg8'],
2026-09-17 16:25:31 +08:00
complete(re) {
wx.showModal({
title: '提示',
showCancel: false,
content: '报名成功,中标会有消息通知',
success(res) {
if (res.confirm) {
wx.navigateBack();
console.log('用户点击确定');
}
}
});
}
});
} else {
wx.showToast({
title: res.msg,
icon: 'none'
});
}
},
() => {
//接口异常处理
wx.showToast({
title: '操作失败',
icon: 'none'
});
},
);
},
// 确认接单
confirmDemand(e) {
// 处理确认接单逻辑
const { status } = e.currentTarget.dataset;
const agree = status === '1';
wx.showModal({
title: '提示',
showCancel: true,
cancelText: '取消',
content: agree ? '是否确认接单?' : '确认拒绝接单?',
success: (res) => {
if (!res.confirm) {
return;
}
let params = {
'demandId': this.data.id,
'opType': 'confirm',
'agree': agree,
}
demandOperate(params).then(
(res) => {
console.log(res);
if (res.code == 1) {
wx.showModal({
title: '提示',
showCancel: false,
content: agree ? '确认接单成功,请通过联系方式与客户沟通开发细节' : '已拒绝成功',
success: (res) => {
if (res.confirm) {
2026-10-09 16:59:09 +08:00
//标记该需求需要刷新,返回列表时同步最新状态与按钮
wx.$util.markDemandRefresh(this.data.id);
2026-09-17 16:25:31 +08:00
if (agree) {
//刷新当前页面,等沟通群二维码渲染完成后再回到顶部,方便直接看到
this.loadDemandDetail(this.data.id).then(() => {
wx.pageScrollTo({
scrollTop: 0,
duration: 300
});
2026-09-17 16:25:31 +08:00
});
} else {
//返回上一页
// wx.navigateBack({ delta: 1 });
wx.$util.backAndRefresh();
}
console.log('用户点击确定');
}
}
});
} else {
wx.showToast({
title: res.msg,
icon: 'none'
});
}
},
() => {
//接口异常处理
wx.showToast({
title: '操作失败',
icon: 'none'
});
},
);
}
});
},
// 开发签约合同
signContractDev(e) {
// 处理签约合同逻辑
const demandId = this.data.id;
const { status } = e.currentTarget.dataset;
const agree = status === '1';
const source = this.data.opType == 'quote' ? 'dev' : 'customer';
console.log(e)
console.log(agree)
//拒绝签约
if (!agree) {
wx.showModal({
title: '提示',
showCancel: true,
cancelText: '取消',
content: '确认放弃签约?',
success: (res) => {
if (!res.confirm) {
return;
}
let params = {
'demandId': this.data.id,
'opType': 'contractDev',
'agree': agree,
}
demandOperate(params).then(
(res) => {
console.log(res);
if (res.code == 1) {
wx.showModal({
title: '提示',
showCancel: false,
content: '已放弃签约',
success: (res) => {
if (res.confirm) {
//返回上一页
// wx.navigateBack({ delta: 1 });
wx.$util.backAndRefresh();
console.log('用户点击确定');
}
}
});
} else {
wx.showToast({
title: res.msg,
icon: 'none'
});
}
}
);
}
});
} else {
wx.navigateTo({
url: `/pages/demand/contract/index?demandId=${demandId}&source=${source}`,
});
}
},
// 客户签约合同
signContractCustomer(e) {
// 处理签约合同逻辑
wx.requestSubscribeMessage({
2026-09-23 17:06:46 +08:00
tmplIds: ['Gl_t3R5a_NoAvmVaDLeERCfFmTLiHURv9eIixtnOKYI'],
2026-09-17 16:25:31 +08:00
complete: (re) => {
this.signContractDev(e);
}
});
},
// 完成工作
completeWork(e) {
// 处理完成工作逻辑
const { status } = e.currentTarget.dataset;
const agree = status === '1';
wx.showModal({
title: '提示',
showCancel: true,
content: agree ? '确认已经完成工作?' : '确认工作完成失败?',
success: (res2) => {
if (res2.confirm) {
let params = {
'demandId': this.data.id,
'opType': 'completeWork',
agree,
}
demandOperate(params).then(
(res) => {
console.log(res);
if (res.code == 1) {
wx.requestSubscribeMessage({
2026-09-30 15:35:40 +08:00
// 验收结果 + 工单结算 + 订单发货提醒(客户支付尾款后提醒开发者发货)
tmplIds: ['0H4GVHXI9G8RtZ1FuS_BuWN8yzOiBQ0-47ym6f08X_I', 'Xpqqk4si-Jh6HqfD-1VS9IH2AtlgVgGJLzgVS7RRMFk', 'jGxNQ11on1yD0d5tGwk4S8jP_CEdddfAkrp9-xVeeZY'],
2026-09-17 16:25:31 +08:00
complete(re) {
wx.showModal({
title: '提示',
showCancel: false,
2026-10-08 21:39:12 +08:00
content: agree
? '工作已完成,请录制产品功能演示视频或提供在线体验地址,发送到需求沟通群,让客户观看后进行验收。'
: '很遗憾,工作完成失败',
2026-09-17 16:25:31 +08:00
success: (res) => {
if (res.confirm) {
wx.$util.backAndRefresh();
console.log('用户点击确定');
}
}
});
}
});
} else {
wx.showToast({
title: res.msg,
icon: 'none'
});
}
},
() => {
//接口异常处理
wx.showToast({
title: '操作失败',
icon: 'none'
});
},
);
}
}
});
},
// 验收通过
acceptPassed() {
// 处理验收通过逻辑
wx.showModal({
title: '提示',
showCancel: true,
cancelText: '不通过',
confirmText: '验收通过',
content: '确认验收通过?',
success: (res2) => {
//确认
if (res2.confirm) {
let params = {
'demandId': this.data.id,
'opType': 'acceptPassed',
'contractType': 2,
'agree': 1,
}
demandOperate(params).then(
(res) => {
console.log(res);
if (res.code == 1) {
wx.requestSubscribeMessage({
2026-09-30 15:35:40 +08:00
// 合同付款提醒 + 确认收货通知(开发者发货后提醒客户确认收货)
tmplIds: ['RxZ1VlzI5cFl_q8fF-WfQlkUqMKp1HGhDCGzAYcmRtk', 'Utj3mlCNu0uiwshpoCeTPVMggXWYC6hVGqFBgGm9TFk'],
2026-09-17 16:25:31 +08:00
complete: (re) => {
wx.showModal({
title: '提示',
showCancel: false,
content: '验收成功,去支付尾款后获取源码',
success: (res3) => {
if (res3.confirm) {
this.onPay(res.data);
console.log('用户点击确定');
}
}
});
}
});
} else {
wx.showToast({
title: res.msg,
icon: 'none'
});
}
},
() => {
//接口异常处理
wx.showToast({
title: '操作失败',
icon: 'none'
});
},
);
} else if (res2.cancel) {
console.log('用户点击取消')
wx.showModal({
title: '确认不通过?',
editable: true,
showCancel: true,
cancelText: '再想想',
confirmText: '不通过',
placeholderText: '请填写原因',
success: (res0) => {
if (res0.confirm) {
let params = {
'demandId': this.data.id,
'opType': 'acceptPassed',
'contractType': 2,
'agree': 0,
'reason': res0.content,
}
demandOperate(params).then(
(res) => {
console.log(res);
if (res.code == 1) {
wx.requestSubscribeMessage({
2026-09-23 17:06:46 +08:00
tmplIds: ['Gl_t3R5a_NoAvmVaDLeERCfFmTLiHURv9eIixtnOKYI'],
2026-09-17 16:25:31 +08:00
complete: (re) => {
wx.showModal({
title: '提示',
showCancel: false,
content: '验收未通过,已驳回给开发人员重新修改',
success: (res1) => {
if (res1.confirm) {
wx.$util.backAndRefresh();
console.log('用户点击确定');
}
}
});
}
});
} else {
wx.showToast({
title: res.msg,
icon: 'none'
});
}
},
() => {
//接口异常处理
wx.showToast({
title: '操作失败',
icon: 'none'
});
},
);
}
}
});
}
}
});
},
// 确认收货
confirmReceipt() {
// 处理确认收货逻辑
wx.showModal({
title: '提示',
showCancel: true,
cancelText: '取消',
content: '是否确认收货?确认收货后平台将立即打款给开发者',
success: (res) => {
if (!res.confirm) {
return;
}
let params = {
'demandId': this.data.id,
'opType': 'confirmReceipt',
'agree': 1,
}
demandOperate(params).then(
(res) => {
console.log(res);
if (res.code == 1) {
wx.showModal({
title: '提示',
showCancel: false,
content: '确认收货成功',
success: (res) => {
if (res.confirm) {
//返回上一页
// wx.navigateBack({ delta: 1 });
wx.$util.backAndRefresh();
console.log('用户点击确定');
}
}
});
} else {
wx.showToast({
title: res.msg,
icon: 'none'
});
}
},
);
}
});
},
//签约订单支付
onPay(order) {
let goodsList = [];
let storeId = order.store_id;
order.order_goods.forEach((data) => {
let query = {
quantity: data.buy_quantity,
storeId: storeId,
spuId: data.spu_id,
goodsName: data.goods_name,
available: 1,
price: data.goods_payment_price,
primaryImage: data.goods_picture_url,
skuId: data.sku_id,
thumb: data.goods_picture_url,
title: data.goods_name,
};
goodsList.push(query);
});
console.log(goodsList);
console.log(JSON.stringify(goodsList));
let urlQueryStr = wx.$util.obj2Params({
orderNo: order.order_no,
goodsRequestList: JSON.stringify(goodsList),
}, true);
console.log(urlQueryStr);
urlQueryStr = urlQueryStr ? `?${urlQueryStr}` : '';
const path = `/pages/order/order-confirm/index${urlQueryStr}`;
wx.navigateTo({
url: path,
});
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
const { id } = options;
const opType = options.opType || '';
console.log(options);
this.setData({
id,
opType
});
this.loadDemandDetail(id);
wx.$util.checkSubscriptionsSetting();
2026-10-08 21:39:12 +08:00
//从列表「前去验收」进入时,提示先到沟通群查看/体验交付成果再验收
if (options.fromAccept == '1') {
this.showAcceptTip();
}
},
// 验收提示:引导客户先到需求沟通群查看或体验交付成果
showAcceptTip() {
wx.showModal({
title: '验收提示',
showCancel: false,
confirmText: '我知道了',
2026-10-09 15:57:00 +08:00
content: '请先到需求沟通群查看开发人员交付的成果演示,确认没有问题后再进行验收。',
2026-10-08 21:39:12 +08:00
success: () => {
console.log('用户点击我知道了');
}
});
2026-09-17 16:25:31 +08:00
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
// 从签约页等操作页返回时,backAndRefresh 会给本页打 freshPage 标记,此时刷新详情
if (this.data.freshPage) {
this.setData({ freshPage: false });
this.loadDemandDetail(this.data.id);
}
2026-09-17 16:25:31 +08:00
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})