微信小店联盟带货小程序

index.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. // pages/distribution/index.js
  2. import * as echarts from '../../ec-canvas/echarts';
  3. let chart = null;
  4. // 初始化图表
  5. function initChart(canvas, width, height, dpr) {
  6. chart = echarts.init(canvas, null, {
  7. width: width,
  8. height: height,
  9. devicePixelRatio: dpr
  10. });
  11. canvas.setChart(chart);
  12. return chart;
  13. }
  14. Page({
  15. data: {
  16. userInfo: {
  17. avatarUrl: '',
  18. nickName: '',
  19. distributionId: '',
  20. level: '普通推广员',
  21. upgradeNeed: '5000.00',
  22. currentAmount: '2390.00',
  23. targetAmount: '8000.00',
  24. progress: 30 // 进度百分比
  25. },
  26. earnings: {
  27. total: '5280.00',
  28. today: '99.00',
  29. yesterday: '188.00',
  30. month: '2390.00'
  31. },
  32. promotion: {
  33. orderCount: 128,
  34. orderTrend: 15.8,
  35. teamCount: 45,
  36. teamTrend: -5.2,
  37. visitCount: 1234,
  38. visitTrend: 23.5,
  39. convertRate: 12.8,
  40. convertTrend: 3.2
  41. },
  42. levelList: [{
  43. name: '普通推广员',
  44. commission: 10,
  45. teamCommission: 0,
  46. requirement: 0
  47. }, {
  48. name: '高级推广员',
  49. commission: 15,
  50. teamCommission: 3,
  51. requirement: 8000
  52. }, {
  53. name: '金牌推广员',
  54. commission: 20,
  55. teamCommission: 5,
  56. requirement: 20000
  57. }, {
  58. name: '钻石推广员',
  59. commission: 25,
  60. teamCommission: 8,
  61. requirement: 50000
  62. }],
  63. currentChart: 'earnings',
  64. ec: {
  65. onInit: initChart
  66. },
  67. chartData: {
  68. earnings: {
  69. dates: [],
  70. values: []
  71. },
  72. orders: {
  73. dates: [],
  74. values: []
  75. },
  76. team: {
  77. dates: [],
  78. values: []
  79. }
  80. }
  81. },
  82. onLoad() {
  83. this.getUserInfo()
  84. this.getDistributionInfo()
  85. this.loadChartData();
  86. },
  87. // 获取用户信息
  88. getUserInfo() {
  89. // TODO: 调用后端API获取用户信息
  90. const userInfo = wx.getStorageSync('userInfo')
  91. if (userInfo) {
  92. this.setData({
  93. 'userInfo.avatarUrl': userInfo.avatarUrl,
  94. 'userInfo.nickName': userInfo.nickName
  95. })
  96. }
  97. },
  98. // 获取分销数据
  99. getDistributionInfo() {
  100. // TODO: 调用后端API获取分销数据
  101. // 这里使用模拟数据
  102. },
  103. // 导航到推广海报页面
  104. navigateToPromotion() {
  105. wx.navigateTo({
  106. url: '/pages/promotion/poster'
  107. })
  108. },
  109. // 导航到推广二维码页面
  110. navigateToQrcode() {
  111. wx.navigateTo({
  112. url: '/pages/promotion/qrcode'
  113. })
  114. },
  115. // 复制推广链接
  116. copyLink() {
  117. // TODO: 获取推广链接
  118. const link = 'https://example.com/share/123456'
  119. wx.setClipboardData({
  120. data: link,
  121. success: () => {
  122. wx.showToast({
  123. title: '链接已复制',
  124. icon: 'success'
  125. })
  126. }
  127. })
  128. },
  129. // 导航到分销规则页面
  130. navigateToRules() {
  131. wx.navigateTo({
  132. url: '/pages/distribution/rules'
  133. })
  134. },
  135. // 显示等级详情
  136. showLevelDetail() {
  137. wx.navigateTo({
  138. url: '/pages/distribution/level'
  139. })
  140. },
  141. // 加载图表数据
  142. loadChartData: function () {
  143. // 模拟7天数据
  144. const now = new Date();
  145. const dates = [];
  146. const data = {
  147. earnings: [],
  148. orders: [],
  149. team: []
  150. };
  151. for (let i = 6; i >= 0; i--) {
  152. const date = new Date(now);
  153. date.setDate(date.getDate() - i);
  154. dates.push(date.getDate() + '日');
  155. // 模拟数据
  156. data.earnings.push(+(Math.random() * 1000).toFixed(2));
  157. data.orders.push(Math.floor(Math.random() * 50));
  158. data.team.push(Math.floor(Math.random() * 20));
  159. }
  160. this.setData({
  161. 'chartData.earnings.dates': dates,
  162. 'chartData.earnings.values': data.earnings,
  163. 'chartData.orders.dates': dates,
  164. 'chartData.orders.values': data.orders,
  165. 'chartData.team.dates': dates,
  166. 'chartData.team.values': data.team
  167. }, () => {
  168. this.updateChart();
  169. });
  170. },
  171. // 切换图表
  172. switchChart: function (e) {
  173. const type = e.currentTarget.dataset.type;
  174. this.setData({ currentChart: type }, () => {
  175. this.updateChart();
  176. });
  177. },
  178. // 更新图表
  179. updateChart: function () {
  180. if (!chart) return;
  181. const data = this.data.chartData[this.data.currentChart];
  182. const option = {
  183. color: ['#ff4d4f'],
  184. grid: {
  185. left: '3%',
  186. right: '4%',
  187. bottom: '3%',
  188. top: '3%',
  189. containLabel: true
  190. },
  191. xAxis: {
  192. type: 'category',
  193. boundaryGap: false,
  194. data: data.dates,
  195. axisLine: {
  196. lineStyle: {
  197. color: '#999'
  198. }
  199. },
  200. axisLabel: {
  201. color: '#666',
  202. fontSize: 12
  203. }
  204. },
  205. yAxis: {
  206. type: 'value',
  207. axisLine: {
  208. show: false
  209. },
  210. axisTick: {
  211. show: false
  212. },
  213. axisLabel: {
  214. color: '#666',
  215. fontSize: 12
  216. },
  217. splitLine: {
  218. lineStyle: {
  219. color: '#f5f5f5'
  220. }
  221. }
  222. },
  223. series: [{
  224. name: this.getSeriesName(),
  225. type: 'line',
  226. smooth: true,
  227. data: data.values,
  228. areaStyle: {
  229. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
  230. offset: 0,
  231. color: 'rgba(255, 77, 79, 0.3)'
  232. }, {
  233. offset: 1,
  234. color: 'rgba(255, 77, 79, 0.1)'
  235. }])
  236. },
  237. lineStyle: {
  238. width: 2
  239. },
  240. symbol: 'circle',
  241. symbolSize: 6
  242. }]
  243. };
  244. chart.setOption(option);
  245. },
  246. // 获取系列名称
  247. getSeriesName: function () {
  248. const names = {
  249. earnings: '佣金收入',
  250. orders: '推广订单',
  251. team: '团队成员'
  252. };
  253. return names[this.data.currentChart];
  254. },
  255. onPullDownRefresh() {
  256. this.getUserInfo()
  257. this.getDistributionInfo()
  258. this.loadChartData();
  259. wx.stopPullDownRefresh()
  260. },
  261. onShareAppMessage() {
  262. return {
  263. title: '邀请你加入分销团队',
  264. path: '/pages/index/index?inviter=' + this.data.userInfo.distributionId,
  265. imageUrl: '/static/images/share.jpg'
  266. }
  267. }
  268. })