index.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. namespace jiemufenbu {
  2. const { line, upLine,clearchart } = require("./F2");
  3. let { getProgramTypeDistribution } = 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. detached: function() {
  30. // 在组件实例被从页面节点树移除时执行
  31. clearchart()
  32. },
  33. /**
  34. * 组件的初始数据
  35. */
  36. data: {
  37. onInitChart: undefined,
  38. DayList: {},
  39. select_act: 0,
  40. select: [
  41. {
  42. text: "时长",
  43. proportionType: "timeSize",
  44. type: 2,
  45. unit: "分",
  46. },
  47. {
  48. text: "频次",
  49. proportionType: "pinci",
  50. type: 1,
  51. unit: "次",
  52. },
  53. {
  54. text: "客户数",
  55. proportionType: "custom",
  56. type: 4,
  57. unit: "个",
  58. },
  59. ],
  60. },
  61. /**
  62. * 组件的方法列表
  63. */
  64. methods: {
  65. init() {
  66. let channelItem = this.data.channel;
  67. Promise.all([
  68. getProgramTypeDistribution({
  69. type: this.data.select[this.data.select_act].type,
  70. industryId: channelItem.channelId,
  71. dataType: this.data.array.index
  72. }),
  73. ]).then((res: any[]) => {
  74. let li = res[0] ? res[0].data : [] , key = this.data.select[this.data.select_act].proportionType, total = 0;
  75. li.map((v:any)=>{
  76. total += Number(v[key])
  77. })
  78. this.setData({
  79. DayList: li.map((v:any)=>{
  80. v.type = '0';
  81. v[key] = Number(v[key] || 0)
  82. v.value = v[key] / total*100
  83. return v
  84. }),
  85. onInitChart: line.bind(this),
  86. })
  87. })
  88. },
  89. upData() {
  90. let channelItem = this.data.channel;
  91. Promise.all([
  92. getProgramTypeDistribution({
  93. type: this.data.select[this.data.select_act].type,
  94. industryId: channelItem.channelId,
  95. dataType: this.data.array.index
  96. }),
  97. ]).then((res: any[]) => {
  98. let li = res[0] ? res[0].data : [] , key = this.data.select[this.data.select_act].proportionType, total = 0;
  99. li.map((v:any)=>{
  100. total += Number(v[key])
  101. })
  102. this.setData({
  103. DayList: li.map((v:any)=>{
  104. v.type = '0';
  105. v[key] = Number(v[key] || 0)
  106. v.value = v[key] / total*100
  107. return v
  108. }),
  109. },()=>{
  110. upLine.bind(this)()
  111. })
  112. })
  113. },
  114. channelChange(event: wxPicker) {
  115. this.setData({
  116. select_act: Number(event.detail.value)
  117. }, () => this.upData())
  118. },
  119. }
  120. })
  121. }