index.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. namespace pindaofenbu {
  2. const { line, upLine,clearchart } = require("./F2");
  3. const { line1, upLine1,clearchart1 } = require("./F21");
  4. let { getChannelDistribution } = require('../../../../utils/api')
  5. let first = true;
  6. Component({
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. array: {
  12. type: Object
  13. },
  14. channel: {
  15. type: Object
  16. },
  17. },
  18. observers: {
  19. 'array': function () {
  20. !first && this.upData()
  21. },
  22. 'channel': function () {
  23. !first && this.upData()
  24. },
  25. },
  26. ready() {
  27. this.init();
  28. first = false;
  29. },
  30. detached: function() {
  31. // 在组件实例被从页面节点树移除时执行
  32. clearchart()
  33. clearchart1()
  34. },
  35. /**
  36. * 组件的初始数据
  37. */
  38. data: {
  39. onInitChart: undefined,
  40. onInitChart1: undefined,
  41. DayList: {},
  42. DayList1: {},
  43. select_act: 0,
  44. select: [
  45. {
  46. text: "费用",
  47. proportionType: "kanlijia",
  48. type: 3,
  49. unit: "万元",
  50. },
  51. {
  52. text: "时长",
  53. proportionType: "timeSize",
  54. type: 2,
  55. unit: "分",
  56. },
  57. {
  58. text: "频次",
  59. proportionType: "pinci",
  60. type: 1,
  61. unit: "次",
  62. },
  63. ],
  64. },
  65. /**
  66. * 组件的方法列表
  67. */
  68. methods: {
  69. init() {
  70. let channelItem = this.data.channel;
  71. Promise.all([
  72. getChannelDistribution({
  73. type: this.data.select[this.data.select_act].type,
  74. industryId: channelItem.channelId,
  75. dataType: this.data.array.index
  76. }),
  77. ]).then((res: any[]) => {
  78. let harddata = res[0].harddata || [],
  79. softdata = res[0].softdata || [];
  80. let key = this.data.select[this.data.select_act].proportionType;
  81. this.setData({
  82. DayList1: softdata.map((v: any) => {
  83. v[key] = Number(v[key] || 0)
  84. return v
  85. }),
  86. DayList: harddata.map((v: any) => {
  87. v[key] = Number(v[key] || 0);
  88. return v
  89. }),
  90. onInitChart: line.bind(this),
  91. onInitChart1: line1.bind(this)
  92. })
  93. })
  94. },
  95. upData() {
  96. let channelItem = this.data.channel;
  97. Promise.all([
  98. getChannelDistribution({
  99. type: this.data.select[this.data.select_act].type,
  100. industryId: channelItem.channelId,
  101. dataType: this.data.array.index
  102. }),
  103. ]).then((res: any[]) => {
  104. let harddata = res[0].harddata || [],
  105. softdata = res[0].softdata || [];
  106. let key = this.data.select[this.data.select_act].proportionType;
  107. this.setData({
  108. DayList1: softdata.map((v: any) => {
  109. v[key] = Number(v[key] || 0)
  110. return v
  111. }),
  112. DayList: harddata.map((v: any) => {
  113. v[key] = Number(v[key] || 0);
  114. return v
  115. }),
  116. }, () => {
  117. upLine.bind(this)()
  118. upLine1.bind(this)()
  119. })
  120. })
  121. },
  122. channelChange(event: wxPicker) {
  123. this.setData({
  124. select_act: Number(event.detail.value)
  125. }, () => this.upData())
  126. },
  127. }
  128. })
  129. }