index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. // pages/index/index.js
  2. import * as echarts from '../../ec-canvas/echarts';
  3. const app = getApp()
  4. import http from "../../utils/http"
  5. import util from "../../utils/util"
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. chartType: 0,
  12. menuH: '32px',
  13. safeTop: `40px`,
  14. ec: '',
  15. date: '',
  16. show: false,
  17. chartShow: true,
  18. starttime: '',
  19. endtime: '',
  20. info: '',
  21. xAxis: '',
  22. price: '',
  23. count: '',
  24. series: '',
  25. start: '',
  26. end: '',
  27. minDate: new Date(2023, 0, 1).getTime(),
  28. maxDate: new Date().getTime(),
  29. token: wx.getStorageSync('token'),
  30. config: ''
  31. },
  32. order(){
  33. if (!wx.getStorageSync('token')) {
  34. util.skip('/service/login/login')
  35. retturn
  36. }
  37. wx.requestSubscribeMessage({
  38. tmplIds: [app.globalData.templateconfig.shop_order_template,app.globalData.templateconfig.shop_finish_template,app.globalData.templateconfig.shop_sales_template],
  39. success :(res) =>{
  40. console.log(res)
  41. },
  42. fail :(e) =>{
  43. console.log(e)
  44. },
  45. complete :(res) =>{
  46. wx.switchTab({
  47. url: '/pages/order/order'
  48. })
  49. }
  50. })
  51. },
  52. /**
  53. * 生命周期函数--监听页面加载
  54. */
  55. onLoad(options) {
  56. this.setData({
  57. safeTop: `${app.globalData.safeTop}px`,
  58. menuH: `${app.globalData.menuH}px`,
  59. })
  60. },
  61. /**
  62. * 生命周期函数--监听页面显示
  63. */
  64. onShow() {
  65. this.setData({
  66. token: wx.getStorageSync('token')
  67. })
  68. this.getInfo()
  69. },
  70. onLoadConfig(option){
  71. this.setData({
  72. config: app.globalData.config
  73. })
  74. },
  75. timeShow() {
  76. this.setData({
  77. show: true,
  78. chartShow: false
  79. })
  80. },
  81. onDisplay() {
  82. this.setData({
  83. show: true,
  84. chartShow: false
  85. });
  86. },
  87. onClose() {
  88. this.setData({
  89. show: false,
  90. chartShow: true
  91. });
  92. },
  93. formatDate(date) {
  94. date = new Date(date);
  95. return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
  96. },
  97. onConfirm(event) {
  98. const [start, end] = event.detail;
  99. let starttime = new Date(start.toLocaleDateString()).getTime();
  100. let endtime = new Date(end.toLocaleDateString()).getTime();
  101. this.setData({
  102. show: false,
  103. starttime: starttime / 1000,
  104. endtime: endtime / 1000,
  105. date: `${util.formatTime(starttime,'yyyy/mm/dd')} - ${util.formatTime(endtime,'yyyy/mm/dd')}`,
  106. });
  107. this.getInfo()
  108. },
  109. //核销
  110. tosweep() {
  111. util.authSkip('/service/sweep/sweep')
  112. },
  113. // 平台公告
  114. toNotice() {
  115. wx.navigateTo({
  116. url: '/service/notice/notice'
  117. })
  118. },
  119. cutChart(e) {
  120. this.setData({
  121. chartType: e.currentTarget.dataset.type,
  122. chartShow: false,
  123. })
  124. if (this.data.chartType == 1) {
  125. this.setData({
  126. series: this.data.count,
  127. chartShow: true,
  128. ec: {
  129. onInit: this.initChart
  130. }
  131. })
  132. } else {
  133. this.setData({
  134. series: this.data.price,
  135. chartShow: true,
  136. ec: {
  137. onInit: this.initChart
  138. }
  139. })
  140. }
  141. },
  142. initChart(canvas, width, height) {
  143. const chart = echarts.init(canvas, null, {
  144. width: width,
  145. height: height
  146. });
  147. canvas.setChart(chart);
  148. var option = {
  149. xAxis: {
  150. type: 'category',
  151. data: this.data.xAxis
  152. },
  153. tooltip: {
  154. show: true,
  155. trigger: 'axis'
  156. },
  157. yAxis: {
  158. type: 'value',
  159. axisLabel: {
  160. interval: 0
  161. }
  162. },
  163. grid:{
  164. left:0,
  165. right:0,
  166. top:10,
  167. bottom:32,
  168. containLabel:true
  169. },
  170. series: [{
  171. data: this.data.series,
  172. type: 'line',
  173. itemStyle: {
  174. normal: {
  175. color: '#671CF7',
  176. lineStyle: {
  177. color: '#671CF7'
  178. }
  179. }
  180. },
  181. }]
  182. };
  183. chart.setOption(option);
  184. return chart;
  185. },
  186. getInfo() {
  187. if (!wx.getStorageSync('token')) return
  188. this.setData({
  189. chartShow: false
  190. })
  191. let data = {};
  192. if (this.data.starttime) {
  193. data['starttime'] = this.data.starttime
  194. data['endtime'] = this.data.endtime
  195. }
  196. http.post('shop/shophome', data, !this.data.info).then(res => {
  197. let xAxis = res.data.form.map(value => {
  198. return value.date
  199. })
  200. let price = res.data.form.map(value => {
  201. return value.price
  202. })
  203. let count = res.data.form.map(value => {
  204. return value.count
  205. })
  206. this.setData({
  207. info: res.data,
  208. xAxis: xAxis,
  209. price: price,
  210. count: count,
  211. date: `${this.formatDate(res.data.form[0].date)} - ${this.formatDate(res.data.form[res.data.form.length-1].date)}`,
  212. })
  213. if (this.data.chartType == 1) {
  214. this.setData({
  215. series: this.data.count,
  216. chartShow: true,
  217. ec: {
  218. onInit: this.initChart
  219. }
  220. })
  221. } else {
  222. this.setData({
  223. series: this.data.price,
  224. chartShow: true,
  225. ec: {
  226. onInit: this.initChart
  227. }
  228. })
  229. }
  230. })
  231. },
  232. /**
  233. * 生命周期函数--监听页面隐藏
  234. */
  235. onHide() {
  236. },
  237. /**
  238. * 生命周期函数--监听页面卸载
  239. */
  240. onUnload() {
  241. },
  242. /**
  243. * 页面相关事件处理函数--监听用户下拉动作
  244. */
  245. onPullDownRefresh() {
  246. },
  247. /**
  248. * 页面上拉触底事件的处理函数
  249. */
  250. onReachBottom() {
  251. },
  252. /**
  253. * 用户点击右上角分享
  254. */
  255. onShareAppMessage() {
  256. return {}
  257. }
  258. })