SituationStatistics.js 11 KB

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