index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  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. options: {
  11. addGlobalClass: true,
  12. },
  13. lifetimes: {
  14. attached: function () {
  15. getApp().globalData.Language.getLanguagePackage(this)
  16. this.setData({
  17. auth: JSON.stringify(wx.getStorageSync('auth')),
  18. userMsg: JSON.stringify(wx.getStorageSync('userMsg')),
  19. site: JSON.stringify(wx.getStorageSync('siteP')),
  20. templetList: JSON.stringify(wx.getStorageSync('templetList')),
  21. languagecode: wx.getStorageSync('languagecode'),
  22. "content.dataid": wx.getStorageSync('userMsg').userid,
  23. "content.username": wx.getStorageSync('userMsg').name,
  24. })
  25. _Http.basic({
  26. "classname": "sysmanage.develop.optiontype.optiontype",
  27. "method": "optiontypeselect",
  28. "content": {
  29. "pageNumber": 1,
  30. "pageSize": 1000,
  31. "typename": "ordertype",
  32. "parameter": {}
  33. },
  34. }).then(res => {
  35. console.log("订单类型", res)
  36. if (res.code != '1') return;
  37. res.data.unshift({
  38. remarks: '全部',
  39. value: ""
  40. })
  41. this.setData({
  42. types: res.data
  43. })
  44. })
  45. _Http.basic({
  46. "classname": "sysmanage.develop.optiontype.optiontype",
  47. "method": "optiontypeselect",
  48. "content": {
  49. "pageNumber": 1,
  50. "pageSize": 1000,
  51. "typename": "tradefield",
  52. },
  53. }).then(res => {
  54. console.log("领域", res)
  55. if (res.code != '1') return;
  56. res.data.unshift({
  57. remarks: '全部',
  58. value: "",
  59. color: "#3874F6"
  60. })
  61. this.setData({
  62. tradefields: res.data
  63. })
  64. })
  65. _Http.basic({
  66. "id": "20220922085103",
  67. "version": 1,
  68. "content": {
  69. pageSize: 1000,
  70. "where": {
  71. "condition": ""
  72. }
  73. }
  74. }).then(res => {
  75. console.log("获取品牌", res)
  76. if (res.code != '1') return;
  77. res.data = res.data.map(v => {
  78. return {
  79. remarks: v.brandname,
  80. value: v.sa_brandid,
  81. }
  82. })
  83. res.data.unshift({
  84. remarks: '全部',
  85. value: "",
  86. color: "#3874F6"
  87. })
  88. this.setData({
  89. brands: res.data
  90. })
  91. })
  92. }
  93. },
  94. data: {
  95. dateTypes: ["全部", "本年", "本月"],
  96. "content": {
  97. pageNumber: 1,
  98. pageTotal: 1,
  99. dateType: "本年",
  100. dataType: "金额",
  101. type: 0,
  102. itemclass: "一级类别",
  103. where: {
  104. begdate: "",
  105. enddate: "",
  106. isleave: "1",
  107. type: "",
  108. tradefield: "",
  109. sa_brandid: ""
  110. }
  111. },
  112. itemclassList: [{
  113. remarks: '一级类别',
  114. value: "一级类别",
  115. color: "#3874F6"
  116. }, {
  117. remarks: '二级类别',
  118. value: "二级类别",
  119. }],
  120. total: 0
  121. },
  122. methods: {
  123. async getList(init = false) {
  124. if (init.detail != undefined) init = init.detail;
  125. let content = this.data.content
  126. const {
  127. dataid,
  128. type,
  129. username,
  130. isleave
  131. } = getCurrentPages()[getCurrentPages().length - 1].data;
  132. if (content.dataid != dataid || content.type != type || isleave != isleave) init = true
  133. content.dataid = dataid;
  134. content.type = type;
  135. content.username = username;
  136. content.where.isleave = isleave;
  137. const dividend = wx.getStorageSync('languagecode') == 'ZH' ? 10000 : 1000,
  138. getMapText = getApp().globalData.Language.getMapText;
  139. if (init) {
  140. content.pageNumber = 1;
  141. content.pageTotal = 1;
  142. }
  143. console.log(content)
  144. if (content.pageNumber > content.pageTotal) return;
  145. console.log(2)
  146. _Http.basic({
  147. "id": 20240524160004,
  148. content
  149. }).then(res => {
  150. this.selectComponent('#ListBox').automaticSetHei();
  151. this.selectComponent('#ListBox').RefreshToComplete();
  152. console.log("订单产品类别占比分析", res)
  153. if (res.code != '1') return wx.showToast({
  154. title: res.data,
  155. icon: "none"
  156. })
  157. res.data = res.data.map(v => {
  158. v.amount = CNY(v.amount)
  159. v.returnamount = CNY(v.returnamount)
  160. v.itemclassamount = CNY(v.itemclassamount)
  161. return v
  162. })
  163. this.setData({
  164. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  165. "content.pageNumber": res.pageNumber + 1,
  166. "content.pageTotal": res.pageTotal,
  167. "content.pageSize": res.pageSize,
  168. total: res.total,
  169. })
  170. try {
  171. this.selectComponent("#TimeRange").onCancel()
  172. } catch (error) {
  173. }
  174. try {
  175. this.selectAllComponents("#Filtrate").forEach(v => v.onCancel())
  176. } catch (error) {
  177. }
  178. if (init) this.initChart(res.data[0].ratio.filter(v => v.ratio), content.dataType == '金额' ? CNY(res.data[0].ratio[0].total / dividend) : res.data[0].ratio[0].total, getMapText);
  179. })
  180. },
  181. initChart(data, total, getMapText) {
  182. let countDown = null,
  183. that = this;
  184. function changeUnwriteoffamounttype(params) {
  185. if (countDown) return;
  186. countDown = setTimeout(() => {
  187. clearTimeout(countDown)
  188. countDown = null;
  189. if (params.itemclassid != that.data.content.where.itemclassid) {
  190. that.setData({
  191. "content.where.itemclassid": params.itemclassid,
  192. "content.pageNumber": 1,
  193. itemclassfullname: params.itemclassfullname
  194. })
  195. }
  196. that.getList()
  197. }, 200)
  198. };
  199. let option = {
  200. tooltip: {
  201. trigger: 'item',
  202. formatter: function (params) {
  203. if (params.value - 0) changeUnwriteoffamounttype(data[params.dataIndex]);
  204. return `${params.marker}${params.name}: ${params.value}%`;
  205. },
  206. },
  207. legend: {
  208. bottom: '5%', // Moved legend to the bottom
  209. left: 'center',
  210. type: 'scroll', // Enable scrolling for the legend
  211. pageIconColor: '#333', // Customize the color of the page icons
  212. pageTextStyle: {
  213. color: '#333' // Customize the text color of the page indicator
  214. }
  215. },
  216. series: [{
  217. type: 'pie',
  218. radius: ['40%', '70%'],
  219. center: ['50%', '42%'], // Adjusted to align with the new legend position
  220. endAngle: 360,
  221. data: data.map(v => {
  222. return {
  223. name: getMapText(v.itemclassfullname),
  224. value: (v.ratio * 100).toFixed(2)
  225. }
  226. }),
  227. label: {
  228. normal: {
  229. show: true,
  230. position: 'outside',
  231. formatter: '{b}: {c} ({d}%)',
  232. textStyle: {
  233. fontSize: 12,
  234. color: '#333'
  235. }
  236. },
  237. emphasis: {
  238. show: true,
  239. textStyle: {
  240. fontSize: 14,
  241. fontWeight: 'bold'
  242. }
  243. },
  244. rich: {
  245. total: {
  246. fontSize: 20,
  247. fontWeight: 'bold',
  248. color: '#333'
  249. },
  250. desc: {
  251. fontSize: 12,
  252. color: '#999'
  253. }
  254. }
  255. },
  256. labelLine: {
  257. normal: {
  258. show: true,
  259. length: 10,
  260. length2: 10
  261. }
  262. }
  263. }]
  264. };
  265. option.graphic = {
  266. type: 'text',
  267. left: 'center',
  268. top: '35%', // Adjusted to align with the new series position
  269. style: {
  270. text: `${getMapText('总计')}\n\n${total}`,
  271. textAlign: 'center',
  272. fill: '#333',
  273. fontSize: 16,
  274. fontWeight: 'bold'
  275. }
  276. };
  277. this.chartComponent = this.selectComponent('#mychart');
  278. this.chartComponent.init((canvas, width, height, dpr) => {
  279. const chart = echarts.init(canvas, null, {
  280. width,
  281. height,
  282. devicePixelRatio: dpr
  283. });
  284. chart.setOption(option);
  285. return chart;
  286. });
  287. },
  288. changeDate({
  289. detail
  290. }) {
  291. this.setData({
  292. "content.dateType": detail.dateType,
  293. "content.where.begdate": detail.begdate || "",
  294. "content.where.enddate": detail.enddate || ""
  295. })
  296. this.getList(true)
  297. },
  298. changeType(e) {
  299. const {
  300. name
  301. } = e.currentTarget.dataset;
  302. if (name == this.data.content.dataType) return;
  303. this.setData({
  304. "content.dataType": name
  305. })
  306. this.getList(true)
  307. },
  308. changeType2({
  309. detail
  310. }) {
  311. this.setData({
  312. "content.where.type": detail,
  313. })
  314. this.getList(true)
  315. },
  316. changeTradefield({
  317. detail
  318. }) {
  319. this.setData({
  320. "content.where.tradefield": detail,
  321. })
  322. this.getList(true)
  323. },
  324. changeItemclass({
  325. detail
  326. }) {
  327. this.setData({
  328. "content.itemclass": detail,
  329. })
  330. this.getList(true)
  331. },
  332. changeSa_brandid({
  333. detail
  334. }) {
  335. this.setData({
  336. "content.where.sa_brandid": detail,
  337. })
  338. this.getList(true)
  339. },
  340. }
  341. })