SPmarketingExpenses.js 7.3 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. Component({
  8. options: {
  9. addGlobalClass: true
  10. },
  11. lifetimes: {
  12. attached: function () {
  13. getApp().globalData.Language.getLanguagePackage(this)
  14. this.setData({
  15. "content.dataid": wx.getStorageSync('userMsg').userid,
  16. "content.username": wx.getStorageSync('userMsg').name,
  17. })
  18. }
  19. },
  20. data: {
  21. dateTypes: ["本年", "本季", "本月"],
  22. "content": {
  23. pageNumber: 1,
  24. pageTotal: 1,
  25. dateType: "本年",
  26. type: 0,
  27. where: {
  28. begdate: "",
  29. enddate: "",
  30. isleave: "1",
  31. }
  32. },
  33. },
  34. methods: {
  35. async getList(init = false) {
  36. if (init.detail != undefined) init = init.detail;
  37. let content = this.data.content
  38. const {
  39. dataid,
  40. type,
  41. username,
  42. isleave
  43. } = getCurrentPages()[getCurrentPages().length - 1].data;
  44. if (content.dataid != dataid || content.type != type || isleave != isleave) init = true
  45. content.dataid = dataid;
  46. content.type = type;
  47. content.username = username;
  48. content.where.isleave = isleave;
  49. if (init) {
  50. content.pageNumber = 1;
  51. content.pageTotal = 1;
  52. content.where.customerstype = "";
  53. }
  54. if (content.pageNumber > content.pageTotal) return;
  55. _Http.basic({
  56. "id": 2024062610330602,
  57. content
  58. }).then(res => {
  59. this.selectComponent('#ListBox').automaticSetHei();
  60. this.selectComponent('#ListBox').RefreshToComplete();
  61. console.log('业务员排行列表', res)
  62. if (res.code != '1') return wx.showToast({
  63. title: res.data,
  64. icon: "none"
  65. })
  66. res.data = res.data.map(v => {
  67. const colors = ['#F56C6C', '#EF8E51', '#FFC148', '#999999'];
  68. v.color = colors[v.rowindex - 1] || colors[3];
  69. v.amount = CNY(v.amount)
  70. return v
  71. })
  72. this.setData({
  73. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  74. "content.pageNumber": res.pageNumber + 1,
  75. "content.pageSize": res.pageSize,
  76. })
  77. this.selectComponent("#TimeRange").onCancel()
  78. })
  79. },
  80. initChart(data, total) {
  81. const getMapText = getApp().globalData.Language.getMapText;
  82. let countDown = null,
  83. that = this;
  84. function changeUnwriteoffamounttype(index) {
  85. if (countDown) return;
  86. countDown = setTimeout(() => {
  87. clearTimeout(countDown)
  88. countDown = null;
  89. if (data[index].key != that.data.content.where.customerstype) that.setData({
  90. "content.where.customerstype": data[index].key || "",
  91. "content.pageNumber": 1,
  92. });
  93. that.getList()
  94. }, 200)
  95. };
  96. let option = {
  97. tooltip: {
  98. trigger: 'item',
  99. confine: true, // Ensure tooltip stays within chart boundaries
  100. formatter: function (params) {
  101. changeUnwriteoffamounttype(params.dataIndex)
  102. return `${getMapText(params.name)}: ${params.value} (${params.percent}%)`;
  103. },
  104. },
  105. legend: {
  106. type: 'scroll', // Enable scrollable legend
  107. bottom: '5%', // Moved legend to the bottom
  108. left: 'center',
  109. pageIconColor: '#333', // Customize page icon color
  110. pageTextStyle: {
  111. color: '#333' // Customize page text style
  112. }
  113. },
  114. series: [{
  115. type: 'pie',
  116. radius: ['40%', '70%'],
  117. center: ['50%', '42%'], // Adjusted to align with the new legend position
  118. endAngle: 360,
  119. data: data.map(v => {
  120. return {
  121. name: getMapText(v.key),
  122. value: (v.ratio).toFixed(2),
  123. }
  124. }),
  125. label: {
  126. normal: {
  127. show: true,
  128. position: 'outside',
  129. formatter: '{b}: {c} ({d}%)',
  130. textStyle: {
  131. fontSize: 12,
  132. color: '#333'
  133. }
  134. },
  135. emphasis: {
  136. show: true,
  137. textStyle: {
  138. fontSize: 14,
  139. fontWeight: 'bold'
  140. }
  141. },
  142. rich: {
  143. total: {
  144. fontSize: 20,
  145. fontWeight: 'bold',
  146. color: '#333'
  147. },
  148. desc: {
  149. fontSize: 12,
  150. color: '#999'
  151. }
  152. }
  153. },
  154. labelLine: {
  155. normal: {
  156. show: true,
  157. length: 10,
  158. length2: 10
  159. }
  160. }
  161. }]
  162. };
  163. option.graphic = {
  164. type: 'text',
  165. left: 'center',
  166. top: '35%', // Adjusted to align with the new series position
  167. style: {
  168. text: `${getMapText('客户总数')}\n\n${total}`,
  169. textAlign: 'center',
  170. fill: '#333',
  171. fontSize: 16,
  172. fontWeight: 'bold'
  173. }
  174. };
  175. this.chartComponent = this.selectComponent('#mychart');
  176. this.chartComponent.init((canvas, width, height, dpr) => {
  177. const chart = echarts.init(canvas, null, {
  178. width,
  179. height,
  180. devicePixelRatio: dpr
  181. });
  182. chart.setOption(option);
  183. return chart;
  184. });
  185. },
  186. changeDate({
  187. detail
  188. }) {
  189. this.setData({
  190. "content.dateType": detail.dateType,
  191. "content.where.begdate": detail.begdate || "",
  192. "content.where.enddate": detail.enddate || ""
  193. })
  194. this.getList(true)
  195. }
  196. }
  197. })