const util = require('../../../utils/util.js'); const api = require('../../../config/api.js'); //获取应用实例 const app = getApp(); Page({ data: { bookServantList:[], consultList: [], questionList: [], imgList: [], remark: '', detail: '', satisfy: '', bookTradeNo: '', type: '', isFinished: false, tradeOrder: { itemName: '', serviceNumber: '', beginDate: '', serviceTime: '', workerName: '' }, code: '', loginShow: false, isCanSumit: false, qrImg:''//加企微二维码 }, onLoad: function (options) { console.log("options", options); if (options) { this.setData({ bookTradeNo: options.id ? options.id : '', // type:options.type }); }     if(options.scene!=undefined && options.scene!=''){ let scene = decodeURIComponent(options.scene); this.setData({ bookTradeNo: scene.split(",")[1], // type:options.type });     } this.getOrderDetail(); }, getOrderDetail() { util.request(api.getTradeOrderList, { bookDetailId: this.data.bookTradeNo }, 'GET').then(res => { if (res.errno === 0) { console.log(res); let svlist=res.data.bookServantList; svlist.forEach(s=>{ s.consultList= []; s.questionList= []; s.imgList= []; s.satisfy= ''; s.detail=''; s.remark=''; }) this.setData({ tradeOrder: res.data, bookServantList:svlist, isCanSumit: true, qrImg:res.data.qrUrl }); // 获取题目 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; }); let dd= this.data.bookServantList; dd.forEach(s=>{ s.consultList=JSON.parse(JSON.stringify(list));; }) 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 bkindex = e.currentTarget.dataset.bkindex; let dd=this.data.bookServantList; dd[bkindex].consultList[index].checked=!checked; let current = dd[bkindex].consultList.filter((item) => { return item.checked; }); dd[bkindex].questionList=current; this.setData({ bookServantList: dd }); // 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; let bkindex=e.currentTarget.dataset.bkindex; let dd=this.data.bookServantList[bkindex]; dd.satisfy=result; this.setData({ // satisfy: result, bookServantList:this.data.bookServantList }); }, remarkInput(e) { console.log(e); let dd=this.data.bookServantList; dd[e.currentTarget.dataset.idx].remark=e.detail.value; this.setData({ bookServantList:dd }); // this.setData({ // remark: e.detail.value // }); }, detailInput(e) { console.log(e); let dd=this.data.bookServantList; dd[e.currentTarget.dataset.idx].detail=e.detail.value; this.setData({ bookServantList:dd }); // this.setData({ // detail: e.detail.value // }); }, previewImg(e) { let img = e.currentTarget.dataset.img; let bkindex = e.currentTarget.dataset.bkindex; wx.previewImage({ current: img, // 当前显示图片的http链接 urls: this.data.bookServantList[bkindex].imgList // 需要预览的图片http链接列表 }) }, delImg(e) { // let imgs = e.currentTarget.dataset.imglist; let index = e.currentTarget.dataset.index; let bkindex=e.currentTarget.dataset.bkindex; let dd=this.data.bookServantList; dd[bkindex].imgList.splice(index, 1); this.setData({ bookServantList: dd }) }, uploadImg(e) { let bkindex=e.currentTarget.dataset.bkindex; let dd=this.data.bookServantList; let imgList= dd[bkindex].imgList; if (imgList >= 9) { wx.showToast({ title: '最多上传9张图片', icon: 'none', duration: 2000 }); return false; } let that = this; let count = 9 - 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 = imgList; if (imgs.length >= 9) { that.setData({ // imgList: imgs bookServantList:dd }); 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 bookServantList:dd }); } else { console.log('上传失败') } } }) } } wx.hideLoading(); } }); }, /** * 生命周期函数--监听页面显示 */ onShow: function (options) { // this.getOrderDetail(); // wx.hideHomeButton({ // success(){ // } // }); }, answerClick(e) { let index1 = e.currentTarget.dataset.index1; let answer = e.currentTarget.dataset.answer; let id = e.currentTarget.dataset.id; let bkindex=e.currentTarget.dataset.bkindex; let dd=this.data.bookServantList; dd[bkindex].questionList[index1].consultId=id; dd[bkindex].questionList[index1].consultName=answer; this.setData({ bookServantList:dd }); // 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 req=[]; let that =this; // this.bookServantList.forEach(sv=>{ for(let k=0;k { return item.consultId == undefined || item.consultId == '' }); if (isEmpty) { wx.showToast({ title: '请填写完整', icon: 'none', duration: 2000 }); return false; } else if (sv.detail == '') { wx.showToast({ title: '请输入具体问题描述', icon: 'none', duration: 2000 }); return false; } else { let title = []; let titleId = []; let consultId = []; let consultName = []; sv.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 = sv.detail; params.imgSrc = sv.imgList.join(','); } } else if (sv.satisfy == 3) { if (sv.remark == '') { wx.showToast({ title: '请填写建议', icon: 'none', duration: 2000 }); return false; } else { params.question = sv.remark; } } req.push(params); } wx.showLoading({ title: '加载中...', }); util.request(api.saveVisitBatch, req, '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() { }, })