index.js 6.8 KB

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