changeRequest.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <hc-new-dialog is-table widths="90%" :show="isShow" title="变更清单添加" @save="addModalSave" @close="addModalClose">
  3. <hc-card-item>
  4. <template #header>
  5. <div class="w-60">
  6. <hc-search-input v-model="searchForm.searchValue" placeholder="请输入清单编号" @search="searchClick" />
  7. </div>
  8. </template>
  9. <template #extra>
  10. <el-link type="primary" @click="showTypeClick">{{ searchForm.showType === 1 ? '显示已分解' : '显示所有' }}</el-link>
  11. </template>
  12. <hc-table
  13. :column="tableColumn" :datas="tableData" :loading="tableLoading"
  14. is-new :index-style="{ width: 60 }" is-check :check-style="{ width: 29 }"
  15. @selection-change="tableCheckChange"
  16. />
  17. </hc-card-item>
  18. </hc-new-dialog>
  19. </template>
  20. <script setup>
  21. import { nextTick, ref, watch } from 'vue'
  22. import { useAppStore } from '~src/store'
  23. import { getArrValue } from 'js-fast-way'
  24. import orderApi from '~api/alter/admin/order'
  25. import mainApi from '~api/tasks/hc-data'
  26. const props = defineProps({
  27. info: {
  28. type: Object,
  29. default: () => ({}),
  30. },
  31. })
  32. //事件
  33. const emit = defineEmits(['finish', 'close'])
  34. const useAppState = useAppStore()
  35. const projectId = ref(useAppState.getProjectId || '')
  36. const contractId = ref(useAppState.getContractId || '')
  37. //双向绑定
  38. // eslint-disable-next-line no-undef
  39. const isShow = defineModel('modelValue', {
  40. default: false,
  41. })
  42. //监听数据
  43. const taskInfo = ref({})
  44. watch(() => props.info, (obj) => {
  45. taskInfo.value = obj
  46. }, { immediate: true, deep: true })
  47. //监听
  48. watch(isShow, (val) => {
  49. if (val) {
  50. nextTick(() => {
  51. getTableData()
  52. })
  53. }
  54. })
  55. //搜索
  56. const searchClick = () => {
  57. getTableData()
  58. }
  59. //显示类型
  60. const showTypeClick = () => {
  61. const { showType } = searchForm.value
  62. searchForm.value.showType = showType === 1 ? 2 : 1
  63. getTableData()
  64. }
  65. //搜索表单
  66. const searchForm = ref({ searchValue: null, showType: 1})
  67. //表格数据
  68. const tableLoading = ref(false)
  69. const tableColumn = ref([
  70. { key: 'formNumber', name: '清单编号', width: 120 },
  71. { key: 'formName', name: '清单名称' },
  72. { key: 'currentPrice', name: '单价(元)', width: 100 },
  73. { key: 'contractTotal', name: '合同数量', width: 100 },
  74. { key: 'changeTotal', name: '合同变更后数量', width: 120 },
  75. { key: 'buildChangeTotal', name: '施工图变更后数量', width: 140 },
  76. { key: 'resolveResidueTotal', name: '分解剩余量', width: 100 },
  77. ])
  78. const tableData = ref([])
  79. const getTableData = async () => {
  80. tableData.value = []
  81. tableLoading.value = true
  82. const {ids, treeId, taskId, dataId, primaryKeyIdMeter} = taskInfo.value
  83. const { data } = await orderApi.addForm({
  84. ...searchForm.value,
  85. primaryKeyIdMeter: primaryKeyIdMeter ?? '',
  86. projectId: projectId.value,
  87. contractId: contractId.value,
  88. taskId: taskId ?? '',
  89. nodeId: treeId ?? '',
  90. dataId: dataId ?? '',
  91. ids: ids ?? '',
  92. })
  93. tableData.value = getArrValue(data)
  94. tableLoading.value = false
  95. }
  96. //表格勾选
  97. const tableCheck = ref([])
  98. const tableCheckChange = (rows) => {
  99. tableCheck.value = rows
  100. }
  101. //保存
  102. const addModalSave = async () => {
  103. const {primaryKeyIdMeter, treeId, dataId, taskId} = taskInfo.value
  104. const { error, code, msg } = await mainApi.changeTokenInventorySave({
  105. projectId: projectId.value,
  106. contractId: contractId.value,
  107. primaryKeyIdMeter: primaryKeyIdMeter ?? '',
  108. formList: tableCheck.value,
  109. nodeId: treeId ?? '',
  110. dataId: dataId ?? '',
  111. taskId: taskId ?? '',
  112. })
  113. if (!error && code === 200) {
  114. addModalClose()
  115. emit('finish')
  116. } else {
  117. window.$message.error(msg ?? '确认失败')
  118. }
  119. }
  120. //关闭弹窗
  121. const addModalClose = () => {
  122. isShow.value = false
  123. emit('close')
  124. }
  125. </script>