index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. pickerIndex: 0,
  5. showText: "全部",
  6. popupShow: false,
  7. activeId: null,
  8. mainActiveIndex: 0,
  9. active: "业绩目标",
  10. targetYear: null,
  11. hrid: null,
  12. departmentid: null,
  13. "year": new Date().getFullYear().toString(),
  14. "content": {
  15. "nocache": true,
  16. "year": new Date().getFullYear().toString(), //年
  17. "targettype": "人员目标", //1
  18. "type": 1, //
  19. "where": {
  20. "condition": ""
  21. }
  22. },
  23. target: null, //目标
  24. showActions: false,
  25. actionSheet: "开票金额",
  26. actions: [{
  27. name: getApp().globalData.Language.getMapText('开票金额'),
  28. value: "1"
  29. }, {
  30. name: getApp().globalData.Language.getMapText('订单金额'),
  31. value: "2"
  32. }, {
  33. name: getApp().globalData.Language.getMapText('出货金额'),
  34. value: "3"
  35. }],
  36. },
  37. onLoad(options) {
  38. getApp().globalData.Language.getLanguagePackage(this, '销售目标');
  39. let wtarget = wx.getStorageSync('auth').target.optionnames.filter(v => v != "查询")
  40. if (wtarget.length == 0) {
  41. wx.showModal({
  42. content: getApp().globalData.Language.getMapText('未获取到应用权限'),
  43. showCancel: false
  44. })
  45. setTimeout(() => {
  46. wx.navigateBack()
  47. }, 1000);
  48. return
  49. }
  50. this.setData({
  51. wtarget,
  52. "content.targettype": wtarget[0] == '业绩目标' ? '人员目标' : '项目目标',
  53. active: wtarget[0]
  54. })
  55. /* 获取部门列表 */
  56. _Http.basic({
  57. "id": 20220922113302,
  58. "content": {
  59. pageSize: 9999
  60. }
  61. }).then(res => {
  62. if (res.code != '1') return wx.showToast({
  63. title: res.msg,
  64. icon: "none"
  65. })
  66. let hrList = res.data.map(v => {
  67. v.hr.unshift({
  68. name: v.depname + ' (包含所有下级)',
  69. hrid: v.departmentid
  70. })
  71. return {
  72. id: v.departmentid,
  73. text: v.depname,
  74. children: v.hr.map(value => {
  75. const text = value.position ? value.name + ` (${value.position})` : value.name;
  76. if (value.hrid == wx.getStorageSync('userMsg').hrid) this.setData({
  77. hrid: value.hrid,
  78. activeId: value.hrid,
  79. text: value.name,
  80. showText: value.name
  81. })
  82. return {
  83. id: value.hrid,
  84. text
  85. }
  86. })
  87. }
  88. })
  89. this.setData({
  90. hrList
  91. })
  92. });
  93. this.getYear(true)
  94. },
  95. getYear(init = false) {
  96. /* 获取年份 */
  97. _Http.basic({
  98. "id": 20230728090204,
  99. "content": {
  100. "targettype": "人员目标",
  101. type: 1,
  102. }
  103. }).then(res => {
  104. console.log("人员开启年度", res)
  105. if (res.code != '1') return wx.showToast({
  106. title: res.msg,
  107. icon: "none"
  108. })
  109. let UYL = {};
  110. res.data.forEach(v => UYL[v.year] = v.status)
  111. this.setData({
  112. userYearList: res.data.map(v => v.year),
  113. UYL,
  114. "content.year": res.data.length ? res.data[res.data.length - 1].year : this.data.content.year,
  115. pickerIndex: res.data.length - 1
  116. })
  117. if (init) this.getData();
  118. })
  119. /* 获取年份 */
  120. _Http.basic({
  121. "id": 20230728090204,
  122. "content": {
  123. "targettype": "项目目标",
  124. type: 1,
  125. }
  126. }).then(res => {
  127. console.log('项目开启年度', res)
  128. if (res.code != '1') return wx.showToast({
  129. title: res.msg,
  130. icon: "none"
  131. })
  132. let PYL = {};
  133. res.data.forEach(v => PYL[v.year] = v.status)
  134. this.setData({
  135. projectYearList: res.data.map(v => v.year),
  136. PYL
  137. })
  138. })
  139. },
  140. onShow() {
  141. this.getData();
  142. },
  143. onClickNav({
  144. detail
  145. }) {
  146. this.setData({
  147. mainActiveIndex: detail.index
  148. })
  149. },
  150. onClickItem({
  151. detail
  152. }) {
  153. let hrid = null,
  154. departmentid = null;
  155. if (detail.text.includes('包含所有下级')) {
  156. departmentid = detail.id
  157. } else {
  158. hrid = detail.id
  159. };
  160. let text = detail.text.split("(")[0];
  161. this.setData({
  162. hrid,
  163. departmentid,
  164. activeId: detail.id,
  165. text
  166. })
  167. },
  168. /* 切换分析对象 */
  169. openPupop() {
  170. this.setData({
  171. popupShow: true
  172. })
  173. },
  174. onClose() {
  175. this.setData({
  176. popupShow: false
  177. })
  178. },
  179. toDetail() {
  180. if (this.data.active == "业绩目标") {
  181. wx.navigateTo({
  182. url: `./person?year=${this.data.content.year}&yearArr=${this.data.userYearList}&pickerIndex=${this.data.pickerIndex}&UYL=${JSON.stringify(this.data.UYL)}`
  183. })
  184. } else {
  185. wx.navigateTo({
  186. url: `./project?year=${this.data.content.year}&yearArr=${this.data.projectYearList}&pickerIndex=${this.data.pickerIndex}&PYL=${JSON.stringify(this.data.PYL)}`
  187. })
  188. }
  189. },
  190. getData(e) {
  191. if (e) this.setData({
  192. showText: this.data.text ? this.data.text : '全部'
  193. })
  194. let content = this.data.content;
  195. if (this.data.hrid) content.hrid = this.data.hrid;
  196. if (this.data.departmentid) content.departmentid = this.data.departmentid;
  197. _Http.basic({
  198. "id": 20220920133102,
  199. content
  200. }).then(res => {
  201. console.log("获取数据", res)
  202. this.onClose()
  203. if (res.code != '1') return wx.showToast({
  204. title: res.data,
  205. icon: "none"
  206. })
  207. let lineData = [],
  208. histogram = [];
  209. res.data.month.forEach(v => {
  210. lineData = lineData.concat([{
  211. label: v.month + getApp().globalData.Language.getMapText('月'),
  212. value: v.l,
  213. type: getApp().globalData.Language.getMapText('基本目标金额')
  214. },
  215. {
  216. label: v.month + getApp().globalData.Language.getMapText('月'),
  217. value: v.h,
  218. type: getApp().globalData.Language.getMapText('挑战目标金额')
  219. },
  220. {
  221. label: v.month + getApp().globalData.Language.getMapText('月'),
  222. value: v.a,
  223. type: getApp().globalData.Language.getMapText('实际订单金额')
  224. }
  225. ])
  226. histogram = histogram.concat([{
  227. label: v.month + getApp().globalData.Language.getMapText('月'),
  228. value: v.pl,
  229. type: getApp().globalData.Language.getMapText('基础目标实际完成率')
  230. },
  231. {
  232. label: v.month + getApp().globalData.Language.getMapText('月'),
  233. value: v.ph,
  234. type: getApp().globalData.Language.getMapText('挑战目标实际完成率')
  235. }
  236. ])
  237. });
  238. //绘制线图
  239. this.selectComponent("#line").render(lineData);
  240. // this.selectComponent("#histogram").render(histogram);
  241. this.setData({
  242. targetYear: {
  243. yl: res.data.y1l,
  244. yh: res.data.y1h,
  245. ya: res.data.y1a,
  246. 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) + '%'
  247. }
  248. });
  249. if (this.data.year == this.data.content.year) {
  250. const m = new Date().getMonth() + 1;
  251. let s = [
  252. [1, 2, 3],
  253. [4, 5, 6],
  254. [7, 8, 9],
  255. [10, 11, 12]
  256. ].findIndex(v => v.some(va => va == m)) + 1;
  257. this.setData({
  258. targetSeason: {
  259. sl: res.data[`s${s}l`],
  260. sh: res.data[`s${s}h`],
  261. sa: res.data[`s${s}a`],
  262. 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) + '%'
  263. },
  264. targetMonth: {
  265. ml: res.data[`m${m}l`],
  266. mh: res.data[`m${m}h`],
  267. ma: res.data[`m${m}a`],
  268. 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) + '%'
  269. }
  270. })
  271. }
  272. })
  273. },
  274. /* 弹出选择 */
  275. select({
  276. detail
  277. }) {
  278. if (this.data.actionSheet == detail.name) return;
  279. this.setData({
  280. actionSheet: detail.name,
  281. "content.type": detail.value,
  282. showActions: false
  283. });
  284. this.getData();
  285. },
  286. cancelActions() {
  287. this.setData({
  288. showActions: false
  289. })
  290. },
  291. openActions() {
  292. this.setData({
  293. showActions: true
  294. })
  295. },
  296. /* 选择年份 */
  297. bindDateChange({
  298. detail
  299. }) {
  300. let index = detail.value;
  301. let year = this.data.active == '业绩目标' ? this.data.userYearList[index] : this.data.projectYearList[index];
  302. if (year == detail.value) return;
  303. this.setData({
  304. "content.year": year,
  305. pickerIndex: index
  306. });
  307. this.getData();
  308. },
  309. /* tabs切换 */
  310. tabsChange({
  311. detail
  312. }) {
  313. let year = this.data.content.year;
  314. if (detail.title == '业绩目标') {
  315. let i = this.data.userYearList.findIndex(v => year == v)
  316. if (i == -1) {
  317. this.setData({
  318. "content.year": this.data.userYearList[this.data.userYearList.length - 1],
  319. pickerIndex: this.data.userYearList.length - 1
  320. })
  321. } else {
  322. this.setData({
  323. pickerIndex: i
  324. })
  325. }
  326. } else {
  327. let i = this.data.projectYearList.findIndex(v => year == v);
  328. if (i == -1) {
  329. this.setData({
  330. "content.year": this.data.projectYearList[this.data.projectYearList.length - 1],
  331. pickerIndex: this.data.projectYearList.length - 1
  332. })
  333. } else {
  334. this.setData({
  335. pickerIndex: i
  336. })
  337. }
  338. }
  339. console.log(detail.name)
  340. this.setData({
  341. "content.targettype": detail.name == '业绩目标' ? '人员目标' : '项目目标',
  342. active: detail.name
  343. });
  344. this.getData();
  345. }
  346. })