personList.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <div class="personList">
  3. <van-cell-group>
  4. <van-field v-model="personType" clearable center readonly label="人员类型:" placeholder="请选择人员类型" input-align="right"
  5. right-icon="arrow-down" @click="showPerson = true" />
  6. <van-popup v-model:show="showPerson" round position="bottom">
  7. <van-picker title="人员类型" :columns="$dictUtils.getDictList('hs_people_type')" :columns-field-names="{
  8. text: 'label',
  9. value: 'value'
  10. }" @cancel="showPerson = false" @confirm="getPersonType" />
  11. </van-popup>
  12. </van-cell-group>
  13. <van-cell-group>
  14. <van-field v-model="religiousType" clearable center readonly label="宗教类型:" placeholder="请选择宗教类型" input-align="right"
  15. right-icon="arrow-down" @click="showPlace = true" />
  16. <van-popup v-model:show="showPlace" round position="bottom">
  17. <van-picker title="宗教类型" :columns="$dictUtils.getDictList('hs_religion_type')" :columns-field-names="{
  18. text: 'label',
  19. value: 'value'
  20. }" @cancel="showPlace = false" @confirm="getType" />
  21. </van-popup>
  22. </van-cell-group>
  23. <van-search v-model="searchForm.name" clearable show-action shape="round" placeholder="请输入搜索关键词" input-align="center"
  24. @search="onLoad" @cancel="onCancel" />
  25. <van-list v-model:loading="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
  26. <van-checkbox-group v-if="type == 1" v-model="checked" ref="checkboxGroup">
  27. <van-button type="primary" size="mini" @click="checkAll">全选</van-button>
  28. <van-button type="primary" size="mini" @click="nocheckAll">取消全选</van-button>
  29. <van-cell-group inset>
  30. <van-cell v-for="(item, index) in list" clickable :key="item" :title="item.name" @click="toggle(index)">
  31. <template #right-icon>
  32. <van-checkbox shape="square" :name="item" :ref="(el) => (checkboxRefs[index] = el)" />
  33. </template>
  34. </van-cell>
  35. </van-cell-group>
  36. </van-checkbox-group>
  37. <van-radio-group v-if="type == 0" v-model="checked">
  38. <van-cell-group inset>
  39. <van-cell v-for="item in list" clickable :key="item" :title="item.name" @click="selectes(item)">
  40. <template #right-icon>
  41. <van-radio :name="item" />
  42. </template>
  43. </van-cell>
  44. </van-cell-group>
  45. </van-radio-group>
  46. </van-list>
  47. </div>
  48. </template>
  49. <script>
  50. import { ref, watch } from "vue";
  51. import UserManage from "@/api/user/UserManage";
  52. export default {
  53. name: "personList",
  54. emits: ["selected"],
  55. props: ["type", "siteId"],
  56. setup(props, { emit }) {
  57. const searchForm = ref({
  58. name: "",
  59. sex: "",
  60. idType: "",
  61. idcard: "",
  62. phone: "",
  63. location: {
  64. id: "",
  65. },
  66. typeOfEmployees: "",
  67. personnelType: "",
  68. religion: "",
  69. createEnd: "",
  70. createBegin: "",
  71. nativePlace: '',
  72. currentResidence: '',
  73. })
  74. // 搜索
  75. const onCancel = () => {
  76. list.value = [];
  77. index = 0;
  78. finished.value = false;
  79. searchForm.value.name = ""
  80. searchForm.value.religion = ""
  81. searchForm.value.personnelType = ""
  82. personType.value = ""
  83. religiousType.value = ""
  84. };
  85. // 选择人员
  86. const checked = ref([]);
  87. const checkboxRefs = ref([]);
  88. const checkboxGroup = ref(null);
  89. const toggle = (index) => {
  90. checkboxRefs.value[index].toggle();
  91. emit("selected", checked.value, 1);
  92. };
  93. // 全选
  94. const checkAll = () => {
  95. checkboxGroup.value.toggleAll(true);
  96. console.log("checked", checked);
  97. emit("selected", checked.value, 1);
  98. };
  99. // 取消全选
  100. const nocheckAll = () => {
  101. checkboxGroup.value.toggleAll(false);
  102. emit("selected", checked.value, 1);
  103. };
  104. const selectes = (val) => {
  105. checked.value = val;
  106. emit("selected", checked.value, 0);
  107. };
  108. const list = ref([]);
  109. const loading = ref(false);
  110. const finished = ref(false);
  111. let index = 0;
  112. watch(
  113. () => {
  114. return { ...searchForm.value };
  115. },
  116. (newValue, oldValue) => {
  117. if (oldValue != newValue) {
  118. index = 0;
  119. onLoad()
  120. }
  121. },
  122. { deep: true }
  123. );
  124. let showPlace = ref(false);
  125. let showPerson = ref(false);
  126. let religiousType = ref('');
  127. let personType = ref('');
  128. const getType = ({ selectedOptions }) => {
  129. showPlace.value = false;
  130. searchForm.value.religion = selectedOptions[0].value;
  131. religiousType.value = selectedOptions[0].label
  132. };
  133. const getPersonType = ({ selectedOptions }) => {
  134. showPerson.value = false;
  135. searchForm.value.personnelType = selectedOptions[0].value;
  136. personType.value = selectedOptions[0].label
  137. };
  138. const onLoad = () => {
  139. if (index == 0) {
  140. list.value = [];
  141. loading.value = true;
  142. }
  143. // 异步更新数据
  144. new UserManage()
  145. .list({
  146. current: index + 1,
  147. size: 15,
  148. ...searchForm.value
  149. })
  150. .then(({ records }) => {
  151. list.value.push(...records)
  152. // 加载状态结束
  153. loading.value = false;
  154. // 数据全部加载完成
  155. if (records.length < 15) {
  156. finished.value = true;
  157. if (finished.value && !loading.value && searchForm.value.location.id != "") {
  158. checked.value.push(...list.value)
  159. }
  160. } else {
  161. index++;
  162. }
  163. });
  164. };
  165. if (props.siteId != "") {
  166. searchForm.value.location.id = props.siteId;
  167. }
  168. return {
  169. // 人员
  170. list,
  171. onLoad,
  172. loading,
  173. finished,
  174. // 搜索
  175. searchForm,
  176. onCancel,
  177. // 全选
  178. checkAll,
  179. // 取消全选
  180. nocheckAll,
  181. toggle,
  182. checked,
  183. checkboxRefs,
  184. checkboxGroup,
  185. // 单选
  186. selectes,
  187. showPlace,
  188. getType,
  189. showPerson,
  190. getPersonType,
  191. religiousType,
  192. personType
  193. };
  194. },
  195. };
  196. </script>
  197. <style scoped>
  198. .personList {
  199. height: 65vh;
  200. overflow: auto;
  201. margin: 10px;
  202. }
  203. .van-button {
  204. top: -5px;
  205. }
  206. .search {
  207. height: 40px;
  208. line-height: 40px;
  209. }
  210. .van-list {
  211. height: 80%;
  212. margin-top: 5px;
  213. }
  214. .keyword {
  215. width: 70%;
  216. height: 25px;
  217. border-radius: 25px;
  218. border: 1px solid;
  219. padding-left: 15px;
  220. }
  221. </style>