// mycustomer/pages/activitylist/activitylist.js const app = getApp(); var utils = require("../../../utils/http"); var page = 1; Page({ /** * 页面的初始数据 */ data: { showType: false, datashow: false, show: false, index: 0, typeIndex: 0, orgName: null, registered: 0, confirmed: 0, unconfirmed: 0, date: '', orgId: '', aid: '', type: '', confirm_date: '', confirm_aid: '', customer_id: '', uid: '', keyword: '', minDate: new Date(2020,0,31).getTime(), maxDate: new Date(2026, 0, 31).getTime(), radioObj: {name: '',id: ''}, list: [], levelIds: ['1'], departlist: [], levelDepart: [], activitylist: [], typeArr: [{ name: '全部', id: '' }, { name: '已确认到场', id: '1' }, { name: '未确认到场', id: '0' }], items: [ {value: 'USA', name: '美国'}, {value: 'CHN', name: '中国', checked: 'true'}, {value: 'BRA', name: '巴西'}, {value: 'JPN', name: '日本'}, {value: 'ENG', name: '英国'}, {value: 'FRA', name: '法国'}, ], activitytype:'1',//0内场,1外场 activitynum:0, activityshow:false, }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { wx.showLoading({ title: '加载中...' }) let dateObj = new Date(); let year = dateObj.getFullYear(); let month = dateObj.getMonth()+1; let day = dateObj.getDate(); this.setData({ confirm_date: `${year}/${month}/${day}` }) page = 1; this.getQrCodelist(); this.getDepartlist(); this.getActivitySignList(); }, inputKeyWord: function(e) { this.setData({ keyword: e.detail.value }) console.log(this.data.keyword) }, handleSearch: function() { this.getDepartlist(); }, radioChange(e) { let data = e.detail.value.split('~'); let obj = { name: data[1], id: data[0] }; this.setData({ radioObj: obj }) }, handleLevel(e) { let id = e.currentTarget.dataset.id; this.setDepartData(this.data.departlist,id); }, setDepartData(list,id,level) { list.forEach(item => { if (id == item.id) { if (!item.children||!item.children.length) { wx.showToast({ title: '没有下级部门了', icon: 'none', duration: 1000 }) } else { if (level) { this.setData({ levelDepart: item.children, levelIds: this.data.levelIds, }) } else { this.data.levelIds.push(id); this.setData({ levelDepart: item.children, levelIds: this.data.levelIds, }) } } console.log(this.data.levelIds) return; } else { if (item.children && item.children.length) { this.setDepartData(item.children,id,level); } } }) }, lastLevel() { if (this.data.levelIds.length == 2) { this.setData({ levelDepart: this.data.departlist, levelIds: ['1'], }) } else { this.data.levelIds.splice(this.data.levelIds.length-1,1); this.setDepartData(this.data.departlist,this.data.levelIds[this.data.levelIds.length - 1],'lastlevel'); } }, bindPickerChange(e) { let index = parseInt(e.detail.value); this.setData({ index: index, aid: this.data.activitylist[index].id }) this.getQrCodelist(); }, showCalendar() { this.setData({ show: true }) }, onConfirm(e) { let dateArr = e.detail; let start = new Date(dateArr[0]); let end = new Date(dateArr[1]); let syear = start.getFullYear(); let eyear = end.getFullYear(); let smonth = start.getMonth() + 1; let emonth = end.getMonth() + 1; let sday = start.getDate(); let eday = end.getDate(); this.setData({ show: false, date: `${syear}-${smonth}-${sday}` + ' - ' + `${eyear}-${emonth}-${eday}`, }) this.getQrCodelist(); }, onClose(e) { this.setData({ show: false }) }, handleShowDepart() { this.setData({ showDepart: true }) }, closeMask() { this.setData({ showType: false, showDepart: false }) }, confirmDepart() { this.setData({ orgName: this.data.radioObj.name, orgId: this.data.radioObj.id, showDepart: false }); this.getQrCodelist(); }, handleShowType() { this.setData({ showType: true, }) }, bindTypeChange(e) { let index = e.currentTarget.dataset.index; let type = e.currentTarget.dataset.id; this.setData({ typeIndex: index, type: type, showType: false }) this.getQrCodelist(); }, scanningCodeTap() { let that = this; wx.scanCode({ success: function (res) { if (res.errMsg == 'scanCode:ok') { let data = res.result.split('&'); if (data && data.length) { that.setData({ confirm_aid: data[0], customer_id: data[1], uid: data[2], activitytype:data[3] }) if(data[3]=='1'){ that.scanQrcode(); }else{ that.setData({ activityshow:true }) } } } } }) }, getQrCodelist() { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/activity/getQrcodeList', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { page: page, limit: 10, date: that.data.date, org_id: that.data.orgId, aid: that.data.aid, type: that.data.type }, success: function (res) { if (res.data.code == '0') { setTimeout(() => { wx.hideLoading(); },3000) wx.stopPullDownRefresh(); that.setData({ datashow: true, list: res.data.data, registered: res.data.top_data.count, confirmed: res.data.top_data.scone_count, unconfirmed: res.data.top_data.no_scone_count }) } } }) }, getDepartlist() { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/activity/getOrgList', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { keyword: this.data.keyword }, success: function (res) { if (res.data.code == '0') { let arr = res.data.data; arr.unshift({ name: '所有部门', id: '', children: [] }) that.setData({ departlist: arr, levelDepart: arr }) } } }) }, getActivitySignList() { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/activity/activitySignList', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: {}, success: function (res) { if (res.data.code == '0') { let rdata = res.data.data; if (rdata && rdata.length) { that.setData({ activitylist: res.data.data, index: 0, aid: res.data.data[0].id }) } else { that.setData({ activitylist: [], index: null, aid: '' }) } } } }) }, addVisitlog() { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/crm_customer/addVisitlog', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { aid: that.data.confirm_aid, confirm_date: that.data.confirm_date, customer_id: that.data.customer_id, deposit_mode: "1", img: "", img1: "", measure_room_img_type: "", media_id: "", media_id1: "", money: "", next_contact_date: "", number_of_visitors: "", package: "", remark: "", starts: 0, state: "已到场", type: "", weixin_media: true, weixin_media1: "", }, success: function (res) { if (res.data.code == '0') { that.scanQrcode(); } } }) }, setnumtap(e){ this.setData({ activitynum:e.detail.value }) }, surestoretap(){ if(!this.data.activitynum){ wx.showToast({ title: '到店人数不能为0!', icon: 'none', duration: 1500 }) return false; } wx.showLoading({ title: '加载中...', }) this.scanQrcode(); }, scanQrcode() { let that = this; utils.$post({ url: app.globalData.webUrl + 'api/activity/scanQrcode', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { aid: that.data.confirm_aid, uid: that.data.uid, cid: that.data.customer_id, number_of_visitors:that.data.activitynum, }, success: function (res) { wx.hideLoading() if (res.data.code == 0) { that.setData({ activityshow:false }) wx.showToast({ title: '已确认到场', icon: 'none', duration: 1500, success: function() { setTimeout(() => { page = 1; that.getQrCodelist(); },1500) } }) } } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { page = 1; }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { page = 1; this.getQrCodelist(); }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { page++; let that = this; utils.$post({ url: app.globalData.webUrl + 'api/activity/getQrcodeList', header: { 'Authorization': 'bearer ' + app.globalData.token }, data: { page: page, limit: 10, date: that.data.date, org_id: that.data.orgId, aid: that.data.aid, type: that.data.type }, success: function (res) { if (res.data.code == '0') { let arr = that.data.list.concat(res.data.data); that.setData({ list: arr }) } } }) }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })