index.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. },
  11. options: {
  12. addGlobalClass: true
  13. },
  14. lifetimes: {
  15. attached: function () {
  16. getApp().globalData.Language.getLanguagePackage(this)
  17. }
  18. },
  19. data: {
  20. "content": {
  21. dataid: wx.getStorageSync('userMsg').userid,
  22. username: wx.getStorageSync('userMsg').name,
  23. enddate: new Date().toISOString().split('T')[0],
  24. where: {}
  25. },
  26. },
  27. methods: {
  28. async getList(init = false) {
  29. let content = this.data.content
  30. const {
  31. dataid,
  32. type,
  33. username,
  34. isleave
  35. } = getCurrentPages()[getCurrentPages().length - 1].data;
  36. if (content.dataid != dataid || content.type != type || isleave != isleave) init = true
  37. content.dataid = dataid;
  38. content.type = type;
  39. content.username = username;
  40. content.where.isleave = isleave;
  41. let dividend = wx.getStorageSync('languagecode') == 'ZH' ? 10000 : 1000,
  42. getMapText = getApp().globalData.Language.getMapText;
  43. _Http.basic({
  44. "id": 20231011201004,
  45. content
  46. }).then(res => {
  47. console.log("报价分析", res)
  48. if (res.code != '1') return wx.showToast({
  49. title: res.data,
  50. icon: "none"
  51. })
  52. this.setData({
  53. list: [{
  54. name: getMapText("报价总次数"),
  55. value: res.data.totalqty
  56. }, {
  57. name: getMapText("客户报价次数"),
  58. text: getMapText("客户报价总次数"),
  59. value: res.data.cusqty
  60. }, {
  61. name: getMapText("项目报价次数"),
  62. text: getMapText("客户报价总次数"),
  63. value: res.data.proqty
  64. }, {
  65. name: getMapText("报价总金额"),
  66. value: CNY(res.data.totalamount >= dividend ? (res.data.totalamount / dividend) : res.data.totalamount),
  67. suffix: res.data.totalamount >= dividend ? getMapText("万") : ""
  68. }, {
  69. name: getMapText("客户报价金额"),
  70. value: CNY(res.data.cusamount >= dividend ? (res.data.cusamount / dividend) : res.data.cusamount),
  71. suffix: res.data.cusamount >= dividend ? getMapText("万") : ""
  72. }, {
  73. name: getMapText("项目报价金额"),
  74. value: CNY(res.data.proamount >= dividend ? (res.data.proamount / dividend) : res.data.proamount),
  75. suffix: res.data.proamount >= dividend ? getMapText("万") : ""
  76. }]
  77. })
  78. })
  79. _Http.basic({
  80. "id": 20231011154704,
  81. content
  82. }).then(res => {
  83. console.log("报价分析图表", res)
  84. if (res.code != '1') return wx.showToast({
  85. title: res.data,
  86. icon: "none"
  87. })
  88. this.initChart(res.data)
  89. })
  90. },
  91. initChart(data) {
  92. console.log("data", data)
  93. const getMapText = getApp().globalData.Language.getMapText,
  94. list = [{
  95. name: "报价总数量",
  96. key: 'newtotalqty',
  97. color: "#5B8FF9"
  98. }, {
  99. name: "客户报价数量",
  100. key: 'newcusqty',
  101. color: "#5AD8A6"
  102. }, {
  103. name: "项目报价数量",
  104. key: 'newproqty',
  105. color: "#5D7092"
  106. }, {
  107. name: "去年同期报价总数量",
  108. key: 'oldtotalqty',
  109. color: "#ECB937"
  110. }, {
  111. name: "去年同期客户报价数量",
  112. key: 'oldcusqty',
  113. color: "#6F5EF9"
  114. }, {
  115. name: "去年同期项目报价数量",
  116. key: 'oldproqty',
  117. color: "#6DC8EC"
  118. }]
  119. const option = {
  120. tooltip: {
  121. trigger: 'axis'
  122. },
  123. legend: {
  124. data: list.map(v => getMapText(v.name)),
  125. },
  126. grid: {
  127. top: '30%', // Adjust grid top to leave space for the legend
  128. left: '3%',
  129. right: '4%',
  130. bottom: '3%',
  131. containLabel: true
  132. },
  133. xAxis: {
  134. type: 'category',
  135. boundaryGap: false,
  136. data: data.map(v => v.date),
  137. axisLabel: {
  138. interval: 0, // Force display all labels
  139. rotate: 45 // Rotate labels to prevent overlap
  140. }
  141. },
  142. yAxis: {
  143. type: 'value'
  144. },
  145. series: list.map(v => {
  146. return {
  147. name: getMapText(v.name),
  148. type: 'line',
  149. stack: 'Total',
  150. data: data.map(obj => obj[v.key]),
  151. itemStyle: {
  152. color: v.color
  153. },
  154. lineStyle: {
  155. color: v.color
  156. }
  157. }
  158. })
  159. };
  160. this.chartComponent = this.selectComponent('#mychart');
  161. this.chartComponent.init((canvas, width, height, dpr) => {
  162. const chart = echarts.init(canvas, null, {
  163. width,
  164. height,
  165. devicePixelRatio: dpr
  166. });
  167. chart.setOption(option);
  168. return chart;
  169. });
  170. },
  171. changeDate({
  172. detail
  173. }) {
  174. this.setData({
  175. "content.enddate": detail
  176. })
  177. this.getList(true)
  178. },
  179. showExplain(e) {
  180. const {
  181. name
  182. } = e.currentTarget.dataset;
  183. getApp().globalData.Language.modeBoxPrompts(getApp().globalData.Language.getMapText('统计到当前查询时间为止的') + name + "(" + getApp().globalData.Language.getMapText('审核状态') + ")")
  184. },
  185. }
  186. })