amplify.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <div class="amplify-container">
  3. <div class="amplify-main">
  4. <ProForm :items-options="items" :model="model"> </ProForm>
  5. <el-container>
  6. <el-table :data="batchDataList" tooltip-effect="dark" style="width: 100%" @selection-change="handleSelectionChange">
  7. <el-table-column type="selection"> </el-table-column>
  8. <el-table-column prop="batchNum" label="所有批次"> </el-table-column>
  9. <el-table-column prop="batchSize" label="数量"> </el-table-column>
  10. </el-table>
  11. <el-container style=" display: flex; flex-direction: column; justify-content: center;margin: 0 30px">
  12. <el-button type="primary" icon="ArrowRightBold" :disabled="!canSelect" @click="clickSelectData"></el-button>
  13. <el-container style="height: 10px"></el-container>
  14. <el-button type="primary" 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. </div>
  23. <el-footer>
  24. <el-button class="submit" type="primary" @click="handleSubmit">提交</el-button>
  25. </el-footer>
  26. </div>
  27. </template>
  28. <script setup lang="tsx" name="amplify">
  29. import { reactive, ref, computed, onMounted } from 'vue'
  30. import ProForm from '@/components/ProForm/index.vue'
  31. import { batchListDataApi, amplifyApi } from '@/api/modules/demo/data'
  32. import { getDictsApi } from '@/api/modules/system/dictData'
  33. let model = {
  34. taskName: 'ssss',
  35. transfer: null
  36. }
  37. let batchDataList = ref(reactive([] as any[]))
  38. let selectedBatchDataList = ref(reactive([] as any[]))
  39. let tempSelectedBatchDataList = ref(reactive([] as any[]))
  40. let tempDeselectedBatchDataList = ref(reactive([] as any[]))
  41. let parameList = ref(reactive([] as any[]))
  42. onMounted(() => {
  43. batchListDataApi().then(res => {
  44. batchDataList.value = reactive(res.data)
  45. })
  46. getDictsApi('expand_data_params').then(res => {
  47. parameList.value = reactive(JSON.parse(res.data[0].remark))
  48. parameList.value.forEach(item => {
  49. items.push({
  50. label: item.name,
  51. prop: item.agName,
  52. span: 12,
  53. rules: [{ required: item.required, message: '不能为空' }],
  54. compOptions: {
  55. elTagName: 'input',
  56. clearable: true,
  57. placeholder: '请输入..'
  58. }
  59. })
  60. model[`${item.agName}`] = item.defaultValue
  61. })
  62. })
  63. })
  64. const handleSelectionChange = data => {
  65. tempSelectedBatchDataList.value = reactive(data)
  66. }
  67. const canSelect = computed(() => {
  68. return tempSelectedBatchDataList.value.length > 0
  69. })
  70. const handleDeselectionChange = data => {
  71. tempDeselectedBatchDataList.value = reactive(data)
  72. }
  73. const clickSelectData = () => {
  74. let set = new Set()
  75. for (let i = 0; i < tempSelectedBatchDataList.value.length; i++) {
  76. set.add(tempSelectedBatchDataList.value[i].batchNum)
  77. selectedBatchDataList.value.push(tempSelectedBatchDataList.value[i])
  78. }
  79. let newArray = [] as any[]
  80. for (let i = 0; i < batchDataList.value.length; i++) {
  81. if (!set.has(batchDataList.value[i].batchNum)) {
  82. newArray.push(batchDataList.value[i])
  83. }
  84. }
  85. batchDataList.value = reactive(newArray)
  86. }
  87. const canDeselect = computed(() => {
  88. return tempDeselectedBatchDataList.value.length > 0
  89. })
  90. const clickDeselectData = () => {
  91. let set = new Set()
  92. for (let i = 0; i < tempDeselectedBatchDataList.value.length; i++) {
  93. set.add(tempDeselectedBatchDataList.value[i].batchNum)
  94. batchDataList.value.push(tempDeselectedBatchDataList.value[i])
  95. }
  96. let newArray = [] as any[]
  97. for (let i = 0; i < selectedBatchDataList.value.length; i++) {
  98. if (!set.has(selectedBatchDataList.value[i].batchNum)) {
  99. newArray.push(selectedBatchDataList.value[i])
  100. }
  101. }
  102. selectedBatchDataList.value = reactive(newArray)
  103. }
  104. const handleSubmit = () => {
  105. amplifyApi(selectedBatchDataList.value).then(res => {
  106. console.log(res)
  107. })
  108. }
  109. let items: ProForm.ItemsOptions[] = reactive([
  110. {
  111. label: '任务名称',
  112. prop: 'taskName',
  113. span: 14,
  114. // labelWidth: '90px',
  115. rules: [{ required: true, message: '请输入任务名称' }],
  116. compOptions: {
  117. elTagName: 'input',
  118. clearable: true,
  119. placeholder: '请输入用户名'
  120. }
  121. }
  122. ])
  123. </script>
  124. <style scoped lang="scss">
  125. @import './index.scss';
  126. </style>