adjustment.vue 11 KB

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