situationAnalysis.js 8.2 KB

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