index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <el-container class="is-vertical">
  3. <sc-page-header @add="table_add()"></sc-page-header>
  4. <scTable ref="xGridTable" :apiObj="$API.production.bom" :formConfig="formConfig" :paramsColums="paramsColums" :columns="columns" :treeConfig="treeConfig">
  5. <template #code_link="{ row }">
  6. <vxe-text status="primary" @click="table_detail(row)">{{ row.bomCode }}</vxe-text>
  7. </template>
  8. <template #action="{ row }">
  9. <el-button v-if="!row.isHaveChildren" type="primary" link @click="table_add(row)">
  10. <template #icon><sc-iconify icon="ant-design:cloud-upload-outlined"></sc-iconify></template>新增
  11. </el-button>
  12. <el-button v-else type="primary" link @click="table_edit(row)">
  13. <template #icon><sc-iconify icon="ant-design:edit-outlined"></sc-iconify></template>修改
  14. </el-button>
  15. <template v-if="row.parentId == 0">
  16. <el-button v-if="row.status == 'enable'" type="primary" link @click="table_change(row)">
  17. <template #icon><sc-iconify icon="material-symbols:lock-outline"></sc-iconify></template>停用
  18. </el-button>
  19. <el-button v-else type="primary" link @click="table_change(row)">
  20. <template #icon><sc-iconify icon="material-symbols:lock-open-outline"></sc-iconify></template>启用
  21. </el-button>
  22. </template>
  23. <el-button v-if="!row.isHaveChildren" type="primary" link @click="table_del(row)">
  24. <template #icon><sc-iconify icon="ant-design:delete-outlined"></sc-iconify></template>删除
  25. </el-button>
  26. </template>
  27. </scTable>
  28. </el-container>
  29. <bom-detail v-if="dialog.detail" ref="bomRef" @success="refreshTable" @closed="dialog.detail = false"></bom-detail>
  30. <bom-desc v-if="dialog.desc" ref="bomDescRef" @closed="dialog.desc = false"></bom-desc>
  31. </template>
  32. <script setup>
  33. import moment from "moment";
  34. import XEUtils from "xe-utils";
  35. import API from "@/api";
  36. import TOOL from "@/utils/tool";
  37. import { statusDic } from "@/utils/basicDic";
  38. import { mapFormItemInput, mapFormItemSelect, mapFormItemDatePicker, mapFormItemTenant } from "@/components/scTable/helper";
  39. import bomDetail from "./detail";
  40. import bomDesc from "./desc";
  41. import store from "@/store";
  42. watch(() => store.state.tenant.tenantId, () => refreshTable());
  43. const treeConfig = reactive({
  44. lazy: true,
  45. hasChildField: "isHaveChildren",
  46. loadMethod: ({ row }) => API.production.bom.getChild({ id: row.id })
  47. })
  48. const selectConfig = reactive({
  49. options: statusDic,
  50. events: {
  51. change: data => XEUtils.merge(formConfig.data, data)
  52. }
  53. });
  54. const daterangeConfig = reactive({
  55. resetValue: () => [],
  56. props: {
  57. type: "daterange",
  58. startPlaceholder: "开始日期",
  59. endPlaceholder: "结束日期",
  60. format: "YYYY-MM-DD"
  61. }
  62. });
  63. const formConfig = reactive({
  64. data: {},
  65. items: [
  66. mapFormItemTenant({ events: { change: data => XEUtils.merge(formConfig.data, data) } }),
  67. mapFormItemInput("bomCodeLike", "BOM单编号"),
  68. mapFormItemInput("materialCodeLike", "产品编码"),
  69. mapFormItemInput("materialNameLike", "产品名称"),
  70. mapFormItemSelect("status", "BOM单状态", selectConfig),
  71. mapFormItemDatePicker("createTime", "创建日期", daterangeConfig)
  72. ]
  73. });
  74. const paramsColums = reactive([
  75. { column: "orderBy", defaultValue: "bomCode_asc" },
  76. { column: "parentId", defaultValue: "0" },
  77. { column: "tenantId" },
  78. { column: "bomCodeLike" },
  79. { column: "materialCodeLike" },
  80. { column: "materialNameLike" },
  81. { column: "status" },
  82. { column: "createTimeBegin", field: "createTime[0]" },
  83. { column: "createTimeEnd", field: "createTime[1]" }
  84. ]);
  85. const columns = reactive([
  86. { type: "seq", fixed: "left", width: 80 },
  87. { visible: computed(() => store.state.tenant.tenantId === "0"), type: "html", field: "tenantName", title: "所属租户", fixed: "left", minWidth: 200, sortable: true, formatter: ({ cellValue, row }) => cellValue || XEUtils.get(XEUtils.find(store.state.tenant.tenants, item => item.id == row.tenantId), "name") },
  88. { type: "html", field: "materialCode", title: "产品编码", fixed: "left", minWidth: 150, treeNode: true, headerAlign: "center", align: "left", sortable: true },
  89. { type: "html", field: "materialName", title: "产品名称", fixed: "left", minWidth: 150, sortable: true },
  90. { field: "bomCode", title: "BOM单编号", minWidth: 150, sortable: true, className: "vxe-table-link-cell", slots: { default: "code_link" } },
  91. { field: "status", title: "BOM单状态", minWidth: 120, editRender: { name: "$cell-tag", options: statusDic } },
  92. { type: "html", field: "createTime", title: "创建日期", minWidth: 120, sortable: true, formatter: ({ cellValue }) => TOOL.dateFormat(cellValue, "YYYY-MM-DD") || cellValue },
  93. { visible: false, type: "html", field: "remark", title: "概要", minWidth: 300, sortable: true },
  94. { title: "操作", fixed: "right", width: 220, slots: { default: "action" } }
  95. ]);
  96. // 显示隐藏 筛选表单
  97. const xGridTable = ref();
  98. const refreshTable = (mode = "add") => (xGridTable.value.searchData(mode), xGridTable.value.reloadColumn(columns));
  99. const bomRef = ref();
  100. const bomDescRef = ref();
  101. const dialog = reactive({
  102. detail: false,
  103. desc: false
  104. });
  105. const table_add = (row = {}) => {
  106. dialog.detail = true;
  107. nextTick(() => bomRef.value?.setData(row));
  108. }
  109. const table_edit = row => {
  110. dialog.detail = true;
  111. nextTick(() => bomRef.value?.setData(row, "edit"));
  112. }
  113. const table_detail = row => {
  114. dialog.desc = true;
  115. nextTick(() => bomDescRef.value?.setData(row));
  116. }
  117. const table_del = ({ id }) => {
  118. ElMessageBox.confirm("是否确认删除该BOM清单?", "删除警告", {
  119. type: "warning",
  120. confirmButtonText: "确定",
  121. cancelButtonText: "取消"
  122. }).then(() => {
  123. API.production.bom.del({ id }).then(() => {
  124. ElMessage.success("操作成功");
  125. refreshTable();
  126. });
  127. }).catch(() => {});
  128. }
  129. const table_change = row => {
  130. const status = row.status == "enable" && "disable" || "enable";
  131. const msg = row.status == "enable" && "停用" || "启用";
  132. ElMessageBox.confirm(`是否确认${msg}该BOM清单?`, `${msg}警告`, {
  133. type: "warning",
  134. confirmButtonText: "确定",
  135. cancelButtonText: "取消"
  136. }).then(() => {
  137. API.production.bom.edit({ id: row.id, status }).then(() => {
  138. ElMessage.success("操作成功");
  139. refreshTable();
  140. });
  141. }).catch(() => {});
  142. }
  143. </script>