index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. })
  23. _Http.basic({
  24. "classname": "sysmanage.develop.optiontype.optiontype",
  25. "method": "optiontypeselect",
  26. "content": {
  27. "pageNumber": 1,
  28. "pageSize": 1000,
  29. "typename": "ordertype",
  30. "parameter": {}
  31. },
  32. }).then(res => {
  33. console.log("订单类型", res)
  34. if (res.code != '1') return;
  35. res.data.unshift({
  36. remarks: '全部',
  37. value: ""
  38. })
  39. this.setData({
  40. types: res.data
  41. })
  42. })
  43. _Http.basic({
  44. "classname": "sysmanage.develop.optiontype.optiontype",
  45. "method": "optiontypeselect",
  46. "content": {
  47. "pageNumber": 1,
  48. "pageSize": 1000,
  49. "typename": "tradefield",
  50. },
  51. }).then(res => {
  52. console.log("领域", res)
  53. if (res.code != '1') return;
  54. res.data.unshift({
  55. remarks: '全部',
  56. value: "",
  57. color: "#3874F6"
  58. })
  59. this.setData({
  60. tradefields: res.data
  61. })
  62. })
  63. _Http.basic({
  64. "id": "20220922085103",
  65. "version": 1,
  66. "content": {
  67. pageSize: 1000,
  68. "where": {
  69. "condition": ""
  70. }
  71. }
  72. }).then(res => {
  73. console.log("获取品牌", res)
  74. if (res.code != '1') return;
  75. res.data = res.data.map(v => {
  76. return {
  77. remarks: v.brandname,
  78. value: v.sa_brandid,
  79. }
  80. })
  81. res.data.unshift({
  82. remarks: '全部',
  83. value: "",
  84. color: "#3874F6"
  85. })
  86. this.setData({
  87. brands: res.data
  88. })
  89. })
  90. }
  91. },
  92. data: {
  93. dateTypes: ["全部", "本年", "本月"],
  94. "content": {
  95. pageNumber: 1,
  96. pageTotal: 1,
  97. dataid: wx.getStorageSync('userMsg').userid,
  98. username: wx.getStorageSync('userMsg').name,
  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. },
  121. methods: {
  122. async getList(init = false) {
  123. if (init.detail != undefined) init = init.detail;
  124. let content = this.data.content
  125. const {
  126. dataid,
  127. type,
  128. username,
  129. isleave
  130. } = getCurrentPages()[getCurrentPages().length - 1].data;
  131. if (content.dataid != dataid || content.type != type || isleave != isleave) init = true
  132. content.dataid = dataid;
  133. content.type = type;
  134. content.username = username;
  135. content.where.isleave = isleave;
  136. const dividend = wx.getStorageSync('languagecode') == 'ZH' ? 10000 : 1000,
  137. getMapText = getApp().globalData.Language.getMapText;
  138. if (init) {
  139. content.pageNumber = 1;
  140. content.pageTotal = 1;
  141. }
  142. if (content.pageNumber > content.pageTotal) return;
  143. _Http.basic({
  144. "id": 20240524160004,
  145. content
  146. }).then(res => {
  147. this.selectComponent('#ListBox').RefreshToComplete();
  148. console.log("订单产品类别占比分析", res)
  149. if (res.code != '1') return wx.showToast({
  150. title: res.data,
  151. icon: "none"
  152. })
  153. res.data = res.data.map(v => {
  154. v.amount = CNY(v.amount)
  155. v.returnamount = CNY(v.returnamount)
  156. v.itemclassamount = CNY(v.itemclassamount)
  157. return v
  158. })
  159. this.setData({
  160. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  161. "content.pageNumber": res.pageNumber + 1,
  162. "content.pageSize": res.pageSize,
  163. })
  164. try {
  165. this.selectComponent("#TimeRange").onCancel()
  166. } catch (error) {
  167. }
  168. try {
  169. this.selectAllComponents("#Filtrate").forEach(v => v.onCancel())
  170. } catch (error) {
  171. }
  172. this.initChart(res.data[0].ratio, content.dataType == '金额' ? CNY(res.data[0].ratio[0].total / dividend) : res.data[0].ratio[0].total, getMapText);
  173. })
  174. },
  175. initChart(data, total, getMapText) {
  176. let option = {
  177. tooltip: {
  178. trigger: 'item'
  179. },
  180. legend: {
  181. bottom: '5%', // Moved legend to the bottom
  182. left: 'center'
  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.itemclassfullname),
  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. changeType(e) {
  267. const {
  268. name
  269. } = e.currentTarget.dataset;
  270. if (name == this.data.content.dataType) return;
  271. this.setData({
  272. "content.dataType": name
  273. })
  274. this.getList(true)
  275. },
  276. changeType2({
  277. detail
  278. }) {
  279. this.setData({
  280. "content.where.type": detail,
  281. })
  282. this.getList(true)
  283. },
  284. changeTradefield({
  285. detail
  286. }) {
  287. this.setData({
  288. "content.where.tradefield": detail,
  289. })
  290. this.getList(true)
  291. },
  292. changeItemclass({
  293. detail
  294. }) {
  295. this.setData({
  296. "content.itemclass": detail,
  297. })
  298. this.getList(true)
  299. },
  300. changeSa_brandid({
  301. detail
  302. }) {
  303. this.setData({
  304. "content.where.sa_brandid": detail,
  305. })
  306. this.getList(true)
  307. },
  308. }
  309. })