index.vue 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  1. <template>
  2. <div class="box">
  3. <div class="tree">
  4. <treeList title="产品分类" submitType="1" :data="treeListData" v-model="sourceList.pagination.productClassifyId" @change="treeChange"
  5. @changeTreeList="getTreeList">
  6. </treeList>
  7. </div>
  8. <div class="content">
  9. <byTable :source="sourceList.data" :tableHeight="tableHeight" :pagination="sourceList.pagination" :config="config" :loading="loading"
  10. highlight-current-row :selectConfig="selectConfig" :action-list="[
  11. {
  12. text: '导出Excel',
  13. action: () => exportExcel(),
  14. disabled: false,
  15. },
  16. {
  17. text: '添加',
  18. action: () => openModal('add'),
  19. disabled: false,
  20. },]" @get-list="getList">
  21. <template #name="{ item }">
  22. <div>
  23. <span class="el-click">{{ item.name }}</span>
  24. </div>
  25. </template>
  26. <template #pic="{ item }">
  27. <div v-if="item.fileList.length > 0">
  28. <img :src="item.fileList[0].fileUrl" class="pic" @click="handleClickFile(item.fileList[0])" />
  29. </div>
  30. <div v-else></div>
  31. </template>
  32. <template #size="{ item }">
  33. <div v-if="item['length'] && item.width && item.height">
  34. <span>{{ item['length'] }}</span>*
  35. <span>{{ item.width }}</span>*
  36. <span>{{ item.height }}</span>
  37. </div>
  38. <div v-else></div>
  39. </template>
  40. <template #price="{ item }">
  41. <div v-if="item.price">
  42. <span>{{ item.currency }} {{ moneyFormat(item.price ,2)}}</span>
  43. </div>
  44. <div v-else></div>
  45. </template>
  46. </byTable>
  47. </div>
  48. <el-dialog :title="modalType == 'add' ? '添加产品' : '编辑产品'" v-model="dialogVisible" width="80%" destroy-on-close>
  49. <div class="public_height_dialog">
  50. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="formDom" v-loading="submitLoading">
  51. <template #nameEnglish>
  52. <div style="width: 100%">
  53. <el-input v-model="formData.data.nameEnglish" placeholder="请输入" onkeyup="value=value.replace(/[^\x00-\xff]/g, '')"></el-input>
  54. </div>
  55. </template>
  56. <template #productionFile>
  57. <div style="width: 100%">
  58. <span style="color:#409eff;cursor:pointer" @click="handleClickUpload('prodFilePath',true)"
  59. v-if="!formData.data.prodFilePath">点击上传</span>
  60. <span style="color:#409eff;cursor:pointer" @click="handleClickUpload('prodFilePath',false)" v-else>点击查看</span>
  61. </div>
  62. </template>
  63. <template #productionFileOne>
  64. <div style="width: 100%">
  65. <el-button type="primary" plain @click="handleClickUpload('prodImgPath',true)" v-if="!formData.data.prodImgPath">点击上传</el-button>
  66. <el-button type="primary" plain @click="handleClickUpload('prodImgPath',false)" v-else>点击查看</el-button>
  67. </div>
  68. </template>
  69. <template #size>
  70. <div style="width: 100%">
  71. <el-form-item label="尺寸" class="margin-b-0 wid100" required>
  72. <el-row>
  73. <el-col :span="8">
  74. <el-form-item prop="length" label-width="0px" class="margin-b-0 wid100">
  75. <el-input-number v-model="formData.data['length']" placeholder="长 (cm)" style="width: 100%" :precision="2" :controls="false"
  76. :min="0" onmousewheel="return false;" />
  77. </el-form-item>
  78. </el-col>
  79. <el-col :span="8">
  80. <el-form-item prop="width" label-width="0px" class="margin-b-0 wid100">
  81. <el-input-number v-model="formData.data.width" placeholder="宽 (cm)" style="width: 100%" :precision="2" :controls="false"
  82. :min="0" onmousewheel="return false;" />
  83. </el-form-item>
  84. </el-col>
  85. <el-col :span="8">
  86. <el-form-item prop="height" label-width="0px" class="margin-b-0 wid100">
  87. <el-input-number v-model="formData.data.height" placeholder="高 (cm)" style="width: 100%" :precision="2" :controls="false"
  88. :min="0" onmousewheel="return false;" />
  89. </el-form-item>
  90. </el-col>
  91. </el-row>
  92. </el-form-item>
  93. </div>
  94. </template>
  95. </byForm>
  96. </div>
  97. <template #footer>
  98. <el-button @click="dialogVisible = false" size="defualt" v-debounce>取 消</el-button>
  99. <el-button type="primary" @click="submitForm()" size="defualt" v-debounce>确 定</el-button>
  100. </template>
  101. </el-dialog>
  102. <el-dialog :title="'BOM 配置'" v-model="bomDialog" width="900" destroy-on-close>
  103. <!-- <div class="public_height_dialog"> -->
  104. <byForm :formConfig="bomFormConfig" :formOption="bomFormOption" v-model="formData.bomData" :rules="bomRules" ref="bomFormDom"
  105. v-loading="submitLoading">
  106. <!-- <template #accessories>
  107. <div style="width: 100%">
  108. <el-button type="primary" @click="openSelectMaterial = true" plain>选择</el-button>
  109. <el-table :data="formData.bomData.productBomDetailList" style="width: 100%; margin-top: 16px" border>
  110. <el-table-column prop="materialName" label="物料名称" min-width="130" />
  111. <el-table-column prop="materialCode" label="物料编码" width="150" />
  112. <el-table-column label="数量" width="150">
  113. <template #default="{ row, $index }">
  114. <div style="width: 100%">
  115. <el-form-item :prop="'productBomDetailList.' + $index + '.quantity'" :rules="bomRules.quantity" :inline-message="true"
  116. class="margin-b-0 wid100">
  117. <el-input-number onmousewheel="return false;" v-model="row.quantity" placeholder="请输入" style="width: 100%" :precision="0"
  118. :controls="false" :min="1" />
  119. </el-form-item>
  120. </div>
  121. </template>
  122. </el-table-column>
  123. <el-table-column label="操作" width="60" align="center" fixed="right">
  124. <template #default="{ $index }">
  125. <el-button type="primary" link @click="handleRemove($index)">删除</el-button>
  126. </template>
  127. </el-table-column>
  128. </el-table>
  129. </div>
  130. </template>
  131. <template #detail>
  132. <div style="width: 100%">
  133. <el-table :data="formData.bomData.processesList" style="width: 100%; " border>
  134. <el-table-column label="序号" type="index" width="80" />
  135. <el-table-column prop="code" label="工序编码" />
  136. <el-table-column prop="name" label="工序名称" />
  137. </el-table>
  138. </div>
  139. </template> -->
  140. <template #detail>
  141. <div style="width: 100%">
  142. <div style="text-align:center;margin-bottom:10px">
  143. 【{{formData.bomData.name}} {{formData.bomData.code}}】BOM单
  144. </div>
  145. <table border class="table" style="width:100%">
  146. <tbody>
  147. <tr>
  148. <td style="width:90px">原材料</td>
  149. <td style="padding:10px">
  150. <el-select v-model="formData.bomData.rawMaterialId" placeholder="请选择原材料" style="width:100%">
  151. <el-option v-for="item in rawMaterialData" :key="item.value" :label="item.label" :value="item.value" filterable />
  152. </el-select>
  153. </td>
  154. </tr>
  155. <tr>
  156. <td>
  157. 包材辅材
  158. </td>
  159. <td style="padding:20px 20px 20px">
  160. <div style="text-align:left"><el-button type="primary" @click="openSelectMaterial = true" plain>选择</el-button></div>
  161. <el-table :data="formData.bomData.productBomDetailList" style="width: 100%;">
  162. <el-table-column prop="materialName" label="物料名称" min-width="130" />
  163. <el-table-column prop="materialCode" label="物料编码" width="150" />
  164. <el-table-column label="数量" width="150">
  165. <template #default="{ row, $index }">
  166. <div style="width: 100%">
  167. <el-form-item :prop="'productBomDetailList.' + $index + '.quantity'" :rules="bomRules.quantity" :inline-message="true"
  168. class="margin-b-0 wid100">
  169. <el-input-number onmousewheel="return false;" v-model="row.quantity" placeholder="请输入" style="width: 100%"
  170. :precision="0" :controls="false" :min="1" />
  171. </el-form-item>
  172. </div>
  173. </template>
  174. </el-table-column>
  175. <el-table-column label="操作" width="60" align="center" fixed="right">
  176. <template #default="{ $index }">
  177. <el-button type="primary" link @click="handleRemove($index)">删除</el-button>
  178. </template>
  179. </el-table-column>
  180. </el-table>
  181. </td>
  182. </tr>
  183. <tr>
  184. <td>
  185. 生产工序
  186. </td>
  187. <td style="padding:0 20px 20px">
  188. <el-table :data="formData.bomData.processesList" style="width: 100%; ">
  189. <el-table-column label="序号" type="index" width="80" />
  190. <el-table-column prop="code" label="工序编码" />
  191. <el-table-column prop="name" label="工序名称" />
  192. </el-table>
  193. </td>
  194. </tr>
  195. </tbody>
  196. </table>
  197. </div>
  198. </template>
  199. </byForm>
  200. <!-- </div> -->
  201. <template #footer>
  202. <el-button @click="bomDialog = false" size="defualt" v-debounce>取 消</el-button>
  203. <el-button type="primary" @click="submitBomForm()" size="defualt" v-debounce>确 定</el-button>
  204. </template>
  205. </el-dialog>
  206. <el-dialog :title="'物料选择'" v-model="openSelectMaterial" width="90%" destroy-on-close>
  207. <SelectMaterial :isNeRawMaterial="'1'" @selectMaterial="selectMaterial"></SelectMaterial>
  208. <template #footer>
  209. <el-button @click="bomDialog = false" size="defualt" v-debounce>取 消</el-button>
  210. </template>
  211. </el-dialog>
  212. <el-dialog title="导入产品" v-model="openExcelDialog" width="400">
  213. <div v-loading="excelLoading">
  214. <el-upload :action="actionUrl + '/productInfo/excelImportByEhsd'" :headers="headers" :on-success="handleSuccess" :on-progress="handleProgress"
  215. :show-file-list="false" :on-error="handleError" accept=".xlsx">
  216. <el-button type="primary">点击导入</el-button>
  217. </el-upload>
  218. </div>
  219. <template #footer>
  220. <el-button @click="openExcelDialog = false" size="default" v-debounce>取 消</el-button>
  221. </template>
  222. </el-dialog>
  223. </div>
  224. </template>
  225. <script setup>
  226. import byTable from "@/components/byTable/index";
  227. import byForm from "@/components/byForm/index";
  228. import treeList from "@/components/product/treeList";
  229. import SelectMaterial from "@/components/product/SelectMaterial.vue";
  230. import { getToken } from "@/utils/auth";
  231. const { proxy } = getCurrentInstance();
  232. const actionUrl = import.meta.env.VITE_APP_BASE_API;
  233. const loading = ref(false);
  234. const submitLoading = ref(false);
  235. const treeData = ref([]);
  236. const treeDataOne = ref([]);
  237. const treeListData = ref([]);
  238. const technologyData = ref([]);
  239. const companyData = ref([]);
  240. const currencyData = computed(
  241. () => proxy.useUserStore().allDict["account_currency"]
  242. );
  243. const headers = ref({ Authorization: "Bearer " + getToken() });
  244. const tableHeight = ref(0);
  245. const getTableHeight = () => {
  246. tableHeight.value = window.innerHeight - 245;
  247. };
  248. getTableHeight();
  249. window.addEventListener("resize", () => {
  250. getTableHeight();
  251. });
  252. const sourceList = ref({
  253. data: [],
  254. pagination: {
  255. total: 3,
  256. pageNum: 1,
  257. pageSize: 10,
  258. type: "",
  259. productClassifyId: "",
  260. keyword: "",
  261. definition: "1",
  262. companyId: "",
  263. },
  264. });
  265. const dialogVisible = ref(false);
  266. const openExcelDialog = ref(false);
  267. const excelLoading = ref(false);
  268. const modalType = ref("add");
  269. const rules = ref({
  270. companyId: [{ required: true, message: "请选择归属公司", trigger: "change" }],
  271. productClassifyId: [
  272. { required: true, message: "请选择产品分类", trigger: "change" },
  273. ],
  274. name: [{ required: true, message: "请输入产品名称", trigger: "blur" }],
  275. customCode: [{ required: true, message: "请输入产品编号", trigger: "blur" }],
  276. length: [{ required: true, message: "请输入长 (cm)", trigger: "blur" }],
  277. width: [{ required: true, message: "请输入宽 (cm)", trigger: "blur" }],
  278. height: [{ required: true, message: "请输入高 (cm)", trigger: "blur" }],
  279. technologyId: [
  280. { required: true, message: "请选择生产工艺", trigger: "change" },
  281. ],
  282. rawMaterialId: [
  283. { required: true, message: "请选择原材料", trigger: "change" },
  284. ],
  285. });
  286. const props = defineProps({
  287. selectStatus: Boolean,
  288. });
  289. const selectConfig = computed(() => [
  290. {
  291. label: "业务公司",
  292. prop: "companyId",
  293. data: companyData.value,
  294. },
  295. ]);
  296. const config = computed(() => {
  297. return [
  298. {
  299. attrs: {
  300. label: "图片",
  301. slot: "pic",
  302. align: "center",
  303. width: 80,
  304. },
  305. },
  306. {
  307. attrs: {
  308. label: "业务公司",
  309. prop: "companyName",
  310. width: 150,
  311. },
  312. },
  313. {
  314. attrs: {
  315. label: "产品分类",
  316. prop: "classifyName",
  317. "min-width": 200,
  318. },
  319. },
  320. {
  321. attrs: {
  322. label: "产品编码",
  323. prop: "customCode",
  324. width: 180,
  325. },
  326. },
  327. {
  328. attrs: {
  329. label: "产品名称",
  330. slot: "name",
  331. "min-width": 200,
  332. },
  333. },
  334. // {
  335. // attrs: {
  336. // label: "产品英文名",
  337. // prop: "nameEnglish",
  338. // "min-width": 120,
  339. // },
  340. // },
  341. // {
  342. // attrs: {
  343. // label: "产品规格",
  344. // prop: "spec",
  345. // width: 120,
  346. // },
  347. // },
  348. {
  349. attrs: {
  350. label: "尺寸 (cm)",
  351. slot: "size",
  352. width: 130,
  353. },
  354. },
  355. {
  356. attrs: {
  357. label: "颜色",
  358. prop: "color",
  359. width: 100,
  360. },
  361. },
  362. {
  363. attrs: {
  364. label: "净重",
  365. prop: "netWeight",
  366. width: 100,
  367. },
  368. render(val) {
  369. if (val) {
  370. return val + " kg";
  371. }
  372. },
  373. },
  374. {
  375. attrs: {
  376. label: "销售价",
  377. slot: "price",
  378. width: 100,
  379. },
  380. },
  381. // {
  382. // attrs: {
  383. // label: "海关编码",
  384. // prop: "hsCode",
  385. // width: 100,
  386. // },
  387. // },
  388. {
  389. attrs: {
  390. label: "原材料编码",
  391. prop: "rawMaterialCode",
  392. width: 120,
  393. },
  394. },
  395. {
  396. attrs: {
  397. label: "原材料",
  398. prop: "rawMaterialName",
  399. "min-width": 300,
  400. },
  401. },
  402. {
  403. attrs: {
  404. label: "操作",
  405. width: "160",
  406. align: "center",
  407. fixed: "right",
  408. },
  409. renderHTML(row) {
  410. return [
  411. // {
  412. // attrs: {
  413. // label: "选择",
  414. // type: "primary",
  415. // text: true,
  416. // },
  417. // el: "button",
  418. // click() {
  419. // clickSelect(row);
  420. // },
  421. // }
  422. {
  423. attrs: {
  424. label: "BOM",
  425. type: "primary",
  426. text: true,
  427. },
  428. el: "button",
  429. click() {
  430. bomSetting(row);
  431. },
  432. },
  433. {
  434. attrs: {
  435. label: "修改",
  436. type: "primary",
  437. text: true,
  438. },
  439. el: "button",
  440. click() {
  441. getDtl(row);
  442. },
  443. },
  444. {
  445. attrs: {
  446. label: "删除",
  447. type: "danger",
  448. text: true,
  449. },
  450. el: "button",
  451. click() {
  452. proxy
  453. .msgConfirm()
  454. .then((res) => {
  455. proxy
  456. .post("/productInfo/delete", {
  457. id: row.id,
  458. })
  459. .then((res) => {
  460. proxy.msgTip("删除成功", 1);
  461. getList();
  462. });
  463. })
  464. .catch((err) => {});
  465. },
  466. },
  467. ];
  468. },
  469. },
  470. ];
  471. });
  472. const formData = reactive({
  473. data: {},
  474. bomData: {},
  475. });
  476. const formOption = reactive({
  477. disabled: false,
  478. inline: true,
  479. labelWidth: 100,
  480. itemWidth: 100,
  481. });
  482. const formDom = ref(null);
  483. const formConfig = computed(() => {
  484. return [
  485. {
  486. type: "title1",
  487. title: "基本信息",
  488. },
  489. {
  490. type: "treeSelect",
  491. prop: "companyId",
  492. label: "业务公司",
  493. data: treeDataOne.value,
  494. propsTreeLabel: "deptName",
  495. propsTreeValue: "deptId",
  496. itemWidth: 50,
  497. },
  498. {
  499. type: "treeSelect",
  500. prop: "productClassifyId",
  501. label: "产品分类",
  502. data: treeData.value,
  503. itemWidth: 50,
  504. disabled: false,
  505. },
  506. {
  507. type: "input",
  508. prop: "name",
  509. label: "产品名称",
  510. itemWidth: 50,
  511. disabled: false,
  512. },
  513. {
  514. type: "slot",
  515. slotName: "nameEnglish",
  516. label: "英文名",
  517. itemWidth: 50,
  518. },
  519. {
  520. type: "input",
  521. prop: "customCode",
  522. label: "产品编号",
  523. itemWidth: 50,
  524. disabled: false,
  525. },
  526. {
  527. type: "uploadImg",
  528. // listType: "picture-card",
  529. // limit: 1,
  530. // accept: ".gif, .jpeg, .jpg, .png",
  531. prop: "fileList",
  532. imgProp: "imageUrl",
  533. label: "产品缩略图",
  534. },
  535. {
  536. type: "slot",
  537. slotName: "productionFileOne",
  538. label: "产品原图",
  539. itemWidth: 100,
  540. },
  541. {
  542. type: "upload",
  543. listType: "text",
  544. accept: "",
  545. limit: 1,
  546. prop: "prodFileList",
  547. label: "生产文件",
  548. },
  549. // {
  550. // type: "slot",
  551. // slotName: "productionFile",
  552. // label: "生产文件",
  553. // itemWidth: 100,
  554. // },
  555. {
  556. type: "title1",
  557. title: "属性信息",
  558. },
  559. {
  560. type: "select",
  561. prop: "rawMaterialId",
  562. label: "原材料",
  563. itemWidth: 50,
  564. data: rawMaterialData.value,
  565. filterable: true,
  566. disabled: false,
  567. fn: (val) => {
  568. let current = rawMaterialData.value.find((x) => x.value == val);
  569. if (current) {
  570. formData.data.price = Number(
  571. parseFloat(
  572. current["length"] * current.width * current.price
  573. ).toFixed(2)
  574. );
  575. }
  576. },
  577. },
  578. {
  579. type: "selectInput",
  580. prop: "price",
  581. selectProp: "currency",
  582. label: "销售价",
  583. itemWidth: 50,
  584. disabledSelect: true,
  585. data: currencyData.value,
  586. disabled: true,
  587. },
  588. {
  589. type: "select",
  590. prop: "technologyId",
  591. label: "生产工艺",
  592. itemWidth: 50,
  593. data: technologyData.value,
  594. filterable: true,
  595. disabled: false,
  596. },
  597. // {
  598. // type: "input",
  599. // prop: "spec",
  600. // label: "规格型号",
  601. // itemWidth: 50,
  602. // disabled: false,
  603. // },
  604. {
  605. type: "input",
  606. prop: "color",
  607. label: "颜色",
  608. itemWidth: 50,
  609. disabled: false,
  610. },
  611. {
  612. type: "slot",
  613. slotName: "size",
  614. prop: "",
  615. label: "",
  616. itemWidth: 50,
  617. disabled: false,
  618. },
  619. // {
  620. // type: "select",
  621. // prop: "innerPackMethod",
  622. // label: "内包装方式",
  623. // required: true,
  624. // itemWidth: 50,
  625. // multiple: true,
  626. // data: innerMethon.value,
  627. // filterable: true,
  628. // placeholder: "内包装方式",
  629. // style: {
  630. // width: "100%",
  631. // },
  632. // disabled: false,
  633. // },
  634. // {
  635. // type: "select",
  636. // prop: "outerPackMethod",
  637. // label: "外包装方式",
  638. // required: true,
  639. // itemWidth: 50,
  640. // multiple: true,
  641. // data: outsideMethon.value,
  642. // filterable: true,
  643. // placeholder: "外包装方式",
  644. // style: {
  645. // width: "100%",
  646. // },
  647. // disabled: false,
  648. // },
  649. {
  650. type: "number",
  651. prop: "netWeight",
  652. label: "净重(kg)",
  653. precision: 2,
  654. min: 0,
  655. controls: false,
  656. itemWidth: 50,
  657. },
  658. {
  659. type: "input",
  660. prop: "hsCode",
  661. label: "海关编码",
  662. itemWidth: 50,
  663. disabled: false,
  664. },
  665. {
  666. type: "input",
  667. itemType: "textarea",
  668. prop: "remark",
  669. label: "备注",
  670. itemWidth: 100,
  671. },
  672. ];
  673. });
  674. const getList = (req) => {
  675. sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  676. loading.value = true;
  677. proxy.post("/productInfo/page", sourceList.value.pagination).then(
  678. (res) => {
  679. sourceList.value.data = res.rows.map((x) => ({
  680. ...x,
  681. fileList: [],
  682. }));
  683. sourceList.value.pagination.total = res.total;
  684. setTimeout(() => {
  685. loading.value = false;
  686. }, 200);
  687. let productIdList = res.rows.map((x) => x.id);
  688. // 请求文件数据并回显
  689. if (productIdList.length > 0) {
  690. // proxy.getFile(productIdList, sourceList.value.data, "id");
  691. proxy
  692. .post("/fileInfo/getList", { businessIdList: productIdList })
  693. .then((fileObj) => {
  694. for (let i = 0; i < sourceList.value.data.length; i++) {
  695. const ele = sourceList.value.data[i];
  696. for (const key in fileObj) {
  697. if (
  698. ele.id == key &&
  699. fileObj[ele.id] &&
  700. fileObj[ele.id].length > 0
  701. ) {
  702. ele.fileList = fileObj[ele.id].filter(
  703. (x) => x.businessType == "0"
  704. );
  705. }
  706. }
  707. }
  708. });
  709. }
  710. },
  711. (err) => {
  712. loading.value = false;
  713. }
  714. );
  715. };
  716. const getDict = () => {
  717. proxy
  718. .get("/tenantDept/list", {
  719. pageNum: 1,
  720. pageSize: 9999,
  721. keyword: "",
  722. tenantId: proxy.useUserStore().user.tenantId,
  723. type: 0,
  724. })
  725. .then((res) => {
  726. companyData.value = res.data.map((x) => ({
  727. ...x,
  728. label: x.deptName,
  729. value: x.deptId,
  730. }));
  731. treeDataOne.value = proxy.handleTree(res.data, "deptId");
  732. });
  733. };
  734. getDict();
  735. const treeChange = (e) => {
  736. if (e.id != undefined) {
  737. sourceList.value.pagination.productClassifyId = e.id;
  738. getList({ productClassifyId: e.id });
  739. }
  740. };
  741. const openModal = () => {
  742. dialogVisible.value = true;
  743. modalType.value = "add";
  744. formData.data = {
  745. definition: "1",
  746. fileList: [],
  747. currency: "",
  748. prodFileList: [],
  749. };
  750. if (currencyData.value && currencyData.value.length > 0) {
  751. formData.data.currency = currencyData.value[0].dictKey;
  752. }
  753. };
  754. const openExcel = () => {
  755. openExcelDialog.value = true;
  756. };
  757. const submitForm = () => {
  758. formDom.value.handleSubmit((valid) => {
  759. if (!formData.data.fileList.length > 0) {
  760. return proxy.msgTip("请上传图片", 2);
  761. }
  762. // formData.data.fileList = formData.data.fileList.map((x) => ({
  763. // id: x.id,
  764. // fileName: x.fileName,
  765. // fileUrl: x.fileUrl,
  766. // }));
  767. submitLoading.value = true;
  768. proxy.post("/productInfo/" + modalType.value, formData.data).then(
  769. (res) => {
  770. proxy.msgTip("操作成功", 1);
  771. dialogVisible.value = false;
  772. submitLoading.value = false;
  773. getList();
  774. },
  775. (err) => {
  776. submitLoading.value = false;
  777. }
  778. );
  779. });
  780. };
  781. const getTreeList = () => {
  782. proxy
  783. .post("/productClassify/tree", { parentId: "", name: "", definition: "1" })
  784. .then((message) => {
  785. treeListData.value = [
  786. {
  787. id: "",
  788. label: "全部",
  789. parentId: "",
  790. children: message,
  791. },
  792. ];
  793. treeData.value = message;
  794. });
  795. };
  796. const getTechnologyData = () => {
  797. proxy.post("/technology/page", { pageNum: 1, pageSize: 999 }).then((res) => {
  798. technologyData.value = res.rows;
  799. });
  800. };
  801. const getDtl = (row) => {
  802. modalType.value = "edit";
  803. proxy.post("/productInfo/detail", { id: row.id }).then((res) => {
  804. formData.data = res;
  805. formData.data.fileList = row.fileList.map((x) => ({
  806. ...x,
  807. url: x.fileUrl,
  808. name: x.fileName,
  809. }));
  810. if (formData.data.fileList.length > 0) {
  811. formData.data.imageUrl = formData.data.fileList[0].fileUrl;
  812. }
  813. proxy
  814. .post("/fileInfo/getList", { businessIdList: [row.id] })
  815. .then((fileObj) => {
  816. if (fileObj[row.id] && fileObj[row.id].length > 0) {
  817. formData.data.prodFileList = fileObj[row.id]
  818. .filter((x) => x.businessType == "2")
  819. .map((item) => {
  820. return {
  821. ...item,
  822. name: item.fileName,
  823. url: item.fileUrl,
  824. };
  825. });
  826. } else {
  827. formData.data.prodFileList = [];
  828. }
  829. });
  830. dialogVisible.value = true;
  831. });
  832. };
  833. const rawMaterialData = ref([]);
  834. const getRawMaterialData = () => {
  835. proxy.post("/productInfo/page", { productClassifyId: 100 }).then((res) => {
  836. rawMaterialData.value = res.rows.map((x) => ({
  837. ...x,
  838. label:
  839. x.name +
  840. "," +
  841. x.customCode +
  842. "," +
  843. `${x["length"]}*${x.width}*${x.height}(cm)` +
  844. "," +
  845. x.color,
  846. value: x.id,
  847. }));
  848. });
  849. };
  850. getRawMaterialData();
  851. const bomDialog = ref(false);
  852. const bomFormDom = ref(null);
  853. const bomFormOption = reactive({
  854. disabled: false,
  855. inline: true,
  856. labelWidth: 100,
  857. itemWidth: 100,
  858. });
  859. const bomFormConfig = computed(() => {
  860. return [
  861. // {
  862. // type: "title1",
  863. // title: "BOM 信息",
  864. // },
  865. // {
  866. // type: "select",
  867. // prop: "rawMaterialId",
  868. // label: "原材料",
  869. // itemWidth: 100,
  870. // data: rawMaterialData.value,
  871. // filterable: true,
  872. // disabled: false,
  873. // },
  874. // {
  875. // type: "slot",
  876. // slotName: "accessories",
  877. // label: "包材辅料",
  878. // itemWidth: 100,
  879. // },
  880. // {
  881. // type: "title1",
  882. // title: "生产工序",
  883. // },
  884. {
  885. type: "slot",
  886. slotName: "detail",
  887. label: "",
  888. },
  889. ];
  890. });
  891. const bomRules = ref({
  892. rawMaterialId: [
  893. { required: true, message: "请选择原材料", trigger: "change" },
  894. ],
  895. quantity: [{ required: true, message: "请输入数量", trigger: "blur" }],
  896. });
  897. const bomSetting = (row) => {
  898. bomDialog.value = true;
  899. proxy.post("/productBomInfo/detail", { id: row.id }).then((res) => {
  900. formData.bomData = {
  901. name: row.name,
  902. code: row.customCode,
  903. id: res.id,
  904. rawMaterialId: res.rawMaterialId,
  905. productBomDetailList: [],
  906. processesList: res.processesList,
  907. };
  908. if (res.productBomDetailList && res.productBomDetailList.length > 0) {
  909. formData.bomData.productBomDetailList = res.productBomDetailList.filter(
  910. (x) => x.type == 2
  911. );
  912. } else {
  913. formData.bomData.productBomDetailList = [];
  914. }
  915. });
  916. };
  917. const submitBomForm = () => {
  918. bomFormDom.value.handleSubmit((valid) => {
  919. if (!formData.bomData.productBomDetailList.length > 0) {
  920. return proxy.msgTip("请选择包材辅料", 2);
  921. }
  922. formData.bomData.productBomDetailList.push({
  923. materialId: formData.bomData.rawMaterialId,
  924. type: 1,
  925. quantity: 1,
  926. });
  927. submitLoading.value = true;
  928. proxy.post("/productBomInfo/edit", formData.bomData).then(
  929. (res) => {
  930. proxy.msgTip("操作成功", 1);
  931. getList();
  932. bomDialog.value = false;
  933. submitLoading.value = false;
  934. },
  935. (err) => {
  936. submitLoading.value = false;
  937. }
  938. );
  939. });
  940. };
  941. const openSelectMaterial = ref(false);
  942. const selectMaterial = (row) => {
  943. let flag = formData.bomData.productBomDetailList.some(
  944. (x) => x.materialId == row.id
  945. );
  946. if (!flag) {
  947. formData.bomData.productBomDetailList.push({
  948. type: 2,
  949. materialName: row.name,
  950. materialCode: row.customCode,
  951. materialId: row.id,
  952. quantity: null,
  953. });
  954. proxy.msgTip("选择成功");
  955. } else {
  956. proxy.msgTip("该物料已选择", 2);
  957. }
  958. };
  959. const handleRemove = (index) => {
  960. formData.bomData.productBomDetailList.splice(index, 1);
  961. };
  962. const handleClickFile = (file) => {
  963. window.open(file.fileUrl, "_blank");
  964. };
  965. const handleProgress = () => {
  966. excelLoading.value = true;
  967. };
  968. const handleError = (err) => {
  969. proxy.msgTip(`${err},请重试`, 2);
  970. openExcelDialog.value = false;
  971. excelLoading.value = false;
  972. };
  973. const handleSuccess = (res) => {
  974. if (res.code != 200) {
  975. return proxy.msgTip(`${err},请重试`, 2);
  976. } else {
  977. proxy.msgTip(`导入成功`, 1);
  978. openExcelDialog.value = false;
  979. excelLoading.value = false;
  980. getList();
  981. }
  982. };
  983. const clickSelect = (item) => {
  984. proxy.$emit("selectProduct", item);
  985. };
  986. const handleClickUpload = async (att, flag) => {
  987. let res = null;
  988. let path = "";
  989. if (flag) {
  990. proxy.msgTip("请稍后", 2);
  991. res = await proxy.post("/fileService/createTempFolder");
  992. if (res && res.path) {
  993. formData.data[att] = res.path;
  994. path = res.path;
  995. }
  996. } else {
  997. path = formData.data[att];
  998. }
  999. let a = document.createElement("a");
  1000. a.href = "printer://" + "ftp://121.37.194.75/" + path + "/";
  1001. a.style.display = "none";
  1002. document.body.appendChild(a);
  1003. a.click();
  1004. document.body.removeChild(a);
  1005. };
  1006. getTechnologyData();
  1007. getTreeList();
  1008. getList();
  1009. const exportExcel = () => {
  1010. proxy.msgTip("正在导出,请稍后", 2);
  1011. proxy
  1012. .postTwo("/productInfo/exportExcel", sourceList.value.pagination)
  1013. .then((res) => {
  1014. proxy.downloadFile(res, "产品数据.xlsx");
  1015. });
  1016. };
  1017. </script>
  1018. <style lang="scss" scoped>
  1019. .box {
  1020. padding: 10px;
  1021. display: flex;
  1022. justify-content: space-between;
  1023. .tree {
  1024. width: 300px;
  1025. }
  1026. .content {
  1027. width: calc(100% - 310px);
  1028. }
  1029. }
  1030. .pic {
  1031. object-fit: contain;
  1032. width: 50px;
  1033. height: 50px;
  1034. cursor: pointer;
  1035. vertical-align: middle;
  1036. }
  1037. .table {
  1038. border-collapse: collapse;
  1039. border-spacing: 0;
  1040. td {
  1041. text-align: center;
  1042. padding: 2px 4px;
  1043. // padding: 5px 10px;
  1044. }
  1045. }
  1046. </style>