situationAnalysis.js 6.2 KB

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