index.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. return {
  60. id: value.hrid,
  61. text
  62. }
  63. })
  64. }
  65. })
  66. this.setData({
  67. hrList
  68. })
  69. });
  70. this.getYear(true)
  71. },
  72. getYear(init = false) {
  73. /* 获取年份 */
  74. _Http.basic({
  75. "classname": "sysmanage.develop.optiontype.optiontype",
  76. "method": "optiontypeselect",
  77. "content": {
  78. pageSize: 999,
  79. "typename": 'targetyearofpersonal',
  80. "parameter": {
  81. "siteid": wx.getStorageSync('siteP').siteid
  82. }
  83. }
  84. }).then(res => {
  85. if (res.msg != '成功') return wx.showToast({
  86. title: res.msg,
  87. icon: "none"
  88. })
  89. this.setData({
  90. userYearList: res.data.map(v => v.year),
  91. "content.year": res.data.length ? res.data[res.data.length - 1].year : this.data.content.year,
  92. year: res.data.length ? res.data[res.data.length - 1].year : this.data.year,
  93. pickerIndex: res.data.length - 1
  94. })
  95. if (init) this.getData();
  96. })
  97. /* 获取年份 */
  98. _Http.basic({
  99. "classname": "sysmanage.develop.optiontype.optiontype",
  100. "method": "optiontypeselect",
  101. "content": {
  102. pageSize: 999,
  103. "typename": 'targetyearofproject',
  104. "parameter": {
  105. "siteid": wx.getStorageSync('siteP').siteid
  106. }
  107. }
  108. }).then(res => {
  109. console.log('项目分类', res)
  110. if (res.msg != '成功') return wx.showToast({
  111. title: res.msg,
  112. icon: "none"
  113. })
  114. this.setData({
  115. projectYearList: res.data.map(v => v.year)
  116. })
  117. })
  118. },
  119. onShow() {
  120. this.getData();
  121. },
  122. onClickNav({
  123. detail
  124. }) {
  125. this.setData({
  126. mainActiveIndex: detail.index
  127. })
  128. },
  129. onClickItem({
  130. detail
  131. }) {
  132. let hrid = null,
  133. departmentid = null;
  134. if (detail.text.includes('包含所有下级')) {
  135. departmentid = detail.id
  136. } else {
  137. hrid = detail.id
  138. };
  139. let text = detail.text.split("(")[0];
  140. this.setData({
  141. hrid,
  142. departmentid,
  143. activeId: detail.id,
  144. text
  145. })
  146. },
  147. /* 切换分析对象 */
  148. openPupop() {
  149. this.setData({
  150. popupShow: true
  151. })
  152. },
  153. onClose() {
  154. this.setData({
  155. popupShow: false
  156. })
  157. },
  158. toDetail() {
  159. if (this.data.active == "业绩目标") {
  160. wx.navigateTo({
  161. url: `./person?year=${this.data.content.year}&yearArr=${this.data.userYearList}&pickerIndex=${this.data.pickerIndex}`
  162. })
  163. } else {
  164. wx.navigateTo({
  165. url: `./project?year=${this.data.content.year}&yearArr=${this.data.projectYearList}&pickerIndex=${this.data.pickerIndex}`
  166. })
  167. }
  168. },
  169. getData(e) {
  170. if (e) this.setData({
  171. showText: this.data.text ? this.data.text : '全部'
  172. })
  173. let content = this.data.content;
  174. if (this.data.hrid) content.hrid = this.data.hrid;
  175. if (this.data.departmentid) content.departmentid = this.data.departmentid;
  176. _Http.basic({
  177. "id": 20220920133102,
  178. content
  179. }).then(res => {
  180. this.onClose()
  181. if (res.msg != '成功') return wx.showToast({
  182. title: res.data,
  183. icon: "none"
  184. })
  185. let lineData = [],
  186. histogram = [];
  187. res.data.month.forEach(v => {
  188. lineData = lineData.concat([{
  189. label: v.month + '月',
  190. value: v.l,
  191. type: "基本目标金额"
  192. },
  193. {
  194. label: v.month + '月',
  195. value: v.h,
  196. type: "挑战目标金额"
  197. },
  198. {
  199. label: v.month + '月',
  200. value: v.a,
  201. type: "实际订单金额"
  202. }
  203. ])
  204. histogram = histogram.concat([{
  205. label: v.month + '月',
  206. value: v.pl,
  207. type: "基础目标实际完成率"
  208. },
  209. {
  210. label: v.month + '月',
  211. value: v.ph,
  212. type: "挑战目标实际完成率"
  213. }
  214. ])
  215. });
  216. //绘制线图
  217. this.selectComponent("#line").render(lineData);
  218. this.selectComponent("#histogram").render(histogram);
  219. this.setData({
  220. targetYear: {
  221. yl: res.data.y1l,
  222. yh: res.data.y1h,
  223. ya: res.data.y1a,
  224. }
  225. });
  226. if (this.data.year == this.data.content.year) {
  227. const m = new Date().getMonth() + 1;
  228. let s = [
  229. [1, 2, 3],
  230. [4, 5, 6],
  231. [7, 8, 9],
  232. [10, 11, 12]
  233. ].findIndex(v => v.some(va => va == m)) + 1;
  234. this.setData({
  235. targetSeason: {
  236. sl: res.data[`s${s}l`],
  237. sh: res.data[`s${s}h`],
  238. sa: res.data[`s${s}a`],
  239. },
  240. targetMonth: {
  241. ml: res.data[`m${m}l`],
  242. mh: res.data[`m${m}h`],
  243. ma: res.data[`m${m}a`]
  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. console.log(123)
  319. this.getData();
  320. },
  321. onShareAppMessage() {}
  322. })