// pages/detail/detail.js const app = getApp(); Page({ /** * 页面的初始数据 */ data: { cover: true, // 蒙层 bright_points: '', // 亮点 message: { //订单状态映射 '0': '确认订单', '1': '订单关闭', '2': '已确认', '3': '订单中止', '4': '订单完成' }, status: 0, //按钮状态 1 我要报名 2 已确认订单 3 订单待确认、订单进行中 show: true, // btn_message: '' }, /** * 需求报名 * @requirement_id {string} 需求ID * @bright_points {string} 亮点 * @enroll_from {number} 报名来源(0:小程序 1:APP 2:后台) */ apply() { wx.kx_request({ url: wx.kx_api.hwRequirement.enrollmentRequire, model: true, type: 'post', data: { requirement_id: this.data.id, bright_points: this.data.bright_points, enroll_from: 0 }, success: res => { wx.showToast({ title: '报名成功', success: res => { this.setData({ cover: true, }, _ => { wx.navigateBack({ delta: 1, }) }) } }) }, fail: res => { if (res.errcode) { wx.showModal({ title: '报名失败', content: res.errmsg, showCancel: false, confirmColor: '#31364C' }) } } }) }, /** * 亮点输入 * @bright_points {string} 亮点 */ input(e) { this.setData({ bright_points: e.detail.value }) }, /** * 打开地图 */ openMap(e) { const name = e.currentTarget.dataset.name; const address = e.currentTarget.dataset.address; // wx.openLocation({ // latitude: 31.544325, // longitude: 120.356595, // name, // address // }) }, /** * 查看合同 * @filePath {string} 合同地址 */ buttonCheck() { // 获取线上合同 如果存在打开合同 不存在进行提示(暂无) const workContract = this.data.hwOrderAPI.workContract; if (workContract) { wx.downloadFile({ url: this.data.hwOrderAPI.workContract, success: (res) => { wx.openDocument({ filePath: res.tempFilePath, }) } }) } else { // wx.showToast({ // icon:'none', // title: '', // }) } }, /** * 确认订单 * @orderId {string} 订单ID * 前台报名需求后 后台生成订单 需前台手动确定订单 */ buttonSubmit() { wx.kx_request({ url: wx.kx_api.hwOrder.confirmOrder, type: 'post', data: { orderId: this.data.hwOrderAPI.id }, success: res => { if (res.errcode === 0) { wx.showToast({ title: '订单已确认', success: res => { // 确认成功后 更改按钮状态 const hwOrderAPI = this.data.hwOrderAPI; hwOrderAPI.status = 2; this.setData({ hwOrderAPI }) } }) } } }) }, /** * 控制cover层的显示与隐藏 */ cover() { const cover = !this.data.cover; this.setData({ cover }) }, /** * */ buttonRight() { }, /** * 生命周期函数--监听页面加载 */ onLoad: function(options) { if (wx.getStorageSync('userid')) { if (options.id && options.status) { // 如果 状态为3 请求订单详情 ID为订单id if (options.status === '3') { wx.kx_request({ url: wx.kx_api.hwOrder.getOrderDetail, data: { orderId: options.id }, success: res => { if (res.errcode === 0) { console.log(res.data.hwOrderAPI.serviceStage) this.setData({ ...res.data.hwRequirementAPI, hwOrderAPI: res.data.hwOrderAPI, // btn_message: res.data.hwOrderAPI.status === 2 && res.data.hwOrderAPI.serviceStage ? `第${res.data.hwOrderAPI.serviceStage}期服务中` : this.data.message[res.data.hwOrderAPI.status] }) } } }) } // 如果状态为1 请求需求详情 ID为需求id if (options.status === '1') { wx.kx_request({ url: wx.kx_api.hwRequirement.getRequirementDetail, data: { hwRequirementId: options.id }, success: res => { if (res.errcode === 0) { this.setData({ ...res.data.hwRequirementAPI }) } } }) } } // 保存状态 if (options.status) { this.setData({ status: Number(options.status), show: false }) } } else { wx.redirectTo({ url: `/pages/login/login?path=/pages/detail/detail&&id=${options.id}&&status=${options.status}`, }) } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function() { }, /** * 生命周期函数--监听页面显示 */ onShow: function() { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function() { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function() { }, /** * 用户点击右上角分享 */ onShareAppMessage: function() { return { title: this.data.name, path: `/pages/detail/detail?id=${this.data.id}&&status=${this.data.status}` } } })