index.js 7.0 KB

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