activitylist.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. // mycustomer/pages/activitylist/activitylist.js
  2. const app = getApp();
  3. var utils = require("../../../utils/http");
  4. var page = 1;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. showType: false,
  11. datashow: false,
  12. show: false,
  13. index: 0,
  14. typeIndex: 0,
  15. orgName: null,
  16. registered: 0,
  17. confirmed: 0,
  18. unconfirmed: 0,
  19. date: '',
  20. orgId: '',
  21. aid: '',
  22. type: '',
  23. confirm_date: '',
  24. confirm_aid: '',
  25. customer_id: '',
  26. uid: '',
  27. keyword: '',
  28. minDate: new Date(2020,0,31).getTime(),
  29. maxDate: new Date(2026, 0, 31).getTime(),
  30. radioObj: {name: '',id: ''},
  31. list: [],
  32. levelIds: ['1'],
  33. departlist: [],
  34. levelDepart: [],
  35. activitylist: [],
  36. typeArr: [{
  37. name: '全部',
  38. id: ''
  39. }, {
  40. name: '已确认到场',
  41. id: '1'
  42. }, {
  43. name: '未确认到场',
  44. id: '0'
  45. }],
  46. items: [
  47. {value: 'USA', name: '美国'},
  48. {value: 'CHN', name: '中国', checked: 'true'},
  49. {value: 'BRA', name: '巴西'},
  50. {value: 'JPN', name: '日本'},
  51. {value: 'ENG', name: '英国'},
  52. {value: 'FRA', name: '法国'},
  53. ],
  54. activitytype:'1',//0内场,1外场
  55. activitynum:0,
  56. activityshow:false,
  57. },
  58. /**
  59. * 生命周期函数--监听页面加载
  60. */
  61. onLoad(options) {
  62. wx.showLoading({
  63. title: '加载中...'
  64. })
  65. let dateObj = new Date();
  66. let year = dateObj.getFullYear();
  67. let month = dateObj.getMonth()+1;
  68. let day = dateObj.getDate();
  69. this.setData({
  70. confirm_date: `${year}/${month}/${day}`
  71. })
  72. page = 1;
  73. this.getQrCodelist();
  74. this.getDepartlist();
  75. this.getActivitySignList();
  76. },
  77. inputKeyWord: function(e) {
  78. this.setData({
  79. keyword: e.detail.value
  80. })
  81. console.log(this.data.keyword)
  82. },
  83. handleSearch: function() {
  84. this.getDepartlist();
  85. },
  86. radioChange(e) {
  87. let data = e.detail.value.split('~');
  88. let obj = {
  89. name: data[1],
  90. id: data[0]
  91. };
  92. this.setData({
  93. radioObj: obj
  94. })
  95. },
  96. handleLevel(e) {
  97. let id = e.currentTarget.dataset.id;
  98. this.setDepartData(this.data.departlist,id);
  99. },
  100. setDepartData(list,id,level) {
  101. list.forEach(item => {
  102. if (id == item.id) {
  103. if (!item.children||!item.children.length) {
  104. wx.showToast({
  105. title: '没有下级部门了',
  106. icon: 'none',
  107. duration: 1000
  108. })
  109. } else {
  110. if (level) {
  111. this.setData({
  112. levelDepart: item.children,
  113. levelIds: this.data.levelIds,
  114. })
  115. } else {
  116. this.data.levelIds.push(id);
  117. this.setData({
  118. levelDepart: item.children,
  119. levelIds: this.data.levelIds,
  120. })
  121. }
  122. }
  123. console.log(this.data.levelIds)
  124. return;
  125. } else {
  126. if (item.children && item.children.length) {
  127. this.setDepartData(item.children,id,level);
  128. }
  129. }
  130. })
  131. },
  132. lastLevel() {
  133. if (this.data.levelIds.length == 2) {
  134. this.setData({
  135. levelDepart: this.data.departlist,
  136. levelIds: ['1'],
  137. })
  138. } else {
  139. this.data.levelIds.splice(this.data.levelIds.length-1,1);
  140. this.setDepartData(this.data.departlist,this.data.levelIds[this.data.levelIds.length - 1],'lastlevel');
  141. }
  142. },
  143. bindPickerChange(e) {
  144. let index = parseInt(e.detail.value);
  145. this.setData({
  146. index: index,
  147. aid: this.data.activitylist[index].id
  148. })
  149. this.getQrCodelist();
  150. },
  151. showCalendar() {
  152. this.setData({
  153. show: true
  154. })
  155. },
  156. onConfirm(e) {
  157. let dateArr = e.detail;
  158. let start = new Date(dateArr[0]);
  159. let end = new Date(dateArr[1]);
  160. let syear = start.getFullYear();
  161. let eyear = end.getFullYear();
  162. let smonth = start.getMonth() + 1;
  163. let emonth = end.getMonth() + 1;
  164. let sday = start.getDate();
  165. let eday = end.getDate();
  166. this.setData({
  167. show: false,
  168. date: `${syear}-${smonth}-${sday}` + ' - ' + `${eyear}-${emonth}-${eday}`,
  169. })
  170. this.getQrCodelist();
  171. },
  172. onClose(e) {
  173. this.setData({
  174. show: false
  175. })
  176. },
  177. handleShowDepart() {
  178. this.setData({
  179. showDepart: true
  180. })
  181. },
  182. closeMask() {
  183. this.setData({
  184. showType: false,
  185. showDepart: false
  186. })
  187. },
  188. confirmDepart() {
  189. this.setData({
  190. orgName: this.data.radioObj.name,
  191. orgId: this.data.radioObj.id,
  192. showDepart: false
  193. });
  194. this.getQrCodelist();
  195. },
  196. handleShowType() {
  197. this.setData({
  198. showType: true,
  199. })
  200. },
  201. bindTypeChange(e) {
  202. let index = e.currentTarget.dataset.index;
  203. let type = e.currentTarget.dataset.id;
  204. this.setData({
  205. typeIndex: index,
  206. type: type,
  207. showType: false
  208. })
  209. this.getQrCodelist();
  210. },
  211. scanningCodeTap() {
  212. let that = this;
  213. wx.scanCode({
  214. success: function (res) {
  215. if (res.errMsg == 'scanCode:ok') {
  216. let data = res.result.split('&');
  217. if (data && data.length) {
  218. that.setData({
  219. confirm_aid: data[0],
  220. customer_id: data[1],
  221. uid: data[2],
  222. activitytype:data[3]
  223. })
  224. if(data[3]=='1'){
  225. that.scanQrcode();
  226. }else{
  227. that.setData({
  228. activityshow:true
  229. })
  230. }
  231. }
  232. }
  233. }
  234. })
  235. },
  236. getQrCodelist() {
  237. let that = this;
  238. utils.$post({
  239. url: app.globalData.webUrl + 'api/activity/getQrcodeList',
  240. header: {
  241. 'Authorization': 'bearer ' + app.globalData.token
  242. },
  243. data: {
  244. page: page,
  245. limit: 10,
  246. date: that.data.date,
  247. org_id: that.data.orgId,
  248. aid: that.data.aid,
  249. type: that.data.type
  250. },
  251. success: function (res) {
  252. if (res.data.code == '0') {
  253. setTimeout(() => {
  254. wx.hideLoading();
  255. },3000)
  256. wx.stopPullDownRefresh();
  257. that.setData({
  258. datashow: true,
  259. list: res.data.data,
  260. registered: res.data.top_data.count,
  261. confirmed: res.data.top_data.scone_count,
  262. unconfirmed: res.data.top_data.no_scone_count
  263. })
  264. }
  265. }
  266. })
  267. },
  268. getDepartlist() {
  269. let that = this;
  270. utils.$post({
  271. url: app.globalData.webUrl + 'api/activity/getOrgList',
  272. header: {
  273. 'Authorization': 'bearer ' + app.globalData.token
  274. },
  275. data: {
  276. keyword: this.data.keyword
  277. },
  278. success: function (res) {
  279. if (res.data.code == '0') {
  280. let arr = res.data.data;
  281. arr.unshift({ name: '所有部门', id: '', children: [] })
  282. that.setData({
  283. departlist: arr,
  284. levelDepart: arr
  285. })
  286. }
  287. }
  288. })
  289. },
  290. getActivitySignList() {
  291. let that = this;
  292. utils.$post({
  293. url: app.globalData.webUrl + 'api/activity/activitySignList',
  294. header: {
  295. 'Authorization': 'bearer ' + app.globalData.token
  296. },
  297. data: {},
  298. success: function (res) {
  299. if (res.data.code == '0') {
  300. let rdata = res.data.data;
  301. if (rdata && rdata.length) {
  302. that.setData({
  303. activitylist: res.data.data,
  304. index: 0,
  305. aid: res.data.data[0].id
  306. })
  307. } else {
  308. that.setData({
  309. activitylist: [],
  310. index: null,
  311. aid: ''
  312. })
  313. }
  314. }
  315. }
  316. })
  317. },
  318. addVisitlog() {
  319. let that = this;
  320. utils.$post({
  321. url: app.globalData.webUrl + 'api/crm_customer/addVisitlog',
  322. header: {
  323. 'Authorization': 'bearer ' + app.globalData.token
  324. },
  325. data: {
  326. aid: that.data.confirm_aid,
  327. confirm_date: that.data.confirm_date,
  328. customer_id: that.data.customer_id,
  329. deposit_mode: "1",
  330. img: "",
  331. img1: "",
  332. measure_room_img_type: "",
  333. media_id: "",
  334. media_id1: "",
  335. money: "",
  336. next_contact_date: "",
  337. number_of_visitors: "",
  338. package: "",
  339. remark: "",
  340. starts: 0,
  341. state: "已到场",
  342. type: "",
  343. weixin_media: true,
  344. weixin_media1: "",
  345. },
  346. success: function (res) {
  347. if (res.data.code == '0') {
  348. that.scanQrcode();
  349. }
  350. }
  351. })
  352. },
  353. setnumtap(e){
  354. this.setData({
  355. activitynum:e.detail.value
  356. })
  357. },
  358. surestoretap(){
  359. if(!this.data.activitynum){
  360. wx.showToast({
  361. title: '到店人数不能为0!',
  362. icon: 'none',
  363. duration: 1500
  364. })
  365. return false;
  366. }
  367. wx.showLoading({
  368. title: '加载中...',
  369. })
  370. this.scanQrcode();
  371. },
  372. scanQrcode() {
  373. let that = this;
  374. utils.$post({
  375. url: app.globalData.webUrl + 'api/activity/scanQrcode',
  376. header: {
  377. 'Authorization': 'bearer ' + app.globalData.token
  378. },
  379. data: {
  380. aid: that.data.confirm_aid,
  381. uid: that.data.uid,
  382. cid: that.data.customer_id,
  383. number_of_visitors:that.data.activitynum,
  384. },
  385. success: function (res) {
  386. wx.hideLoading()
  387. if (res.data.code == 0) {
  388. that.setData({
  389. activityshow:false
  390. })
  391. wx.showToast({
  392. title: '已确认到场',
  393. icon: 'none',
  394. duration: 1500,
  395. success: function() {
  396. setTimeout(() => {
  397. page = 1;
  398. that.getQrCodelist();
  399. },1500)
  400. }
  401. })
  402. }
  403. }
  404. })
  405. },
  406. /**
  407. * 生命周期函数--监听页面初次渲染完成
  408. */
  409. onReady() {
  410. },
  411. /**
  412. * 生命周期函数--监听页面显示
  413. */
  414. onShow() {
  415. page = 1;
  416. },
  417. /**
  418. * 生命周期函数--监听页面隐藏
  419. */
  420. onHide() {
  421. },
  422. /**
  423. * 生命周期函数--监听页面卸载
  424. */
  425. onUnload() {
  426. },
  427. /**
  428. * 页面相关事件处理函数--监听用户下拉动作
  429. */
  430. onPullDownRefresh() {
  431. page = 1;
  432. this.getQrCodelist();
  433. },
  434. /**
  435. * 页面上拉触底事件的处理函数
  436. */
  437. onReachBottom() {
  438. page++;
  439. let that = this;
  440. utils.$post({
  441. url: app.globalData.webUrl + 'api/activity/getQrcodeList',
  442. header: {
  443. 'Authorization': 'bearer ' + app.globalData.token
  444. },
  445. data: {
  446. page: page,
  447. limit: 10,
  448. date: that.data.date,
  449. org_id: that.data.orgId,
  450. aid: that.data.aid,
  451. type: that.data.type
  452. },
  453. success: function (res) {
  454. if (res.data.code == '0') {
  455. let arr = that.data.list.concat(res.data.data);
  456. that.setData({
  457. list: arr
  458. })
  459. }
  460. }
  461. })
  462. },
  463. /**
  464. * 用户点击右上角分享
  465. */
  466. onShareAppMessage() {
  467. }
  468. })