selectStaff.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. var app = getApp()
  2. var that;
  3. Component({
  4. mixins: [],
  5. data: {
  6. all_user_list: {},
  7. isShow: false,
  8. keyVal:''
  9. },
  10. props: {
  11. onConfirm: (data) => console.log(data),
  12. onClose: (data) => console.log(data),
  13. defaultUser: '',
  14. },
  15. didMount() {
  16. that = this;
  17. this.setData({ isShow: this.props.isShow })
  18. this.getData();
  19. },
  20. didUpdate() { },
  21. didUnmount() { },
  22. methods: {
  23. onReset(){
  24. this.setData({
  25. isVal: false,
  26. keyVal:''
  27. })
  28. },
  29. //搜索
  30. bindKeyInput(e) {
  31. this.setData({
  32. keyVal:e.detail.value,
  33. isVal: e.detail.value ? true : false
  34. })
  35. },
  36. onConfirm() {
  37. this.props.onConfirm(this.data.selectUserId);
  38. this.props.onClose();
  39. },
  40. radioChange: function (e) {
  41. var selectUserId = this.data.selectUserId;
  42. var isExist = false;
  43. let item = e.target.dataset.item;
  44. let index = e.target.dataset.index;
  45. let checked = `userList[${index}].checked`;//获取当前控制选中的字段
  46. let elm = this.data.userList[index].checked;//当前的状态
  47. this.setData({
  48. [checked]: !elm,
  49. })
  50. if (e.detail.value) {//当有值时选中
  51. selectUserId.forEach((element, _this) => {
  52. if (element.id == item.id) {
  53. isExist = true;
  54. }
  55. });
  56. if (!isExist) {
  57. selectUserId.push(item);
  58. }
  59. } else {//取消选中
  60. selectUserId.forEach((element, index, _this) => {
  61. if (element.id == item.id) {
  62. _this.splice(index, 1);
  63. }
  64. });
  65. }
  66. this.setData({
  67. selectUserId: selectUserId
  68. })
  69. },
  70. getData(keywords) {
  71. app.$get("api/employee/list", { dept_id: 0, keywords: keywords }).then((res) => {
  72. var list = res.data.data.list;
  73. var arr = this.props.defaultUser;
  74. if(typeof(arr)=='string'){
  75. // arr=arr.substr(1, arr.length-2);
  76. arr= arr.split(',');
  77. }
  78. var ids=[],userList=list;
  79. // list.forEach(item=>{
  80. // if(item.is_official==1){
  81. // userList.push(item)
  82. // }
  83. // })
  84. userList.map(item=>{
  85. item.checked = false;
  86. if (arr.length > 0) {
  87. arr.forEach(item2 => {
  88. if (item.id == item2) {
  89. item.checked = true;
  90. ids.push(item);
  91. }
  92. })
  93. }
  94. })
  95. this.setData({
  96. userList: userList,
  97. all_user_list: userList,
  98. selectUserId:ids.length>0? ids:[]
  99. })
  100. })
  101. },
  102. //关闭
  103. onClose(e) {
  104. this.props.onClose();
  105. }
  106. },
  107. });