index.js 12 KB

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