index.js 8.5 KB

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