SiteSelectModal.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <!--用户选择框-->
  2. <template>
  3. <div>
  4. <BasicModal
  5. v-bind="$attrs"
  6. @register="register"
  7. :title="modalTitle"
  8. :width="showSelected ? '1200px' : '900px'"
  9. wrapClassName="j-user-select-modal"
  10. @ok="handleOk"
  11. destroyOnClose
  12. @visible-change="visibleChange"
  13. >
  14. <a-row>
  15. <a-col :span="showSelected ? 18 : 24">
  16. <BasicTable
  17. ref="tableRef"
  18. :columns="columns"
  19. :scroll="tableScroll"
  20. v-bind="getBindValue"
  21. :useSearchForm="true"
  22. :formConfig="formConfig"
  23. :api="getSiteList"
  24. :searchInfo="searchInfo"
  25. :rowSelection="rowSelection"
  26. :indexColumnProps="indexColumnProps"
  27. :afterFetch="afterFetch"
  28. >
  29. <!-- update-begin-author:taoyan date:2022-5-25 for: VUEN-1112一对多 用户选择 未显示选择条数,及清空 -->
  30. <template #tableTitle></template>
  31. <!-- update-end-author:taoyan date:2022-5-25 for: VUEN-1112一对多 用户选择 未显示选择条数,及清空 -->
  32. </BasicTable>
  33. </a-col>
  34. <a-col :span="showSelected ? 6 : 0">
  35. <BasicTable
  36. v-bind="selectedTable"
  37. :dataSource="selectRows"
  38. :useSearchForm="true"
  39. :formConfig="{ showActionButtonGroup: false, baseRowStyle: { minHeight: '40px' } }"
  40. >
  41. <!--操作栏-->
  42. <template #action="{ record }">
  43. <a href="javascript:void(0)" @click="handleDeleteSelected(record)"><Icon icon="ant-design:delete-outlined"></Icon></a>
  44. </template>
  45. </BasicTable>
  46. </a-col>
  47. </a-row>
  48. </BasicModal>
  49. </div>
  50. </template>
  51. <script lang="ts">
  52. import { defineComponent, unref, ref, watch } from 'vue';
  53. import { BasicModal, useModalInner } from '/@/components/Modal';
  54. import { getSiteList } from './SiteSelect';
  55. import { createAsyncComponent } from '/@/utils/factory/createAsyncComponent';
  56. import { useSelectBiz } from '/@/components/Form/src/jeecg/hooks/useSelectBiz';
  57. import { useAttrs } from '/@/hooks/core/useAttrs';
  58. import { selectProps } from '/@/components/Form/src/jeecg/props/props';
  59. export default defineComponent({
  60. name: 'SiteSelectModal',
  61. components: {
  62. //此处需要异步加载BasicTable
  63. BasicModal,
  64. BasicTable: createAsyncComponent(() => import('/@/components/Table/src/BasicTable.vue'), {
  65. loading: true,
  66. }),
  67. },
  68. props: {
  69. ...selectProps,
  70. //选择框标题
  71. modalTitle: {
  72. type: String,
  73. default: '选择站点',
  74. },
  75. //update-begin---author:wangshuai ---date:20230703 for:【QQYUN-5685】5、离职人员可以选自己------------
  76. //排除用户id的集合
  77. excludeSiteIdList: {
  78. type: Array,
  79. default: [],
  80. },
  81. //update-end---author:wangshuai ---date:20230703 for:【QQYUN-5685】5、离职人员可以选自己------------
  82. },
  83. emits: ['register', 'getSelectResult'],
  84. setup(props, { emit, refs }) {
  85. // update-begin-author:taoyan date:2022-5-24 for: VUEN-1086 【移动端】用户选择 查询按钮 效果不好 列表展示没有滚动条
  86. const tableScroll = ref<any>({ x: false });
  87. const tableRef = ref();
  88. //注册弹框
  89. const [register, { closeModal }] = useModalInner(() => {
  90. if (window.innerWidth < 900) {
  91. tableScroll.value = { x: 900 };
  92. } else {
  93. tableScroll.value = { x: false };
  94. }
  95. //update-begin-author:taoyan date:2022-6-2 for: VUEN-1112 一对多 用户选择 未显示选择条数,及清空
  96. setTimeout(() => {
  97. if (tableRef.value) {
  98. tableRef.value.setSelectedRowKeys(selectValues['value'] || []);
  99. }
  100. }, 800);
  101. //update-end-author:taoyan date:2022-6-2 for: VUEN-1112 一对多 用户选择 未显示选择条数,及清空
  102. });
  103. // update-end-author:taoyan date:2022-5-24 for: VUEN-1086 【移动端】用户选择 查询按钮 效果不好 列表展示没有滚动条
  104. const attrs = useAttrs();
  105. //表格配置
  106. const config = {
  107. canResize: false,
  108. bordered: true,
  109. size: 'small',
  110. };
  111. const getBindValue = Object.assign({}, unref(props), unref(attrs), config);
  112. const [{ rowSelection, visibleChange, selectValues, indexColumnProps, getSelectResult, handleDeleteSelected, selectRows }] = useSelectBiz(
  113. getSiteList,
  114. getBindValue
  115. );
  116. const searchInfo = ref(props.params);
  117. // update-begin--author:liaozhiyang---date:20230811---for:【issues/657】右侧选中列表删除无效
  118. watch(rowSelection.selectedRowKeys, (newVal) => {
  119. //update-begin---author:wangshuai ---date: 20230829 for:null指针异常导致控制台报错页面不显示------------
  120. if(tableRef.value){
  121. tableRef.value.setSelectedRowKeys(newVal);
  122. }
  123. //update-end---author:wangshuai ---date: 20230829 for:null指针异常导致控制台报错页面不显示------------
  124. });
  125. // update-end--author:liaozhiyang---date:20230811---for:【issues/657】右侧选中列表删除无效
  126. //查询form
  127. const formConfig = {
  128. baseColProps: {
  129. xs: 24,
  130. sm: 8,
  131. md: 6,
  132. lg: 8,
  133. xl: 6,
  134. xxl: 6,
  135. },
  136. //update-begin-author:taoyan date:2022-5-24 for: VUEN-1086 【移动端】用户选择 查询按钮 效果不好 列表展示没有滚动条---查询表单按钮的栅格布局和表单的保持一致
  137. // actionColOptions: {
  138. // xs: 24,
  139. // sm: 8,
  140. // md: 8,
  141. // lg: 8,
  142. // xl: 8,
  143. // xxl: 8,
  144. // },
  145. //update-end-author:taoyan date:2022-5-24 for: VUEN-1086 【移动端】用户选择 查询按钮 效果不好 列表展示没有滚动条---查询表单按钮的栅格布局和表单的保持一致
  146. schemas: [
  147. {
  148. label: '站点',
  149. field: 'companyName',
  150. component: 'JInput',
  151. },
  152. ],
  153. };
  154. //定义表格列
  155. const columns = [
  156. {
  157. title: '站点名称',
  158. dataIndex: 'companyName',
  159. width: 300,
  160. align: 'left',
  161. },
  162. {
  163. title: '站点id',
  164. dataIndex: 'siteId',
  165. width: 120,
  166. },
  167. ];
  168. //已选择的table信息
  169. const selectedTable = {
  170. pagination: false,
  171. showIndexColumn: false,
  172. scroll: { y: 390 },
  173. size: 'small',
  174. canResize: false,
  175. bordered: true,
  176. rowKey: 'id',
  177. columns: [
  178. {
  179. title: '站点名称',
  180. dataIndex: 'companyName',
  181. width: 40,
  182. },
  183. {
  184. title: '操作',
  185. dataIndex: 'action',
  186. align: 'center',
  187. width: 40,
  188. slots: { customRender: 'action' },
  189. },
  190. ],
  191. };
  192. /**
  193. * 确定选择
  194. */
  195. function handleOk() {
  196. getSelectResult((options, values) => {
  197. //回传选项和已选择的值
  198. emit('getSelectResult', options, values);
  199. //关闭弹窗
  200. closeModal();
  201. });
  202. }
  203. //update-begin---author:wangshuai ---date:20230703 for:【QQYUN-5685】5、离职人员可以选自己------------
  204. /**
  205. * 用户返回结果逻辑查询
  206. */
  207. function afterFetch(record) {
  208. let excludeList = props.excludeSiteIdList;
  209. if(!excludeList){
  210. return record;
  211. }
  212. let arr:any[] = [];
  213. //如果存在过滤用户id集合,并且后台返回的数据不为空
  214. if(excludeList.length>0 && record && record.length>0){
  215. for(let item of record){
  216. if(excludeList.indexOf(item.id)<0){
  217. arr.push({...item})
  218. }
  219. }
  220. return arr;
  221. }
  222. return record;
  223. }
  224. //update-end---author:wangshuai ---date:20230703 for:【QQYUN-5685】5、离职人员可以选自己------------
  225. return {
  226. //config,
  227. handleOk,
  228. searchInfo,
  229. register,
  230. indexColumnProps,
  231. visibleChange,
  232. getBindValue,
  233. getSiteList,
  234. formConfig,
  235. columns,
  236. rowSelection,
  237. selectRows,
  238. selectedTable,
  239. handleDeleteSelected,
  240. tableScroll,
  241. tableRef,
  242. afterFetch,
  243. };
  244. },
  245. });
  246. </script>