const app = getApp(); var utils = require("../../../utils/http") const util = require("../../../utils/util"); let page = 1, sharepage = 1; Page({ /** * 页面的初始数据 */ data: { imgUrl: app.globalData.imgUrl, clientype: app.globalData.clientype, aid: '', activityobj: {}, itemDataMsg: {}, wshareshow: false, showAction: false, titype: 1, trackflag: false, tracktype: '1', customerlist: [], trackimgarr: [], nowimagearr: [], actions: [], nowcid: '', recordtext: '', visitobj: {}, housestate: '预约回访', seletime: '', visitcount: 0, visitlogarr: [], statype: '1', activitylist: [], wactivitylist: [], wcolumns: [], activityname: '', invitecrm: [], showUpcrm: [], datashow: true, start: "", end: '', columns: [], showPicker: false, nowaid: '', personobj: app.globalData.personMsg, typeflag: false, ranktype: '预约', orgtype: '公司排行', shareranklist: [], gotranklist: [], sharemyrankobj: {}, gotmyrankobj: {}, topdataobj: {}, type: 1, tacktype: 1, tackarr: [ { id: 1, text: '自定义' }, { id: 3, text: '已装修' }, { id: 4, text: '无需求' }, { id: 5, text: '有需求' }, { id: 6, text: '超地域' }, { id: 7, text: '未交房' }, { id: 8, text: '在外地' }, { id: 9, text: '无购买力' }, { id: 10, text: '未接通电话' }, ], nowtext1: '自定义', tacktext: '', amountdate: '', nowtext: false, timeshow: false, amountime: 1, amountime1: 1, visitdate: '', apointobj: {}, customerobj: {}, nowidx: 0, scoleval: 0, nowdate: '', cluestate: 1, activityType: '', addwxarr: [], addwxtypeflag: false, nextvisitflag: false,//true是必填,false不必传 下次回访时间 measurenum: '', measuretime: '', amountarr: [], signOrderTagText: "转单", deliveryTagText: "签单", signTag: "转", deliveryTag: "签" }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if (this.data.clientype == 'vL0CQQ') { this.setData({ signOrderTagText: "签单", deliveryTagText: "交定", signTag: "签", deliveryTag: "定" }) } 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({ aid: options.aid, amountdate: str, start: str, nowdate: str, personobj: app.globalData.personMsg, imgUrl: app.globalData.imgUrl, }) if (!!options.type) { this.setData({ activityType: options.type }) } if (!!options.type && options.type == 'broker') { this.activityfun(); } else { this.crmtopdatafun(); this.activityfun(); this.crmlistfun(); this.ranklistfun(); this.activitylistfun('0'); this.activitylistfun('1'); } if(options.ltype){ this.setData({ type:options.ltype }) } }, crmtopdatafun() { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/activity/statistics', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { aid: that.data.aid, }, success: function (res) { if (res.data.code == '0') { that.setData({ topdataobj: res.data.data }) } } }) }, setranktypetap(e) { this.setData({ ranktype: e.currentTarget.dataset.text }) this.ranklistfun(); }, 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: '' }) }, openorgtypetap(e) { this.setData({ typeflag: true, }) }, closeorgtypetap(e) { this.setData({ typeflag: false }) }, setorgtypetap(e) { this.setData({ orgtype: e.currentTarget.dataset.type, typeflag: false }) this.ranklistfun(); }, ranklistfun() { const that = this; sharepage = 1; var str = "api/activity/ranking_list"; let data = { id: that.data.aid, type: that.data.ranktype, is_org: this.data.orgtype == '公司排行' ? 0 : '1',//0公司排行,1团队排行, page: sharepage, limit: 15, }; if (this.data.orgtype == '部门排行') { str = "api/activity/org_ranking_list"; data = { id: that.data.aid, type: that.data.ranktype, page: sharepage, limit: 15, }; } utils.$post({ url: app.globalData.webUrl + str, header: { 'Authorization': 'bearer ' + app.globalData.token }, data: data, success: function (res) { setTimeout(() => { wx.hideLoading() }, 1000) if (res.data.code == "0") { if (that.data.orgtype == '公司排行' || that.data.orgtype == '团队排行') { that.setData({ shareranklist: res.data.data.data, sharemyrankobj: res.data.data.my, }) } else { that.setData({ gotranklist: res.data.data.data, gotmyrankobj: res.data.data.my, }) } } } }) }, setoptap(obj) { const that = this; let customerobj = obj.detail; // 详情的状态已经修改过了 if (!customerobj.addtoptime) { this.crmlistfun(); } else { if (that.data.statype == 1) { let invitecrm = []; invitecrm = invitecrm.concat(that.data.invitecrm); invitecrm[that.data.nowidx].addtoptime = '2022'; var obj = invitecrm.splice(that.data.nowidx, 1); invitecrm.unshift(obj[0]); that.setData({ invitecrm: invitecrm }) } else { let showUpcrm = []; showUpcrm = showUpcrm.concat(that.data.showUpcrm); showUpcrm[that.data.nowidx].addtoptime = '2022'; var obj = showUpcrm.splice(that.data.nowidx, 1); showUpcrm.unshift(obj[0]); that.setData({ showUpcrm: showUpcrm }) } } }, setypetap(e) { this.setData({ type: e.currentTarget.dataset.type }) if (this.data.type == 1) { this.setData({ tacktype: 1, cluestate: this.data.customerobj.state == "待确认" ? 1 : 2 }) } else if (this.data.type == 2) { this.setData({ tacktype: 3 }) } }, bindsignChange: function (e) { this.setData({ amountdate: e.detail.value }) }, bindsigndate1: function (e) { this.setData({ addtime: e.detail.value }) }, dothis() { }, trackfuntap: function (e) { this.setData({ tracktype: e.currentTarget.dataset.type }) }, textareatap: function (e) { const that = this; if (this.data.nowtext1 != '自定义') { if (this.data.tacktext.indexOf(this.data.nowtext1) != 0) { that.setData({ tacktext: this.data.nowtext1 }) } else { that.setData({ tacktext: e.detail.value }) } } else { that.setData({ tacktext: e.detail.value }) } }, addtracktap: function (e) { this.getsetfun(); this.setData({ trackflag: true, nowcid: e.currentTarget.dataset.aid, nowidx: e.currentTarget.dataset.idx, }) this.selectComponent('#addtrack').setcrmfun(); this.activitylistfun('0'); this.activitylistfun('1'); this.typeinitfun(); }, // 加微类型等 getsetfun() { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/get_setting', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: {}, success: function (res) { if (res.data.code == 0) { var arr = res.data.data.img_type, amountarr = []; for (let i in arr) { let obj = { id: i, name: "上传" + arr[i], color: "#384855", }; amountarr.push(obj); } that.setData({ addwxarr: res.data.data.wechat_type, nextvisitflag: res.data.data.next_visit_time_is_ok == 1 ? true : false, amountarr: amountarr }) } that.loginbox = that.selectComponent("#addtrack"); that.loginbox.crmsgfun(); } }) }, activitylistfun(cate) { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/activity/activity_list', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { cate: cate }, success: function (res) { setTimeout(() => { wx.hideLoading() }, 1000) if (res.data.code == "0") { if (cate == '0') { let columns = []; for (let i in res.data.data) { columns.push(res.data.data[i].title) } that.setData({ activitylist: res.data.data, columns: columns }) } else { let columns1 = []; for (let i in res.data.data) { columns1.push(res.data.data[i].title) } that.setData({ wactivitylist: res.data.data, wcolumns: columns1 }) } } } }) }, statypetap(e) { this.setData({ statype: e.currentTarget.dataset.type }) this.crmlistfun(); }, crmmsgtap(e) { wx.navigateTo({ url: "/pages/other/other?cid=" + e.currentTarget.dataset.aid + '&type=88&aid=' + this.data.aid, }); }, crmlistfun() { const that = this; page = 1; utils.$post({ url: app.globalData.webUrl + 'api/activity/invite_list', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { p: page, pagesize: 15, aid: that.data.aid, type: that.data.statype == 1 ? '预约活动' : that.data.statype == 2 ? '已到场' : that.data.statype == 3 ? '已交定' : '已签单' }, success: function (res) { if (res.data.code == '0') { for (let i = 0; i < res.data.data.length; i++) { res.data.data[i].lastday = util.nowdayDiff( res.data.data[i].last_contact_date ); } if (that.data.statype == 1) { that.setData({ invitecrm: res.data.data }) } else { that.setData({ showUpcrm: res.data.data }) } } } }) }, callphonetap(e) { const that = this; wx.showLoading({ title: '正在拨打电话...', }) utils.$post({ url: app.globalData.webUrl + 'api/crmCustomer/getCrmPhone', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: e.currentTarget.dataset.aid }, success: function (res) { if (res.data.code == 0) { wx.hideLoading(); let dataObj = res.data; dataObj.aid = e.currentTarget.dataset.aid; that.setData({ itemDataMsg: dataObj }) if (dataObj.out_call_check == 1) { if (dataObj.out_call_phone.length == 1) { that.onCallBindFunc(dataObj.out_call_phone[0],dataObj); } else { let mobileArr = dataObj.out_call_phone.map(v => { return {name: v}; }) that.setData({ actions: mobileArr, showAction: true }) } } else { that.onCallBindFunc(dataObj.out_call_phone[0],dataObj); } } else { wx.hideLoading(); } } }) }, outCallMobileApi(dataObj) { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/outCall/mobile', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: dataObj.aid, alertshow: '123' }, success: function (res) { if (res.data.code == 1) {} } }) }, onCallBindFunc(phone,dataObj) { const that = this; utils.$post({ url: app.globalData.webUrl + 'api/outCall/bind', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { phone: phone, customer_id: dataObj.aid, alertshow: '123' }, success: function (res) { wx.hideLoading(); if (res.data.code == 1) { that.outCallMobileApi(dataObj); wx.makePhoneCall({ phoneNumber: dataObj.phone.phone ? dataObj.phone.phone : dataObj.phone.phone1 ? dataObj.phone.phone1 : dataObj.phone.phone2, success() { that.getsetfun(); that.setData({ trackflag: true, nowcid: dataObj.aid, }) that.selectComponent('#addtrack').setcrmfun(); that.activitylistfun('0'); that.activitylistfun('1'); that.typeinitfun(); } }) } else { if (res.data.mobile) { wx.makePhoneCall({ phoneNumber: res.data.mobile, success() { that.getsetfun(); that.setData({ trackflag: true, nowcid: dataObj.aid, }) that.selectComponent('#addtrack').setcrmfun(); that.activitylistfun('0'); that.activitylistfun('1'); that.typeinitfun(); } }) } else { wx.showLoading({ title: '电话拨通中,请等待5s-10s', duration: 5000, icon: "none" }) setTimeout(() => { wx.hideLoading(); },5000) } } } }) }, onClose() { const that = this; this.setData({ showAction: false, trackflag: true, nowcid: this.data.itemDataMsg.aid, }) that.getsetfun(); that.selectComponent('#addtrack').setcrmfun(); that.activitylistfun('0'); that.activitylistfun('1'); that.typeinitfun(); }, onSelect(e) { this.onCallBindFunc(e.detail.name,this.data.itemDataMsg); this.setData({ showAction: false }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, sharewaytap: function () { this.setData({ wshareshow: true }) }, shareurltap: function () { wx.showLoading({ title: '加载中...', }) if (this.data.activityType && this.data.activityType == 'broker') { util.schemefun('/share/pages/activitymsg/activitymsg', 'aid=' + this.data.aid + '&bid=' + app.globalData.brokeruserId + '&ctp=' + app.globalData.clientype + '&t=b', this.data.aid, 'activity', ''); } else { this.activitytap(); util.schemefun('/share/pages/activitymsg/activitymsg', 'aid=' + this.data.aid + '&uid=' + app.globalData.personMsg.id + '&ctp=' + app.globalData.clientype, this.data.aid, 'activity', ''); } }, activityfun: function () { var that = this; if (that.data.activityType && that.data.activityType == 'broker') { utils.$post({ url: app.globalData.webUrl + 'api/agents_work/activity_detail', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, uid: app.globalData.personMsg.id }, success: function (res) { if (res.data.code == '0') { that.setData({ activityobj: res.data.data }) wx.setNavigationBarTitle({ title: res.data.data.title }) } } }) } else { utils.$post({ url: app.globalData.webUrl + 'api/activity/details', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, uid: app.globalData.personMsg.id }, success: function (res) { if (res.data.code == '0') { that.setData({ activityobj: res.data.data }) wx.setNavigationBarTitle({ title: res.data.data.title }) } } }) } }, setpostertap: function () { if (this.data.activityType && this.data.activityType == 'broker') { wx.navigateTo({ url: '/index/pages/setposter/setposter?type=activity&aid=' + this.data.aid + "&tp=broker" + "&listshare=", }) } else { wx.navigateTo({ url: '/index/pages/setposter/setposter?type=activity&aid=' + this.data.aid + "&listshare=", }) } }, collectap: function () { var that = this; let activityobj = that.data.activityobj; if (!that.data.activityobj.collected) { utils.$post({ url: app.globalData.webUrl + 'api/activity/collection', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { user_id: app.globalData.personMsg.id, id: that.data.aid }, success: function (res) { if (res.data.code == '0') { wx.showToast({ title: res.data.msg, icon: 'success', duration: 2000 }) activityobj.collected = true; that.setData({ activityobj: activityobj }) } } }) } else { utils.$post({ url: app.globalData.webUrl + 'api/activity/collectCancel', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { user_id: app.globalData.personMsg.id, id: that.data.aid }, success: function (res) { if (res.data.code == '0') { wx.showToast({ title: res.data.msg, icon: 'none', duration: 2000 }) activityobj.collected = false; that.setData({ activityobj: activityobj }) } } }) } }, activitytap: function () { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/share/addlog', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { id: that.data.aid, type: 'activity', }, success: function (r) { } }) }, prelooktap() { wx.previewImage({ current: this.data.activityobj.cover, // 当前显示图片的http链接 urls: [this.data.activityobj.cover], // 需要预览的图片http链接列表 fail(res) { console.log(res) } }) }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { if (this.data.type == 1) { wx.stopPullDownRefresh(); return false; } if (this.data.type == '3') { this.ranklistfun(); wx.stopPullDownRefresh() } else { this.crmtopdatafun(); const that = this; page = 1; utils.$post({ url: app.globalData.webUrl + 'api/activity/invite_list', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { p: page, pagesize: 15, aid: that.data.aid, type: that.data.statype == 1 ? '预约活动' : that.data.statype == 2 ? '已到场' : that.data.statype == 3 ? '已交定' : '已签单' }, success: function (res) { wx.stopPullDownRefresh() if (res.data.code == '0') { for (let i = 0; i < res.data.data.length; i++) { res.data.data[i].lastday = util.nowdayDiff( res.data.data[i].last_contact_date ); } if (that.data.statype == 1) { that.setData({ invitecrm: res.data.data }) } else { that.setData({ showUpcrm: res.data.data }) } } } }) } }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { const that = this; if (this.data.type == 1) { return false; } if (that.data.type == 3) { sharepage = sharepage * 1 + 1; var str = "api/activity/ranking_list"; let data = { id: that.data.aid, type: that.data.ranktype, is_org: this.data.orgtype == '公司排行' ? 0 : '1',//0公司排行,1团队排行, page: sharepage, limit: 15, }; if (this.data.orgtype == '部门排行') { str = "api/activity/org_ranking_list"; data = { id: that.data.aid, type: that.data.ranktype, page: sharepage, limit: 15, }; } utils.$post({ url: app.globalData.webUrl + str, header: { 'Authorization': 'bearer ' + app.globalData.token }, data: data, success: function (res) { setTimeout(() => { wx.hideLoading() }, 1000) if (res.data.code == "0") { if (that.data.orgtype == '公司排行' || that.data.orgtype == '团队排行') { let shareranklist = that.data.shareranklist; shareranklist = shareranklist.concat(res.data.data.data); that.setData({ shareranklist: shareranklist }) } else { let gotranklist = that.data.gotranklist; gotranklist = gotranklist.concat(res.data.data.data); that.setData({ gotranklist: gotranklist }) } } } }) } else { page = page * 1 + 1; utils.$post({ url: app.globalData.webUrl + 'api/activity/invite_list', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { p: page, pagesize: 15, aid: that.data.aid, type: that.data.statype == 1 ? '预约活动' : that.data.statype == 2 ? '已到场' : that.data.statype == 3 ? '已交定' : '已签单' }, success: function (res) { if (res.data.code == '0') { for (let i = 0; i < res.data.data.length; i++) { res.data.data[i].lastday = util.nowdayDiff( res.data.data[i].last_contact_date ); } if (that.data.statype == 1) { let invitecrm = that.data.invitecrm; invitecrm = invitecrm.concat(res.data.data); that.setData({ invitecrm: invitecrm }) } else { let showUpcrm = that.data.showUpcrm; showUpcrm = showUpcrm.concat(res.data.data); that.setData({ showUpcrm: showUpcrm }) } } } }) } }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { var img = this.data.activityobj.cover; if (this.data.activityType && this.data.activityType == 'broker') { return { title: this.data.activityobj.title, imageUrl: img, path: '/share/pages/activitymsg/activitymsg?aid=' + this.data.aid + '&bid=' + app.globalData.brokeruserId + "&ctp=" + app.globalData.clientype + '&t=b' } } else { var poster = this.data.activityobj.poster; this.activitytap(); return { title: this.data.activityobj.title, imageUrl: poster, path: '/share/pages/activitymsg/activitymsg?aid=' + this.data.aid + '&uid=' + app.globalData.personMsg.id + "&ctp=" + app.globalData.clientype } } } })