index.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. namespace pindaofenbu {
  2. const { line, upLine } = require("./F2");
  3. const { line1, upLine1 } = 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. /**
  31. * 组件的初始数据
  32. */
  33. data: {
  34. onInitChart: undefined,
  35. onInitChart1: undefined,
  36. DayList: {},
  37. DayList1: {},
  38. select_act: 0,
  39. select: [
  40. {
  41. text: "费用",
  42. proportionType: "kanlijia",
  43. type: 3,
  44. unit: "万元",
  45. },
  46. {
  47. text: "时长",
  48. proportionType: "timeSize",
  49. type: 2,
  50. unit: "分",
  51. },
  52. {
  53. text: "频次",
  54. proportionType: "pinci",
  55. type: 1,
  56. unit: "次",
  57. },
  58. ],
  59. },
  60. /**
  61. * 组件的方法列表
  62. */
  63. methods: {
  64. init() {
  65. let channelItem = this.data.channel;
  66. Promise.all([
  67. getChannelDistribution({
  68. type: this.data.select[this.data.select_act].type,
  69. industryId: channelItem.channelId,
  70. dataType: this.data.array.index
  71. }),
  72. ]).then((res: any[]) => {
  73. let harddata = res[0].harddata || [],
  74. softdata = res[0].softdata || [];
  75. let key = this.data.select[this.data.select_act].proportionType;
  76. this.setData({
  77. DayList1: softdata.map((v: any) => {
  78. v[key] = Number(v[key] || 0)
  79. return v
  80. }),
  81. DayList: harddata.map((v: any) => {
  82. v[key] = Number(v[key] || 0);
  83. return v
  84. }),
  85. onInitChart: line.bind(this),
  86. onInitChart1: line1.bind(this)
  87. })
  88. })
  89. },
  90. upData() {
  91. let channelItem = this.data.channel;
  92. Promise.all([
  93. getChannelDistribution({
  94. type: this.data.select[this.data.select_act].type,
  95. industryId: channelItem.channelId,
  96. dataType: this.data.array.index
  97. }),
  98. ]).then((res: any[]) => {
  99. let harddata = res[0].harddata || [],
  100. softdata = res[0].softdata || [];
  101. let key = this.data.select[this.data.select_act].proportionType;
  102. this.setData({
  103. DayList1: softdata.map((v: any) => {
  104. v[key] = Number(v[key] || 0)
  105. return v
  106. }),
  107. DayList: harddata.map((v: any) => {
  108. v[key] = Number(v[key] || 0);
  109. return v
  110. }),
  111. }, () => {
  112. upLine.bind(this)()
  113. })
  114. })
  115. },
  116. channelChange(event: wxPicker) {
  117. this.setData({
  118. select_act: Number(event.detail.value)
  119. }, () => this.upData())
  120. },
  121. }
  122. })
  123. }