index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. tradefieldIndex: 0,
  5. pickerIndex: 0,
  6. targetYear: null,
  7. hrid: null,
  8. "year": new Date().getFullYear().toString(),
  9. "content": {
  10. "nocache": true,
  11. "year": new Date().getFullYear().toString(), //年
  12. "type": 1,
  13. "where": {
  14. "condition": ""
  15. }
  16. },
  17. target: null, //目标
  18. showActions: false,
  19. actionSheet: getApp().globalData.Language.getMapText('开票金额'),
  20. actions: [{
  21. name: getApp().globalData.Language.getMapText('开票金额'),
  22. value: "1"
  23. }, {
  24. name: getApp().globalData.Language.getMapText('订单金额'),
  25. value: "2"
  26. }, {
  27. name: getApp().globalData.Language.getMapText('出货金额'),
  28. value: "3"
  29. }],
  30. },
  31. onLoad(options) {
  32. // this.getYear(true)
  33. getApp().globalData.Language.getLanguagePackage(this, 'E-订单');
  34. },
  35. getYear(init = false) {
  36. /* 获取年份 */
  37. _Http.basic({
  38. "classname": "sysmanage.develop.optiontype.optiontype",
  39. "method": "optiontypeselect",
  40. "content": {
  41. pageSize: 999,
  42. "typename": 'targetyearofpersonal',
  43. "parameter": {
  44. "siteid": wx.getStorageSync('siteP').siteid
  45. }
  46. }
  47. }).then(res => {
  48. if (res.msg != '成功') return wx.showToast({
  49. title: res.msg,
  50. icon: "none"
  51. })
  52. this.setData({
  53. userYearList: res.data.map(v => v.year),
  54. "content.year": res.data.length ? res.data[res.data.length - 1].year : this.data.content.year,
  55. year: res.data.length ? res.data[res.data.length - 1].year : this.data.year,
  56. pickerIndex: res.data.length - 1
  57. })
  58. if (init) this.getData();
  59. })
  60. /* 获取年份 */
  61. _Http.basic({
  62. "classname": "sysmanage.develop.optiontype.optiontype",
  63. "method": "optiontypeselect",
  64. "content": {
  65. pageSize: 999,
  66. "typename": 'targetyearofproject',
  67. "parameter": {
  68. "siteid": wx.getStorageSync('siteP').siteid
  69. }
  70. }
  71. }).then(res => {
  72. console.log('项目分类', res)
  73. if (res.msg != '成功') return wx.showToast({
  74. title: res.msg,
  75. icon: "none"
  76. })
  77. this.setData({
  78. projectYearList: res.data.map(v => v.year)
  79. })
  80. })
  81. },
  82. onShow() {
  83. this.getData();
  84. },
  85. getData() {
  86. let content = this.data.content;
  87. _Http.basic({
  88. "id": wx.getStorageSync('userrole') == '业务员' ? 20230111163102 : 20230110151902,
  89. content
  90. }).then(res => {
  91. console.log("业绩目标", res)
  92. if (res.msg != '成功') return wx.showToast({
  93. title: res.data,
  94. icon: "none"
  95. })
  96. this.setData({
  97. list: res.data,
  98. tradefieldIndex: 0
  99. })
  100. this.setShowData();
  101. })
  102. },
  103. bindTradefieldChange(e) {
  104. this.setData({
  105. tradefieldIndex: e.detail.value
  106. })
  107. this.setShowData()
  108. },
  109. setShowData() {
  110. let data = this.data.list[this.data.tradefieldIndex];
  111. let lineData = [],
  112. histogram = [];
  113. data.month.forEach(v => {
  114. lineData = lineData.concat([{
  115. label: v.month + getApp().globalData.Language.getMapText('月'),
  116. value: v.l,
  117. type: getApp().globalData.Language.getMapText('基本目标金额')
  118. },
  119. {
  120. label: v.month + getApp().globalData.Language.getMapText('月'),
  121. value: v.h,
  122. type: getApp().globalData.Language.getMapText('挑战目标金额')
  123. },
  124. {
  125. label: v.month + getApp().globalData.Language.getMapText('月'),
  126. value: v.a,
  127. type: getApp().globalData.Language.getMapText('实际订单金额')
  128. }
  129. ])
  130. histogram = histogram.concat([{
  131. label: v.month + getApp().globalData.Language.getMapText('月'),
  132. value: v.pl,
  133. type: getApp().globalData.Language.getMapText('基础目标实际完成率')
  134. },
  135. {
  136. label: v.month + getApp().globalData.Language.getMapText('月'),
  137. value: v.ph,
  138. type: getApp().globalData.Language.getMapText('挑战目标实际完成率')
  139. }
  140. ])
  141. });
  142. //绘制线图
  143. this.selectComponent("#line").render(lineData);
  144. // this.selectComponent("#histogram").render(histogram);
  145. this.setData({
  146. targetYear: {
  147. yl: data.y1l,
  148. yh: data.y1h,
  149. ya: data.y1a,
  150. jl: (res.data.y1a == 0 && res.data.y1l == 0) ? '0.00%' : res.data.y1l == 0 ? res.data.y1a + '%' : (res.data.y1a / res.data.y1l * 100).toFixed(2) + '%'
  151. // jl: data.y1a || data.y1l?(data.y1a / data.y1l * 100).toFixed(2) + '%':'0.00%'
  152. }
  153. });
  154. if (this.data.year == this.data.content.year) {
  155. const m = new Date().getMonth() + 1;
  156. let s = [
  157. [1, 2, 3],
  158. [4, 5, 6],
  159. [7, 8, 9],
  160. [10, 11, 12]
  161. ].findIndex(v => v.some(va => va == m)) + 1;
  162. this.setData({
  163. targetSeason: {
  164. sl: data[`s${s}l`],
  165. sh: data[`s${s}h`],
  166. sa: data[`s${s}a`],
  167. jl: (res.data[`s${s}a`] == 0 && res.data[`s${s}l`] == 0) ? '0.00%' : res.data[`s${s}l`] == 0 ? res.data[`s${s}a`] + '%' : (res.data[`s${s}a`] / res.data[`s${s}l`] * 100).toFixed(2) + '%'
  168. // jl: data[`s${s}a`] || data[`s${s}l`] ? (data[`s${s}a`] / data[`s${s}l`] * 100).toFixed(2) + '%' : "0.00%"
  169. },
  170. targetMonth: {
  171. ml: data[`m${m}l`],
  172. mh: data[`m${m}h`],
  173. ma: data[`m${m}a`],
  174. jl: (res.data[`m${m}a`] == 0 && res.data[`m${m}l`] == 0) ? '0.00%' : res.data[`m${m}l`] == 0 ? res.data[`m${m}a`] + '%' : (res.data[`m${m}a`] / res.data[`m${m}l`] * 100).toFixed(2) + '%'
  175. // jl: data[`m${m}a`] || data[`m${m}l`] ? (data[`m${m}a`] / data[`m${m}l`] * 100).toFixed(2) + '%' : "0.00%"
  176. }
  177. })
  178. }
  179. },
  180. /* 弹出选择 */
  181. select({
  182. detail
  183. }) {
  184. if (this.data.actionSheet == detail.name) return;
  185. this.setData({
  186. actionSheet: detail.name,
  187. "content.type": detail.value,
  188. showActions: false
  189. });
  190. this.getData();
  191. },
  192. cancelActions() {
  193. this.setData({
  194. showActions: false
  195. })
  196. },
  197. openActions() {
  198. this.setData({
  199. showActions: true
  200. })
  201. },
  202. /* 选择年份 */
  203. bindDateChange({
  204. detail
  205. }) {
  206. let index = detail.value;
  207. let year = this.data.userYearList[index];
  208. if (year == detail.value) return;
  209. this.setData({
  210. "content.year": year,
  211. pickerIndex: index
  212. });
  213. this.getData();
  214. },
  215. onShareAppMessage() {}
  216. })