adjustment.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <hc-card class="hc-debit-pay-material-adjustment">
  3. <template #header>
  4. <div class="w-40">
  5. <el-input v-model="searchForm.materialNumber" placeholder="材料编码" />
  6. </div>
  7. <div class="ml-3 w-60">
  8. <hc-search-input v-model="searchForm.materialName" placeholder="请输入材料名称" @search="getTableData" />
  9. </div>
  10. </template>
  11. <hc-body :split="rowBindingShow" padding="0">
  12. <hc-card-item>
  13. <hc-table :column="tableColumn" :datas="tableData" :is-index="false" :loading="tableLoading">
  14. <template #action="{ row }">
  15. <template v-if="row.rowBindingData">
  16. <el-link type="success" :disabled="treeLoadNode.length <= 0" @click="confirmBinding(row)">确认绑定</el-link>
  17. <el-link type="danger" @click="cancelBinding(row)">取消绑定</el-link>
  18. </template>
  19. <template v-else>
  20. <el-link type="warning" @click="rowBinding(row)">绑定清单</el-link>
  21. <el-link type="primary" @click="rowEditClick(row)">编辑</el-link>
  22. </template>
  23. </template>
  24. </hc-table>
  25. </hc-card-item>
  26. <template #right>
  27. <hc-card-item scrollbar>
  28. <el-tree ref="treeRef" :data="treeLoadNode" node-key="id" :props="treeProps" :default-checked-keys="treeNodeCheckList" show-checkbox check-strictly>
  29. <template #default="{ data }">
  30. <div class="data-custom-tree-node">
  31. <div class="level">{{ data.formName }}</div>
  32. <div v-if="data.isFormNode" class="submit-input">
  33. <el-input v-model="data.adjustFactor" size="small" placeholder="请输入调差参数" :disabled="data.isQuote === 1" />
  34. </div>
  35. </div>
  36. </template>
  37. </el-tree>
  38. </hc-card-item>
  39. </template>
  40. </hc-body>
  41. <!-- 调差系数编辑 -->
  42. <hc-new-dialog v-model="isFormModal" title="调差系数编辑" is-footer-center is-table widths="50rem" @close="modalClose">
  43. <hc-table :column="tableColumn1" :datas="tableData2" :is-index="false">
  44. <template #adjustFactor="{ row }">
  45. <hc-table-input v-model="row.adjustFactor" :disabled="row.isQuote === 1" />
  46. </template>
  47. <template #action="{ row }">
  48. <el-link type="danger" :disabled="row.isQuote === 1" @click="dischargeBinding(row)">解除绑定关系</el-link>
  49. </template>
  50. </hc-table>
  51. <template #footer>
  52. <el-button hc-btn @click="modalClose">取消</el-button>
  53. <el-button :loading="saveLoaing" hc-btn type="primary" @click="modalSave">提交</el-button>
  54. </template>
  55. </hc-new-dialog>
  56. </hc-card>
  57. </template>
  58. <script setup>
  59. import { onActivated, onDeactivated, ref } from 'vue'
  60. import { useAppStore } from '~src/store'
  61. import { HcDelMsg } from 'hc-vue3-ui'
  62. import { getArrValue } from 'js-fast-way'
  63. import mainApi from '~api/debit-pay/material/adjustment'
  64. //初始化
  65. const store = useAppStore()
  66. const projectId = ref(store.getProjectId)
  67. const contractId = ref(store.getContractId)
  68. //渲染完成
  69. onActivated(() => {
  70. getTableData()
  71. })
  72. //搜索表单
  73. const searchForm = ref({ materialNumber: '', materialName: '' })
  74. //表格
  75. const tableColumn = [
  76. { key: 'materialNumber', name: '材料编码' },
  77. { key: 'materialName', name: '材料名称' },
  78. { key: 'unit', name: '材料单位' },
  79. { key: 'action', name: '操作', width: 140, align: 'center' },
  80. ]
  81. const tableData = ref([])
  82. //获取表格数据
  83. const tableLoading = ref(false)
  84. const getTableData = async () => {
  85. tableLoading.value = true
  86. const { error, code, data } = await mainApi.getAllMaterial({
  87. ...searchForm.value,
  88. projectId: projectId.value,
  89. contractId: contractId.value,
  90. })
  91. tableLoading.value = false
  92. if (!error && code === 200) {
  93. tableData.value = getArrValue(data)
  94. } else {
  95. tableData.value = []
  96. }
  97. }
  98. //调差树
  99. const treeRef = ref(null)
  100. const treeProps = {
  101. label: 'formName', children: 'children',
  102. disabled: (data) => {
  103. return data.isQuote === 1
  104. },
  105. class: (data) => {
  106. return `${data.isFormNode === 1 ? 'is-form-node' : 'no-form-check'}`
  107. },
  108. }
  109. const treeLoadNode = ref([])
  110. //绑定清单
  111. const rowBindingShow = ref(false)
  112. const treeNodeCheckList = ref([])
  113. const rowBinding = async (row) => {
  114. if (rowBindingShow.value) {
  115. window.$message.error('请先操作完上一个清单')
  116. return
  117. }
  118. rowBindingShow.value = true
  119. row.rowBindingData = true
  120. //获取树的数据
  121. const { data } = await mainApi.getAdjustFormTree({
  122. projectId: projectId.value,
  123. contractId: contractId.value,
  124. materialId: row.id,
  125. })
  126. treeLoadNode.value = getArrValue(data['vo2s'])
  127. treeNodeCheckList.value = getArrValue(data['ids'])
  128. }
  129. //确认绑定
  130. const confirmBinding = async (row) => {
  131. const nodes = treeRef.value?.getCheckedNodes()
  132. if (nodes.length <= 0) {
  133. window.$message.error('请先勾选要绑定的节点')
  134. return false
  135. }
  136. //处理数据
  137. let newArr = []
  138. for (let i = 0; i < nodes.length; i++) {
  139. newArr.push({
  140. id: nodes[i].id,
  141. adjustFactor: nodes[i].adjustFactor ?? '',
  142. })
  143. }
  144. //发起请求
  145. const { error, code, msg } = await mainApi.linkFormMaterial({
  146. projectId: projectId.value,
  147. contractId: contractId.value,
  148. materialId: row.id,
  149. forms: newArr,
  150. })
  151. if (!error && code === 200) {
  152. window.$message.success(msg)
  153. cancelBinding(row)
  154. getTableData().then()
  155. } else {
  156. window.$message.error(msg ?? '操作失败')
  157. }
  158. }
  159. //取消绑定
  160. const cancelBinding = (row) => {
  161. rowBindingShow.value = false
  162. row.rowBindingData = false
  163. }
  164. //编辑表格
  165. const tableColumn1 = [
  166. { key: 'formName', name: '清单名称' },
  167. { key: 'formNumber', name: '清单编号' },
  168. { key: 'materialName', name: '绑定材料名称' },
  169. { key: 'adjustFactor', name: '调差系数' },
  170. { key: 'action', name: '操作', width: 110, align: 'center' },
  171. ]
  172. const tableData2 = ref([])
  173. const getLinkAllForm = async () => {
  174. const { data } = await mainApi.linkAllForm({
  175. projectId: projectId.value,
  176. contractId: contractId.value,
  177. materialId: tableRowID.value,
  178. })
  179. tableData2.value = getArrValue(data)
  180. }
  181. //编辑
  182. const isFormModal = ref(false)
  183. const tableRowID = ref('')
  184. const rowEditClick = (row) => {
  185. isFormModal.value = true
  186. tableRowID.value = row.id
  187. getLinkAllForm()
  188. }
  189. //解除绑定关系
  190. const dischargeBinding = (row) => {
  191. HcDelMsg({
  192. title: '确认操作提醒',
  193. text: '确认要解除绑定关系?',
  194. }, async (resolve) => {
  195. const { error, code, msg } = await mainApi.removeLinkForm(row.id)
  196. if (!error && code === 200) {
  197. window.$message.success(msg)
  198. getLinkAllForm()
  199. resolve()
  200. } else {
  201. window.$message.error(msg ?? '操作失败')
  202. }
  203. })
  204. }
  205. //保存
  206. const saveLoaing = ref(false)
  207. const modalSave = async () => {
  208. const list = tableData2.value
  209. if (list.length <= 0) {
  210. window.$message.error('无数据可提交')
  211. return
  212. }
  213. //处理数据
  214. let newArr = []
  215. for (let i = 0; i < list.length; i++) {
  216. newArr.push({
  217. id: list[i].id,
  218. adjustFactor: list[i].adjustFactor,
  219. })
  220. }
  221. //发起请求
  222. const { error, code, msg } = await mainApi.submitLinkForm(newArr)
  223. if (!error && code === 200) {
  224. window.$message.success(msg)
  225. modalClose()
  226. } else {
  227. window.$message.error(msg ?? '操作失败')
  228. }
  229. }
  230. //取消关闭
  231. const modalClose = () => {
  232. isFormModal.value = false
  233. tableData2.value = []
  234. tableRowID.value = ''
  235. }
  236. //页面卸载
  237. onDeactivated(() => {
  238. rowBindingShow.value = false
  239. })
  240. </script>
  241. <style lang="scss">
  242. .hc-debit-pay-material-adjustment .el-tree {
  243. --el-fill-color-blank: transparent;
  244. --el-tree-node-hover-bg-color: white;
  245. .el-tree-node.no-form-check .el-tree-node__content .el-checkbox {
  246. display: none;
  247. }
  248. .el-tree-node.is-form-node .el-tree-node__content .el-checkbox {
  249. display: inline-flex;
  250. }
  251. .data-custom-tree-node {
  252. position: relative;
  253. display: flex;
  254. align-items: center;
  255. width: 100%;
  256. flex: 1;
  257. white-space: nowrap;
  258. overflow: hidden;
  259. text-overflow: ellipsis;
  260. color: #101010;
  261. .level {
  262. position: relative;
  263. flex: 1;
  264. height: 100%;
  265. display: flex;
  266. align-items: center;
  267. white-space: nowrap;
  268. overflow: hidden;
  269. text-overflow: ellipsis;
  270. }
  271. .submit-input {
  272. position: unset;
  273. margin-left: 10px;
  274. margin-right: 2px;
  275. width: 100px;
  276. }
  277. .el-input .el-input__wrapper {
  278. background-color: white;
  279. }
  280. }
  281. }
  282. </style>