index.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. targetYear: null,
  10. hrid: null,
  11. departmentid: null,
  12. "year": new Date().getFullYear().toString(),
  13. "content": {
  14. "nocache": true,
  15. "year": new Date().getFullYear().toString(), //年
  16. "targettype": "人员目标", //1
  17. "type": 1, //
  18. "where": {
  19. "condition": ""
  20. }
  21. },
  22. target: null, //目标
  23. showActions: false,
  24. actionSheet: "开票金额",
  25. actions: [{
  26. name: '开票金额',
  27. value: "1"
  28. }, {
  29. name: '订单金额',
  30. value: "2"
  31. }, {
  32. name: '出货金额',
  33. value: "3"
  34. }],
  35. },
  36. onLoad(options) {
  37. /* 获取部门列表 */
  38. _Http.basic({
  39. "id": 20220922113302,
  40. "content": {
  41. pageSize: 9999
  42. }
  43. }).then(res => {
  44. if (res.msg != '成功') return wx.showToast({
  45. title: res.msg,
  46. icon: "none"
  47. })
  48. let hrList = res.data.map(v => {
  49. v.hr.unshift({
  50. name: v.depname + ' (包含所有下级)',
  51. hrid: v.departmentid
  52. })
  53. return {
  54. id: v.departmentid,
  55. text: v.depname,
  56. children: v.hr.map(value => {
  57. const text = value.position ? value.name + ` (${value.position})` : value.name
  58. return {
  59. id: value.hrid,
  60. text
  61. }
  62. })
  63. }
  64. })
  65. this.setData({
  66. hrList
  67. })
  68. });
  69. this.getYear(true)
  70. },
  71. getYear(init = false) {
  72. /* 获取年份 */
  73. _Http.basic({
  74. "classname": "sysmanage.develop.optiontype.optiontype",
  75. "method": "optiontypeselect",
  76. "content": {
  77. pageSize: 999,
  78. "typename": 'targetyearofpersonal',
  79. "parameter": {
  80. "siteid": wx.getStorageSync('siteP').siteid
  81. }
  82. }
  83. }).then(res => {
  84. if (res.msg != '成功') return wx.showToast({
  85. title: res.msg,
  86. icon: "none"
  87. })
  88. this.setData({
  89. userYearList: res.data.map(v => v.year),
  90. "content.year": res.data.length ? res.data[res.data.length - 1].year : this.data.content.year,
  91. year: res.data.length ? res.data[res.data.length - 1].year : this.data.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. wx.navigateTo({
  159. url: `./person?year=${this.data.content.year}&yearArr=${this.data.userYearList}&pickerIndex=${this.data.pickerIndex}`
  160. })
  161. },
  162. getData(e) {
  163. if (e) this.setData({
  164. showText: this.data.text ? this.data.text : '全部'
  165. })
  166. let content = this.data.content;
  167. if (this.data.hrid) content.hrid = this.data.hrid;
  168. if (this.data.departmentid) content.departmentid = this.data.departmentid;
  169. _Http.basic({
  170. "id": 20220920133102,
  171. content
  172. }).then(res => {
  173. this.onClose()
  174. if (res.msg != '成功') return wx.showToast({
  175. title: res.data,
  176. icon: "none"
  177. })
  178. let lineData = [],
  179. histogram = [];
  180. res.data.month.forEach(v => {
  181. lineData = lineData.concat([{
  182. label: v.month + '月',
  183. value: v.l,
  184. type: "基本目标金额"
  185. },
  186. {
  187. label: v.month + '月',
  188. value: v.h,
  189. type: "挑战目标金额"
  190. },
  191. {
  192. label: v.month + '月',
  193. value: v.a,
  194. type: "实际订单金额"
  195. }
  196. ])
  197. histogram = histogram.concat([{
  198. label: v.month + '月',
  199. value: v.pl,
  200. type: "基础目标实际完成率"
  201. },
  202. {
  203. label: v.month + '月',
  204. value: v.ph,
  205. type: "挑战目标实际完成率"
  206. }
  207. ])
  208. });
  209. //绘制线图
  210. this.selectComponent("#line").render(lineData);
  211. this.selectComponent("#histogram").render(histogram);
  212. this.setData({
  213. targetYear: {
  214. yl: res.data.y1l,
  215. yh: res.data.y1h,
  216. ya: res.data.y1a,
  217. }
  218. });
  219. if (this.data.year == this.data.content.year) {
  220. const m = new Date().getMonth() + 1;
  221. let s = [
  222. [1, 2, 3],
  223. [4, 5, 6],
  224. [7, 8, 9],
  225. [10, 11, 12]
  226. ].findIndex(v => v.some(va => va == m)) + 1;
  227. this.setData({
  228. targetSeason: {
  229. sl: res.data[`s${s}l`],
  230. sh: res.data[`s${s}h`],
  231. sa: res.data[`s${s}a`],
  232. },
  233. targetMonth: {
  234. ml: res.data[`m${m}l`],
  235. mh: res.data[`m${m}h`],
  236. ma: res.data[`m${m}a`]
  237. }
  238. })
  239. }
  240. })
  241. },
  242. /* 弹出选择 */
  243. select({
  244. detail
  245. }) {
  246. if (this.data.actionSheet == detail.name) return;
  247. this.setData({
  248. actionSheet: detail.name,
  249. "content.type": detail.value,
  250. showActions: false
  251. });
  252. this.getData();
  253. },
  254. cancelActions() {
  255. this.setData({
  256. showActions: false
  257. })
  258. },
  259. openActions() {
  260. this.setData({
  261. showActions: true
  262. })
  263. },
  264. /* 选择年份 */
  265. bindDateChange({
  266. detail
  267. }) {
  268. let index = detail.value;
  269. let year = this.data.userYearList[index];
  270. if (year == detail.value) return;
  271. this.setData({
  272. "content.year": year,
  273. pickerIndex: index
  274. });
  275. this.getData();
  276. },
  277. onShareAppMessage() {}
  278. })