AmplifyForm.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <template>
  2. <div class="amplify-main">
  3. <ProForm :items-options="items" :model="model"></ProForm>
  4. <el-button type="primary" v-if="showSelectBatchButton" style="margin-left: 50px" @click="showDataSelectionDialog()">选择批次</el-button>
  5. <el-dialog v-model="dataDialogVisible" title="选择数据批次" style="width: 70vw">
  6. <el-container>
  7. <el-table :data="batchDataList" tooltip-effect="dark" style="width: 100%; margin-bottom: 30px" @selection-change="handleSelectionChange">
  8. <el-table-column type="selection"></el-table-column>
  9. <el-table-column prop="batchNum" label="所有批次"></el-table-column>
  10. <el-table-column prop="batchSize" label="数量"></el-table-column>
  11. </el-table>
  12. <el-container style="display: flex; flex-direction: column; align-items: center; justify-content: center; margin: 0 30px">
  13. <el-button type="primary" icon="ArrowRightBold" :disabled="!canSelect" @click="clickSelectData"></el-button>
  14. <el-button type="primary" style="margin: 10px 0 0" icon="ArrowLeftBold" :disabled="!canDeselect" @click="clickDeselectData"></el-button>
  15. </el-container>
  16. <el-table :data="selectedBatchDataList" tooltip-effect="dark" style="width: 100%" @selection-change="handleDeselectionChange">
  17. <el-table-column type="selection"></el-table-column>
  18. <el-table-column prop="batchNum" label="已选批次"></el-table-column>
  19. <el-table-column prop="batchSize" label="数量"></el-table-column>
  20. </el-table>
  21. </el-container>
  22. <template #footer>
  23. <div class="dialog-footer">
  24. <el-button @click="dataDialogVisible = false">取消</el-button>
  25. <el-button type="primary" @click="confirmSelection">确定</el-button>
  26. </div>
  27. </template>
  28. </el-dialog>
  29. </div>
  30. </template>
  31. <script setup lang="tsx">
  32. import { reactive, ref, computed, onMounted, defineEmits } from 'vue'
  33. import ProForm from '@/components/ProForm/index.vue'
  34. import { batchListDataApi } from '@/api/modules/demo/data'
  35. import { getDictsApi } from '@/api/modules/system/dictData'
  36. const emit = defineEmits(['updateData', 'updateModel', 'updateParams'])
  37. // 数据
  38. let model = {
  39. taskName: 'sss',
  40. transfer: null
  41. }
  42. const dataDialogVisible = ref(false)
  43. let batchDataList = ref(reactive([] as any[]))
  44. let selectedBatchDataList = ref(reactive([] as any[]))
  45. let tempSelectedBatchDataList = ref(reactive([] as any[]))
  46. let tempDeselectedBatchDataList = ref(reactive([] as any[]))
  47. let parameList = ref(reactive([] as any[]))
  48. let queryBatchData = ref(reactive([] as any[]))
  49. const props = defineProps({ showSelectBatchButton: Boolean })
  50. onMounted(() => {
  51. batchListDataApi().then(res => {
  52. queryBatchData.value = reactive(res.data)
  53. })
  54. getDictsApi('expand_data_params').then(res => {
  55. parameList.value = reactive(JSON.parse(res.data[0].remark))
  56. parameList.value.forEach(item => {
  57. items.push({
  58. label: item.name,
  59. prop: item.agName,
  60. span: 12,
  61. rules: [{ required: item.required === 'true', message: item.name + '不能为空' }],
  62. compOptions: {
  63. elTagName: 'input',
  64. clearable: true,
  65. placeholder: '请输入' + item.name
  66. }
  67. })
  68. model[`${item.agName}`] = item.defaultValue
  69. })
  70. emit('updateModel', model)
  71. // Emit parameList 给父组件
  72. emit('updateParams', parameList.value)
  73. })
  74. })
  75. const handleSelectionChange = data => {
  76. tempSelectedBatchDataList.value = reactive(data)
  77. }
  78. let canSelect = computed(() => tempSelectedBatchDataList.value.length > 0)
  79. const handleDeselectionChange = data => {
  80. tempDeselectedBatchDataList.value = reactive(data)
  81. }
  82. const clickSelectData = () => {
  83. let set = new Set()
  84. tempSelectedBatchDataList.value.forEach(batch => {
  85. set.add(batch.batchNum)
  86. selectedBatchDataList.value.push(batch)
  87. })
  88. batchDataList.value = reactive(batchDataList.value.filter(batch => !set.has(batch.batchNum)))
  89. emit('updateData', selectedBatchDataList.value)
  90. }
  91. const canDeselect = computed(() => tempDeselectedBatchDataList.value.length > 0)
  92. const clickDeselectData = () => {
  93. let set = new Set()
  94. tempDeselectedBatchDataList.value.forEach(batch => {
  95. set.add(batch.batchNum)
  96. batchDataList.value.push(batch)
  97. })
  98. selectedBatchDataList.value = reactive(selectedBatchDataList.value.filter(batch => !set.has(batch.batchNum)))
  99. emit('updateData', selectedBatchDataList.value)
  100. }
  101. const showDataSelectionDialog = () => {
  102. if (selectedBatchDataList.value.length === 0) {
  103. batchDataList.value = queryBatchData.value
  104. }
  105. dataDialogVisible.value = true
  106. }
  107. const confirmSelection = () => {
  108. emit('updateData', selectedBatchDataList.value)
  109. dataDialogVisible.value = false
  110. }
  111. const labeledTypeData = [
  112. {
  113. label: 'obb',
  114. value: 'obb'
  115. },
  116. {
  117. label: 'hbb',
  118. value: 'hbb'
  119. }
  120. ]
  121. let items: ProForm.ItemsOptions[] = reactive([
  122. {
  123. label: '任务名称',
  124. prop: 'taskName',
  125. span: 14,
  126. rules: [{ required: true, message: '请输入任务名称' }],
  127. compOptions: {
  128. elTagName: 'input',
  129. clearable: true,
  130. placeholder: '请输入用户名'
  131. }
  132. },
  133. {
  134. label: '扩充方式',
  135. prop: 'augmentationType',
  136. span: 14,
  137. rules: [{ required: true, message: '请输入扩充方式' }],
  138. compOptions: {
  139. elTagName: 'select',
  140. enum: labeledTypeData
  141. }
  142. }
  143. ])
  144. </script>
  145. <style scoped lang="scss">
  146. @import './index.scss';
  147. </style>