zero.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <hc-new-card>
  3. <template #header>
  4. <hc-new-switch :datas="tabTab" :keys="tabKey" :round="false" size="default" @change="tabChange" />
  5. <div v-if="tabKey === 'key2'" class="ml-3 w-40">
  6. <el-select v-model="searchForm.key1" filterable block placeholder="选择工区">
  7. <el-option label="工区1" value="1" />
  8. <el-option label="工区2" value="2" />
  9. <el-option label="工区3" value="3" />
  10. </el-select>
  11. </div>
  12. </template>
  13. <template #extra>
  14. <div class="text-14px text-red-5">提示:生成零号变更后,不可撤回和删除</div>
  15. </template>
  16. <div class="relative h-full flex">
  17. <div :id="`hc_tree_card_${uuid}`">
  18. <hc-card-item scrollbar>
  19. <hc-lazy-tree tree-key="id" :h-props="treeProps" @load="treeLoadNode" @node-tap="treeNodeTap" />
  20. </hc-card-item>
  21. </div>
  22. <div :id="`hc_table_card_${uuid}`" class="flex-1">
  23. <hc-card-item class="h-full">
  24. <template #header>
  25. <div class="text-orange font-400">零号变更数据列表</div>
  26. </template>
  27. <template #extra>
  28. <el-button hc-btn type="primary" :disabled="isBuildZeroChange" @click="buildZeroChange">
  29. <hc-icon name="pencil-ruler-2" />
  30. <span>一键生成零号变更</span>
  31. </el-button>
  32. </template>
  33. <hc-table :is-index="false" :column="tableColumn" :datas="tableData" :loading="tableLoading" is-new />
  34. </hc-card-item>
  35. </div>
  36. </div>
  37. </hc-new-card>
  38. </template>
  39. <script setup>
  40. import { nextTick, onMounted, ref } from 'vue'
  41. import { useAppStore } from '~src/store'
  42. import { getArrValue, getObjValue, getRandom } from 'js-fast-way'
  43. import unitApi from '~api/project/debit/contract/unit'
  44. import mainApi from '~api/alter/admin/zero'
  45. import website from '~src/config'
  46. defineOptions({
  47. name: 'AlterAdminZero',
  48. })
  49. const uuid = getRandom(4)
  50. const useAppState = useAppStore()
  51. const projectId = ref(useAppState.getProjectId || '')
  52. const contractId = ref(useAppState.getContractId || '')
  53. const isBuildZeroChange = ref(false)
  54. //渲染完成
  55. onMounted(() => {
  56. setSplitRef()
  57. if (!website.localModel) {
  58. isBuildZeroChange.value = false
  59. } else {
  60. //甬台温,零号变更按钮禁用
  61. isBuildZeroChange.value = true
  62. }
  63. })
  64. //初始化设置拖动分割线
  65. const setSplitRef = () => {
  66. //配置参考: https://split.js.org/#/?direction=vertical&snapOffset=0
  67. nextTick(() => {
  68. window.$split(['#hc_tree_card_' + uuid, '#hc_table_card_' + uuid], {
  69. sizes: [20, 80],
  70. snapOffset: 0,
  71. minSize: [50, 500],
  72. })
  73. })
  74. }
  75. //类型tab数据和相关处理
  76. const tabKey = ref('key1')
  77. const tabTab = ref([
  78. { key: 'key1', name: '普通变更' },
  79. { key: 'key2', name: '工区变更' },
  80. ])
  81. const tabChange = (item) => {
  82. tabKey.value = item?.key
  83. }
  84. //数据格式
  85. const treeProps = {
  86. label: 'nodeName',
  87. children: 'children',
  88. isLeaf: 'notExsitChild',
  89. }
  90. //懒加载的数据
  91. const treeLoadNode = async ({ item, level }, resolve) => {
  92. let id = 0
  93. if (level !== 0) {
  94. const nodeData = getObjValue(item)
  95. id = nodeData?.id || ''
  96. }
  97. //获取数据
  98. const { data } = await unitApi.lazyTree({
  99. contractId: contractId.value,
  100. id: id,
  101. })
  102. resolve(getArrValue(data))
  103. }
  104. const nodeId = ref('')
  105. const treeNodeTap = ({ data }) => {
  106. nodeId.value = data?.id || ''
  107. getTableData()
  108. }
  109. //搜索表单
  110. const searchForm = ref({ key1: null, nodeId: null })
  111. //表格数据
  112. const tableLoading = ref(false)
  113. const tableColumn = ref([
  114. { key: 'formNumber', name: '清单编号' },
  115. { key: 'formName', name: '清单名称' },
  116. { key: 'currentPrice', name: '现行单价' },
  117. { key: 'contractTotal', name: '合同数量' },
  118. { key: 'contractMoney', name: '清单金额' },
  119. { key: 'buildChangeTotal', name: '生成变更时划分数量' },
  120. { key: 'currentChangeTotal', name: '现划分数量' },
  121. { key: 'updateTotal', name: '修正量' },
  122. { key: 'updateMoney', name: '修正金额' },
  123. { key: 'verifyTotal', name: '核实量' },
  124. { key: 'verifyMoney', name: '核实金额' },
  125. ])
  126. const tableData = ref([])
  127. const getTableData = async () => {
  128. tableData.value = []
  129. tableLoading.value = true
  130. const { data } = await mainApi.getZeroChange({
  131. projectId: projectId.value,
  132. contractId: contractId.value,
  133. nodeId: nodeId.value,
  134. })
  135. tableData.value = getArrValue(data)
  136. tableLoading.value = false
  137. }
  138. //一键生成零号变更
  139. const buildZeroLoading = ref(false)
  140. const buildZeroChange = async () => {
  141. buildZeroLoading.value = true
  142. const { error, code } = await mainApi.buildZeroChange({
  143. projectId: projectId.value,
  144. contractId: contractId.value,
  145. nodeId: nodeId.value,
  146. })
  147. if (!error && code === 200) {
  148. window.$message.success('生成成功')
  149. getTableData().then()
  150. } else {
  151. window.$message.error('生成失败')
  152. }
  153. buildZeroLoading.value = false
  154. }
  155. </script>
  156. <style lang="scss">
  157. .search-form-box .el-form-item {
  158. margin-bottom: 0;
  159. }
  160. </style>