index.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // components/toufang/index.ts
  2. namespace kehuyoushi {
  3. let scrollType = 0;
  4. let { getDetail } = 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. DayList: {},
  36. timeout: undefined,
  37. scrollTop1: "",
  38. scrollTop2: "",
  39. // scrollTop1: 0,
  40. // scrollTop2: 0,
  41. select_act: 0,
  42. select: [
  43. {
  44. text: "费用",
  45. proportionType: "fee",
  46. type: 3,
  47. unit: "元",
  48. },
  49. {
  50. text: "时长",
  51. proportionType: "timeSize",
  52. type: 2,
  53. unit: "分",
  54. },
  55. {
  56. text: "频次",
  57. proportionType: "pinci",
  58. type: 1,
  59. unit: "次",
  60. },
  61. {
  62. text: "客户量",
  63. proportionType: "customer",
  64. type: 4,
  65. unit: "个",
  66. },
  67. ]
  68. },
  69. /**
  70. * 组件的方法列表
  71. */
  72. methods: {
  73. init() {
  74. let channelItem = this.data.channel;
  75. let arrayItem = this.data.array;
  76. Promise.all([
  77. getDetail({
  78. channelId: channelItem.channelId,
  79. end: arrayItem.endDate,
  80. order: this.data.select[this.data.select_act].type,
  81. start: arrayItem.startDate
  82. }),
  83. ]).then((res: adDay[]) => {
  84. this.setData({
  85. DayList: res[0],
  86. })
  87. })
  88. },
  89. upData() {
  90. let channelItem = this.data.channel;
  91. let arrayItem = this.data.array;
  92. Promise.all([
  93. getDetail({
  94. channelId: channelItem.channelId,
  95. end: arrayItem.endDate,
  96. order: this.data.select[this.data.select_act].type,
  97. start: arrayItem.startDate
  98. }),
  99. ]).then((res: adDay[]) => {
  100. this.setData({
  101. DayList: res[0],
  102. })
  103. })
  104. },
  105. channelChange(event: wxPicker) {
  106. this.setData({
  107. select_act: Number(event.detail.value)
  108. }, () => this.upData())
  109. },
  110. dragEnd1(detail: any) {
  111. if (!this.data.DayList.now || !this.data.DayList.now.length || scrollType !== 0) return
  112. if (this.data.timeout) {
  113. clearTimeout(this.data.timeout);
  114. this.data.timeout = null;
  115. }
  116. this.data.timeout = setTimeout(() => {
  117. scrollType = 1;
  118. clearTimeout(this.data.timeout);
  119. this.data.timeout = null;
  120. let indiex = (detail.detail.scrollTop / 33).toFixed(0);
  121. let list = this.data.DayList.before[indiex] || {};
  122. let p = {
  123. scrollTop2: this.data.scrollTop2,
  124. scrollTop1: 'top' + indiex
  125. }
  126. for (let i = 0; i < this.data.DayList.now.length; i++) {
  127. const v = this.data.DayList.now[i];
  128. if (v.brand !== list.brand) continue
  129. // let ni = i - 2 > 0 ? i - 2 : 0
  130. p.scrollTop2 = 'bottom' + i
  131. // p.scrollTop2 = ni * 33
  132. break
  133. }
  134. this.setData(p)
  135. scrollType = 0
  136. }, 300);
  137. },
  138. dragEnd2(detail: any) {
  139. if (!this.data.DayList.now || !this.data.DayList.now.length || scrollType !== 0) return
  140. if (this.data.timeout) {
  141. clearTimeout(this.data.timeout);
  142. this.data.timeout = null;
  143. }
  144. console.log(this.data.timeout)
  145. this.data.timeout = setTimeout(() => {
  146. scrollType = 2;
  147. clearTimeout(this.data.timeout);
  148. this.data.timeout = null;
  149. let index = (detail.detail.scrollTop / 33).toFixed(0);
  150. let list = this.data.DayList.now[index] || {};
  151. let p = {
  152. scrollTop1: this.data.scrollTop1,
  153. scrollTop2: 'bottom' + index
  154. }
  155. for (let i = 0; i < this.data.DayList.before.length; i++) {
  156. const v = this.data.DayList.before[i];
  157. if (v.brand !== list.brand) continue
  158. console.log(v.brand)
  159. // let ni = i - 2 > 0 ? i - 2 : 0
  160. // p.scrollTop1 = ni * 33
  161. p.scrollTop1 = 'top' + i
  162. break
  163. }
  164. this.setData(p)
  165. scrollType = 0
  166. }, 300)
  167. },
  168. }
  169. })
  170. }