index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import * as echarts from '../../ec-canvas/echarts';
  2. const util = require('../../utils/util.js')
  3. const app = getApp();
  4. var barec1 = null
  5. var barec2 = null
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. ec1: {
  12. onInit: function (canvas, width, height,dpr) {
  13. barec1 = echarts.init(canvas, null, {
  14. width: width,
  15. height: height,
  16. devicePixelRatio: dpr
  17. });
  18. canvas.setChart(barec1);
  19. return barec1;
  20. }
  21. },
  22. ec2: {
  23. onInit: function (canvas, width, height,dpr) {
  24. barec2 = echarts.init(canvas, null, {
  25. width: width,
  26. height: height,
  27. devicePixelRatio: dpr
  28. });
  29. canvas.setChart(barec2);
  30. return barec2;
  31. }
  32. },
  33. dateList: [{
  34. id: 1,
  35. name: "七天"
  36. }, {
  37. id: 2,
  38. name: "本月"
  39. }, {
  40. id: 3,
  41. name: "今年"
  42. }],
  43. searchParams: {
  44. dateType: '',
  45. dateTypeName: ''
  46. },
  47. saleXdata:[],
  48. saleYdata:[],
  49. saleOdata:[],
  50. userInfo:{},
  51. },
  52. /**
  53. * 生命周期函数--监听页面加载
  54. */
  55. onLoad: function (options) {
  56. this.setData({
  57. userInfo: app.globalData.userInfo
  58. })
  59. this.getStatis();
  60. },
  61. /**
  62. * 用户点击右上角分享
  63. */
  64. onShareAppMessage: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面显示
  68. */
  69. onShow: function () {
  70. if (typeof this.getTabBar === 'function' &&
  71. this.getTabBar()) {
  72. this.getTabBar().setData({
  73. current: 1 // 根据tab的索引值设置
  74. })
  75. }
  76. },
  77. bindDatePickerChange: function (e) {
  78. var item = this.data.dateList[e.detail.value]
  79. this.setData({
  80. ['searchParams.dateType']: e.detail.value,
  81. ['searchParams.dateTypeName']: item.name
  82. })
  83. },
  84. bindData() {
  85. var option = {
  86. color: ["#37A2DA"],
  87. grid: {
  88. left: '5%',
  89. right: '5%',
  90. top: '5%',
  91. bottom: '5%',
  92. containLabel: true
  93. },
  94. tooltip: {
  95. show: true,
  96. trigger: 'axis'
  97. },
  98. xAxis: {
  99. type: 'category',
  100. boundaryGap: false,
  101. data: this.data.saleXdata,
  102. },
  103. yAxis: {
  104. x: 'center',
  105. type: 'value',
  106. splitLine: {
  107. lineStyle: {
  108. type: 'dashed'
  109. }
  110. }
  111. },
  112. series: [{
  113. name: '销售总额',
  114. type: 'line',
  115. smooth: true,
  116. data: this.data.saleYdata
  117. }]
  118. };
  119. var option2 = {
  120. color: ["#37A2DA"],
  121. grid: {
  122. left: '5%',
  123. right: '5%',
  124. top: '5%',
  125. bottom: '5%',
  126. containLabel: true
  127. },
  128. tooltip: {
  129. show: true,
  130. trigger: 'axis'
  131. },
  132. xAxis: {
  133. type: 'category',
  134. boundaryGap: false,
  135. data: this.data.saleXdata,
  136. },
  137. yAxis: {
  138. x: 'center',
  139. type: 'value',
  140. splitLine: {
  141. lineStyle: {
  142. type: 'dashed'
  143. }
  144. }
  145. },
  146. series: [{
  147. name: '订单数量',
  148. type: 'line',
  149. smooth: true,
  150. data: this.data.saleOdata
  151. }]
  152. };
  153. console.log(option)
  154. console.log(option2)
  155. barec1.setOption(option);
  156. barec2.setOption(option2);
  157. },
  158. toList(){
  159. wx.navigateTo({
  160. url: 'salesTotalList',
  161. })
  162. },
  163. getStatis(){
  164. if(!app.globalData.isLogin){
  165. return
  166. }
  167. let that = this;
  168. if(this.data.userInfo.mgvmRole==1){
  169. return;
  170. }
  171. util.request(util.api.salesOrderApp, null, "GET", false, true,app.globalData.token).then((res)=>{
  172. if (res.code == 200) {
  173. let dataList = res.result;
  174. let saleXdata = [];
  175. let saleYdata = [];
  176. let saleOdata = [];
  177. dataList.forEach(d => {
  178. // d.orderNumber
  179. if(this.data.userInfo.mgvmRole==3){
  180. saleYdata.push(d.agentMoney==null?0:d.agentMoney)
  181. }else if(this.data.userInfo.mgvmRole==2){
  182. saleYdata.push(d.storeCommission==null?0:d.storeCommission)
  183. }else if(this.data.userInfo.mgvmRole==0){
  184. console.log(d.productSellPrice)
  185. saleYdata.push(d.productSellPrice==null?0:d.productSellPrice)
  186. }else if(this.data.userInfo.mgvmRole==4){
  187. saleYdata.push(d.areaAgentMoney==null?0:d.areaAgentMoney)
  188. }
  189. let createTime = util.formatDate(d.createTime,'MM')+"-"+util.formatDate(d.createTime,'dd')
  190. saleXdata.push( createTime)
  191. saleOdata.push(d.orderNumber==null?0:d.orderNumber)
  192. });
  193. that.setData({
  194. saleYdata:saleYdata,
  195. saleXdata:saleXdata,
  196. saleOdata:saleOdata
  197. })
  198. setTimeout(this.bindData, 1000);
  199. }else{
  200. util.toast(res.message);
  201. }
  202. }).catch((res) => {})
  203. }
  204. })