selectSectionStaff.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. var app = getApp()
  2. var that;
  3. Component({
  4. mixins: [],
  5. data: {
  6. userList: [],//人员集合
  7. all_user_list: [],//人员集合
  8. isShow: false,
  9. showId: 0,//显示的部门ID下员工
  10. terr: [
  11. { name: '全部', id: 0 }
  12. ],
  13. all_rule_list: [],
  14. rule_tree: [],
  15. selectUserId: [],
  16. isAllChecked: false,
  17. isItem: true,
  18. searchVal: '',
  19. isAll: true,
  20. userData:[],
  21. },
  22. props: {
  23. onClose: (data) => console.log(data),
  24. onConfirm: (data) => console.log(data),
  25. selectUser: [],
  26. isAllSelect: true,//是否多选
  27. isLeadership:false,//是否限制人员选择
  28. isBoss:false,//是否去除创始人
  29. },
  30. didMount() {
  31. that = this;
  32. app.login(app.globalData.corpId, function (is) {
  33. if(is){
  34. that.setData({
  35. selectUserId: that.props.selectUser,
  36. isAll: that.props.isAllSelect,
  37. userData:app.globalData.userData.employee_detail.manage_scope,
  38. terr:[{name: '全部', id:0}]
  39. })
  40. }
  41. that.getData(0);
  42. that.getBmData();
  43. })
  44. },
  45. didUpdate() { },
  46. didUnmount() {
  47. },
  48. methods: {
  49. onConfirm() {
  50. if(this.data.selectUserId.length==0){
  51. app.globalData.showToast("请选择一名员工")
  52. return
  53. }
  54. this.props.onConfirm(this.data.selectUserId);
  55. this.onClose();
  56. },
  57. //搜索
  58. bindKeyInput(e) {
  59. var userList = this.data.userList;
  60. var items = userList.filter((item) => {
  61. return item.name.indexOf(e.detail.value) >= 0
  62. });
  63. this.setData({
  64. searchVal: items,
  65. isItem: e.detail.value ? false : true
  66. })
  67. },
  68. changeSection(e) {
  69. var item = e.target.dataset.item;
  70. var terr = this.data.terr;
  71. terr.push(item);
  72. if (item._child.length > 0) {
  73. that.setData({
  74. rule_tree: item._child,
  75. terr: terr,
  76. isAllChecked: false
  77. })
  78. } else {
  79. that.setData({
  80. rule_tree: [],
  81. terr: terr,
  82. isAllChecked: false
  83. })
  84. }
  85. this.getData(item.id);
  86. },
  87. //点击导航栏
  88. activeItem(e) {
  89. var item = e.target.dataset.item;
  90. var index = e.target.dataset.index;
  91. var terr = this.data.terr;
  92. if ((index + 1) == terr.length) { return false };
  93. this.setData({ rule_tree: [] });
  94. if (index == 0) {
  95. this.setData({
  96. terr: [{ name: '全部', id: 0 }],
  97. rule_tree: this.data.all_rule_list,
  98. isAllChecked: false
  99. })
  100. } else {
  101. var arr = terr.slice(0, index + 1);
  102. this.setData({
  103. rule_tree: item._child,
  104. terr: arr,
  105. isAllChecked: false
  106. })
  107. }
  108. this.getData(item.id);
  109. },
  110. // 点击下一级
  111. openDown(e) {
  112. this.setData({ rule_tree: [] });
  113. var item = e.target.dataset.item;
  114. var terr = this.data.terr;
  115. terr.push(item);
  116. if (item._child.length > 0) {
  117. that.setData({
  118. rule_tree: item._child,
  119. terr: terr,
  120. isAllChecked: false
  121. })
  122. }
  123. this.getData(item.id);
  124. },
  125. getArrDifference(arr1, arr2) {
  126. var obj = {};
  127. arr1.concat(arr2).forEach(function (v, i, arr) {
  128. obj[v.id] = v;
  129. });
  130. return obj;
  131. },
  132. //全选择
  133. ruleActiveAll(e) {
  134. var userList = this.data.userList;
  135. var selectUserId = this.data.selectUserId;
  136. if (e.detail.value) {
  137. userList.map(item => {
  138. item.checked = true;
  139. })
  140. if (selectUserId.length > 0) {
  141. var obj = this.getArrDifference(selectUserId, userList);
  142. this.setData({
  143. selectUserId: Object.values(obj),
  144. userList: userList,
  145. isAllChecked: true
  146. })
  147. } else {
  148. this.setData({
  149. selectUserId: userList,
  150. userList: userList,
  151. isAllChecked: true
  152. })
  153. }
  154. } else {
  155. userList.map(item => {
  156. item.checked = false;
  157. })
  158. this.setData({
  159. userList: userList,
  160. selectUserId: [],
  161. isAllChecked: false
  162. })
  163. }
  164. },
  165. //单选择
  166. radioChange: function (e) {
  167. var item = e.target.dataset.item;
  168. var selectUserId = this.data.selectUserId;
  169. var isExist = false;
  170. if (e.detail.value) {
  171. if (!this.data.isAll) {//当设置单选择时
  172. if (selectUserId.length > 0) {
  173. app.globalData.showToast("只能选择一名人员");
  174. return;
  175. }
  176. }
  177. selectUserId.forEach((element, index, _this) => {
  178. if (element.id == item.id) {
  179. isExist = true;
  180. }
  181. });
  182. if (!isExist) {
  183. selectUserId.push(item);
  184. }
  185. } else {
  186. selectUserId.forEach((element, index, _this) => {
  187. if (element.id == item.id) {
  188. _this.splice(index, 1);
  189. }
  190. });
  191. }
  192. this.setData({
  193. selectUserId: selectUserId
  194. })
  195. },
  196. //关闭
  197. onClose(e) {
  198. this.props.onClose();
  199. },
  200. //获取人员列表
  201. getData(dept_id) {
  202. this.setData({
  203. userList:[],
  204. all_user_list:[]
  205. })
  206. app.$get("api/employee/list", { dept_id: dept_id }).then((res) => {
  207. var list = res.data.data.list||[];
  208. var selectUserId = this.data.selectUserId;
  209. var arr=[];
  210. var userList=list;
  211. if(this.props.isBoss){
  212. userList=[];
  213. list.forEach(item=>{
  214. if(item.is_creator!=1){
  215. userList.push(item)
  216. }
  217. })
  218. }
  219. userList.map((item) => {
  220. item.checked = false;
  221. if (selectUserId.length > 0) {
  222. selectUserId.forEach(item2 => {
  223. if (item.id == item2.id) {
  224. item.checked = true;
  225. }
  226. })
  227. }
  228. })
  229. that.data.userData.map((item)=>{
  230. userList.map((item2)=>{
  231. if(item.id==item2.id){
  232. arr.push(item2);
  233. }
  234. })
  235. })
  236. this.setData({
  237. userList:that.props.isLeadership? arr:userList,
  238. all_user_list:that.props.isLeadership? arr:userList,
  239. })
  240. })
  241. },
  242. //获取部门列表
  243. getBmData() {
  244. app.$get("api/department/tree", {}).then((res) => {
  245. var list = res.data.data.list;
  246. this.setData({
  247. rule_tree: list,
  248. all_rule_list: list
  249. })
  250. })
  251. },
  252. },
  253. });