achieveList.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. word: '昨日新增',
  7. type: 'yesterday',
  8. list: [],
  9. provinceList: [],
  10. province: '',
  11. total: 0,
  12. },
  13. // 事件处理
  14. // 选择省份
  15. provinceChange: function (e) {
  16. this.setData({ "province": this.data.provinceList[e.detail.value].name });
  17. this.getCount(this.data.provinceList[e.detail.value])
  18. },
  19. onLoad: function (options) {
  20. var that = this;
  21. // 获取地址栏统计类型
  22. const { type } = options;
  23. let word;
  24. if (type === 'yesterday') word = "昨日新增";
  25. else if (type === 'week') word = '本周新增';
  26. else if (type === 'month') word = '本月新增';
  27. else word = '团队统计'
  28. that.setData({ type: options.type, word });
  29. this.getXzqh();
  30. },
  31. /**
  32. * 根据选择的省份进行统计
  33. * @param {Object} object 选择的省份Object
  34. */
  35. getCount(object) {
  36. const { code: province } = object;
  37. wx.request({
  38. url: `${app.globalData.publicUrl}/api/htyd/count/${this.data.type}?r_mobile=${app.globalData.userInfo.mobile}&province=${province}`,
  39. method: 'get',
  40. success: res => {
  41. const { data } = res.data
  42. const keys = Object.keys(data);
  43. const arr = [];
  44. for (const key of keys) {
  45. arr.push({ tc: `${key.includes('套餐') ? key : `${key}-套餐`}`, tzNum: data[key], jpNum: 0 })
  46. }
  47. if (arr.length <= 0) wx.showToast({
  48. title: '未查到相关数据',
  49. icon: "none"
  50. })
  51. this.setData({
  52. list: arr,
  53. total: arr.reduce((p, n) => p + (n.tzNum || 0) + (n.jpNum || 0), 0)
  54. })
  55. }
  56. })
  57. },
  58. /**
  59. * 查询行政区划
  60. * @param {String} pcode 上级code
  61. */
  62. getXzqh(pcode) {
  63. const query = {};
  64. if (pcode) query.pcode = pcode;
  65. wx.request({
  66. url: `${app.globalData.publicUrl}/api/htyd/xzqh`,
  67. method: "get",
  68. success: res => {
  69. this.setData({
  70. provinceList: res.data.data
  71. })
  72. console.log(this.data.provinceList);
  73. }
  74. })
  75. }
  76. })