updateProduct.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. <template>
  2. <div class="app-container">
  3. <div style="width: 100%; height: 85vh; overflow: auto">
  4. <el-row style="padding-top: 20px">
  5. <el-col :span="24">
  6. <el-descriptions title="基本信息" column="1"> </el-descriptions>
  7. <basicInfo ref="basicRefs" @updateValue="updateValue"></basicInfo>
  8. <el-descriptions title="销售信息" column="1"> </el-descriptions>
  9. <salesInfo
  10. ref="salesRefs"
  11. @updateValue="updateValue"
  12. @skuRemove="skuRemove"
  13. :saleModels="form.saleModel"
  14. ></salesInfo>
  15. <el-descriptions title="商品详情" column="1"> </el-descriptions>
  16. <productInfo
  17. ref="productRefs"
  18. @updateValue="updateValue"
  19. ></productInfo>
  20. <div class="dialog-footer" style="text-align: center">
  21. <el-button @click="submitCancel">取 消</el-button>
  22. <el-button type="primary" @click="submitForm" :loading="btnLading"
  23. >发 布</el-button
  24. >
  25. <el-button
  26. type="primary"
  27. @click="submitFormDraft"
  28. v-if="$route.query.params.type == 'draft'"
  29. >存入草稿箱</el-button
  30. >
  31. </div>
  32. </el-col>
  33. <phoneView style="position: absolute; bottom: 50px; right: 50px">
  34. <div slot="conts">
  35. <div>
  36. <el-carousel height="200px">
  37. <el-carousel-item
  38. v-for="(item, index) in headerImg.slice(1)"
  39. :key="index"
  40. >
  41. <el-image
  42. v-if="item.type == 'img'"
  43. style="width: 100%; height: 200px"
  44. :src="item.src"
  45. :preview-src-list="[item.src]"
  46. >
  47. </el-image>
  48. <video
  49. v-if="item.type == 'video'"
  50. :key="index"
  51. controls
  52. :src="item.src"
  53. style="width: 100%; height: 200px"
  54. ></video>
  55. </el-carousel-item>
  56. </el-carousel>
  57. </div>
  58. <img
  59. style="width: 100%"
  60. src="https://bucket.sxdirectpurchase.com/fileUpload/test/47fc6132-0b3e-4b5c-b858-f78d363eba90.png"
  61. alt=""
  62. />
  63. <div class="card">
  64. <div class="spuName">{{ form ? form.title : "" }}</div>
  65. <div class="price_info">
  66. <div class="price_group">
  67. <span>¥</span>
  68. <span
  69. class="price"
  70. :key="item"
  71. v-for="item in form.skuList ? form.skuList.slice(0, 1) : []"
  72. >{{
  73. item.skuPriceList ? item.skuPriceList[0].price : 0
  74. }}元</span
  75. >
  76. <span>/{{ form.unit }}</span>
  77. </div>
  78. <span class="ys">已售 0</span>
  79. </div>
  80. </div>
  81. <div class="card" style="margin-top: 10px">
  82. <div class="spuName">规格/价格</div>
  83. <div v-for="(item, index) in form.skuList" :key="index">
  84. <div class="price_info">
  85. <span
  86. >{{
  87. item.skuSpecsList[0] ? item.skuSpecsList[0].specsName : ""
  88. }}
  89. {{
  90. item.skuSpecsList[0].specsValue
  91. ? item.skuSpecsList[0].specsValue
  92. : ""
  93. }}</span
  94. >
  95. </div>
  96. <div
  97. style="
  98. display: flex;
  99. flex-direction: row;
  100. justify-content: space-between;
  101. "
  102. >
  103. <span style="font-size: 14px; color: red">
  104. <span>¥</span>
  105. <span
  106. >{{
  107. item.skuPriceList
  108. ? item.skuPriceList[0].price
  109. ? item.skuPriceList[0].price
  110. : ""
  111. : ""
  112. }}元</span
  113. ><span>/{{ form.unit }}</span></span
  114. >
  115. <span style="font-size: 14px"
  116. >{{
  117. item.skuPriceList
  118. ? item.skuPriceList[0].minPurchase
  119. ? item.skuPriceList[0].minPurchase
  120. : ""
  121. : ""
  122. }}/{{ form.unit }}起购</span
  123. >
  124. <span style="font-size: 14px"
  125. >库存:{{ item.stock + item.predictStocks
  126. }}{{ form.unit }}</span
  127. >
  128. </div>
  129. </div>
  130. </div>
  131. <div class="card" style="margin-top: 10px">
  132. <el-form
  133. :model="form"
  134. ref="queryForm"
  135. size="small"
  136. :inline="true"
  137. label-width="80px"
  138. label-position="left"
  139. >
  140. <el-row>
  141. <el-col :span="24">
  142. <el-form-item label="发货地" prop="spuName">
  143. <div style="width: 185px">
  144. {{
  145. form.shippingAddrBean
  146. ? form.shippingAddrBean.addr
  147. : ""
  148. }}
  149. {{
  150. form.shippingAddrBean
  151. ? form.shippingAddrBean.addrDetail
  152. ? form.shippingAddrBean.addrDetail
  153. : ""
  154. : ""
  155. }}
  156. </div>
  157. </el-form-item>
  158. </el-col>
  159. <el-col :span="24">
  160. <el-form-item label="发货时间" prop="spuName">
  161. {{ form.shippingTimeDesc }}
  162. </el-form-item>
  163. </el-col>
  164. <el-col :span="24">
  165. <el-form-item label="商品属性" prop="spuName">
  166. <div>查看></div>
  167. </el-form-item>
  168. </el-col>
  169. <el-col :span="24">
  170. <el-form-item label="包装方式" prop="spuName">
  171. {{ form.packing }}
  172. </el-form-item>
  173. </el-col>
  174. </el-row>
  175. </el-form>
  176. </div>
  177. <div class="card" style="margin-top: 10px">
  178. <div
  179. style="
  180. display: flex;
  181. flex-direction: row;
  182. justify-content: space-between;
  183. align-items: center;
  184. "
  185. >
  186. <span class="spuName">商品评价</span>
  187. <span>好评率 <span style="color: red">100%</span></span>
  188. </div>
  189. <div
  190. style="
  191. display: flex;
  192. flex-direction: column;
  193. justify-content: center;
  194. align-items: center;
  195. "
  196. >
  197. <img
  198. style="width: 40%"
  199. src="https://directpurchase-oss-dev.oss-cn-chengdu.aliyuncs.com/wx/static/images/kong.png"
  200. alt=""
  201. />
  202. <span>还没有评价~</span>
  203. </div>
  204. </div>
  205. <div class="card" style="margin-top: 10px">
  206. <div class="spuName">商品介绍</div>
  207. <div style="font-size: 14px; line-height: 25px">
  208. {{ form.spuDesc }}
  209. </div>
  210. </div>
  211. <div class="card" style="margin-top: 10px">
  212. <div class="spuName">商品详情</div>
  213. <div style="font-size: 14px; line-height: 25px">
  214. <el-image
  215. v-for="(item, index) in form.spuDetailList"
  216. :key="index"
  217. :src="item.fileUrl"
  218. fit="fill"
  219. :preview-src-list="[item.fileUrl]"
  220. >
  221. </el-image>
  222. </div>
  223. <div style="font-size: 14px; line-height: 25px">
  224. <el-image
  225. v-for="(item, index) in form.specialList"
  226. :key="index"
  227. :src="item.fileUrl"
  228. fit="fill"
  229. :preview-src-list="[item.fileUrl]"
  230. >
  231. </el-image>
  232. </div>
  233. </div>
  234. </div>
  235. </phoneView>
  236. </el-row>
  237. </div>
  238. <Amap></Amap>
  239. </div>
  240. </template>
  241. <script>
  242. import { publishGoods } from "@/api/publish/index";
  243. import { getStoreInfo } from "@/api/common/index";
  244. import {
  245. saveGoodsDraft,
  246. updateGoods,
  247. getGoodsInfo,
  248. getGoodsDraftById,
  249. removeSkuBySkuId,
  250. } from "@/api/manage/product";
  251. import basicInfo from "./module/basic-info.vue";
  252. import productInfo from "./module/product-info.vue";
  253. import salesInfo from "./module/sales-info.vue";
  254. import phoneView from "@/components/phoneView/index.vue";
  255. import Amap from "@/components/Map/map.vue";
  256. import moment from "moment";
  257. export default {
  258. name: "updateProduct",
  259. components: { Amap, phoneView, basicInfo, salesInfo, productInfo },
  260. data() {
  261. return {
  262. form: {},
  263. headerImg: [],
  264. btnLading: false,
  265. skulist: [],
  266. };
  267. },
  268. created() {
  269. window.addEventListener("beforeunload", function (e) {
  270. this.$store.dispatch("tagsView/delView", this.$route); //关闭当前页
  271. this.$router.replace({ path: "/product/member/index" });
  272. });
  273. },
  274. mounted() {
  275. this.getInfo();
  276. if (
  277. (this.$route.query.params != "[object Object]" &&
  278. this.$route.query.params) ||
  279. JSON.parse(localStorage.getItem("productInfo"))
  280. ) {
  281. let info = {};
  282. if (
  283. this.$route.query.params != "[object Object]" &&
  284. this.$route.query.params
  285. ) {
  286. info = this.$route.query.params;
  287. } else {
  288. info = JSON.parse(localStorage.getItem("productInfo"));
  289. }
  290. if (info.type == "draft") {
  291. this.form.goodsDraftId = info.id;
  292. getGoodsDraftById({ goodsDraftId: info.id }).then((res) => {
  293. if (res.code == 200) {
  294. this.form = res.data.goodsDto;
  295. this.form.goodsDraftId = info.id;
  296. this.headerImg = [];
  297. if (this.form.vid) {
  298. this.headerImg.push({
  299. type: "video",
  300. src: this.form.vid,
  301. sort: 1,
  302. });
  303. }
  304. if (this.form.pic) {
  305. this.headerImg.push({
  306. type: "img",
  307. src: this.form.pic,
  308. sort: 2,
  309. });
  310. }
  311. this.headerImg = this.unique(this.headerImg);
  312. if (this.form.bannerList?.length > 0) {
  313. this.form.bannerList.forEach((e, index) => {
  314. this.headerImg.push({
  315. type: "img",
  316. src: e.fileUrl,
  317. sort: index + 4,
  318. });
  319. });
  320. }
  321. this.headerImg.sort((a, b) => a.sort - b.sort); //排序 视频在最前面>封面>商品banner
  322. if (this.form.scope == 0) {
  323. this.$refs.salesRefs.setShowCom(false);
  324. } else if (this.form.saleType == 2 && this.form.scope == 0) {
  325. this.$refs.salesRefs.setShowCom(false);
  326. } else {
  327. this.$refs.salesRefs.setShowCom(true);
  328. }
  329. this.$refs.basicRefs.getFormInfo(this.form);
  330. this.$refs.salesRefs.getFormInfo(this.form);
  331. this.$refs.productRefs.getFormInfo(this.form);
  332. }
  333. });
  334. } else {
  335. getGoodsInfo({ spuId: info.id }).then((res) => {
  336. if (res.code == 200) {
  337. this.form = res.data;
  338. this.headerImg = [];
  339. if (this.form.vid) {
  340. this.headerImg.push({
  341. type: "video",
  342. src: this.form.vid,
  343. sort: 1,
  344. });
  345. }
  346. if (this.form.pic) {
  347. this.headerImg.push({
  348. type: "img",
  349. src: this.form.pic,
  350. sort: 2,
  351. });
  352. }
  353. this.headerImg = this.unique(this.headerImg);
  354. if (this.form.bannerList?.length > 0) {
  355. this.form.bannerList.forEach((e, index) => {
  356. this.headerImg.push({
  357. type: "img",
  358. src: e.fileUrl,
  359. sort: index + 4,
  360. });
  361. });
  362. }
  363. this.headerImg.sort((a, b) => a.sort - b.sort); //排序 视频在最前面>封面>商品banner
  364. if (this.form.scope == 0) {
  365. this.$refs.salesRefs.setShowCom(false);
  366. } else if (this.form.saleType == 2 && this.form.scope == 0) {
  367. this.$refs.salesRefs.setShowCom(false);
  368. } else {
  369. this.$refs.salesRefs.setShowCom(true);
  370. }
  371. this.$refs.basicRefs.getFormInfo(this.form);
  372. this.$refs.salesRefs.getFormInfo(this.form);
  373. this.$refs.productRefs.getFormInfo(this.form);
  374. }
  375. });
  376. }
  377. }
  378. },
  379. methods: {
  380. skuRemove(list) {
  381. console.log("list", list);
  382. this.skulist = list;
  383. },
  384. getInfo() {
  385. getStoreInfo().then((res) => {
  386. if (res.code == 200) {
  387. if (res.data.scope == 0) {
  388. if (this.form.saleType == 2) {
  389. this.$refs.salesRefs.setShowCom(true);
  390. } else {
  391. this.$refs.salesRefs.setShowCom(false);
  392. }
  393. } else {
  394. this.$refs.salesRefs.setShowCom(true);
  395. }
  396. }
  397. });
  398. },
  399. submitCancel() {
  400. this.$confirm("是否取消发布,所填写的信息将会消失?", "提示", {
  401. confirmButtonText: "确定",
  402. cancelButtonText: "取消",
  403. type: "warning",
  404. })
  405. .then(() => {
  406. this.$store.dispatch("tagsView/delView", this.$route); //关闭当前页
  407. this.$router.replace({ path: "/product/member/index" });
  408. })
  409. .catch(() => {
  410. this.$message({
  411. type: "info",
  412. message: "已取消删除",
  413. });
  414. });
  415. },
  416. submitFormDraft() {
  417. if (!this.form.presaleStartTime && !this.form.presaleEndTime) {
  418. if (this.form.datePicke) {
  419. this.form.presaleStartTime = moment(
  420. this.form.datePicker[0]
  421. ).valueOf();
  422. this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();
  423. }
  424. }
  425. if (this.form.categoryId?.length > 0) {
  426. this.form.categoryId =
  427. this.form.categoryId[this.form.categoryId.length - 1];
  428. }
  429. // if (this.form.bannerList?.length > 0) {
  430. // this.form.bannerList.shift();
  431. // }
  432. saveGoodsDraft(this.form).then((res) => {
  433. if (res.code == 200) {
  434. this.$message.success(`保存成功!请前往草稿箱查看`);
  435. this.$store.dispatch("tagsView/delView", this.$route); //关闭当前页
  436. this.$router.replace({ path: "/product/member/index" });
  437. }
  438. });
  439. },
  440. async submitForm() {
  441. let basic = await this.$refs.basicRefs.formvalidate();
  442. if (basic) {
  443. let sales = await this.$refs.salesRefs.formvalidate();
  444. if (sales) {
  445. let product = await this.$refs.productRefs.formvalidate();
  446. if (!product) {
  447. return;
  448. }
  449. } else {
  450. return;
  451. }
  452. } else {
  453. return;
  454. }
  455. if (this.form.skuList === "") {
  456. this.$message.error(`商品规格不能为空`);
  457. return;
  458. }
  459. // if (this.form.bannerList?.length > 0) {
  460. // this.form.bannerList.shift();
  461. // }
  462. this.btnLading = true;
  463. if (!this.form.presaleStartTime && !this.form.presaleEndTime) {
  464. if (this.form.datePicke) {
  465. this.form.presaleStartTime = moment(
  466. this.form.datePicker[0]
  467. ).valueOf();
  468. this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();
  469. }
  470. }
  471. if (this.form.categoryId?.length > 0) {
  472. this.form.categoryId =
  473. this.form.categoryId[this.form.categoryId.length - 1];
  474. }
  475. if (this.form.id) {
  476. if (this.skulist?.length > 0) {
  477. removeSkuBySkuId({ skuIds: this.skulist.toString() }).then(
  478. (res) => {}
  479. );
  480. }
  481. if (this.form.skuList.length < 1 || this.form.skuList === "") {
  482. this.$message.error(`规格不能为空`);
  483. return;
  484. }
  485. if (!this.form.shippingAddrBean.provinceCode) {
  486. this.$message.error(`请点击选择地址,选择发货地址的省市区!`);
  487. return;
  488. }
  489. updateGoods(this.form).then((res) => {
  490. if (res.code == 200) {
  491. this.btnLading = false;
  492. this.$message.success(`编辑成功!`);
  493. this.$store.dispatch("tagsView/delView", this.$route); //关闭当前页
  494. this.$router.replace({ path: "/product/member/index" });
  495. } else {
  496. this.btnLading = false;
  497. }
  498. });
  499. } else {
  500. publishGoods(this.form).then((res) => {
  501. if (res.code == 200) {
  502. this.btnLading = false;
  503. this.$message.success(`发布成功!`);
  504. this.$store.dispatch("tagsView/delView", this.$route); //关闭当前页
  505. this.$router.replace({ path: "/product/member/index" });
  506. } else {
  507. this.btnLading = false;
  508. }
  509. });
  510. }
  511. },
  512. updateValue(val) {
  513. this.form = { ...this.form, ...val };
  514. if (this.form.saleType == 2) {
  515. this.$refs.salesRefs.setShowCom(true);
  516. } else if (this.form.scope == 0) {
  517. this.$refs.salesRefs.setShowCom(false);
  518. } else {
  519. this.$refs.salesRefs.setShowCom(true);
  520. }
  521. this.headerImg = [];
  522. if (val.vid || this.form.vid) {
  523. this.headerImg.push({
  524. type: "video",
  525. src: val.vid ? val.vid : this.form.vid,
  526. sort: 1,
  527. });
  528. }
  529. if (this.form?.bannerList && this.form?.bannerList.length > 0) {
  530. this.form.bannerList.forEach((e, index) => {
  531. this.headerImg.push({
  532. type: "img",
  533. src: e.fileUrl,
  534. sort: index + 4,
  535. });
  536. });
  537. }
  538. this.headerImg.sort((a, b) => a.sort - b.sort); //排序 视频在最前面>封面>商品banner
  539. console.log("1231231", this.form);
  540. },
  541. unique(arr) {
  542. const res = new Map();
  543. return arr.filter((arr) => !res.has(arr.src) && res.set(arr.src, 1));
  544. },
  545. },
  546. };
  547. </script>
  548. <style>
  549. .required {
  550. color: red;
  551. }
  552. .el-upload-list__item {
  553. width: 60px !important;
  554. height: 60px !important;
  555. }
  556. .el-upload--picture-card {
  557. width: 80px;
  558. height: 80px;
  559. display: flex;
  560. flex-direction: row;
  561. justify-content: center;
  562. align-items: center;
  563. }
  564. .tips {
  565. font-size: 12px;
  566. color: red;
  567. }
  568. </style>
  569. <style scoped>
  570. .card {
  571. /* height: 85px; */
  572. width: 95%;
  573. background: white;
  574. margin: auto;
  575. border-radius: 10px;
  576. line-height: 30px;
  577. padding: 10px;
  578. }
  579. .spuName {
  580. text-decoration: none;
  581. font-weight: bold;
  582. word-wrap: normal;
  583. font-size: 18px;
  584. color: #333333;
  585. }
  586. .price_group {
  587. color: #ff2f2f;
  588. }
  589. .price {
  590. text-decoration: none;
  591. font-weight: bold;
  592. word-wrap: normal;
  593. font-size: 25px;
  594. color: #ff2f2f;
  595. }
  596. .price_info {
  597. display: flex;
  598. flex-direction: row;
  599. justify-content: space-between;
  600. align-items: center;
  601. }
  602. .ys {
  603. font-size: 14px;
  604. }
  605. </style>