situationAnalysis.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. import * as echarts from '../../ec-canvas/echarts';
  8. Component({
  9. properties: {
  10. idname: {
  11. type: [String || Number]
  12. },
  13. keyName: {
  14. type: String
  15. }
  16. },
  17. options: {
  18. addGlobalClass: true
  19. },
  20. lifetimes: {
  21. attached: function () {
  22. getApp().globalData.Language.getLanguagePackage(this)
  23. this.setData({
  24. "content.dataid": wx.getStorageSync('userMsg').userid,
  25. "content.username": wx.getStorageSync('userMsg').name,
  26. })
  27. }
  28. },
  29. data: {
  30. dateTypes: ["全部", "本年"],
  31. "content": {
  32. pageNumber: 1,
  33. pageTotal: 1,
  34. dateType: "本年",
  35. type: 0,
  36. where: {
  37. begdate: "",
  38. enddate: "",
  39. isleave: "1",
  40. }
  41. },
  42. filterShow: false,
  43. filtratelist: [{
  44. label: "项目状态",
  45. index: null,
  46. showName: "value", //显示字段
  47. valueKey: "status", //返回Key
  48. selectKey: "value", //传参 代表选着字段 不传参返回整个选择对象
  49. value: "", //选中值
  50. type: "checkbox",
  51. list: [{
  52. value: "跟进中"
  53. }, {
  54. value: "已成交"
  55. }, {
  56. value: "已失败"
  57. }, {
  58. value: "已结案"
  59. }]
  60. }]
  61. },
  62. methods: {
  63. async getList(init = false) {
  64. console.log(13123)
  65. if (init.detail != undefined) init = init.detail;
  66. let content = this.data.content
  67. const {
  68. dataid,
  69. type,
  70. username,
  71. isleave
  72. } = getCurrentPages()[getCurrentPages().length - 1].data;
  73. if (content.dataid != dataid || content.type != type || isleave != isleave) init = true
  74. content.dataid = dataid;
  75. content.type = type;
  76. content.username = username;
  77. content.where.isleave = isleave;
  78. if (init) {
  79. content.pageNumber = 1;
  80. content.pageTotal = 1;
  81. content.where[this.data.keyName] = "";
  82. }
  83. if (content.pageNumber > content.pageTotal) return;
  84. _Http.basic({
  85. "id": 20231019090104,
  86. content
  87. }).then(res => {
  88. this.selectComponent('#ListBox').automaticSetHei();
  89. this.selectComponent('#ListBox').RefreshToComplete();
  90. console.log('项目列表', res)
  91. if (res.code != '1') return wx.showToast({
  92. title: res.data,
  93. icon: "none"
  94. })
  95. res.data = res.data.map(v => {
  96. v.signamount_due = CNY(v.signamount_due)
  97. v.dealamount = CNY(v.dealamount)
  98. return v
  99. })
  100. this.setData({
  101. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  102. "content.pageNumber": res.pageNumber + 1,
  103. "content.pageSize": res.pageSize,
  104. })
  105. this.selectComponent("#TimeRange").onCancel()
  106. if (init) _Http.basic({
  107. id: this.data.idname,
  108. content
  109. }).then(res1 => {
  110. console.log("图标", res1)
  111. this.initChart(res1.data, res.total);
  112. })
  113. })
  114. },
  115. initChart(data, total) {
  116. const getMapText = getApp().globalData.Language.getMapText;
  117. let countDown = null,
  118. that = this;
  119. function changeUnwriteoffamounttype(index) {
  120. if (countDown) return;
  121. countDown = setTimeout(() => {
  122. clearTimeout(countDown)
  123. countDown = null;
  124. let value = data[index].key,
  125. keyName = that.data.keyName;
  126. if (keyName == 'projecttype') {
  127. value = value.split("-")[0]
  128. }
  129. if (data[index].key != that.data.content.where[keyName]) that.setData({
  130. [`content.where.${keyName}`]: value || "",
  131. "content.pageNumber": 1,
  132. });
  133. that.getList()
  134. }, 200)
  135. };
  136. let option = {
  137. tooltip: {
  138. trigger: 'item',
  139. confine: true, // Ensure tooltip stays within chart boundaries
  140. formatter: function (params) {
  141. changeUnwriteoffamounttype(params.dataIndex)
  142. return `${getMapText(params.name)}: ${params.value} (${params.percent}%)`;
  143. },
  144. },
  145. legend: {
  146. type: 'scroll', // Enable scrollable legend
  147. bottom: '5%', // Moved legend to the bottom
  148. left: 'center',
  149. pageIconColor: '#333', // Customize page icon color
  150. pageTextStyle: {
  151. color: '#333' // Customize page text style
  152. }
  153. },
  154. series: [{
  155. type: 'pie',
  156. radius: ['40%', '70%'],
  157. center: ['50%', '42%'], // Adjusted to align with the new legend position
  158. endAngle: 360,
  159. data: data.map(v => {
  160. return {
  161. name: getMapText(v.key),
  162. value: (v.ratio).toFixed(2),
  163. }
  164. }),
  165. label: {
  166. normal: {
  167. show: true,
  168. position: 'outside',
  169. formatter: '{b}: {c} ({d}%)',
  170. textStyle: {
  171. fontSize: 12,
  172. color: '#333'
  173. }
  174. },
  175. emphasis: {
  176. show: true,
  177. textStyle: {
  178. fontSize: 14,
  179. fontWeight: 'bold'
  180. }
  181. },
  182. rich: {
  183. total: {
  184. fontSize: 20,
  185. fontWeight: 'bold',
  186. color: '#333'
  187. },
  188. desc: {
  189. fontSize: 12,
  190. color: '#999'
  191. }
  192. }
  193. },
  194. labelLine: {
  195. normal: {
  196. show: true,
  197. length: 10,
  198. length2: 10
  199. }
  200. }
  201. }]
  202. };
  203. option.graphic = {
  204. type: 'text',
  205. left: 'center',
  206. top: '35%', // Adjusted to align with the new series position
  207. style: {
  208. text: `${getMapText('项目总数')}\n\n${total}`,
  209. textAlign: 'center',
  210. fill: '#333',
  211. fontSize: 16,
  212. fontWeight: 'bold'
  213. }
  214. };
  215. this.chartComponent = this.selectComponent('#mychart');
  216. this.chartComponent.init((canvas, width, height, dpr) => {
  217. const chart = echarts.init(canvas, null, {
  218. width,
  219. height,
  220. devicePixelRatio: dpr
  221. });
  222. chart.setOption(option);
  223. return chart;
  224. });
  225. },
  226. upDateList() {
  227. _Http.updateList = () => {
  228. let content = JSON.parse(JSON.stringify(this.data.content));
  229. console.log("content", content)
  230. try {
  231. content.pageSize = (content.pageNumber - 1) * content.pageSize;
  232. content.pageNumber = 1;
  233. } catch (error) {
  234. console.log("error", error)
  235. }
  236. _Http.basic({
  237. id: '20231019090104',
  238. content
  239. }).then(res => {
  240. console.log("更新列表", res);
  241. if (res.code == '1') {
  242. this.setData({
  243. list: res.data
  244. })
  245. }
  246. })
  247. }
  248. },
  249. toDetail(e) {
  250. console.log(e)
  251. wx.navigateTo({
  252. url: '/packageA/project/detail?id=' + e.currentTarget.dataset.item.sa_projectid,
  253. })
  254. this.upDateList();
  255. },
  256. changeDate({
  257. detail
  258. }) {
  259. this.setData({
  260. "content.dateType": detail.dateType,
  261. "content.where.begdate": detail.begdate || "",
  262. "content.where.enddate": detail.enddate || ""
  263. })
  264. this.getList(true)
  265. },
  266. clickOpen() {
  267. this.setData({
  268. filterShow: true
  269. })
  270. },
  271. /* 处理筛选 */
  272. handleFilter({
  273. detail
  274. }) {
  275. if (detail.name == "confirm") {
  276. this.setData({
  277. "content.where.status": detail.status
  278. })
  279. this.selectComponent('#Filtrate').setShowArrText(detail.status)
  280. this.getList(true)
  281. } else if (detail.name == 'reset') {
  282. this.setData({
  283. "content.where.status": []
  284. })
  285. this.selectComponent('#Filtrate').setShowArrText([])
  286. this.getList(true)
  287. }
  288. },
  289. }
  290. })