index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. const _Http = getApp().globalData.http;
  2. Component({
  3. properties: {
  4. isdep: {
  5. type: Boolean,
  6. value: true
  7. },
  8. isusers: {
  9. type: Boolean,
  10. value: true
  11. },
  12. defaultMy: {
  13. type: Boolean,
  14. value: true
  15. },
  16. exclution: {
  17. type: Boolean,
  18. value: true
  19. },
  20. dimissionF: {
  21. type: Boolean
  22. },
  23. defaultIsleave: {
  24. type: [Number, String], // 0 在职 1离职 空全部
  25. value: "0"
  26. }
  27. },
  28. data: {
  29. takeEffect: "", //生效筛选项
  30. result: {
  31. name: ""
  32. },
  33. users: {
  34. label: "业务员",
  35. active: {}
  36. },
  37. isleave: "0",
  38. tabs: [{
  39. value: "",
  40. name: "全部"
  41. }, {
  42. value: "0",
  43. name: "在职"
  44. }, {
  45. value: "1",
  46. name: "离职"
  47. }],
  48. searchValue: "",
  49. depGroud: [],
  50. userObj: {}
  51. },
  52. lifetimes: {
  53. attached: function () {}
  54. },
  55. methods: {
  56. searchChange({
  57. detail
  58. }) {
  59. if (detail.length == 0) return this.searchClear()
  60. let list = JSON.parse(JSON.stringify(this.data.users.copyList));
  61. this.setData({
  62. 'users.list': list.filter(v => v.name.includes(detail) || v.accountno.includes(detail))
  63. })
  64. },
  65. searchClear() {
  66. this.setData({
  67. 'users.list': JSON.parse(JSON.stringify(this.data.users.copyList))
  68. })
  69. },
  70. changLeave(e) {
  71. this.setData({
  72. isleave: e.currentTarget.dataset.value,
  73. 'result.isleave': e.currentTarget.dataset.value
  74. })
  75. this.getUsers()
  76. },
  77. initDepAndUser(init = true) {
  78. if (init) this.setData({
  79. takeEffect: "", //生效筛选项
  80. result: {},
  81. })
  82. return new Promise((resolve) => {
  83. _Http.basic({
  84. "classname": "webmanage.sale.salearea.salearea",
  85. "method": "query_area",
  86. "content": {},
  87. }).then(res => {
  88. console.log("获取区域", res)
  89. if (this.data.isdep && this.data.depGroud.length == 0) this.setData({
  90. depGroud: [{
  91. label: "营销区域",
  92. list: res.data,
  93. active: ""
  94. }]
  95. })
  96. if (init) {
  97. this.setData({
  98. isleave: this.data.defaultIsleave
  99. })
  100. if (res.data.length) {
  101. this.selectDep({
  102. currentTarget: {
  103. dataset: {
  104. item: res.data[0],
  105. index: 0
  106. }
  107. }
  108. })
  109. }
  110. }
  111. resolve(res.data.length ? res.data[0] : {
  112. sa_saleareaid: 0
  113. })
  114. })
  115. })
  116. },
  117. async getUsers(sa_saleareaid) {
  118. let list = [],
  119. userObj = this.data.userObj;
  120. try {
  121. if (sa_saleareaid && userObj['user' + sa_saleareaid].length) list = userObj['user' + sa_saleareaid];
  122. } catch (error) {
  123. }
  124. if (!sa_saleareaid) sa_saleareaid = this.data.result.sa_saleareaid;
  125. let res = {}
  126. if (list.length == 0) res = await _Http.basic({
  127. id: 20221011144603,
  128. "content": {
  129. isExport: 0,
  130. isHasSub: 1,
  131. "pageNumber": 1,
  132. "pageSize": 999,
  133. "where": {
  134. "condition": "",
  135. status: this.data.isleave
  136. },
  137. sa_saleareaid
  138. },
  139. })
  140. if (res.code == 1) {
  141. res.data.filter(v => {
  142. if (!list.some(s => s.userid == v.userid)) list.push(v)
  143. })
  144. userObj['user' + sa_saleareaid] = list;
  145. }
  146. this.setData({
  147. "users.list": list,
  148. "users.copyList": JSON.parse(JSON.stringify(list)),
  149. "users.active": {},
  150. userObj
  151. })
  152. },
  153. selectDep(e) {
  154. const {
  155. item,
  156. index
  157. } = e.currentTarget.dataset;
  158. let depGroud = this.data.depGroud.slice(0, index + 1);
  159. depGroud[index].active = item.sa_saleareaid;
  160. if (item.subarea.length) {
  161. if (item.subarea[0].areaname != '全部') {
  162. item.subarea.unshift(JSON.parse(JSON.stringify(item)))
  163. item.subarea[0].areaname = '全部';
  164. item.subarea[0].subarea = [];
  165. }
  166. depGroud.push({
  167. label: item.areaname + '下级区域',
  168. list: item.subarea,
  169. active: item.sa_saleareaid
  170. })
  171. }
  172. item.name = item.areaname
  173. item.isleave = this.data.isleave;
  174. this.getUsers(item.sa_saleareaid)
  175. this.setData({
  176. depGroud,
  177. takeEffect: "dep",
  178. result: item,
  179. selectDepObj: item
  180. })
  181. },
  182. selectUser(e) {
  183. const {
  184. item
  185. } = e.currentTarget.dataset;
  186. this.setData({
  187. 'users.active': item.userid,
  188. takeEffect: "user",
  189. result: item
  190. })
  191. },
  192. }
  193. })