index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <template>
  2. <div style="height: calc(100vh - 114px); overflow-y: auto; overflow-x: hidden">
  3. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="submit">
  4. <template #skuClassifyId>
  5. <div style="width: 100%">
  6. <el-cascader
  7. v-model="formData.data.skuClassifyId"
  8. :options="classifyList"
  9. :props="{ checkStrictly: true, value: 'id', label: 'name', emitPath: false }"
  10. clearable
  11. style="width: 100%" />
  12. </div>
  13. </template>
  14. <template #brand>
  15. <div style="width: 100%">{{ formData.data.brand }}</div>
  16. </template>
  17. <template #specification>
  18. <div style="width: 100%">
  19. <div>
  20. <el-icon style="cursor: pointer; transform: translateY(4px); font-size: 24px; margin-left: 10px" @click="addSpecification"><Plus /></el-icon>
  21. </div>
  22. <el-table :data="formData.data.skuSpecList" :row-style="{ height: '35px' }" header-row-class-name="tableHeader">
  23. <el-table-column label="规格图" align="center" width="100">
  24. <template #default="{ row, $index }">
  25. <el-form-item :prop="'skuSpecList.' + $index + '.specImgUrl'">
  26. <el-upload
  27. class="avatar-uploader"
  28. action="https://winfaster.obs.cn-south-1.myhuaweicloud.com"
  29. :data="uploadData"
  30. :show-file-list="false"
  31. :on-success="
  32. (response, uploadFile) => {
  33. return handleSuccess(uploadFile, $index);
  34. }
  35. "
  36. :before-upload="uploadFile">
  37. <el-image v-if="row.specImgUrl" :src="row.specImgUrl" fit="scale-down" class="avatar" />
  38. <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
  39. </el-upload>
  40. </el-form-item>
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="设计图" align="center" width="100">
  44. <template #default="{ row, $index }">
  45. <el-form-item :prop="'skuSpecList.' + $index + '.designImgUrl'">
  46. <!-- <el-upload
  47. class="avatar-uploader"
  48. action="https://winfaster.obs.cn-south-1.myhuaweicloud.com"
  49. :data="uploadDesignData"
  50. :show-file-list="false"
  51. :on-success="
  52. (response, uploadFile) => {
  53. return handleDesignSuccess(uploadFile, $index);
  54. }
  55. "
  56. :before-upload="uploadDesignFile"> -->
  57. <el-image
  58. v-if="row.designImgUrl"
  59. :src="row.designImgUrl"
  60. fit="scale-down"
  61. style="width: 50px; height: 50px; cursor: pointer"
  62. @click="openFile(row.designImgUrl)" />
  63. <!-- <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
  64. </el-upload> -->
  65. </el-form-item>
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="品名" min-width="220">
  69. <template #default="{ row, $index }">
  70. <el-form-item :prop="'skuSpecList.' + $index + '.name'" :rules="rulesSpec.name" :inline-message="true" style="width: 100%">
  71. <el-input v-model="row.name" placeholder="请输入品名" />
  72. </el-form-item>
  73. </template>
  74. </el-table-column>
  75. <el-table-column label="品号" width="160">
  76. <template #default="{ row, $index }">
  77. <el-form-item :prop="'skuSpecList.' + $index + '.code'" :rules="rulesSpec.code" :inline-message="true" style="width: 100%">
  78. <el-input v-model="row.code" placeholder="请输入品号" />
  79. </el-form-item>
  80. </template>
  81. </el-table-column>
  82. <el-table-column label="图稿文件" align="center" width="160">
  83. <template #default="{ row, $index }">
  84. <el-button type="primary" @click="clickDrawingFile($index)" v-if="!row.sharedFolder" text>选择</el-button>
  85. <a style="color: #409eff; cursor: pointer; word-break: break-all" @click="clickDrawingFile($index)" v-else>{{ row.sharedFolder }}</a>
  86. </template>
  87. </el-table-column>
  88. <el-table-column label="加工版面" width="140">
  89. <template #default="{ row, $index }">
  90. <el-form-item :prop="'skuSpecList.' + $index + '.machinedPanel'" style="width: 100%">
  91. <el-select v-model="row.machinedPanel" placeholder="加工版面" clearable>
  92. <el-option v-for="item in useUserStore().allDict['processing_layout']" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
  93. </el-select>
  94. </el-form-item>
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="尺寸(长宽高,cm)" align="center" width="280">
  98. <template #default="{ row, $index }">
  99. <el-row>
  100. <el-col :span="8">
  101. <el-form-item :prop="'skuSpecList.' + $index + '.length'" :rules="rulesSpec.length" :inline-message="true" style="width: 100%">
  102. <el-input-number
  103. onmousewheel="return false;"
  104. v-model="row.length"
  105. placeholder="长"
  106. style="width: 100%"
  107. :controls="false"
  108. :min="0"
  109. :precision="2" />
  110. </el-form-item>
  111. </el-col>
  112. <el-col :span="8">
  113. <el-form-item :prop="'skuSpecList.' + $index + '.width'" :rules="rulesSpec.width" :inline-message="true" style="width: 100%">
  114. <el-input-number
  115. onmousewheel="return false;"
  116. v-model="row.width"
  117. placeholder="宽"
  118. style="width: 100%"
  119. :controls="false"
  120. :min="0"
  121. :precision="2" />
  122. </el-form-item>
  123. </el-col>
  124. <el-col :span="8">
  125. <el-form-item :prop="'skuSpecList.' + $index + '.height'" :rules="rulesSpec.height" :inline-message="true" style="width: 100%">
  126. <el-input-number
  127. onmousewheel="return false;"
  128. v-model="row.height"
  129. placeholder="高"
  130. style="width: 100%"
  131. :controls="false"
  132. :min="0"
  133. :precision="2" />
  134. </el-form-item>
  135. </el-col>
  136. </el-row>
  137. </template>
  138. </el-table-column>
  139. <el-table-column label="净重(g)" width="120">
  140. <template #default="{ row, $index }">
  141. <el-form-item :prop="'skuSpecList.' + $index + '.netWeight'" :rules="rulesSpec.netWeight" :inline-message="true" style="width: 100%">
  142. <el-input-number
  143. onmousewheel="return false;"
  144. v-model="row.netWeight"
  145. placeholder="净重"
  146. style="width: 100%"
  147. :controls="false"
  148. :min="0"
  149. :precision="2" />
  150. </el-form-item>
  151. </template>
  152. </el-table-column>
  153. <el-table-column label="BOM" align="left" width="250">
  154. <template #default="{ row, $index }">
  155. <el-button
  156. v-if="!row.bomSpecId"
  157. type="primary"
  158. size="small"
  159. @click="handleOpen($index)"
  160. style="margin: 5px 0; background-color: #43b214; border-color: #43b214">
  161. 选择BOM
  162. </el-button>
  163. <div style="width: 100%; display: flex; align-items: center" v-else>
  164. <el-icon style="font-size: 16px; cursor: pointer" @click="clickRemoveBOM($index)"><Remove /></el-icon>
  165. <span>{{ row.bomSpecName }}</span>
  166. </div>
  167. </template>
  168. </el-table-column>
  169. <el-table-column label="操作" align="center" fixed="right" width="60">
  170. <template #default="{ $index }">
  171. <el-button type="danger" @click="clickDelete($index)" text>删除</el-button>
  172. </template>
  173. </el-table-column>
  174. </el-table>
  175. </div>
  176. </template>
  177. <template #mainImgUrl>
  178. <div style="width: 100%">
  179. <div style="color: #aaaaaa">图片不超过5M,支持JPEG、JPG、PNG格式;</div>
  180. <div style="color: #aaaaaa">建议主图大于640*640,主题鲜明、图片清晰、提升买家满意度;</div>
  181. <el-upload
  182. class="avatar-uploader-main"
  183. action="https://winfaster.obs.cn-south-1.myhuaweicloud.com"
  184. :data="uploadMainData"
  185. :show-file-list="false"
  186. :on-success="handleMainSuccess"
  187. :before-upload="uploadMainFile">
  188. <el-image v-if="formData.data.mainImgUrl" :src="formData.data.mainImgUrl" fit="scale-down" class="avatar" />
  189. <el-icon v-else class="avatar-uploader-main-icon"><Plus /></el-icon>
  190. </el-upload>
  191. </div>
  192. </template>
  193. <template #detailText>
  194. <div style="width: 100%">
  195. <div v-if="props.detailStatus">
  196. <div v-html="getStyle(formData.data.detailText)"></div>
  197. </div>
  198. <Editor v-else :value="formData.data.detailText" @updateValue="updateValue" ref="editor" />
  199. </div>
  200. </template>
  201. </byForm>
  202. <div style="width: 100%; text-align: center; margin: 10px">
  203. <el-button v-if="props.detailStatus" @click="clickCancel()" size="large">关 闭</el-button>
  204. <el-button v-if="!props.detailStatus" @click="clickCancel()" size="large">取 消</el-button>
  205. <el-button type="primary" @click="submitForm()" v-if="!props.detailStatus" size="large" v-preReClick>确 定</el-button>
  206. </div>
  207. <el-dialog title="选择BOM" v-if="openBOM" v-model="openBOM" width="84%">
  208. <SelectBOM :selectStatus="true" :bomClassifyIdList="[1]" @selectBOM="selectBOM"></SelectBOM>
  209. <template #footer>
  210. <el-button @click="openBOM = false" size="large">关 闭</el-button>
  211. </template>
  212. </el-dialog>
  213. <el-dialog title="选择BOM" v-if="openDrawingFile" v-model="openDrawingFile" width="70%">
  214. <SelectPicture @selectPic="selectPic"></SelectPicture>
  215. <template #footer>
  216. <el-button @click="openDrawingFile = false" size="large">关 闭</el-button>
  217. </template>
  218. </el-dialog>
  219. </div>
  220. </template>
  221. <script setup>
  222. import byForm from "@/components/byForm/index";
  223. import { ElMessage } from "element-plus";
  224. import Editor from "@/components/Editor/index.vue";
  225. import SelectBOM from "@/views/group/BOM/management/index";
  226. import SelectPicture from "@/components/select-picture/index.vue";
  227. const { proxy } = getCurrentInstance();
  228. const emit = defineEmits(["clickCancel"]);
  229. const submit = ref(null);
  230. const formOption = reactive({
  231. inline: true,
  232. labelWidth: "120px",
  233. itemWidth: 100,
  234. rules: [],
  235. labelPosition: "right",
  236. });
  237. const formData = reactive({
  238. data: {
  239. brand: "胜德科技",
  240. type: 1,
  241. source: 1,
  242. craftProductionLineId: "1",
  243. mainImgUrl: "",
  244. detailText: "",
  245. skuSpecList: [
  246. {
  247. specImgUrl: "",
  248. designImgUrl: "",
  249. name: "",
  250. code: "",
  251. barCode: "",
  252. machinedPanel: "",
  253. length: undefined,
  254. width: undefined,
  255. height: undefined,
  256. netWeight: undefined,
  257. sharedFolder: "",
  258. bomSpecId: "",
  259. remark: "",
  260. packagingMaterialList: [],
  261. expressPackingList: [],
  262. },
  263. ],
  264. },
  265. });
  266. const formConfig = computed(() => {
  267. return [
  268. {
  269. type: "title",
  270. title: "基本信息",
  271. label: "",
  272. },
  273. {
  274. type: "slot",
  275. prop: "skuClassifyId",
  276. slotName: "skuClassifyId",
  277. label: "类目",
  278. itemWidth: 50,
  279. },
  280. {
  281. type: "input",
  282. prop: "barCode",
  283. label: "条码",
  284. itemType: "text",
  285. itemWidth: 50,
  286. },
  287. {
  288. type: "input",
  289. prop: "groupItemNumber",
  290. label: "群组品号",
  291. itemType: "text",
  292. itemWidth: 50,
  293. },
  294. {
  295. type: "input",
  296. prop: "code",
  297. label: "编码",
  298. itemType: "text",
  299. itemWidth: 50,
  300. },
  301. {
  302. type: "input",
  303. prop: "name",
  304. label: "名称",
  305. itemType: "text",
  306. },
  307. {
  308. type: "title",
  309. title: "材质特征",
  310. label: "",
  311. },
  312. {
  313. type: "slot",
  314. slotName: "brand",
  315. label: "品牌",
  316. },
  317. {
  318. type: "input",
  319. prop: "modelNumber",
  320. label: "型号",
  321. itemType: "text",
  322. itemWidth: 50,
  323. },
  324. {
  325. type: "input",
  326. prop: "material",
  327. label: "材质",
  328. itemType: "text",
  329. itemWidth: 50,
  330. },
  331. {
  332. type: "slot",
  333. slotName: "specification",
  334. label: "规格",
  335. },
  336. {
  337. type: "title",
  338. title: "工艺路线",
  339. label: "",
  340. },
  341. {
  342. type: "select",
  343. label: "工艺路线",
  344. prop: "craftProductionLineId",
  345. data: [],
  346. itemWidth: 50,
  347. },
  348. {
  349. type: "title",
  350. title: "图片介绍",
  351. label: "",
  352. },
  353. {
  354. type: "slot",
  355. slotName: "mainImgUrl",
  356. label: "主图",
  357. },
  358. {
  359. type: "slot",
  360. slotName: "detailText",
  361. label: "详情描述",
  362. },
  363. ];
  364. });
  365. const rules = ref({
  366. groupItemNumber: [{ required: true, message: "请输入群组品号", trigger: "blur" }],
  367. code: [{ required: true, message: "请输入编码", trigger: "blur" }],
  368. name: [{ required: true, message: "请输入名称", trigger: "blur" }],
  369. });
  370. const rulesSpec = ref({
  371. code: [{ required: true, message: "请输入品号", trigger: "blur" }],
  372. name: [{ required: true, message: "请输入品名", trigger: "blur" }],
  373. length: [{ required: true, message: "请输入长", trigger: "blur" }],
  374. width: [{ required: true, message: "请输入宽", trigger: "blur" }],
  375. height: [{ required: true, message: "请输入高", trigger: "blur" }],
  376. netWeight: [{ required: true, message: "请输入净重", trigger: "blur" }],
  377. });
  378. const classifyList = ref([]);
  379. const getBomClassify = () => {
  380. proxy.post("/skuClassify/tree", {}).then((res) => {
  381. classifyList.value = res;
  382. });
  383. };
  384. getBomClassify();
  385. const addSpecification = () => {
  386. if (!props.detailStatus) {
  387. if (formData.data.skuSpecList && formData.data.skuSpecList.length > 0) {
  388. formData.data.skuSpecList.push({
  389. specImgUrl: "",
  390. designImgUrl: "",
  391. name: "",
  392. code: "",
  393. barCode: "",
  394. machinedPanel: "",
  395. length: undefined,
  396. width: undefined,
  397. height: undefined,
  398. netWeight: undefined,
  399. sharedFolder: "",
  400. bomSpecId: "",
  401. remark: "",
  402. packagingMaterialList: [],
  403. expressPackingList: [],
  404. });
  405. } else {
  406. formData.data.skuSpecList = [
  407. {
  408. specImgUrl: "",
  409. designImgUrl: "",
  410. name: "",
  411. code: "",
  412. barCode: "",
  413. machinedPanel: "",
  414. length: undefined,
  415. width: undefined,
  416. height: undefined,
  417. netWeight: undefined,
  418. sharedFolder: "",
  419. bomSpecId: "",
  420. remark: "",
  421. packagingMaterialList: [],
  422. expressPackingList: [],
  423. },
  424. ];
  425. }
  426. }
  427. };
  428. const uploadData = ref({});
  429. const uploadFile = async (file) => {
  430. const res = await proxy.post("/fileInfo/getSing", { fileName: file.name });
  431. uploadData.value = res.uploadBody;
  432. file.id = res.id;
  433. file.fileName = res.fileName;
  434. file.fileUrl = res.fileUrl;
  435. return true;
  436. };
  437. const handleSuccess = (uploadFile, index) => {
  438. formData.data.skuSpecList[index].specImgUrl = uploadFile.raw.fileUrl;
  439. };
  440. // const uploadDesignData = ref({});
  441. // const uploadDesignFile = async (file) => {
  442. // const res = await proxy.post("/fileInfo/getSing", { fileName: file.name });
  443. // uploadDesignData.value = res.uploadBody;
  444. // file.id = res.id;
  445. // file.fileName = res.fileName;
  446. // file.fileUrl = res.fileUrl;
  447. // return true;
  448. // };
  449. // const handleDesignSuccess = (uploadFile, index) => {
  450. // formData.data.skuSpecList[index].designImgUrl = uploadFile.raw.fileUrl;
  451. // };
  452. const clickDelete = (index) => {
  453. formData.data.skuSpecList.splice(index, 1);
  454. };
  455. const editor = ref(null);
  456. const updateValue = (val) => {
  457. formData.data.detailText = val;
  458. };
  459. const uploadMainData = ref({});
  460. const uploadMainFile = async (file) => {
  461. const res = await proxy.post("/fileInfo/getSing", { fileName: file.name });
  462. uploadMainData.value = res.uploadBody;
  463. file.id = res.id;
  464. file.fileName = res.fileName;
  465. file.fileUrl = res.fileUrl;
  466. return true;
  467. };
  468. const handleMainSuccess = (response, uploadFile) => {
  469. formData.data.mainImgUrl = uploadFile.raw.fileUrl;
  470. };
  471. const submitForm = () => {
  472. submit.value.handleSubmit(() => {
  473. if (formData.data.skuSpecList && formData.data.skuSpecList.length > 0) {
  474. let type = "add";
  475. if (formData.data.id) {
  476. type = "edit";
  477. }
  478. proxy.post("/sku/" + type, formData.data).then(() => {
  479. ElMessage({
  480. message: type == "add" ? "添加成功" : "编辑成功",
  481. type: "success",
  482. });
  483. emit("clickCancel", true);
  484. });
  485. } else {
  486. return ElMessage("请添加规格");
  487. }
  488. });
  489. };
  490. const clickCancel = () => {
  491. emit("clickCancel", false);
  492. };
  493. const props = defineProps({
  494. rowData: Object,
  495. detailStatus: Boolean,
  496. });
  497. onMounted(() => {
  498. formOption.disabled = props.detailStatus;
  499. if (props.rowData && props.rowData.id) {
  500. proxy.post("/sku/detail", { id: props.rowData.id }).then((res) => {
  501. for (var text in res) {
  502. formData.data[text] = res[text];
  503. }
  504. if (!props.detailStatus) {
  505. editor.value.changeHtml(formData.data.detailText);
  506. }
  507. });
  508. }
  509. });
  510. const getStyle = (text) => {
  511. if (text) {
  512. return text.replace(/\n|\r\n/g, "<br>");
  513. } else {
  514. return "";
  515. }
  516. };
  517. const rowIndex = ref(null);
  518. const openBOM = ref(false);
  519. const handleOpen = (index) => {
  520. rowIndex.value = index;
  521. openBOM.value = true;
  522. };
  523. const selectBOM = (item) => {
  524. if (item.id) {
  525. formData.data.skuSpecList[rowIndex.value].bomSpecId = item.id;
  526. formData.data.skuSpecList[rowIndex.value].bomSpecName = item.name;
  527. formData.data.skuSpecList[rowIndex.value].length = item.length;
  528. formData.data.skuSpecList[rowIndex.value].width = item.width;
  529. formData.data.skuSpecList[rowIndex.value].height = item.height;
  530. formData.data.skuSpecList[rowIndex.value].netWeight = item.netWeight;
  531. ElMessage({ message: "选择完成", type: "success" });
  532. openBOM.value = false;
  533. }
  534. };
  535. const clickRemoveBOM = (index) => {
  536. formData.data.skuSpecList[index].bomSpecId = "";
  537. formData.data.skuSpecList[index].bomSpecName = "";
  538. };
  539. const drawingFileIndex = ref(0);
  540. const openDrawingFile = ref(false);
  541. const clickDrawingFile = (index) => {
  542. drawingFileIndex.value = index;
  543. openDrawingFile.value = true;
  544. };
  545. const selectPic = (row) => {
  546. formData.data.skuSpecList[drawingFileIndex.value].sharedFolder = row.artworkName + "/" + row.fileName;
  547. formData.data.skuSpecList[drawingFileIndex.value].designImgUrl = row.imgUrl;
  548. ElMessage({ message: "选择完成", type: "success" });
  549. openDrawingFile.value = false;
  550. };
  551. const openFile = (path) => {
  552. window.open(path);
  553. };
  554. </script>
  555. <style lang="scss" scoped>
  556. .avatar-uploader .avatar {
  557. width: 50px;
  558. height: 50px;
  559. display: block;
  560. background-color: black;
  561. }
  562. .avatar-uploader .el-upload {
  563. border: 1px dashed var(--el-border-color);
  564. border-radius: 6px;
  565. cursor: pointer;
  566. position: relative;
  567. overflow: hidden;
  568. transition: var(--el-transition-duration-fast);
  569. }
  570. .avatar-uploader .el-upload:hover {
  571. border-color: var(--el-color-primary);
  572. }
  573. .el-icon.avatar-uploader-icon {
  574. font-size: 28px;
  575. color: #8c939d;
  576. width: 50px;
  577. height: 50px;
  578. text-align: center;
  579. border: 1px dashed var(--el-border-color);
  580. }
  581. ::v-deep(.el-input-number .el-input__inner) {
  582. text-align: left;
  583. }
  584. .avatar-uploader-main .avatar {
  585. width: 148px;
  586. height: 148px;
  587. display: block;
  588. background-color: black;
  589. }
  590. .avatar-uploader-main .el-upload {
  591. border: 1px dashed var(--el-border-color);
  592. border-radius: 6px;
  593. cursor: pointer;
  594. position: relative;
  595. overflow: hidden;
  596. transition: var(--el-transition-duration-fast);
  597. }
  598. .avatar-uploader-main .el-upload:hover {
  599. border-color: var(--el-color-primary);
  600. }
  601. .el-icon.avatar-uploader-main-icon {
  602. font-size: 28px;
  603. color: #8c939d;
  604. width: 148px;
  605. height: 148px;
  606. text-align: center;
  607. border: 1px dashed var(--el-border-color);
  608. }
  609. :deep(.el-dialog) {
  610. margin-top: 10px !important;
  611. margin-bottom: 10px !important;
  612. }
  613. </style>