zero.vue 5.0 KB

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