index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <template>
  2. <div class="main-box">
  3. <LjFoldLayout ref="LjFoldLayoutRef" v-bind="layoutSetting" :dwname="dwname">
  4. <template #left>
  5. <TreeFilter
  6. ref="LjTreeRef"
  7. id="mtrltypeid"
  8. label="mtrltype"
  9. :searchable="false"
  10. :expand-on-click-node="true"
  11. :request-api="gMtrltypeList"
  12. @change="changeTreeFilter"
  13. />
  14. </template>
  15. <div class="main-box flx-col">
  16. <LjVxeTable
  17. ref="VxeTableRef"
  18. row-key="mtrlid"
  19. :columns="columns"
  20. :request-api="getData"
  21. :data-callback="dataCallback"
  22. :dwname="dwname"
  23. :table-props="tableProps"
  24. :table-events="tableEvents"
  25. :init-param="initParams"
  26. :auto-load-layout="false"
  27. pagination
  28. >
  29. <!-- 表格 header 按钮 -->
  30. <template #tableHeader>
  31. <el-button-group>
  32. <el-button @click="handleOpenNewTable">{{ $t("common.add") }}</el-button>
  33. <el-button @click="fDelete">{{ $t("common.delText") }}</el-button>
  34. <el-button @click="fBan">{{ $t("common.disable") }}</el-button>
  35. </el-button-group>
  36. </template>
  37. </LjVxeTable>
  38. </div>
  39. </LjFoldLayout>
  40. </div>
  41. <LjDialog
  42. ref="LjDrawerRef"
  43. class="is-selector"
  44. v-bind="{
  45. ...drawerDefineProp
  46. }"
  47. :style="{ padding: 0 }"
  48. >
  49. <template #header>
  50. <div class="flx-1">
  51. <span class="text-h5-b">物料: {{ mtrlname }}</span>
  52. </div>
  53. </template>
  54. <div class="flx-1 h-full">
  55. <LjHeaderMenu :data="mainData" :action="orderStatus ? orderEditAction : orderDefaultAction" />
  56. <Detail class="flx-1" :data="mainData" :status="orderStatus" :enum="enumMap" />
  57. </div>
  58. </LjDialog>
  59. </template>
  60. <script setup lang="ts" name="baseinfo_mtrldeflist">
  61. import { ref, onMounted, provide } from "vue";
  62. import { getMtrlDefList } from "@/api/modules/basicinfo";
  63. import { useHooks as useHooks_mtrltype } from "@/views/baseinfo/mtrltype/hooks/index";
  64. import Detail from "./detail.vue";
  65. import { useHooks } from "./hooks/index";
  66. import LjDialog from "@/components/LjDialog/index.vue";
  67. import LjHeaderMenu from "@/components/LjHeaderMenu/index.vue";
  68. import { useI18n } from "vue-i18n";
  69. import { useAuthButtons } from "@/hooks/useAuthButtons";
  70. import { cloneDeep } from "lodash-es";
  71. import { traverseNode } from "@/utils/index";
  72. const dwname = "web_mtrldeflist";
  73. const mainData = ref({});
  74. const mtrltype = ref({});
  75. const initParams = ref({ mtrltypeids: undefined as Number[] });
  76. const tableProps = {
  77. height: "auto",
  78. editConfig: { trigger: "click", mode: "cell" }
  79. // rowClassName: rowClsNameFunc
  80. // exportConfig: {
  81. // filename: t("menu.saletaskmx") + formatToDate(new Date(), "YYYY-MM-DD HH:mm:ss")
  82. // }
  83. };
  84. const layoutSetting = {
  85. dwname: dwname,
  86. right: {
  87. hidden: true
  88. }
  89. };
  90. const { t } = useI18n();
  91. const { VxeTableRef, LjDetailRef, VxeTableMxRef, columns, fDelete, fSave, fBan } = useHooks(t);
  92. const { gMtrltypeList } = useHooks_mtrltype(t);
  93. const { CheckPower, CheckOption, buttonNew, buttonDefault } = useAuthButtons(t);
  94. const orderStatus = ref("");
  95. const mtrlname = ref("");
  96. const enumMap = ref(new Map());
  97. const orderDefaultAction = [
  98. buttonDefault({
  99. label: t("common.cancelText"),
  100. icon: "iconchevron-left"
  101. }),
  102. buttonNew({
  103. label: t("common.saveText"),
  104. icon: "iconsave-01",
  105. clickFunc: item => {
  106. const save_data = orderStatus.value == "new" ? LjDetailRef.value?.infoParam : LjDetailRef.value?._mainData;
  107. save_data.mxlist = VxeTableMxRef.value?.tableData;
  108. fSave({ mtrl: save_data }).then(() => {
  109. LjDrawerRef.value.hide();
  110. });
  111. }
  112. })
  113. ];
  114. const orderEditAction = [
  115. buttonNew({
  116. label: t("common.saveText"),
  117. icon: "iconsave-01",
  118. clickFunc: item => {
  119. const save_data = orderStatus.value == "new" ? LjDetailRef.value?.infoParam : LjDetailRef.value?._mainData;
  120. save_data.mxlist = VxeTableMxRef.value?.tableData;
  121. fSave({ mtrl: save_data }).then(() => {
  122. LjDrawerRef.value.hide();
  123. });
  124. }
  125. })
  126. ];
  127. const changeTreeFilter = (val: any) => {
  128. console.log("val :>> ", val);
  129. let mtrltypeids = [] as Number[];
  130. traverseNode(val, (node: any) => node?.mtrltypeid && mtrltypeids.push(parseInt(node.mtrltypeid)));
  131. initParams.value.mtrltypeids = mtrltypeids.length > 0 ? mtrltypeids : undefined;
  132. };
  133. /*
  134. * @description 抽屉默认属性
  135. */
  136. const drawerDefineProp = {
  137. draggable: true,
  138. overflow: true,
  139. width: "40%"
  140. // modalClass: "lj-file-dialog"
  141. };
  142. const getData = (params: any) => {
  143. return getMtrlDefList(params);
  144. };
  145. const dataCallback = (data: any) => {
  146. if (data.tableinfo?.columns) {
  147. data.tableinfo?.columns.map((item: any) => {
  148. if (item?.enum) {
  149. enumMap.value.set(item.field, item.enum);
  150. }
  151. });
  152. }
  153. return {
  154. list: data.datatable,
  155. tableinfo: data.tableinfo,
  156. total: data.totalcnt,
  157. pageNum: data.pageindex,
  158. pageSize: data.pagesize
  159. };
  160. };
  161. const LjDrawerRef = ref();
  162. const handleDBlClickTable = ({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex, $event }: any) => {
  163. // 弹窗
  164. mainData.value = cloneDeep(row);
  165. mtrlname.value = row.name;
  166. orderStatus.value = "edit";
  167. LjDrawerRef.value.show();
  168. };
  169. const handleOpenNewTable = () => {
  170. mainData.value = {
  171. mtrlid: 0
  172. };
  173. mtrlname.value = "";
  174. orderStatus.value = "new";
  175. LjDrawerRef.value.show();
  176. };
  177. // 返回绑定的事件
  178. const tableEvents = {
  179. "cell-dblclick": handleDBlClickTable
  180. // "cell-click": handleClickTable
  181. };
  182. </script>