// pages/demand/detail.js import { fetchDemandDetail, joinDemandBidding, demandOperate } from '../../../services/demand/fetchDemand'; import { fetchIncomeRates, calcActualAccount, toPercent } from '../../../services/home/home'; Page({ /** * 页面的初始数据 */ data: { id: 0, quotedPrice: '', needDays: '', remark: '', actualAccount: 0, payPlatform: 'android', // 客户发布需求时的手机系统 platformName: '安卓', payFeePercent: 1, commissionRatio: 0.1, // 平台服务费比例,来自 common/getMiniConfig commissionPercent: 10, androidPayFeeRate: 0.01, iosPayFeeRate: 0.12, androidFeePercent: 1, iosFeePercent: 12, activeValues: [0, 1, 2, 3, 4], demandInfo: null, freshPage: false, // 返回本页时是否需要重新拉取详情(签约/发货/支付后置为 true) copyUrl: '' // 剪贴板复制失败时,弹出可长按选择的链接 }, /** * 获取需求详情 */ /** * 获取需求详情 * @param {number|string} id * @returns {Promise} 详情渲染完成后 resolve */ loadDemandDetail(id) { return new Promise((resolve) => { fetchDemandDetail({ id: id }).then( (res) => { if (!res || res.code !== 1 || !res.data) { wx.showToast({ title: (res && res.msg) || '加载失败', icon: 'none' }); if (!this.data.demandInfo) { setTimeout(() => { wx.navigateBack({ delta: 1 }); }, 1500); } resolve(); return; } const demandInfo = res.data; this.setData({ demandInfo, ...this.incomePreview(this.getQuoteAmount(demandInfo), { payPlatform: demandInfo.pay_platform }) }, () => resolve()); // setData 回调:页面已重新渲染 }, () => { wx.showToast({ title: '网络异常,请重试', icon: 'none' }); resolve(); }, ); }); }, // 报价金额:优先已投标报价,其次合同总费用,最后为当前输入 getQuoteAmount(demandInfo) { return demandInfo?.myBidding?.quoted_price || demandInfo?.demand_contracts?.total_amount || this.data.quotedPrice || 0; }, // 按客户发布需求时的手机系统计算预计到手 incomePreview(amount, rates) { const commissionRatio = rates && rates.commissionRatio !== undefined ? rates.commissionRatio : this.data.commissionRatio; const androidPayFeeRate = rates && rates.androidPayFeeRate !== undefined ? rates.androidPayFeeRate : this.data.androidPayFeeRate; const iosPayFeeRate = rates && rates.iosPayFeeRate !== undefined ? rates.iosPayFeeRate : this.data.iosPayFeeRate; const rawPlatform = rates && rates.payPlatform !== undefined ? rates.payPlatform : this.data.payPlatform; const payPlatform = rawPlatform === 'ios' ? 'ios' : 'android'; const payFeeRate = payPlatform === 'ios' ? iosPayFeeRate : androidPayFeeRate; return { actualAccount: calcActualAccount(amount, commissionRatio, payFeeRate), payPlatform, payFeePercent: toPercent(payFeeRate), platformName: payPlatform === 'ios' ? 'iOS' : '安卓', }; }, // 拉取平台服务费和支付费率,并重算预计到手金额 async loadCommissionRatio() { const rates = await fetchIncomeRates(); this.setData({ commissionRatio: rates.commissionRatio, commissionPercent: toPercent(rates.commissionRatio), androidPayFeeRate: rates.androidPayFeeRate, iosPayFeeRate: rates.iosPayFeeRate, androidFeePercent: toPercent(rates.androidPayFeeRate), iosFeePercent: toPercent(rates.iosPayFeeRate), ...this.incomePreview(this.getQuoteAmount(this.data.demandInfo), { ...rates, payPlatform: (this.data.demandInfo && this.data.demandInfo.pay_platform) || this.data.payPlatform, }), }); }, // 取文件扩展名对应的 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] : ''; }, //文件预览 fileView(e) { const fileUrl = e.currentTarget.dataset.url; 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 }); wx.downloadFile({ url: fileUrl, 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 }); wx.openDocument({ 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); } } }); } }); }, 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 : '') }); } }); }, // 复制链接(失败自动重试一次,仍失败则弹出可长按选择的链接供手动复制) 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: '' }); }, 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') { this.setData(this.incomePreview(value)); } 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 }); }, //交付凭证截图预览 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}`, }); }, //参与竞标 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.$util.markDemandRefresh(this.data.id); wx.requestSubscribeMessage({ tmplIds: ['JGQJ3a-enop3Jfrcb7av4e5bX8p0Cah_5txloDHhBNw', 'fuSe71gltzwYTjNrc6N2bWg4cuO4qlhYjgo-09D3Gg8'], 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.$util.markDemandRefresh(this.data.id); wx.showModal({ title: '提示', showCancel: false, content: agree ? '确认接单成功,请通过联系方式与客户沟通开发细节' : '已拒绝成功', success: (res) => { if (res.confirm) { if (agree) { //刷新当前页面,等沟通群二维码渲染完成后再回到顶部,方便直接看到 this.loadDemandDetail(this.data.id).then(() => { wx.pageScrollTo({ scrollTop: 0, duration: 300 }); }); } 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.$util.markDemandRefresh(this.data.id); 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({ tmplIds: ['Gl_t3R5a_NoAvmVaDLeERCfFmTLiHURv9eIixtnOKYI'], 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.$util.markDemandRefresh(this.data.id); wx.requestSubscribeMessage({ // 验收结果 + 工单结算 + 订单发货提醒(客户支付尾款后提醒开发者发货) tmplIds: ['0H4GVHXI9G8RtZ1FuS_BuWN8yzOiBQ0-47ym6f08X_I', 'Xpqqk4si-Jh6HqfD-1VS9IH2AtlgVgGJLzgVS7RRMFk', 'jGxNQ11on1yD0d5tGwk4S8jP_CEdddfAkrp9-xVeeZY'], complete(re) { wx.showModal({ title: '提示', showCancel: false, content: agree ? '工作已完成,请录制产品功能演示视频或提供在线体验地址,发送到需求沟通群,让客户观看后进行验收。' : '很遗憾,工作完成失败', 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.$util.markDemandRefresh(this.data.id); //支付页成功后 redirectTo 结果页,返回本页时需重新拉取详情 this.setData({ freshPage: true }); wx.requestSubscribeMessage({ // 合同付款提醒 + 确认收货通知(开发者发货后提醒客户确认收货) tmplIds: ['RxZ1VlzI5cFl_q8fF-WfQlkUqMKp1HGhDCGzAYcmRtk', 'Utj3mlCNu0uiwshpoCeTPVMggXWYC6hVGqFBgGm9TFk'], 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.$util.markDemandRefresh(this.data.id); wx.requestSubscribeMessage({ tmplIds: ['Gl_t3R5a_NoAvmVaDLeERCfFmTLiHURv9eIixtnOKYI'], 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.$util.markDemandRefresh(this.data.id); 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); this.loadCommissionRatio(); wx.$util.checkSubscriptionsSetting(); //从列表「前去验收」进入时,提示先到沟通群查看/体验交付成果再验收 if (options.fromAccept == '1') { this.showAcceptTip(); } }, // 验收提示:引导客户先到需求沟通群查看或体验交付成果 showAcceptTip() { wx.showModal({ title: '验收提示', showCancel: false, confirmText: '我知道了', content: '请先到需求沟通群查看开发人员交付的成果演示,确认没有问题后再进行验收。', success: () => { console.log('用户点击我知道了'); } }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { // 从签约页等操作页返回时,backAndRefresh 会给本页打 freshPage 标记,此时刷新详情 if (this.data.freshPage) { this.setData({ freshPage: false }); this.loadDemandDetail(this.data.id); } }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })