// pages/demand/detail.js import { fetchDemandDetail, joinDemandBidding, demandOperate } from '../../../services/demand/fetchDemand'; Page({ /** * 页面的初始数据 */ data: { id: 0, quotedPrice: '', needDays: '', remark: '', actualAccount: 0, activeValues: [0, 1, 2, 3, 4], demandInfo: null }, /** * 获取需求详情 */ /** * 获取需求详情 * @param {number|string} id * @returns {Promise} 详情渲染完成后 resolve */ 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(); }, ); }); }, //文件预览 fileView(e) { const fileUrl = e.currentTarget.dataset.url; wx.downloadFile({ url: fileUrl, success: function (res) { const filePath = res.tempFilePath wx.openDocument({ filePath: filePath, success: function (res) { console.log('打开文档成功') } }) } }) }, //文件复制 fileUrlCopy(e) { const url = e.currentTarget.dataset.url; wx.setClipboardData({ data: url, success: function () { wx.showToast({ title: '下载链接已复制', icon: 'success' }); }, fail: function () { wx.showToast({ title: '下载链接复制失败', icon: 'none' }); } }); }, 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 }); }, //交付凭证截图预览 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.setStorageSync('bidDemandId', 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.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.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.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.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.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.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(); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { // 从签约页等操作页返回时,backAndRefresh 会给本页打 freshPage 标记,此时刷新详情 if (this.data.freshPage) { this.setData({ freshPage: false }); this.loadDemandDetail(this.data.id); } }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })