index.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. const _Http = getApp().globalData.http,
  2. currency = require("../../utils/currency"),
  3. CNY = (value, symbol = "¥", precision = 2) => currency(value, {
  4. symbol,
  5. precision
  6. }).format();
  7. import * as echarts from '../ec-canvas/echarts';
  8. Component({
  9. properties: {},
  10. options: {
  11. addGlobalClass: true
  12. },
  13. lifetimes: {
  14. attached: function () {
  15. getApp().globalData.Language.getLanguagePackage(this)
  16. this.setData({
  17. auth: JSON.stringify(wx.getStorageSync('auth')),
  18. userMsg: JSON.stringify(wx.getStorageSync('userMsg')),
  19. site: JSON.stringify(wx.getStorageSync('siteP')),
  20. templetList: JSON.stringify(wx.getStorageSync('templetList')),
  21. languagecode: wx.getStorageSync('languagecode'),
  22. })
  23. }
  24. },
  25. data: {
  26. dateTypes: ["全部", "本年", "本月"],
  27. "content": {
  28. pageNumber: 1,
  29. pageTotal: 1,
  30. dataid: wx.getStorageSync('userMsg').userid,
  31. username: wx.getStorageSync('userMsg').name,
  32. dateType: "本年",
  33. dataType: "金额",
  34. type: 0,
  35. where: {
  36. begdate: "",
  37. enddate: "",
  38. isleave: "1",
  39. type: "",
  40. }
  41. },
  42. },
  43. methods: {
  44. async getList(init = false) {
  45. if (init.detail != undefined) init = init.detail;
  46. let content = this.data.content
  47. const {
  48. dataid,
  49. type,
  50. username,
  51. isleave
  52. } = getCurrentPages()[getCurrentPages().length - 1].data;
  53. if (content.dataid != dataid || content.type != type || isleave != isleave) init = true
  54. content.dataid = dataid;
  55. content.type = type;
  56. content.username = username;
  57. content.where.isleave = isleave;
  58. const dividend = wx.getStorageSync('languagecode') == 'ZH' ? 10000 : 1000,
  59. getMapText = getApp().globalData.Language.getMapText;
  60. if (init) {
  61. content.pageNumber = 1;
  62. content.pageTotal = 1;
  63. }
  64. if (content.pageNumber > content.pageTotal) return;
  65. _Http.basic({
  66. "id": 20231012134604,
  67. content
  68. }).then(res => {
  69. this.selectComponent('#ListBox').RefreshToComplete();
  70. console.log("订单类型占比分析", res)
  71. if (res.code != '1') return wx.showToast({
  72. title: res.data,
  73. icon: "none"
  74. })
  75. res.data = res.data.map(v => {
  76. v.amount = CNY(v.amount)
  77. v.returnamount = CNY(v.returnamount)
  78. return v
  79. })
  80. this.setData({
  81. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  82. "content.pageNumber": res.pageNumber + 1,
  83. "content.pageSize": res.pageSize,
  84. })
  85. this.selectComponent("#TimeRange").onCancel()
  86. this.initChart(res.data[0].ratio, content.dataType == '金额' ? CNY(res.data[0].ratio[0].total / dividend) : res.data[0].ratio[0].total, getMapText);
  87. })
  88. },
  89. initChart(data, total, getMapText) {
  90. let option = {
  91. tooltip: {
  92. trigger: 'item'
  93. },
  94. legend: {
  95. bottom: '5%', // Moved legend to the bottom
  96. left: 'center'
  97. },
  98. series: [{
  99. type: 'pie',
  100. radius: ['40%', '70%'],
  101. center: ['50%', '42%'], // Adjusted to align with the new legend position
  102. endAngle: 360,
  103. data: data.map(v => {
  104. return {
  105. name: getMapText(v.type),
  106. value: (v.ratio * 100).toFixed(2),
  107. itemStyle: {
  108. color: {
  109. '标准订单': '#5B8FF9',
  110. '特殊订单': '#5AD8A6',
  111. '促销订单': '#5D7092',
  112. '项目订单': '#F6BD16',
  113. '工具订单': '#6F5EF9',
  114. '工具借用订单': '#6DC8EC'
  115. } [v.type] || '#CCCCCC' // Default color if type is not matched
  116. }
  117. }
  118. }),
  119. label: {
  120. normal: {
  121. show: true,
  122. position: 'outside',
  123. formatter: '{b}: {c} ({d}%)',
  124. textStyle: {
  125. fontSize: 12,
  126. color: '#333'
  127. }
  128. },
  129. emphasis: {
  130. show: true,
  131. textStyle: {
  132. fontSize: 14,
  133. fontWeight: 'bold'
  134. }
  135. },
  136. rich: {
  137. total: {
  138. fontSize: 20,
  139. fontWeight: 'bold',
  140. color: '#333'
  141. },
  142. desc: {
  143. fontSize: 12,
  144. color: '#999'
  145. }
  146. }
  147. },
  148. labelLine: {
  149. normal: {
  150. show: true,
  151. length: 10,
  152. length2: 10
  153. }
  154. }
  155. }]
  156. };
  157. option.graphic = {
  158. type: 'text',
  159. left: 'center',
  160. top: '35%', // Adjusted to align with the new series position
  161. style: {
  162. text: `${getMapText('总计')}\n\n${total}`,
  163. textAlign: 'center',
  164. fill: '#333',
  165. fontSize: 16,
  166. fontWeight: 'bold'
  167. }
  168. };
  169. this.chartComponent = this.selectComponent('#mychart');
  170. this.chartComponent.init((canvas, width, height, dpr) => {
  171. const chart = echarts.init(canvas, null, {
  172. width,
  173. height,
  174. devicePixelRatio: dpr
  175. });
  176. chart.setOption(option);
  177. return chart;
  178. });
  179. },
  180. changeDate({
  181. detail
  182. }) {
  183. this.setData({
  184. "content.dateType": detail.dateType,
  185. "content.where.begdate": detail.begdate || "",
  186. "content.where.enddate": detail.enddate || ""
  187. })
  188. this.getList(true)
  189. },
  190. changeType(e) {
  191. const {
  192. name
  193. } = e.currentTarget.dataset;
  194. if (name == this.data.content.dataType) return;
  195. this.setData({
  196. "content.dataType": name
  197. })
  198. this.getList(true)
  199. }
  200. }
  201. })