index.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // pages/channelRanking/index.ts
  2. const chartCatch: antvChart = {
  3. toufangfenxiChart: undefined
  4. }
  5. let { getChannelRank } = require('../../utils/api')
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. array: [
  12. {
  13. key: "fee",
  14. name: "费用",
  15. unit: "元",
  16. type: 1,
  17. },
  18. {
  19. key: "timeSize",
  20. name: "时长",
  21. unit: "分",
  22. type: 2,
  23. },
  24. {
  25. key: "pinci",
  26. name: "频次",
  27. unit: "次",
  28. type: 3,
  29. }
  30. ],
  31. list: [],
  32. array_act: 0,
  33. start: "",
  34. end: '',
  35. onInitChart: undefined,
  36. height: 0
  37. },
  38. startTimeChange(e: any) {
  39. this.setData({
  40. start: e.detail.value
  41. },()=> this.getselect())
  42. },
  43. endTimeChange(e: any) {
  44. this.setData({
  45. end: e.detail.value
  46. },()=> this.getselect())
  47. },
  48. bindPickerChange(e: any) {
  49. this.setData({
  50. array_act: e.detail.value
  51. },()=> this.getselect())
  52. },
  53. getselect(){
  54. let s = new Date(this.data.start), e= new Date(this.data.end);
  55. if(e.getTime() - s.getTime() < 0) return wx.showToast({
  56. title: "时间选择错误",
  57. icon: "none"
  58. })
  59. const p: any = {
  60. start: this.data.start,
  61. end: this.data.end,
  62. dataType: this.data.array[this.data.array_act].type
  63. }
  64. getChannelRank(p).then((res: any) => {
  65. p.onInitChart = (F2: any, config: any) => {
  66. if (chartCatch.toufangfenxiChart !== undefined) chartCatch.toufangfenxiChart.destroy(), chartCatch.toufangfenxiChart = undefined;
  67. chartCatch.toufangfenxiChart = new F2.Chart(config);
  68. const data = res|| [];
  69. if (!chartCatch.toufangfenxiChart) return
  70. chartCatch.toufangfenxiChart.legend(false)
  71. const key = this.data.array[this.data.array_act].key;
  72. let dataP:any = {};
  73. dataP[key] = {
  74. tickCount: 5
  75. }
  76. chartCatch.toufangfenxiChart.source(data.sort((a:any, b:any)=>a[key] - b[key]), dataP);
  77. chartCatch.toufangfenxiChart.coord({
  78. transposed: true
  79. });
  80. chartCatch.toufangfenxiChart.tooltip({
  81. triggerOn: ['touchstart', 'touchmove'],
  82. onShow: (ev: tooltipOnShow) => {
  83. let num:string = ev.items[0].value;
  84. if(Number(num) > 100000000) num = (Number(num) / 100000000).toFixed(2) + '亿';
  85. else if(Number(num) > 10000) num = (Number(num) / 10000).toFixed(2) + '万';
  86. ev.items[0].name = ev.items[0].title
  87. ev.items[0].value = num + this.data.array[this.data.array_act].unit
  88. }
  89. });
  90. chartCatch.toufangfenxiChart.axis(key, {
  91. label: (text: string, index: number, total: number) => {
  92. let align = 'center';
  93. if (index === 0) align = 'left';
  94. if (index === total - 1) align = 'right';
  95. let num:string|number = Number(text);
  96. if(num > 100000000) num = num / 100000000 + '亿';
  97. else if(num > 10000) num = num / 10000 + '万';
  98. return {
  99. textAlign: align,
  100. text: num
  101. }
  102. }
  103. });
  104. chartCatch.toufangfenxiChart.interval()
  105. .position('channelName*' + key)
  106. .color('#409eff')
  107. .adjust('stack');
  108. chartCatch.toufangfenxiChart.render();
  109. return chartCatch.toufangfenxiChart;
  110. }
  111. p.list = (res || [])
  112. p.height = (res || []).length < 2 ? 20 :(res || []).length * 5;
  113. this.setData(p)
  114. })
  115. },
  116. /**
  117. * 生命周期函数--监听页面加载
  118. */
  119. onLoad() {
  120. const nowDate = new Date();
  121. const date = new Date(nowDate.getTime() - 86400000);
  122. let month: string | number = date.getMonth() + 1;
  123. let day: string | number = date.getDate();
  124. month > 9 ? "" : month = '0' + month;
  125. day > 9 ? "" : day = '0' + day;
  126. const p: any = {
  127. start: [date.getFullYear(), month, day].join("-"),
  128. end: [date.getFullYear(), month, day].join("-"),
  129. dataType: this.data.array[this.data.array_act].type
  130. }
  131. getChannelRank(p).then((res: any) => {
  132. p.onInitChart = (F2: any, config: any) => {
  133. if (chartCatch.toufangfenxiChart !== undefined) chartCatch.toufangfenxiChart.destroy(), chartCatch.toufangfenxiChart = undefined;
  134. chartCatch.toufangfenxiChart = new F2.Chart(config);
  135. const data = res|| [];
  136. if (!chartCatch.toufangfenxiChart) return
  137. chartCatch.toufangfenxiChart.legend(false)
  138. const key = this.data.array[this.data.array_act].key;
  139. let dataP:any = {};
  140. dataP[key] = {
  141. tickCount: 5
  142. }
  143. chartCatch.toufangfenxiChart.source(data.sort((a:any, b:any)=>a[key] - b[key]), dataP);
  144. chartCatch.toufangfenxiChart.coord({
  145. transposed: true
  146. });
  147. chartCatch.toufangfenxiChart.tooltip({
  148. triggerOn: ['touchstart', 'touchmove'],
  149. onShow: (ev: tooltipOnShow) => {
  150. let num:string = ev.items[0].value;
  151. if(Number(num) > 100000000) num = (Number(num) / 100000000).toFixed(2) + '亿';
  152. else if(Number(num) > 10000) num = (Number(num) / 10000).toFixed(2) + '万';
  153. ev.items[0].name = ev.items[0].title
  154. ev.items[0].value = num + this.data.array[this.data.array_act].unit
  155. }
  156. });
  157. chartCatch.toufangfenxiChart.axis(key, {
  158. label: (text: string, index: number, total: number) => {
  159. let align = 'center';
  160. if (index === 0) align = 'left';
  161. if (index === total - 1) align = 'right';
  162. let num:string|number = Number(text);
  163. if(num > 100000000) num = num / 100000000 + '亿';
  164. else if(num > 10000) num = num / 10000 + '万';
  165. return {
  166. textAlign: align,
  167. text: num
  168. }
  169. }
  170. });
  171. chartCatch.toufangfenxiChart.interval()
  172. .position('channelName*' + key)
  173. .color('#409eff')
  174. .adjust('stack');
  175. chartCatch.toufangfenxiChart.render();
  176. return chartCatch.toufangfenxiChart;
  177. }
  178. p.list = (res || [])
  179. p.height = (res || []).length < 2 ? 20 :(res || []).length * 5;
  180. this.setData(p)
  181. })
  182. },
  183. upLine() {
  184. if (chartCatch.toufangfenxiChart === undefined) return
  185. chartCatch.toufangfenxiChart.clear()
  186. },
  187. /**
  188. * 生命周期函数--监听页面初次渲染完成
  189. */
  190. onReady() {
  191. },
  192. /**
  193. * 生命周期函数--监听页面显示
  194. */
  195. onShow() {
  196. /**
  197. * 生命周期函数--监听页面隐藏
  198. */
  199. },
  200. onHide() {
  201. },
  202. /**
  203. * 生命周期函数--监听页面卸载
  204. */
  205. onUnload() {
  206. },
  207. /**
  208. * 页面相关事件处理函数--监听用户下拉动作
  209. */
  210. onPullDownRefresh() {
  211. },
  212. /**
  213. * 页面上拉触底事件的处理函数
  214. */
  215. onReachBottom() {
  216. },
  217. /**
  218. * 用户点击右上角分享
  219. */
  220. onShareAppMessage() {
  221. }
  222. })