JVxeSiteSelectCell.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <!--站点选择组件-->
  2. <template>
  3. <div>
  4. <JSelectBiz @change="handleChange" @handleOpen="handleOpen" :loading="loadingEcho" v-bind="attrs"></JSelectBiz>
  5. <SiteSelectModal :rowKey="rowKey" @register="regModal" @getSelectResult="setValue" v-bind="getBindValue" :excludeSiteIdList="excludeSiteIdList"></SiteSelectModal>
  6. </div>
  7. </template>
  8. <script lang="ts">
  9. import { unref } from 'vue';
  10. import SiteSelectModal from './modal/SiteSelectModal.vue';
  11. import JSelectBiz from '/@/components/Form/src/jeecg/components/base/JSelectBiz.vue';
  12. import { defineComponent, ref, reactive, watchEffect, watch, provide } from 'vue';
  13. import { useModal } from '/@/components/Modal';
  14. import { propTypes } from '/@/utils/propTypes';
  15. import { useRuleFormItem } from '/@/hooks/component/useFormItem';
  16. import { useAttrs } from '/@/hooks/core/useAttrs';
  17. import { SelectValue } from 'ant-design-vue/es/select';
  18. export default defineComponent({
  19. name: 'JVxeSiteSelectCell',
  20. components: {
  21. SiteSelectModal,
  22. JSelectBiz,
  23. },
  24. inheritAttrs: false,
  25. props: {
  26. value: propTypes.oneOfType([propTypes.string, propTypes.array]),
  27. labelKey: {
  28. type: String,
  29. default: 'companyName',
  30. },
  31. rowKey: {
  32. type: String,
  33. default: 'siteId',
  34. },
  35. params: {
  36. type: Object,
  37. default: () => {},
  38. },
  39. //update-begin---author:wangshuai ---date:20230703 for:【QQYUN-5685】5、离职人员可以选自己------------
  40. //排除用户id的集合
  41. excludeSiteIdList:{
  42. type: Array,
  43. default: () => [],
  44. }
  45. //update-end---author:wangshuai ---date:20230703 for:【QQYUN-5685】5、离职人员可以选自己------------
  46. },
  47. emits: ['options-change', 'change', 'update:value'],
  48. setup(props, { emit }) {
  49. const emitData = ref<any[]>();
  50. //注册model
  51. const [regModal, { openModal }] = useModal();
  52. //表单值
  53. const [state] = useRuleFormItem(props, 'value', 'change', emitData);
  54. //下拉框选项值
  55. const selectOptions = ref<SelectValue>([]);
  56. //下拉框选中值
  57. let selectValues = reactive<Recordable>({
  58. value: [],
  59. change: false,
  60. });
  61. // 是否正在加载回显数据
  62. const loadingEcho = ref<boolean>(false);
  63. //下发 selectOptions,xxxBiz组件接收
  64. provide('selectOptions', selectOptions);
  65. //下发 selectValues,xxxBiz组件接收
  66. provide('selectValues', selectValues);
  67. //下发 loadingEcho,xxxBiz组件接收
  68. provide('loadingEcho', loadingEcho);
  69. const tag = ref(false);
  70. const attrs = useAttrs();
  71. /**
  72. * 监听组件值
  73. */
  74. watchEffect(() => {
  75. props.value && initValue();
  76. // 查询条件重置的时候 界面显示未清空
  77. if (!props.value) {
  78. selectValues.value = [];
  79. }
  80. });
  81. /**
  82. * 监听selectValues变化
  83. */
  84. watch(selectValues, () => {
  85. if (selectValues) {
  86. state.value = selectValues.value;
  87. }
  88. });
  89. //update-begin---author:wangshuai ---date:20230703 for:【QQYUN-5685】5、离职人员可以选自己------------
  90. const excludeSiteIdList = ref<any>([]);
  91. /**
  92. * 需要监听一下excludeSiteIdList,否则modal获取不到
  93. */
  94. watch(()=>props.excludeSiteIdList,(data)=>{
  95. excludeSiteIdList.value = data;
  96. },{ immediate: true })
  97. //update-end---author:wangshuai ---date:20230703 for:【QQYUN-5685】5、离职人员可以选自己------------
  98. /**
  99. * 打卡弹出框
  100. */
  101. function handleOpen() {
  102. tag.value = true;
  103. openModal(true, {
  104. isUpdate: false,
  105. });
  106. }
  107. /**
  108. * 将字符串值转化为数组
  109. */
  110. function initValue() {
  111. let value = props.value ? props.value : [];
  112. if (value && typeof value === 'string' && value != 'null' && value != 'undefined') {
  113. state.value = value.split(',');
  114. selectValues.value = value.split(',');
  115. } else {
  116. // 【VUEN-857】兼容数组(行编辑的用法问题)
  117. selectValues.value = value;
  118. }
  119. }
  120. /**
  121. * 设置下拉框的值
  122. */
  123. function setValue(options, values) {
  124. selectOptions.value = options;
  125. //emitData.value = values.join(",");
  126. state.value = values;
  127. selectValues.value = values;
  128. emit('update:value', values.join(','));
  129. }
  130. const getBindValue = Object.assign({}, unref(props), unref(attrs));
  131. //update-begin---author:wangshuai ---date:20230711 for:换成异步组件加载,否则会影响到其他页面描述------------
  132. /**
  133. * 下拉框值改变回调事件
  134. * @param values
  135. */
  136. function handleChange(values) {
  137. emit('update:value', values);
  138. }
  139. //update-end---author:wangshuai ---date:20230711 for:换成异步组件加载,否则会影响到其他页面描述------------
  140. return {
  141. state,
  142. attrs,
  143. selectOptions,
  144. getBindValue,
  145. selectValues,
  146. loadingEcho,
  147. tag,
  148. regModal,
  149. setValue,
  150. handleOpen,
  151. excludeSiteIdList,
  152. handleChange,
  153. };
  154. },
  155. });
  156. </script>
  157. <style lang="less" scoped>
  158. .j-select-row {
  159. @width: 82px;
  160. .left {
  161. width: calc(100% - @width - 8px);
  162. }
  163. .right {
  164. width: @width;
  165. }
  166. .full {
  167. width: 100%;
  168. }
  169. :deep(.ant-select-search__field) {
  170. display: none !important;
  171. }
  172. }
  173. </style>