unit.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <div class="relative h-full flex">
  3. <div :id="`hc_tree_card_${uuid}`">
  4. <hc-new-card scrollbar>
  5. <template #header>
  6. <el-button hc-btn type="primary">重新设置treeCode</el-button>
  7. </template>
  8. <hc-lazy-tree :h-props="treeProps" is-load-menu @load="treeLoadNode" @loadMenu="treeLoadMenu" @menuTap="treeMenuTap" @nodeTap="treeNodeTap" />
  9. </hc-new-card>
  10. </div>
  11. <div :id="`hc_table_card_${uuid}`" class="flex-1">
  12. <hc-new-card scrollbar title="合同计量单元">
  13. <template #extra>
  14. <el-button hc-btn type="primary" @click="editModalShow = true">修改</el-button>
  15. <el-button hc-btn type="danger">删除</el-button>
  16. <el-button hc-btn type="warning" @click="treeModalShow = true">增补单元</el-button>
  17. <el-button hc-btn type="success">导入</el-button>
  18. </template>
  19. <div class="relative">
  20. <infoTable />
  21. <HcTitle title="清单分解汇总列表">
  22. <template #extra>
  23. <div class="text-sm text-orange">温馨提示:累计分解量 > 合同变更后量,整行文字红色</div>
  24. </template>
  25. </HcTitle>
  26. <hc-table :column="tableColumn" :datas="tableData" :loading="tableLoading" is-new :index-style="{ width: 60 }">
  27. <template #key1="{ row }">
  28. <i class="i-iconoir-open-select-hand-gesture inline-block" />
  29. </template>
  30. </hc-table>
  31. </div>
  32. </hc-new-card>
  33. </div>
  34. <!-- 节点新增和编辑 -->
  35. <treeForm v-model="treeModalShow" />
  36. <!-- 修改合同计量单元 -->
  37. <rowData v-model="editModalShow" :is-table="isInfoView" />
  38. <!-- 调整排序 -->
  39. <hc-new-dialog v-model="sortModalShow" is-table widths="1100px" title="调整排序" @save="sortModalSave">
  40. <hc-table
  41. ui="hc-table-row-drop"
  42. :column="sortTableColumn" :datas="sortTableData" :loading="sortTableLoading"
  43. is-row-drop quick-sort is-new :index-style="{ width: 80 }"
  44. @row-drop="sortTableRowDrop" @row-sort="sortTableRowDrop"
  45. >
  46. <template #key2="{ row }">
  47. <span class="text-link">{{ row?.key2 }}</span>
  48. </template>
  49. <template #action="{ index }">
  50. <span class="text-link text-xl" @click="upSortClick(index)">
  51. <HcIcon name="arrow-up" fill />
  52. </span>
  53. <span class="text-link ml-2 text-xl" @click="downSortClick(index)">
  54. <HcIcon name="arrow-down" fill />
  55. </span>
  56. </template>
  57. </hc-table>
  58. </hc-new-dialog>
  59. </div>
  60. </template>
  61. <script setup>
  62. import { nextTick, onMounted, ref } from 'vue'
  63. import { getRandom } from 'js-fast-way'
  64. import infoTable from './components/unit/info-table.vue'
  65. import treeForm from './components/unit/tree-form.vue'
  66. import rowData from './components/unit/row-data.vue'
  67. defineOptions({
  68. name: 'ProjectDebitContractUnit',
  69. })
  70. const uuid = getRandom(4)
  71. //渲染完成
  72. onMounted(() => {
  73. setSplitRef()
  74. })
  75. //初始化设置拖动分割线
  76. const setSplitRef = () => {
  77. //配置参考: https://split.js.org/#/?direction=vertical&snapOffset=0
  78. nextTick(() => {
  79. window.$split(['#hc_tree_card_' + uuid, '#hc_table_card_' + uuid], {
  80. sizes: [20, 80],
  81. snapOffset: 0,
  82. minSize: [50, 500],
  83. })
  84. })
  85. }
  86. //搜索表单
  87. const searchForm = ref({})
  88. //数据格式
  89. const treeProps = {
  90. label: 'name',
  91. children: 'children',
  92. isLeaf: 'leaf',
  93. }
  94. //懒加载的数据
  95. const treeLoadNode = ({ level }, resolve) => {
  96. if (level === 0) {
  97. return resolve([{ name: 'region' }])
  98. }
  99. if (level > 3) {
  100. return resolve([])
  101. }
  102. setTimeout(() => {
  103. resolve([
  104. { name: 'leaf', leaf: true },
  105. { name: 'zone' },
  106. ])
  107. }, 500)
  108. }
  109. //节点点击
  110. const isInfoView = ref(false)
  111. const treeNodeTap = ({ node }) => {
  112. isInfoView.value = node.isLeaf
  113. }
  114. //菜单
  115. const treeLoadMenu = ({ item, level }, resolve) => {
  116. if (level === 1) {
  117. return resolve([
  118. { icon: 'lock', label: '锁定', key: 'lock' },
  119. { icon: 'upload-cloud', label: '导入', key: 'lead' },
  120. { icon: 'add', label: '新增', key: 'add' },
  121. { icon: 'arrow-up-down-line', label: '排序', key: 'sort' },
  122. ])
  123. } else {
  124. return resolve([
  125. { icon: 'lock', label: '锁定', key: 'lock' },
  126. { icon: 'upload-cloud', label: '导入', key: 'lead' },
  127. { icon: 'add', label: '新增', key: 'add' },
  128. { icon: 'pencil', label: '修改', key: 'edit' },
  129. { icon: 'arrow-up-down-line', label: '排序', key: 'sort' },
  130. { icon: 'close', label: '删除', key: 'del' },
  131. ])
  132. }
  133. }
  134. const treeMenuTap = ({ key, node, data }) => {
  135. if (key === 'add') {
  136. treeModalShow.value = true
  137. }
  138. if (key === 'edit') {
  139. treeModalShow.value = true
  140. }
  141. if (key === 'sort') {
  142. sortModalShow.value = true
  143. }
  144. }
  145. //表格数据
  146. const tableLoading = ref(false)
  147. const tableColumn = ref([
  148. { key: 'key1', name: '分解明细', width: 80, align: 'center' },
  149. { key: 'key2', name: '清单编号', width: 120, align: 'center' },
  150. { key: 'key3', name: '清单名称', align: 'center' },
  151. { key: 'key4', name: '合同变更数量', width: 110, align: 'center' },
  152. { key: 'key5', name: '施工图变更后汇总数量', align: 'center' },
  153. { key: 'key6', name: '单价(元)', width: 90, align: 'center' },
  154. { key: 'key7', name: '施工图变更后汇总金额(元)', align: 'center' },
  155. ])
  156. const tableData = ref([
  157. { key2: '1111' },
  158. ])
  159. //弹窗
  160. const treeModalShow = ref(false)
  161. const editModalShow = ref(false)
  162. //调整排序
  163. const sortModalShow = ref(false)
  164. //表格数据
  165. const sortTableColumn = ref([
  166. { key:'key1', name: '节点名称' },
  167. { key:'action', name: '排序', width: 90 },
  168. ])
  169. const sortTableLoading = ref(false)
  170. const sortTableData = ref([
  171. { key1: '1' }, { key1: '2' }, { key1: '3' },
  172. ])
  173. //拖动完成
  174. const sortTableRowDrop = (rows) => {
  175. sortTableData.value = [] // 先清空,否则排序会异常
  176. nextTick(() => {
  177. sortTableData.value = rows
  178. })
  179. }
  180. //向下
  181. const downSortClick = (index) => {
  182. const indexs = index + 1
  183. const data = sortTableData.value
  184. if (indexs !== data.length) {
  185. const tmp = data.splice(indexs, 1)
  186. sortTableData.value.splice(index, 0, tmp[0])
  187. } else {
  188. window?.$message?.warning('已经处于置底,无法下移')
  189. }
  190. }
  191. //向上
  192. const upSortClick = (index) => {
  193. const data = sortTableData.value || []
  194. if (index !== 0) {
  195. const tmp = data.splice(index - 1, 1)
  196. sortTableData.value.splice(index, 0, tmp[0])
  197. } else {
  198. window?.$message?.warning('已经处于置顶,无法上移')
  199. }
  200. }
  201. const sortModalSave = () => {
  202. sortModalShow.value = false
  203. }
  204. </script>