123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487 |
- // 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)
- }
- })
- } else {
- wx.showToast({
- title: res.data.msg,
- icon: "none",
- duration: 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() {
- }
- })
|