index.js 10 KB

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