situationAnalysis.js 9.3 KB

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