index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. pickerIndex: res.data.length - 1
  93. })
  94. if (init) this.getData();
  95. })
  96. /* 获取年份 */
  97. _Http.basic({
  98. "classname": "sysmanage.develop.optiontype.optiontype",
  99. "method": "optiontypeselect",
  100. "content": {
  101. pageSize: 999,
  102. "typename": 'targetyearofproject',
  103. "parameter": {
  104. "siteid": wx.getStorageSync('siteP').siteid
  105. }
  106. }
  107. }).then(res => {
  108. console.log('项目分类', res)
  109. if (res.msg != '成功') return wx.showToast({
  110. title: res.msg,
  111. icon: "none"
  112. })
  113. this.setData({
  114. projectYearList: res.data.map(v => v.year)
  115. })
  116. })
  117. },
  118. onShow() {
  119. this.getData();
  120. },
  121. onClickNav({
  122. detail
  123. }) {
  124. this.setData({
  125. mainActiveIndex: detail.index
  126. })
  127. },
  128. onClickItem({
  129. detail
  130. }) {
  131. let hrid = null,
  132. departmentid = null;
  133. if (detail.text.includes('包含所有下级')) {
  134. departmentid = detail.id
  135. } else {
  136. hrid = detail.id
  137. };
  138. let text = detail.text.split("(")[0];
  139. this.setData({
  140. hrid,
  141. departmentid,
  142. activeId: detail.id,
  143. text
  144. })
  145. },
  146. /* 切换分析对象 */
  147. openPupop() {
  148. this.setData({
  149. popupShow: true
  150. })
  151. },
  152. onClose() {
  153. this.setData({
  154. popupShow: false
  155. })
  156. },
  157. toDetail() {
  158. if (this.data.active == "业绩目标") {
  159. wx.navigateTo({
  160. url: `./person?year=${this.data.content.year}&yearArr=${this.data.userYearList}&pickerIndex=${this.data.pickerIndex}`
  161. })
  162. } else {
  163. wx.navigateTo({
  164. url: `./project?year=${this.data.content.year}&yearArr=${this.data.projectYearList}&pickerIndex=${this.data.pickerIndex}`
  165. })
  166. }
  167. },
  168. getData(e) {
  169. if (e) this.setData({
  170. showText: this.data.text ? this.data.text : '全部'
  171. })
  172. let content = this.data.content;
  173. if (this.data.hrid) content.hrid = this.data.hrid;
  174. if (this.data.departmentid) content.departmentid = this.data.departmentid;
  175. _Http.basic({
  176. "id": 20220920133102,
  177. content
  178. }).then(res => {
  179. this.onClose()
  180. if (res.msg != '成功') return wx.showToast({
  181. title: res.data,
  182. icon: "none"
  183. })
  184. let lineData = [],
  185. histogram = [];
  186. res.data.month.forEach(v => {
  187. lineData = lineData.concat([{
  188. label: v.month + '月',
  189. value: v.l,
  190. type: "基本目标金额"
  191. },
  192. {
  193. label: v.month + '月',
  194. value: v.h,
  195. type: "挑战目标金额"
  196. },
  197. {
  198. label: v.month + '月',
  199. value: v.a,
  200. type: "实际订单金额"
  201. }
  202. ])
  203. histogram = histogram.concat([{
  204. label: v.month + '月',
  205. value: v.pl,
  206. type: "基础目标实际完成率"
  207. },
  208. {
  209. label: v.month + '月',
  210. value: v.ph,
  211. type: "挑战目标实际完成率"
  212. }
  213. ])
  214. });
  215. //绘制线图
  216. this.selectComponent("#line").render(lineData);
  217. // this.selectComponent("#histogram").render(histogram);
  218. this.setData({
  219. targetYear: {
  220. yl: res.data.y1l,
  221. yh: res.data.y1h,
  222. ya: res.data.y1a,
  223. jl: (res.data.y1a == 0 && res.data.y1l == 0) ? '0.00%' : (res.data.y1a / res.data.y1l * 100).toFixed(2) + '%'
  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. jl: (res.data[`s${s}a`] == 0 && res.data[`s${s}l`] == 0) ? '0.00%' : (res.data[`s${s}a`] / res.data[`s${s}l`] * 100).toFixed(2) + '%'
  240. },
  241. targetMonth: {
  242. ml: res.data[`m${m}l`],
  243. mh: res.data[`m${m}h`],
  244. ma: res.data[`m${m}a`],
  245. jl: (res.data[`m${m}a`] == 0 && res.data[`m${m}l`] == 0) ? '0.00%' : (res.data[`m${m}a`] / res.data[`m${m}l`] * 100).toFixed(2) + '%'
  246. }
  247. })
  248. }
  249. })
  250. },
  251. /* 弹出选择 */
  252. select({
  253. detail
  254. }) {
  255. if (this.data.actionSheet == detail.name) return;
  256. this.setData({
  257. actionSheet: detail.name,
  258. "content.type": detail.value,
  259. showActions: false
  260. });
  261. this.getData();
  262. },
  263. cancelActions() {
  264. this.setData({
  265. showActions: false
  266. })
  267. },
  268. openActions() {
  269. this.setData({
  270. showActions: true
  271. })
  272. },
  273. /* 选择年份 */
  274. bindDateChange({
  275. detail
  276. }) {
  277. let index = detail.value;
  278. let year = this.data.active == '业绩目标' ? this.data.userYearList[index] : this.data.projectYearList[index];
  279. if (year == detail.value) return;
  280. this.setData({
  281. "content.year": year,
  282. pickerIndex: index
  283. });
  284. this.getData();
  285. },
  286. /* tabs切换 */
  287. tabsChange({
  288. detail
  289. }) {
  290. let year = this.data.content.year;
  291. if (detail.title == '业绩目标') {
  292. let i = this.data.userYearList.findIndex(v => year == v)
  293. if (i == -1) {
  294. this.setData({
  295. "content.year": this.data.userYearList[this.data.userYearList.length - 1],
  296. pickerIndex: this.data.userYearList.length - 1
  297. })
  298. } else {
  299. this.setData({
  300. pickerIndex: i
  301. })
  302. }
  303. } else {
  304. let i = this.data.projectYearList.findIndex(v => year == v);
  305. if (i == -1) {
  306. this.setData({
  307. "content.year": this.data.projectYearList[this.data.projectYearList.length - 1],
  308. pickerIndex: this.data.projectYearList.length - 1
  309. })
  310. } else {
  311. this.setData({
  312. pickerIndex: i
  313. })
  314. }
  315. }
  316. this.setData({
  317. "content.targettype": detail.title == '业绩目标' ? '人员目标' : '项目目标',
  318. active: detail.title
  319. });
  320. console.log(123)
  321. this.getData();
  322. },
  323. onShareAppMessage() {}
  324. })