index.js 12 KB

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