tree-form.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <hc-new-dialog v-model="isShow" is-table widths="95%" title="合同计量单元新增" :loading="addNodeLoading" @save="modalSave">
  3. <div class="relative h-full flex">
  4. <div :id="`hc_tree_card_${uuid}`">
  5. <hc-new-card scrollbar>
  6. <template #header>
  7. <div class="text-sm text-orange">↓ 选择部位【点击新增】</div>
  8. </template>
  9. <div class="tree-list">
  10. <div v-for="(item, index) in treeDataList" :key="index" class="item" @click="treeListClick(item)">
  11. <HcIcon name="box-3" fill />
  12. <span class="ml-1">{{ item.nodeName }}</span>
  13. </div>
  14. </div>
  15. </hc-new-card>
  16. </div>
  17. <div :id="`hc_table_card_${uuid}`" class="flex-1">
  18. <hc-new-card scrollbar title="合同计量单元">
  19. <hc-table :is-index="false" :column="tableColumn" :datas="tableData" is-new :index-style="{ width: 60 }">
  20. <template #nodeName="{ row }">
  21. <hc-table-input v-model="row.nodeName" />
  22. </template>
  23. <template #startStake="{ row }">
  24. <hc-table-input v-model="row.startStake" />
  25. </template>
  26. <template #endStake="{ row }">
  27. <hc-table-input v-model="row.endStake" />
  28. </template>
  29. <template #contractPicture="{ row }">
  30. <hc-table-input v-model="row.contractPicture" />
  31. </template>
  32. <template #isAddChildNode="{ row }">
  33. <el-radio-group v-model="row.isAddChildNode">
  34. <el-radio :label="1">是</el-radio>
  35. <el-radio :label="2" class="ml-2">否</el-radio>
  36. </el-radio-group>
  37. </template>
  38. <template #action="{ index }">
  39. <el-link type="danger" @click="delRowClick(index)">删除</el-link>
  40. </template>
  41. </hc-table>
  42. </hc-new-card>
  43. </div>
  44. </div>
  45. </hc-new-dialog>
  46. </template>
  47. <script setup>
  48. import { nextTick, ref, watch } from 'vue'
  49. import { getArrValue, getRandom } from 'js-fast-way'
  50. import unitApi from '~api/project/debit/contract/unit.js'
  51. import { useAppStore } from '~src/store'
  52. const props = defineProps({
  53. ids: {
  54. type: [String, Number],
  55. default: '',
  56. },
  57. menuType:{
  58. type: [String, Number],
  59. default: '',
  60. },
  61. templateId:{
  62. type: [String, Number],
  63. default: '',
  64. },
  65. })
  66. //事件
  67. const emit = defineEmits(['finish', 'close'])
  68. const useAppState = useAppStore()
  69. const projectId = ref(useAppState.getProjectId || '')
  70. const contractId = ref(useAppState.getContractId || '')
  71. const menuType = ref(props.menuType)
  72. const ids = ref(props.ids)
  73. const templateId = ref(props.templateId)
  74. const uuid = getRandom(4)
  75. //双向绑定
  76. // eslint-disable-next-line no-undef
  77. const isShow = defineModel('modelValue', {
  78. default: false,
  79. })
  80. //监听
  81. watch(() => [
  82. props.ids,
  83. props.menuType,
  84. props.templateId,
  85. ], ([Ids, Type, Tem]) => {
  86. console.log(Type, 'Type')
  87. ids.value = Ids
  88. menuType.value = Type
  89. templateId.value = Tem
  90. }, { immediate: true })
  91. //监听
  92. watch(isShow, (val) => {
  93. if (val) {
  94. setSplitRef()
  95. getTreeDataList()
  96. }
  97. })
  98. //初始化设置拖动分割线
  99. const setSplitRef = () => {
  100. //配置参考: https://split.js.org/#/?direction=vertical&snapOffset=0
  101. nextTick(() => {
  102. window.$split(['#hc_tree_card_' + uuid, '#hc_table_card_' + uuid], {
  103. sizes: [20, 80],
  104. snapOffset: 0,
  105. minSize: [50, 500],
  106. })
  107. })
  108. }
  109. const treeDataList = ref([])
  110. const treeListClick = (item) => {
  111. tableData.value.push({
  112. nodeName: item.nodeName,
  113. startStake: '',
  114. endStake: '',
  115. contractPicture: '',
  116. isAddChildNode: 1,
  117. leftNodeId:item.id,
  118. })
  119. }
  120. const getTreeDataList = async ()=>{
  121. const { error, code, data } = await unitApi.getLeftList({
  122. id:ids.value,
  123. })
  124. if (!error && code === 200) {
  125. treeDataList.value = getArrValue(data)
  126. } else {
  127. treeDataList.value = []
  128. }
  129. }
  130. //表格数据
  131. const tableColumn = ref([
  132. { key: 'nodeName', name: '名称' },
  133. { key: 'startStake', name: '开始桩号' },
  134. { key: 'endStake', name: '结束桩号' },
  135. { key: 'contractPicture', name: '合同图号' },
  136. { key: 'isAddChildNode', name: '是否划分子节点', width: 120, align: 'center' },
  137. { key: 'action', name: '操作', width: 80, align: 'center' },
  138. ])
  139. const tableData = ref([])
  140. //删除
  141. const delRowClick = (index) => {
  142. tableData.value.splice(index, 1)
  143. }
  144. const addNodeLoading = ref(false)
  145. const modalSave = async () => {
  146. if (tableData.value.length === 0) {
  147. window.$message.warning('请选择部位点击新增')
  148. return
  149. }
  150. const { error, code, msg } = await unitApi.addNode({
  151. contractId:contractId.value,
  152. projectId:projectId.value,
  153. contractNodeId:ids.value,
  154. requestType:menuType.value === 'add' ? 1 : 2, //请求类型 1=节点新增 2=增补单元新增
  155. templateId: templateId.value,
  156. dataList:tableData.value,
  157. })
  158. //判断状态
  159. addNodeLoading.value = false
  160. if (!error && code === 200) {
  161. window?.$message?.success(msg)
  162. tableData.value = []
  163. }
  164. emit('finish')
  165. }
  166. </script>
  167. <style lang="scss" scoped>
  168. .tree-list {
  169. position: relative;
  170. .item {
  171. position: relative;
  172. height: 24px;
  173. display: flex;
  174. align-items: center;
  175. white-space: nowrap;
  176. cursor: pointer;
  177. transition: color .2s;
  178. &:hover {
  179. color: var(--el-color-primary);
  180. }
  181. }
  182. }
  183. </style>