// miniprogram/xqaddtrack/xqaddtrack.js const utils = require("../../utils/http"); const util = require("../../utils/util"); const app = getApp(); Component({ /** * 组件的属性列表 */ properties: { trackflag: { type: Boolean, value: false }, nowcid: { type: String, value: '' }, addwxarr: Array, columns: Array, activitylist: Array, wactivitylist: Array, wcolumns: Array, nextvisitflag: { type: Boolean, value: false//true是必填,false不必传 下次回访时间 }, amountarr: Array, activityobj: Object }, /** * 组件的初始数据 */ data: { imgUrl: app.globalData.imgUrl, clientype: app.globalData.clientype, aid: '', aType: "2", storeIndex: null, activityobj: {}, titype: 1, trackflag: false, showWPicker: false, subscribeAbled: false, tracktype: '1', clueType: "1", trackimgarr: [], nowimagearr: [], visitField: [], nowcid: '', recordtext: '', visitcount: 0, firstmoney: '', staylength: '', visitlogarr: [], statype: '1', activityname: '', invitecrm: [], showUpcrm: [], datashow: true, showSelect: true, start: "", end: '', nowaid: '', personobj: app.globalData.personMsg, typeflag: false, type: 1, tacktype: 3, tackarr: [], subscribeTitle: "提交预约", nowtext1: '自定义', tacktext: '', amountdate: '', nowtext: false, amountime: 1, amountime1: 1, visitdate: '', apointobj: {}, customerobj: {}, changeModuleObj: {}, subscribeObj: {}, moduleSwitchObj: {}, nowidx: 0, scoleval: 0, orderTime: '', nowdate: '', cluestate: 1, activityType: '', nextdate: "1", addwxarr: [], addwxtypeflag: false, measurenum: '', measuretime: '', showPicker: false, storenum: 1, loglist: [], orderactivitydate: '', activityvalue: '', subscribelist: [], amountext: [], storeArr: [], amountshow: false, trackimgarr1: [], nowimagearr1: [], depositproductlist: [], depositproductnum: '', deposit_mode: '1', appointype: '',//1是预约活动,2是预约到店 storeactivityvalue: '', storeactivityid: '', reachstoretime: "", subType: "1", signOrderTagText: "转单", deliveryTagText: "签单", contractTagText: "合同", extarr: [ { keyname: '', value: '', keytext: '', select: '', id: '' } ], }, /** * 组件的方法列表 */ methods: { getChangeModule() { if (this.data.clientype == 'vL0CQQ') { this.setData({ signOrderTagText: "签单", deliveryTagText: "交定", contractTagText: "签单" }) } const that = this; utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/changeModule', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: this.data.nowcid }, success: function (res) { if (res.data.code == 0) { that.setData({ changeModuleObj: res.data.data }) } } }) }, getSubscribeModule() { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/subscribeModule', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: this.data.nowcid }, success: function (res) { if (res.data.code == 0) { that.setData({ subscribeObj: res.data.data }) } } }) }, getModuleSwitch() { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/moduleSwitch', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: {}, success: function (res) { if (res.data.code == 0) { that.setData({ moduleSwitchObj: res.data.data }) } } }) }, getClueTag() { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/clueTag', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: {}, success: function (res) { if (res.data.code == 0) { let clueTagArr = res.data.data; clueTagArr.unshift('自定义'); clueTagArr = clueTagArr.map((v,i) => { return {id: i+1, text: v}; }) that.setData({ tackarr: clueTagArr }) } } }) }, getVisitField() { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/visitField', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: this.data.nowcid }, success: function (res) { if (res.data.code == 0) { that.setData({ visitField: res.data.data }) that.selectComponent('#customfield').getField(); } } }) }, getShoplistApi() { if (this.data.storeArr.length) { return; } const that = this; utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/shop_list', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: {}, success: function (res) { if (res.data.code == 0) { that.setData({ storeArr: res.data.data }) } } }) }, setcrmfun(cid) { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/get_portrait_field', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: this.data.nowcid }, success: function (res) { if (res.data.code == 0) { let extarr = []; for (let i in res.data.data) { for (let j in res.data.data[i].child) { if (res.data.data[i].child[j].keyname == 'add_wechat_type') { let obj = { keyname: res.data.data[i].child[j].keyname, value: res.data.data[i].child[j].value ? res.data.data[i].child[j].value : '', keytext: res.data.data[i].child[j].valname, select: res.data.data[i].child[j].select, id: res.data.data[i].child[j].id }; extarr[0] = obj; } } } that.setData({ extarr: extarr }) } } }) }, amounthouseimgtap() { if (this.data.amountarr.length == 1) { this.uploadimg(); } else { this.setData({ amountshow: true, }) } }, onClose() { this.setData({ amountshow: false }) }, onSelect(event) { let amountext = this.data.amountext; amountext.push(event.detail.name.slice(2, event.detail.name.length)); this.setData({ amountext: amountext, amountshow: false, }) this.uploadimg(); }, prelooktap(e) { wx.previewImage({ current: this.data.loglist[e.currentTarget.dataset.src].img[e.currentTarget.dataset.idx], // 当前显示图片的http链接 urls: this.data.loglist[e.currentTarget.dataset.src].img, // 需要预览的图片http链接列表 fail(res) { console.log(res) } }) }, previewImg(e) { wx.previewImage({ current: this.data.visitlogarr[e.currentTarget.dataset.src].img[e.currentTarget.dataset.idx], // 当前显示图片的http链接 urls: this.data.visitlogarr[e.currentTarget.dataset.src].img, // 需要预览的图片http链接列表 fail(res) { console.log(res) } }) }, preview1Img(e) { wx.previewImage({ current: this.data.visitlogarr[e.currentTarget.dataset.src].img1[e.currentTarget.dataset.idx], // 当前显示图片的http链接 urls: this.data.visitlogarr[e.currentTarget.dataset.src].img1, // 需要预览的图片http链接列表 fail(res) { console.log(res) } }) }, preview2Img(e) { wx.previewImage({ current: this.data.visitlogarr[e.currentTarget.dataset.src].delivery_img[e.currentTarget.dataset.idx], // 当前显示图片的http链接 urls: this.data.visitlogarr[e.currentTarget.dataset.src].delivery_img, // 需要预览的图片http链接列表 fail(res) { console.log(res) } }) }, preview3Img(e) { wx.previewImage({ current: this.data.visitlogarr[e.currentTarget.dataset.src].sign_img[e.currentTarget.dataset.idx], // 当前显示图片的http链接 urls: this.data.visitlogarr[e.currentTarget.dataset.src].sign_img, // 需要预览的图片http链接列表 fail(res) { console.log(res) } }) }, preview4Img(e){ wx.previewImage({ current: this.data.visitlogarr[e.currentTarget.dataset.src].portraitarr[e.currentTarget.dataset.field].valname[e.currentTarget.dataset.idx], // 当前显示图片的http链接 urls: this.data.visitlogarr[e.currentTarget.dataset.src].portraitarr[e.currentTarget.dataset.field].valname, // 需要预览的图片http链接列表 fail(res) { console.log(res) } }) }, cancleappointap(e) { let that = this; let obj = this.data.subscribelist[e.currentTarget.dataset.idx]; if (obj.order_type > 0) { if (obj.type == "预约量房") { wx.showLoading() this.addrecord(4, obj.subscribe_date); } if (obj.type == "预约到店") { wx.showLoading() this.addrecord(5, obj.subscribe_date); } if (obj.type == "预约活动") { wx.showLoading() this.addrecord(6, obj.subscribe_date); } } }, crmsgfun() { let date = new Date(); let m = date.getMonth() * 1 + 1; let d = date.getDate(); let str = date.getFullYear() + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? ('0' + d) : d); this.setData({ amountdate: str, start: str, nowdate: str, visitdate: str }) this.crmmsgfun(); this.tracklog(); }, dothis() { }, bindPickerChange: function(e) { this.setData({ storeIndex: e.detail.value }) }, closetracktap: function () { this.setData({ trackflag: false }) }, setstorenumtap(e) { this.setData({ storenum: e.detail.value }) }, setorderTimenumtap() { this.setData({ orderTime: e.detail.value }) }, getOrderTimeInput(e) { this.setData({ orderTime: e.detail.value }) }, setstaylengthnumtap() { this.setData({ staylength: e.detail.value }) }, jdHandleClick(e) { this.setData({ deposit_mode: e.currentTarget.dataset.text }) }, amountimetap1(e) { let num = e.currentTarget.dataset.text; let date = new Date(); let nowTime = date.getTime(); let oneDayTime = 24 * 60 * 60 * 1000; var day = date.getDay(); //显示周日 var sun = nowTime - (day - 7) * oneDayTime; //显示周六 var wen = nowTime - (day - 6) * oneDayTime; let str = num == 1 ? 0 : num == 2 ? 1 : ''; let timenum = num == 3 ? wen : num == 4 ? sun : nowTime + str * oneDayTime; let year = new Date(timenum).getFullYear(); let month = new Date(timenum).getMonth(); let daystr = new Date(timenum).getDate(); this.setData({ amountime1: num, visitdate: year + '-' + (month * 1 + 1) + '-' + daystr }) if (this.data.tacktype == 3) { this.setData({ amountime1: num }) if (num == 5) { return false; } this.setData({ visitdate: year + '-' + (month * 1 + 1) + '-' + daystr }) } else if (this.data.tacktype == 4) { this.setData({ amountime1: num }) if (num == 5) { return false; } this.setData({ visitdate: year + '-' + (month * 1 + 1) + '-' + daystr }) } else if (this.data.tacktype == 5) { this.setData({ amountime1: num }) if (num == 5) { return false; } this.setData({ visitdate: year + '-' + (month * 1 + 1) + '-' + daystr }) } }, setSubscriteDate(e) { let num = e.detail; let date = new Date(); let nowTime = date.getTime(); let oneDayTime = 24 * 60 * 60 * 1000; var day = date.getDay(); //显示周日 var sun = nowTime - (day - 7) * oneDayTime; //显示周六 var wen = nowTime - (day - 6) * oneDayTime; let str = num == 1 ? 0 : num == 2 ? 1 : ''; let timenum = num == 3 ? wen : num == 4 ? sun : nowTime + str * oneDayTime; let year = new Date(timenum).getFullYear(); let month = new Date(timenum).getMonth(); let daystr = new Date(timenum).getDate(); this.setData({ nextdate: num, reachstoretime: year + '-' + (month * 1 + 1) + '-' + daystr }) if (this.data.tacktype == 3) { this.setData({ nextdate: num }) if (num == 5) { return false; } this.setData({ reachstoretime: year + '-' + (month * 1 + 1) + '-' + daystr }) } else if (this.data.tacktype == 4) { this.setData({ nextdate: num }) if (num == 5) { return false; } this.setData({ reachstoretime: year + '-' + (month * 1 + 1) + '-' + daystr }) } else if (this.data.tacktype == 5) { this.setData({ nextdate: num }) if (num == 5) { return false; } this.setData({ reachstoretime: year + '-' + (month * 1 + 1) + '-' + daystr }) } }, setlfyyDate(e) { let num = e.detail; let date = new Date(); let nowTime = date.getTime(); let oneDayTime = 24 * 60 * 60 * 1000; var day = date.getDay(); //显示周日 var sun = nowTime - (day - 7) * oneDayTime; //显示周六 var wen = nowTime - (day - 6) * oneDayTime; let str = num == 1 ? 0 : num == 2 ? 1 : ''; let timenum = num == 3 ? wen : num == 4 ? sun : nowTime + str * oneDayTime; let year = new Date(timenum).getFullYear(); let month = new Date(timenum).getMonth(); let daystr = new Date(timenum).getDate(); this.setData({ nextdate: num, measuretime: year + '-' + (month * 1 + 1) + '-' + daystr }) if (this.data.tacktype == 3) { this.setData({ nextdate: num }) if (num == 5) { return false; } this.setData({ measuretime: year + '-' + (month * 1 + 1) + '-' + daystr }) } else if (this.data.tacktype == 4) { this.setData({ nextdate: num }) if (num == 5) { return false; } this.setData({ measuretime: year + '-' + (month * 1 + 1) + '-' + daystr }) } else if (this.data.tacktype == 5) { this.setData({ nextdate: num }) if (num == 5) { return false; } this.setData({ measuretime: year + '-' + (month * 1 + 1) + '-' + daystr }) } }, uptracklogtap: function () { const that = this; wx.chooseMedia({ count: 9, mediaType: ['image'], sizeType: ['compressed'], sourceType: ['album', 'camera'], success(res) { // tempFilePath可以作为img标签的src属性显示图片 if (res.errMsg == "chooseMedia:ok") { that.createImagePayment1(res.tempFiles); } }, fail(res) { wx.showToast({ title: '上传失败请重试!', icon: 'error', duration: 2000 }) } }) }, createImagePayment1: function (imgUrl) { var that = this; if (imgUrl.length == 0) return; var lent = that.data.trackimgarr1.length + imgUrl.length; if (lent > 9) { lent = 9 } else { lent = lent; } let trackimgarr1 = that.data.trackimgarr1; let len = imgUrl.length; if ((trackimgarr1.length + len) > 9) { for (let j = 0; j < len; j++) { if (trackimgarr1.length < 9) { trackimgarr1.push(imgUrl[j]); } } } else { trackimgarr1 = trackimgarr1.concat(imgUrl); } that.setData({ trackimgarr1: trackimgarr1 }) }, uploadimg: function () { const that = this; wx.chooseMedia({ count: 9, mediaType: ['image'], sizeType: ['compressed'], sourceType: ['album', 'camera'], success(res) { // tempFilePath可以作为img标签的src属性显示图片 res.tempFilePaths // console.log(res) // var trackimgarr=that.data.trackimgarr; if (res.errMsg == "chooseMedia:ok") { // let len=res.tempFilePaths.length; that.createImagePayment(res.tempFiles); // if((trackimgarr.length+len)>9){ // for(let j=0;j 9) { lent = 9 } else { lent = lent; } let trackimgarr = that.data.trackimgarr; let len = imgUrl.length; if ((trackimgarr.length + len) > 9) { for (let j = 0; j < len; j++) { if (trackimgarr.length < 9) { trackimgarr.push(imgUrl[j]); } } } else { trackimgarr = trackimgarr.concat(imgUrl); } that.setData({ trackimgarr: trackimgarr }) }, delimgtap: function (e) { const that = this; wx.showModal({ title: '确认删除', content: '是否删除这张图片?', success(res) { if (res.confirm) { let trackimgarr = that.data.trackimgarr, amountext = that.data.amountext; trackimgarr.splice(e.currentTarget.dataset.idx, 1) amountext.splice(e.currentTarget.dataset.idx, 1) that.setData({ trackimgarr: trackimgarr, amountext: amountext }) } } }) }, deltracktap: function (e) { const that = this; wx.showModal({ title: '确认删除', content: '是否删除这张图片?', success(res) { if (res.confirm) { let trackimgarr1 = that.data.trackimgarr1; trackimgarr1.splice(e.currentTarget.dataset.idx, 1) that.setData({ trackimgarr1: trackimgarr1 }) } } }) }, ossuploadimg: function (e) { let that = this; let trackimgarr = that.data.trackimgarr; var arr = []; for (let i = 0; i < trackimgarr.length; i++) { //获取文件后缀 // 随机生成文件名称 let rstr = trackimgarr[i].tempFilePath.split('.'); var fileRandName = Date.now() + "" + parseInt(Math.random() * 10000) + i; var imgName = fileRandName + '.' + 'png'; // var fileName = that.data.; var date = new Date(); var time = date.getFullYear() + '' + (date.getMonth() * 1 + 1) + '' + date.getDate(); var imgstr = 'crm/' + time + '/' + imgName; var nowimagearr = that.data.nowimagearr; nowimagearr.push(imgstr); that.setData({ nowimagearr: nowimagearr }) wx.uploadFile({ url: 'https://o.nczyzs.com', filePath: trackimgarr[i].tempFilePath, name: 'file', formData: { // name: that.data.imgSrc[0], key: 'crm/' + time + '/' + imgName, policy: "eyJleHBpcmF0aW9uIjoiMjAyNS0wMS0wMVQxMjowMDowMC4wMDBaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF1dfQ==", OSSaccessKeyId: "LTAI5tHjWupJSCAycy2yVbQZ", success_action_status: "200", signature: "bWaeUQYnGAcWynj3FxAfGZLy5n0=", }, header: { "Content-Type": "multipart/form-data", 'accept': 'application/json', }, success: function (rs) { if (rs.errMsg == 'uploadFile:ok') { arr.push('0'); if (arr.length == trackimgarr.length) { that.addrecord(); } } }, fail(res) { wx.hideLoading() } }) } }, setmoney: function (e) { this.setData({ money: e.detail.value }) }, setfirstmoney(e) { this.setData({ firstmoney: e.detail.value }) }, setwxtypetap(e) { let text = '', extarr = this.data.extarr; for (let i in this.data.extarr[0].select) { if (this.data.extarr[0].select[i].id == e.currentTarget.dataset.text) { text = this.data.extarr[0].select[i].name; } } if (extarr[0].keytext != text) { extarr[0].keytext = text; extarr[0].value = e.currentTarget.dataset.text; } else { extarr[0].keytext = text; extarr[0].value = e.currentTarget.dataset.text; } this.setData({ extarr: extarr, addwxtypeflag: false }) this.editwxtap(); }, setoptap() { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/crmCustomer/customer_top', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { type: 2, id: that.data.nowcid, }, success: function (res) { if (res.data.code == '0') { let customerobj = that.data.customerobj; if (customerobj.addtoptime) { customerobj.addtoptime = ''; } else { customerobj.addtoptime = '2022'; } that.setData({ customerobj: customerobj }) that.triggerEvent('myevent', that.data.customerobj) } } }) }, addwxtap() { let extarr = this.data.extarr; if (this.data.extarr[0].select.length == 2) { this.setData({ addwxtypeflag: true }) } else { extarr[0].keytext = this.data.extarr[0].select[0].name; extarr[0].value = this.data.extarr[0].select[0].id; this.setData({ addwxtypeflag: false, extarr: extarr }) this.editwxtap(); } }, inputap() { this.setData({ nowtext: !this.data.nowtext }) }, onChange(event) { this.setData({ scoleval: event.detail, }); }, measurehousetap(e) { let num = e.currentTarget.dataset.type; // 量房预约 let date = new Date(); let nowTime = date.getTime(); let oneDayTime = 24 * 60 * 60 * 1000; var day = date.getDay(); //显示周日 var sun = nowTime - (day - 7) * oneDayTime; //显示周六 var wen = nowTime - (day - 6) * oneDayTime; let str = num == 1 ? 0 : num == 2 ? 1 : ""; let timenum = num == 3 ? wen : num == 4 ? sun : nowTime + str * oneDayTime; let year = new Date(timenum).getFullYear(); let month = new Date(timenum).getMonth(); let daystr = new Date(timenum).getDate(); this.setData({ measurenum: num }) if (num == 5) { return false; } this.setData({ measuretime: year + "-" + (month * 1 + 1) + "-" + daystr }) if (!!this.data.reachstorenum) { let num = util.dayDiff( new Date(this.data.reachstoretime.split("-").join("/")), new Date(this.data.measuretime.split("-").join("/")) ); if (num == 0) { this.setData({ measuretime: '', measurenum: this.data.measurenum != 5 ? "" : this.data.measurenum }) wx.showToast({ title: '同一时间只能预约一个提醒,请重新预约!', icon: 'none', duration: 2000 }) return false; } } if (!!this.data.activityvalue) { let num = util.dayDiff( new Date(this.data.measuretime.split("-").join("/")), new Date(this.data.orderactivitydate.split("-").join("/")) ); if (num == 0) { this.setData({ measuretime: '', measurenum: this.data.measurenum != 5 ? "" : this.data.measurenum }) wx.showToast({ title: '同一时间只能预约一个提醒,请重新预约!', icon: 'none', duration: 2000 }) } } }, // 到店 reachstoretap(e) { let num = e.currentTarget.dataset.type; let date = new Date(); let nowTime = date.getTime(); let oneDayTime = 24 * 60 * 60 * 1000; var day = date.getDay(); //显示周日 var sun = nowTime - (day - 7) * oneDayTime; //显示周六 var wen = nowTime - (day - 6) * oneDayTime; let str = num == 1 ? 0 : num == 2 ? 1 : ""; let timenum = num == 3 ? wen : num == 4 ? sun : nowTime + str * oneDayTime; let year = new Date(timenum).getFullYear(); let month = new Date(timenum).getMonth(); let daystr = new Date(timenum).getDate(); this.setData({ reachstorenum: num }) if (num == 5) { return false; } this.setData({ reachstoretime: year + "-" + (month * 1 + 1) + "-" + daystr }) if (!!this.data.measurenum) { let num = util.dayDiff( new Date(this.data.reachstoretime.split("-").join("/")), new Date(this.data.measuretime.split("-").join("/")) ); if (num == 0) { this.setData({ reachstoretime: "", reachstorenum: this.reachstorenum != 5 ? "" : this.reachstorenum }) wx.showToast({ title: '同一时间只能预约一个提醒,请重新预约!', icon: 'none', duration: 2000 }) return false; } } if (!!this.data.activityvalue) { let num = util.dayDiff( new Date(this.data.reachstoretime.split("-").join("/")), new Date(this.data.orderactivitydate.split("-").join("/")) ); if (num == 0) { this.setData({ reachstoretime: "", reachstorenum: this.reachstorenum != 5 ? "" : this.reachstorenum }) wx.showToast({ title: '同一时间只能预约一个提醒,请重新预约!', icon: 'none', duration: 2000 }) } } }, setitypetap(e) { this.setData({ titype: e.currentTarget.dataset.text, }) if (e.currentTarget.dataset.text == 2) { let curIndex = ""; let amountext = this.data.amountext; amountext = []; if (this.data.amountarr.length == 1) { amountext[0] = this.data.amountarr[0].name.slice(2, this.data.amountarr[0].name.length) } if (this.data.changeModuleObj.lf.show == 1) { curIndex = "3"; } else if (this.data.changeModuleObj.dd.show == 1) { curIndex = "4"; } else if (this.data.changeModuleObj.hd.show == 1) { curIndex = "5"; } else if (this.data.changeModuleObj.jd.show == 1) { curIndex = "6"; } else if (this.data.changeModuleObj.zd.show == 1) { curIndex = "7"; } else { curIndex = "8"; } this.setData({ tacktype: curIndex, amountext: amountext, trackimgarr: [], trackimgarr1: [], nowimagearr1: [], }) this.visitlogfun('量房'); this.packagefun(); setTimeout(() => { this.selectComponent('#customfield').getField(); },300) } else if (e.currentTarget.dataset.text == 3) { this.subscribefun(); if (this.data.subscribeObj.hd.show == 1) { if (!this.data.wactivitylist.length) { this.setData({ subType: 1, subscribeAbled: true, subscribeTitle: "~暂无外场活动-无法预约~" }) } else { this.setData({ subType: 1, subscribeAbled: false, subscribeTitle: "提交预约" }) } } else if (this.data.subscribeObj.dd.show == 1) { this.setData({ subType: 2, subscribeAbled: false, subscribeTitle: "提交预约" }) } else if (this.data.subscribeObj.lf.show == 1) { this.setData({ subType: 3, subscribeAbled: false, subscribeTitle: "提交预约" }) } setTimeout(() => { this.selectComponent('#customfield').getField(); },300) } else { setTimeout(() => { this.selectComponent('#customfield').getField(); },300) this.setData({ trackimgarr1: [], nowimagearr1: [], }) this.tracklog(); } this.depositinitfun(); }, packagefun() { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/customerPackage/list', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: {}, success: function (res) { if (res.data.code == "0") { that.setData({ depositproductlist: res.data.data }) if (!!that.data.customerobj.package_id) { for (let i in that.data.depositproductlist) { if (that.data.depositproductlist[i].id == that.data.customerobj.package_id) { that.setData({ depositproductnum: i }) } } } else { that.setData({ depositproductnum: '', }) } } } }) }, bindsigndate: function (e) { this.setData({ addtime: e.detail.value }) }, bindproductap(e) { this.setData({ depositproductnum: e.detail.value }) }, settacktap(e) { this.setData({ tacktype: e.currentTarget.dataset.text, trackimgarr: [], nowimagearr: [], trackimgarr1: [], nowimagearr1: [], tacktext: '', nowtext1: '自定义', amountdate: this.data.nowdate }) let customerobj = this.data.customerobj; if (e.currentTarget.dataset.text == 3) { let amountext = this.data.amountext; amountext = []; if (this.data.amountarr.length == 1) { amountext[0] = this.data.amountarr[0].name.slice(2, this.data.amountarr[0].name.length) } this.setData({ amountext: amountext }) this.visitlogfun('量房'); } else if (e.currentTarget.dataset.text == 4) { this.visitlogfun('到店'); this.getShoplistApi(); if (this.data.changeModuleObj.ddhd.show == 1) { this.setData({ activityname: this.data.activityobj.title, nowaid: this.data.activityobj.id }) } } else if (e.currentTarget.dataset.text == 5) { this.visitlogfun('到场'); let arr = customerobj.subscirbe; this.setData({ activityname: this.data.activityobj.title, nowaid: this.data.activityobj.id }) } else if (e.currentTarget.dataset.text == 6) { this.depositinitfun(); } else if (e.currentTarget.dataset.text == 7) { this.setData({ firstmoney: this.data.customerobj.down_payment }) this.signinitfun(); } setTimeout(() => { this.selectComponent('#customfield').getField(); },300) }, setsubtypetap(e) { let year = new Date().getFullYear(); let month = new Date().getMonth(); let daystr = new Date().getDate(); if (!this.data.wactivitylist.length && e.currentTarget.dataset.text == 1) { this.setData({ reachstoretime: year + '-' + (month * 1 + 1) + '-' + daystr, measuretime: year + '-' + (month * 1 + 1) + '-' + daystr, subType: e.currentTarget.dataset.text, subscribeAbled: true, subscribeTitle: "~暂无外场活动-无法预约~" }) } else { this.setData({ reachstoretime: year + '-' + (month * 1 + 1) + '-' + daystr, measuretime: year + '-' + (month * 1 + 1) + '-' + daystr, subType: e.currentTarget.dataset.text, subscribeAbled: false, subscribeTitle: "提交预约" }) } setTimeout(() => { this.selectComponent('#customfield').getField(); },300) }, setextap(e) { this.setData({ nowtext1: e.currentTarget.dataset.text, tacktext: e.currentTarget.dataset.text == '自定义' ? '' : e.currentTarget.dataset.text }) }, setcluestatetap(e) { const that = this; if (e.currentTarget.dataset.text == 1) { if (this.data.customerobj.state == "待确认" || !this.data.customerobj.state) { this.setData({ cluestate: e.currentTarget.dataset.text, }) } } else { this.setData({ cluestate: e.currentTarget.dataset.text, }) } }, setcluetypetap(e) { this.setData({ clueType: e.currentTarget.dataset.text }) }, amountypetap(e) { if (e.currentTarget.dataset.text == '2' && this.data.tacktype == 5 && this.data.activitylist.length == 0) { wx.showToast({ title: '公司暂无活动不能预约活动', icon: 'none', duration: 2000 }) return false; } const that = this; let day = new Date(); let month = day.getMonth() * 1 + 1; let date = day.getDate(); let year = day.getFullYear(); let str = year + '-' + month + '-' + date; if (e.currentTarget.dataset.text == '2' && this.data.tacktype == 5) { this.setData({ amountdate: this.data.activitylist[0].start_date, nowaid: this.data.activitylist[0].id, start: this.data.activitylist[0].start_date, end: this.data.activitylist[0].end_date, activityname: this.data.activitylist[0].title, }) } else { this.setData({ amountdate: str, amountime: 1 }) } }, bindwChange: function (e) { this.setData({ amountdate: e.detail.value }) }, bindvisitChange: function (e) { this.setData({ visitdate: e.detail.value }) }, setactivitytap() { if (this.data.activityobj.cate == 1) { this.setData({ showWPicker: true, nowaid: '', appointype: 1 }) } else { this.setData({ showPicker: true, nowaid: '', appointype: 1 }) } }, setactivitytap1() { this.setData({ showPicker: true, nowaid: '', appointype: 2 }) }, setactivitytap2() { if (this.data.aType == 1) { this.setData({ showPicker: true, nowaid: '', appointype: 1 }) } else { this.setData({ showWPicker: true, nowaid: '', appointype: 1 }) } }, onCancel() { this.setData({ showPicker: false, showWPicker: false, showSelect: true, }) }, showDesignerDialog() { this.setData({ showSelect: false, }) }, submitDesigner(e) { let itemArr = e.detail; const that = this; utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/reserveDesigner', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: this.data.nowcid, designerId: itemArr.map(v => v.id).join(',') }, success: function (res) { if (res.data.code == 0) { wx.showToast({ title: '指派成功', icon: "success", duration: 1500, success: function() { setTimeout(() => { that.setData({ showSelect: true }) },1500) that.crmmsgfun(); } }) } } }) }, // 量房预约 clearmeasuretap() { this.setData({ measurenum: '', measuretime: '' }) }, showmeasuretap() { this.setData({ ordertimeshow: true, ordertype: 1 }) }, bindlfDate(e) { this.setData({ measuretime: e.detail.value }) }, cleareachstoretap() { this.setData({ reachstorenum: '', reachstoretime: '' }) }, showreachstoretap() { this.setData({ ordertimeshow: true, ordertype: 2 }) }, bindactivityChange: function (e) { if (this.data.titype == 2) { this.setData({ showPicker: false, start: this.data.activitylist[e.detail.index].start_date, end: this.data.activitylist[e.detail.index].end_date, activityname: e.detail.value, nowaid: this.data.activitylist[e.detail.index].id }) } else if (this.data.titype == 3) { this.setData({ showPicker: false, start: this.data.activitylist[e.detail.index].start_date, end: this.data.activitylist[e.detail.index].end_date, activityvalue: this.data.appointype == 1 ? e.detail.value : this.data.activityvalue, nowaid: this.data.activitylist[e.detail.index].id, storeactivityvalue: this.data.appointype == 2 ? e.detail.value : this.data.storeactivityvalue, storeactivityid: this.data.appointype == 2 ? this.data.activitylist[e.detail.index].id : this.data.storeactivityid, }) } }, onRadioChange(e) { this.setData({ aType: e.detail, activityvalue: "", nowaid: "" }) }, bindWactivityChange(e) { if (this.data.titype == 2) { this.setData({ showWPicker: false, start: this.data.activitylist[e.detail.index].start_date, end: this.data.activitylist[e.detail.index].end_date, activityname: e.detail.value, nowaid: this.data.activitylist[e.detail.index].id }) } else if (this.data.titype == 3) { this.setData({ showWPicker: false, start: this.data.activitylist[e.detail.index].start_date, end: this.data.activitylist[e.detail.index].end_date, activityvalue: this.data.appointype == 1 ? e.detail.value : this.data.activityvalue, nowaid: this.data.activitylist[e.detail.index].id, storeactivityvalue: this.data.appointype == 2 ? e.detail.value : this.data.storeactivityvalue, storeactivityid: this.data.appointype == 2 ? this.data.activitylist[e.detail.index].id : this.data.storeactivityid, }) } }, bindstoretap: function (e) { this.setData({ reachstoretime: e.detail.value, reachstorenum: 3 }) if (!!this.data.measurenum) { let num = util.dayDiff( new Date(this.data.reachstoretime.split("-").join("/")), new Date(this.data.measuretime.split("-").join("/")) ); if (num == 0) { this.setData({ reachstoretime: "", reachstorenum: this.reachstorenum != 5 ? "" : this.reachstorenum }) wx.showToast({ title: '同一时间只能预约一个提醒,请重新预约!', icon: 'none', duration: 2000 }) return false; } } if (!!this.data.activityvalue) { let num = util.dayDiff( new Date(this.data.reachstoretime.split("-").join("/")), new Date(this.data.orderactivitydate.split("-").join("/")) ); if (num == 0) { this.setData({ reachstoretime: "", reachstorenum: this.reachstorenum != 5 ? "" : this.reachstorenum }) wx.showToast({ title: '同一时间只能预约一个提醒,请重新预约!', icon: 'none', duration: 2000 }) } } }, bindactivitytap: function (e) { this.setData({ orderactivitydate: e.detail.value }) if (!!this.data.measurenum) { let num = util.dayDiff( new Date(this.data.orderactivitydate.split("-").join("/")), new Date(this.data.measuretime.split("-").join("/")) ); if (num == 0) { this.setData({ orderactivitydate: '' }) wx.showToast({ title: '同一时间只能预约一个提醒,请重新预约!', icon: 'none', duration: 2000 }) return false; } } if (!!this.data.reachstorenum) { let num = util.dayDiff( new Date(this.data.reachstoretime.split("-").join("/")), new Date(this.data.orderactivitydate.split("-").join("/")) ); if (num == 0) { this.setData({ orderactivitydate: '' }) wx.showToast({ title: '同一时间只能预约一个提醒,请重新预约!', icon: 'none', duration: 2000 }) } } }, depositinitfun() { let date = new Date(); let year = date.getFullYear(); let month = date.getMonth(); month = month * 1 + 1; let day = date.getDate(); let str = year + "-" + month + "-" + day; if (!!this.data.customerobj.deposit) { this.setData({ money: this.data.customerobj.deposit_money1 ? this.data.customerobj.deposit_money1 : '', addtime: this.data.customerobj.deposit ? this.data.customerobj.deposit.split(' ')[0] : '' }) } else { this.setData({ addtime: str, money: '' }) } }, signinitfun() { let date = new Date(); let year = date.getFullYear(); let month = date.getMonth(); month = month * 1 + 1; let day = date.getDate(); let str = year + "-" + month + "-" + day; if (!!this.data.customerobj.sign) { this.setData({ money: this.data.customerobj.money ? this.data.customerobj.money : '', addtime: this.data.customerobj.sign ? this.data.customerobj.sign.split(' ')[0] : '' }) } else { this.setData({ addtime: str, money: '' }) } }, typeinitfun() { const that = this; let day = new Date(); let month = day.getMonth() * 1 + 1; let date = day.getDate(); let year = day.getFullYear(); let str = year + '-' + month + '-' + date; this.setData({ visitdate: str, amountdate: str, nowtext1: '自定义', tacktext: '' }) }, closeaddwxtap() { this.setData({ addwxtypeflag: false }) }, crmmsgfun() { const that = this; if (!this.data.nextvisitflag) { this.setData({ visitdate: '', amountime1: '' }) } else { let date = new Date(); let m = date.getMonth() * 1 + 1; let d = date.getDate(); let str = date.getFullYear() + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? ('0' + d) : d); this.setData({ visitdate: str, amountime1: 1 }) } this.getChangeModule(); this.getSubscribeModule(); this.getModuleSwitch(); this.getClueTag(); this.getVisitField(); utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/detail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: this.data.nowcid }, success: function (res) { if (res.data.code == "0") { let apointobj = that.data.apointobj; that.setData({ customerobj: res.data.data }) let arr = res.data.data.subscirbe; apointobj = {}; for (let i in arr) { if (arr[i].type == '预约活动') { that.setData({ activityname: arr[i].activity.title, nowaid: arr[i].aid }) } apointobj[arr[i].type] = arr[i].subscribe_date; } that.setData({ apointobj: apointobj, cluestate: that.data.customerobj.state == "待确认" ? 1 : 2 }) } } }) }, editwxtap() { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/add_customer_extfield', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.nowcid, alertshow: '1', ext: [ { id: this.data.extarr[0].id, keyname: this.data.extarr[0].keyname, value: this.data.extarr[0].value } ] }, success: function (res) { if (res.data.code == "0") { } } }) }, tracklog: function (e) { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/visitlog', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.nowcid }, success: function (res) { setTimeout(() => { wx.hideLoading() }, 1000) if (res.data.code == "0") { let t = 0; var str = "red"; for (let i = 0; i < res.data.data.length; i++) { res.data.data[i].portraitarr=JSON.parse(res.data.data[i].save_portrait_field); res.data.data[i].colortime = res.data.data[i].addtime.split(' ')[0]; if (i == 0) { res.data.data[0].color = str; t = t * 1 + 1; } else if (res.data.data[i].addtime.split(' ')[0] != res.data.data[i - 1].addtime.split(' ')[0]) { t = t * 1 + 1; if (t % 3 == 0) { str = 'red'; } else if (t % 3 == 1) { str = 'blue'; } else if (t % 3 == 2) { str = 'cyan'; } res.data.data[i].color = str; } else { res.data.data[i].color = str; } if(res.data.data[i].portraitarr){ for(let j=0;j { wx.hideLoading() }, 1000) if (res.data.code == "0") { for (let i = 0; i < res.data.data.length; i++) { res.data.data[i].colortime = res.data.data[i].addtime.split(' ')[0]; } that.setData({ loglist: res.data.data }) } } }) }, subscribefun() { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/crmCustomer/subscribe', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.nowcid, }, success: function (res) { setTimeout(() => { wx.hideLoading() }, 1000) if (res.data.code == "0") { let date = new Date(); let year = date.getFullYear(); let month = date.getMonth(); month = month * 1 + 1; let day = date.getDate(); let date1 = year + "/" + month + "/" + day; for (let i = 0; i < res.data.data.length; i++) { let num = util.dayDiff( new Date(res.data.data[i].subscribe_date.split('-').join('/')), new Date(date1) ); res.data.data[i].order_type = num >= 0 ? 1 : 0; res.data.data[i].colortime = res.data.data[i].addtime.split(' ')[0]; } that.setData({ subscribelist: res.data.data }) } } }) }, getstate: function (num) { const that = this; switch (this.data.titype * 1) { case 1: let str = ""; str = this.data.cluestate == 1 ? "待确认" : this.data.cluestate == 2 ? "未到访" : "无效"; return str; case 2: let str1 = ""; str1 = that.data.tacktype == 3 ? "已量房" : this.data.tacktype == 4 ? "已到店" : this.data.tacktype == 5 ? "已到场" : this.data.tacktype == 6 ? "已交定" : this.data.tacktype == 7 ? "已签单" : "预约回访"; return str1; case 3: let str2 = ""; str2 = num == 1 ? "预约量房" : num == 2 ? "预约到店" : num == 3 ? "预约活动" : num == 4 ? "未量房" : num == 5 ? "未到店" : num == 6 ? "未到场" : ""; return str2; default: break; } }, addappointap() { const that = this; if (!!this.data.measuretime) { this.addrecord(1); } if (!!this.data.reachstoretime) { this.addrecord(2); } if (!!this.data.nowaid && !!this.data.orderactivitydate) { this.addrecord(3); } }, ossuploadimg1: function (e) { let that = this; let trackimgarr = that.data.trackimgarr1; var arr = []; for (let i = 0; i < trackimgarr.length; i++) { //获取文件后缀 // 随机生成文件名称 let rstr = trackimgarr[i].tempFilePath.split('.'); var fileRandName = Date.now() + "" + parseInt(Math.random() * 10000) + i; var imgName = fileRandName + '.' + 'png'; // var fileName = that.data.; var date = new Date(); var time = date.getFullYear() + '' + (date.getMonth() * 1 + 1) + '' + date.getDate(); var imgstr = 'crm/' + time + '/' + imgName; var nowimagearr = that.data.nowimagearr1; nowimagearr.push(imgstr); that.setData({ nowimagearr1: nowimagearr }) wx.uploadFile({ url: 'https://o.nczyzs.com', filePath: trackimgarr[i].tempFilePath, name: 'file', formData: { // name: that.data.imgSrc[0], key: 'crm/' + time + '/' + imgName, policy: "eyJleHBpcmF0aW9uIjoiMjAyNS0wMS0wMVQxMjowMDowMC4wMDBaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF1dfQ==", OSSaccessKeyId: "LTAI5tHjWupJSCAycy2yVbQZ", success_action_status: "200", signature: "bWaeUQYnGAcWynj3FxAfGZLy5n0=", }, header: { "Content-Type": "multipart/form-data", 'accept': 'application/json', }, success: function (rs) { if (rs.errMsg == 'uploadFile:ok') { arr.push('0'); if (arr.length == trackimgarr.length) { that.addrecord(); } } }, fail(res) { wx.hideLoading() } }) } }, addrecord: function (num, time) { this.selectComponent('#customfield').addCustomer(); let that = this; wx.showLoading({ title: '加载中...', }) utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/addvisitlog', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { customer_id: that.data.nowcid, img: that.data.titype == 2 && that.data.tacktype == 3 ? that.data.nowimagearr.join(',') : '', img1: that.data.titype == 1 ? that.data.nowimagearr1.join(',') : '', delivery_img: that.data.titype == 2 && that.data.tacktype == 6 ? that.data.nowimagearr1.join(',') : '', sign_img: that.data.titype == 2 && that.data.tacktype == 7 ? that.data.nowimagearr1.join(',') : '', type: this.data.clueType, next_contact_date: that.data.visitdate, remark: that.data.tacktext, starts: that.data.scoleval * 2, state: that.getstate(num), aid: num == 3 ? that.data.nowaid : num == 2 ? this.data.storeactivityid : that.data.titype == 2 && this.data.tacktype == 5 ? that.data.nowaid : that.data.titype == 2 && this.data.tacktype == 4 && this.data.changeModuleObj.ddhd.show == 1 ? that.data.nowaid : '', money: this.data.money, deposit_mode: this.data.deposit_mode, confirm_date: num >= 4 ? time : num == 1 ? this.data.measuretime : num == 2 ? this.data.reachstoretime : num == 3 ? this.data.orderactivitydate : that.data.tacktype == 3 ? this.data.amountdate : that.data.tacktype == 4 ? this.data.amountdate : this.data.tacktype == 5 ? this.data.amountdate : '', number_of_visitors: that.data.titype == 2 && that.data.tacktype == 4 ? that.data.storenum : '', measure_room_img_type: that.data.titype == 2 && that.data.tacktype == 3 ? that.data.amountext.length > 0 ? that.data.amountext.join(',') : '' : '', package: this.data.titype == 2 && this.data.tacktype == 6 ? this.data.depositproductlist.length > 0 && this.data.depositproductnum !== '' ? this.data.depositproductlist[this.data.depositproductnum].id : '' : '', talking_order_time: this.data.titype == 2 && this.data.tacktype == 4 ? this.data.orderTime : "", stay_length: this.data.titype == 2 && this.data.tacktype == 5 ? this.data.staylength : "", down_payment: this.data.titype == 2 && this.data.tacktype == 7 ? this.data.firstmoney : "", shop_id: this.data.titype == 2 && this.data.tacktype == 4 && (this.data.storeIndex || this.data.storeIndex == 0) ? this.data.storeArr[this.data.storeIndex].id : '' }, success: function (res) { wx.hideLoading() if (res.data.code == "0") { wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000 }) that.crmmsgfun(); that.typeinitfun(); if (that.data.titype == 1) { that.setData({ trackimgarr1: [], nowimagearr1: [], }) that.tracklog(); } else if (that.data.titype == 2) { let amountext = that.data.amountext; amountext = []; if (that.data.amountarr.length == 1) { amountext[0] = that.data.amountarr[0].name.slice(2, that.data.amountarr[0].name.length) } that.setData({ tacktype: 3, amountext: amountext, orderTime: "", staylength: "", firstmoney: "", trackimgarr1: [], nowimagearr1: [], }) that.visitlogfun('量房'); that.tracklog(); } else if (that.data.titype == 3) { that.setData({ nowaid: '', activityvalue: '', orderactivitydate: '', reachstoretime: '', reachstorenum: '', measurenum: '', measuretime: '', appointype: '', storeactivityid: '', storeactivityvalue: '' }) that.subscribefun(); } that.setData({ trackimgarr: [], nowimagearr: [], tacktext: '', money: '', storeIndex: null }) that.triggerEvent("run", '') } } }) }, saverecordtap: function (e) { const that = this; if (that.data.tacktype == 1 || that.data.tacktype == 3 || that.data.tacktype == 4 || that.data.tacktype == 5 || that.data.tacktype == 6 || that.data.tacktype == 7) { if (this.data.nextvisitflag && !that.data.visitdate) { wx.showToast({ title: "下次回访时间不能为空", icon: 'none', duration: 2000 }) return false; } } if (that.data.titype == 2 && that.data.tacktype == 3) { if (that.data.trackimgarr.length > 0) { that.ossuploadimg(); } else { wx.showToast({ title: "确定量房必须传照片!", icon: 'none', duration: 2000 }) } } else if (that.data.titype == 2 && that.data.tacktype == 6) { if (that.data.trackimgarr1.length > 0) { that.ossuploadimg1(); } else { wx.showToast({ title: `请上传${that.data.deliveryTagText}依据!`, icon: 'none', duration: 2000 }) return; } } else if (that.data.titype == 2 && that.data.tacktype == 7) { if (that.data.trackimgarr1.length > 0) { that.ossuploadimg1(); } else { wx.showToast({ title: `请上传${that.data.contractTagText}依据!`, icon: 'none', duration: 2000 }) return; } } else { if (that.data.titype == 1) { if (that.data.trackimgarr1.length > 0) { that.ossuploadimg1(); } else { that.addrecord(); } } else { that.addrecord(); } } }, } })