situationAnalysis.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. customerstype: ""
  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": 20231018164504,
  57. content
  58. }).then(res => {
  59. this.selectComponent('#ListBox').RefreshToComplete();
  60. console.log('客户列表', res)
  61. if (res.code != '1') return wx.showToast({
  62. title: res.data,
  63. icon: "none"
  64. })
  65. this.setData({
  66. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  67. "content.pageNumber": res.pageNumber + 1,
  68. "content.pageSize": res.pageSize,
  69. })
  70. this.selectComponent("#TimeRange").onCancel()
  71. if (init) _Http.basic({
  72. id: this.data.idname,
  73. content
  74. }).then(res1 => {
  75. console.log("图标", res1)
  76. this.initChart(res1.data, res.total);
  77. })
  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. upDateList() {
  187. _Http.updateList = () => {
  188. let content = JSON.parse(JSON.stringify(this.data.content));
  189. console.log("content", content)
  190. try {
  191. content.pageSize = (content.pageNumber - 1) * content.pageSize;
  192. content.pageNumber = 1;
  193. } catch (error) {
  194. console.log("error", error)
  195. }
  196. _Http.basic({
  197. id: '20231018164504',
  198. content
  199. }).then(res => {
  200. console.log("更新列表", res);
  201. if (res.code == '1') {
  202. this.setData({
  203. list: res.data
  204. })
  205. }
  206. })
  207. }
  208. },
  209. toDetail(e) {
  210. console.log(e)
  211. wx.navigateTo({
  212. url: '/packageA/setclient/detail?id=' + e.currentTarget.dataset.item.sa_customersid,
  213. })
  214. this.upDateList();
  215. },
  216. changeDate({
  217. detail
  218. }) {
  219. this.setData({
  220. "content.dateType": detail.dateType,
  221. "content.where.begdate": detail.begdate || "",
  222. "content.where.enddate": detail.enddate || ""
  223. })
  224. this.getList(true)
  225. }
  226. }
  227. })