const util = require('../../../utils/util.js'); const api = require('../../../config/api.js'); //获取应用实例 const app = getApp(); Page({ data: { consultList: [], questionList: [], imgList: [], remark: '', detail: '', satisfy: '', bookTradeNo: '', type: '', isFinished: false, tradeOrder: { itemName: '', serviceNumber: '', beginDate: '', serviceTime: '', workerName: '' }, code: '', loginShow: false, }, onLoad: function (options) { console.log("options", options); if (options) { this.setData({ bookTradeNo: options.id, // type:options.type }); this.getOrderDetail(); } // 获取题目 // this.getConsoultType(); // let that=this; // wx.login({ // success(res) { // console.log(res); // let params = { // code: res.code, // bookTradeNo:that.data.bookTradeNo // }; // if (res.code) { // that.setData({ // code: res.code // }); // util.request(api.loginCusUnionId, params, 'POST').then(response => { // if (response.errno === 0) { // console.log(response); // if(response.data.tradeOrder==null||response.data.tradeOrder==''){ // wx.showToast({ // title: '您还没有购买过任何商品,如有疑问,欢迎咨询4009218787', // icon: 'none', // duration: 2000 // }); // }else{ // that.setData({ // tradeOrder:response.data.tradeOrder // }); // that.getConsoultType(); // } // } else { // wx.login({ // success(res) { // console.log(res); // if (res.code) { // that.setData({ // code: res.code // }); // } // }}); // that.setData({ // loginShow: true // }); // } // }); // } else { // console.log('登录失败!' + res.errMsg) // } // } // }); }, getOrderDetail(){ util.request(api.getTradeOrderList, { bookDetailId: this.data.bookTradeNo}, 'GET').then(res => { if (res.errno === 0) { console.log(res); this.setData({ tradeOrder:res.data }); // 获取题目 this.getConsoultType(); } else { wx.showToast({ title: res.errmsg, icon: 'none', duration: 2000 }); } }).catch((err)=>{ console.log(err) }); }, getConsoultType() { util.request(api.getConsoultType, { type: this.data.tradeOrder.goodsType }, 'GET').then(res => { if (res.errno === 0) { console.log(res); let list = res.data[0].children; list.forEach(item => { item.checked = false; }); this.setData({ consultList: list }); } else { wx.showToast({ title: res.errmsg, icon: 'none', duration: 2000 }); } }).catch((err)=>{ console.log(err) }); }, questionClick(e) { let checked = e.currentTarget.dataset.checked; let index = e.currentTarget.dataset.index; let item = `consultList[${index}].checked`; this.setData({ [item]: !checked }); let current = this.data.consultList.filter(item => { return item.checked }); this.setData({ questionList: current }); }, selectSatisfy(e) { let result = e.currentTarget.dataset.satisfy; this.setData({ satisfy: result }); }, remarkInput(e) { this.setData({ remark: e.detail.value }); }, detailInput(e) { this.setData({ detail: e.detail.value }); }, previewImg(e) { let img = e.currentTarget.dataset.img; let imgs = this.data.imgList wx.previewImage({ current: img, // 当前显示图片的http链接 urls: imgs // 需要预览的图片http链接列表 }) }, delImg(e) { let imgs = this.data.imgList; let index = e.currentTarget.dataset.index; imgs.splice(index, 1); this.setData({ imgList: imgs }) }, uploadImg() { if (this.data.imgList.length >= 9) { wx.showToast({ title: '最多上传9张图片', icon: 'none', duration: 2000 }); return false; } let that = this; let count = 9 - that.data.imgList.length; wx.chooseImage({ count: count, sizeType: ['original', 'compressed'], sourceType: ['album', 'camera'], success: function (res) { console.log(res); let tempFilePaths = res.tempFilePaths; // for(let i=0;i=9){ // that.setData({ // imgList:imgs // }); // return false; // }else{ // imgs.push(tempFilePaths[i]); // } // } // that.setData({ // imgList:imgs // }); // console.log(that.data.imgList); wx.showLoading({ title: '上传中...', }); for (let i = 0; i < tempFilePaths.length; i++) { let imgs = that.data.imgList; if (imgs.length >= 9) { that.setData({ imgList: imgs }); return false; } else { wx.uploadFile({ url: api.StorageUpload, filePath: tempFilePaths[i], name: 'file', success(res) { console.log(res); let data = JSON.parse(res.data); if (data.errno == 0) { imgs.push(data.data.url); that.setData({ imgList: imgs }); } else { console.log('上传失败') } } }) } } wx.hideLoading(); } }); }, /** * 生命周期函数--监听页面显示 */ onShow: function (options) { // wx.hideHomeButton({ // success(){ // } // }); }, answerClick(e) { let index1 = e.currentTarget.dataset.index1; let answer = e.currentTarget.dataset.answer; let id = e.currentTarget.dataset.id; let obj1 = `questionList[${index1}].consultId`; let obj2 = `questionList[${index1}].consultName`; this.setData({ [obj1]: id, [obj2]: answer }); console.log(this.data.questionList); }, maskClick(e) { let answer = e.currentTarget.dataset.answer; this.setData({ isUnMask: answer }); }, getPhoneNumber(e) { console.log(e.detail); let params = { // type:'保洁', code: this.data.code, encryptedData: e.detail.encryptedData, iv: e.detail.iv, bookTradeNo: this.data.bookTradeNo // loginType: '', // openId: "", // sessionKey: "", // tel: "", // unionId: "", // userPassword: "" }; util.request(api.loginCusTel, params, 'POST').then(res => { if (res.errno === 0) { console.log(res); this.setData({ loginShow: false }); if (res.data.tradeOrder == null || res.data.tradeOrder == '') { wx.showToast({ title: '您还没有购买过任何商品,如有疑问,欢迎咨询4009218787', icon: 'none', duration: 2000 }); } else { this.setData({ tradeOrder: res.data.tradeOrder }); this.getConsoultType(); } } else { this.setData({ loginShow: true }); wx.showToast({ title: res.errmsg, icon: 'none', duration: 2000 }); let that = this; wx.login({ success(res) { console.log(res); if (res.code) { that.setData({ code: res.code }); } } }); } }) }, sumitRevisit() { let params = { bookTime: this.data.tradeOrder.beginDate + ' ' + this.data.tradeOrder.serviceTime, bookTradeNo: this.data.tradeOrder.bookTradeNo, cusTel: this.data.tradeOrder.cusPhone, degree: this.data.satisfy, type: this.data.tradeOrder.goodsType, worderNo: this.data.tradeOrder.workerNo, workerName: this.data.tradeOrder.workerName, } if (this.data.satisfy == 2) { let isEmpty = this.data.questionList.some(item => { return item.consultId == undefined || item.consultId == '' }); if (isEmpty) { wx.showToast({ title: '请填写完整', icon: 'none', duration: 2000 }); return false; } else if (this.data.detail == '') { wx.showToast({ title: '请输入具体问题描述', icon: 'none', duration: 2000 }); return false; } else { let title = []; let titleId = []; let consultId = []; let consultName = []; this.data.questionList.forEach(item => { title.push(item.name); titleId.push(item.id); consultId.push(item.consultId); consultName.push(item.consultName); }); params.title = title.join(','); params.titleId = titleId.join(','); params.consultId = consultId.join(','); params.consultName = consultName.join(','); params.question = this.data.detail; params.imgSrc = this.data.imgList.join(','); } } else if (this.data.satisfy == 3) { if (this.data.remark == '') { wx.showToast({ title: '请填写建议', icon: 'none', duration: 2000 }); return false; } else { params.question = this.data.remark; } } wx.showLoading({ title: '加载中...', }); util.request(api.saveVisit, params, 'POST').then(res => { wx.hideLoading(); if (res.errno === 0) { console.log(res); wx.showToast({ title: '提交成功', icon: 'success', duration: 2000 }); this.setData({ isFinished: true }); } else { wx.showToast({ title: res.errmsg, icon: 'none', duration: 2000 }); } }).catch((err) => { wx.hideLoading(); }); }, goDetail() { wx.navigateTo({ url: '/pages/qwOrderDetail/qwOrderDetail?payId=' + this.data.tradeOrder.payId }); }, onOverlayHide() { }, })