index.ts 2.9 KB

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