index.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // components/toufang/index.ts
  2. namespace hangyezhanbi{
  3. let { getRatio } = require('../../../../utils/api')
  4. let first = true;
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. array: {
  11. type: Object
  12. },
  13. channel: {
  14. type: Object
  15. },
  16. },
  17. observers: {
  18. 'array': function () {
  19. !first && this.upData()
  20. },
  21. 'channel': function () {
  22. !first && this.upData()
  23. }
  24. },
  25. ready() {
  26. this.init();
  27. first = false;
  28. },
  29. /**
  30. * 组件的初始数据
  31. */
  32. data: {
  33. onInitChart: undefined,
  34. DayList: [],
  35. select_act: 0,
  36. select: [
  37. {
  38. text: "费用",
  39. proportionType: "fee",
  40. type: 3,
  41. unit: "元",
  42. },
  43. {
  44. text: "时长",
  45. proportionType: "timeSize",
  46. type: 2,
  47. unit: "分",
  48. },
  49. {
  50. text: "频次",
  51. proportionType: "pinci",
  52. type: 1,
  53. unit: "次",
  54. },
  55. {
  56. text: "客户量",
  57. proportionType: "customer",
  58. type: 4,
  59. unit: "个",
  60. },
  61. ]
  62. },
  63. /**
  64. * 组件的方法列表
  65. */
  66. methods: {
  67. init() {
  68. let channelItem = this.data.channel;
  69. let arrayItem = this.data.array;
  70. Promise.all([
  71. getRatio({
  72. channelId: channelItem.channelId,
  73. order: this.data.select[this.data.select_act].type,
  74. end: arrayItem.endDate,
  75. start: arrayItem.startDate
  76. }),
  77. ]).then((res: adDay[][]) => {
  78. let total = 0, key = this.data.select[this.data.select_act].proportionType
  79. for (let i = 0; i < (res[0] || []).length; i++) {
  80. const v:any = (res[0] || [])[i] || {};
  81. total += Number(v[this.data.select[this.data.select_act].proportionType] || 0)
  82. }
  83. this.setData({
  84. DayList: (res[0] || []).map((v: any) => {
  85. v.p = Number(v[this.data.select[this.data.select_act].proportionType] / total * 100).toFixed(2)
  86. return v
  87. }).sort((a:any,b:any)=>{
  88. return b[key] - a[key]
  89. }),
  90. })
  91. })
  92. },
  93. upData() {
  94. let channelItem = this.data.channel;
  95. let arrayItem = this.data.array;
  96. Promise.all([
  97. getRatio({
  98. channelId: channelItem.channelId,
  99. order: this.data.select[this.data.select_act].type,
  100. end: arrayItem.endDate,
  101. start: arrayItem.startDate
  102. }),
  103. ]).then((res: adDay[][]) => {
  104. let total = 0, key = this.data.select[this.data.select_act].proportionType
  105. for (let i = 0; i < (res[0] || []).length; i++) {
  106. const v:any = (res[0] || [])[i] || {};
  107. total += Number(v[this.data.select[this.data.select_act].proportionType] || 0)
  108. }
  109. this.setData({
  110. DayList: (res[0] || []).map((v: any) => {
  111. v.p = Number(v[this.data.select[this.data.select_act].proportionType] / total * 100).toFixed(2)
  112. return v
  113. }).sort((a:any,b:any)=>{
  114. return b[key] - a[key]
  115. }),
  116. })
  117. // },()=>upLine.bind(this)())
  118. })
  119. },
  120. channelChange(event:wxPicker){
  121. this.setData({
  122. select_act: Number(event.detail.value)
  123. },()=>this.upData())
  124. }
  125. }
  126. })
  127. }