updateProduct.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  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/product/index" });
  272. });
  273. },
  274. mounted() {
  275. if (
  276. (this.$route.query.params != "[object Object]" &&
  277. this.$route.query.params) ||
  278. JSON.parse(localStorage.getItem("productInfo"))
  279. ) {
  280. let info = {};
  281. if (
  282. this.$route.query.params != "[object Object]" &&
  283. this.$route.query.params
  284. ) {
  285. info = this.$route.query.params;
  286. } else {
  287. info = JSON.parse(localStorage.getItem("productInfo"));
  288. }
  289. if (info.type == "draft") {
  290. this.form.goodsDraftId = info.id;
  291. getGoodsDraftById({ goodsDraftId: info.id }).then((res) => {
  292. if (res.code == 200) {
  293. this.form = res.data.goodsDto;
  294. this.form.goodsDraftId = info.id;
  295. this.headerImg = [];
  296. if (this.form.vid) {
  297. this.headerImg.push({
  298. type: "video",
  299. src: this.form.vid,
  300. sort: 1,
  301. });
  302. }
  303. if (this.form.pic) {
  304. this.headerImg.push({
  305. type: "img",
  306. src: this.form.pic,
  307. sort: 2,
  308. });
  309. }
  310. this.headerImg = this.unique(this.headerImg);
  311. if (this.form.bannerList?.length > 0) {
  312. this.form.bannerList.forEach((e, index) => {
  313. this.headerImg.push({
  314. type: "img",
  315. src: e.fileUrl,
  316. sort: index + 4,
  317. });
  318. });
  319. }
  320. this.headerImg.sort((a, b) => a.sort - b.sort); //排序 视频在最前面>封面>商品banner
  321. this.$refs.basicRefs.getFormInfo(this.form, this.$route.query.type);
  322. this.$refs.salesRefs.getFormInfo(this.form);
  323. this.$refs.productRefs.getFormInfo(this.form);
  324. }
  325. });
  326. } else {
  327. getGoodsInfo({ spuId: info.id }).then((res) => {
  328. if (res.code == 200) {
  329. this.form = res.data;
  330. this.headerImg = [];
  331. if (this.form.vid) {
  332. this.headerImg.push({
  333. type: "video",
  334. src: this.form.vid,
  335. sort: 1,
  336. });
  337. }
  338. if (this.form.pic) {
  339. this.headerImg.push({
  340. type: "img",
  341. src: this.form.pic,
  342. sort: 2,
  343. });
  344. }
  345. this.headerImg = this.unique(this.headerImg);
  346. if (this.form.bannerList?.length > 0) {
  347. this.form.bannerList.forEach((e, index) => {
  348. this.headerImg.push({
  349. type: "img",
  350. src: e.fileUrl,
  351. sort: index + 4,
  352. });
  353. });
  354. }
  355. this.headerImg.sort((a, b) => a.sort - b.sort); //排序 视频在最前面>封面>商品banner
  356. this.$refs.basicRefs.getFormInfo(this.form, this.$route.query.type);
  357. this.$refs.salesRefs.getFormInfo(this.form);
  358. this.$refs.productRefs.getFormInfo(this.form);
  359. }
  360. });
  361. }
  362. }
  363. },
  364. methods: {
  365. skuRemove(list) {
  366. this.skulist = list;
  367. },
  368. submitCancel() {
  369. this.$confirm("是否取消发布,所填写的信息将会消失?", "提示", {
  370. confirmButtonText: "确定",
  371. cancelButtonText: "取消",
  372. type: "warning",
  373. })
  374. .then(() => {
  375. this.$store.dispatch("tagsView/delView", this.$route); //关闭当前页
  376. this.$router.replace({ path: "/product/product/index" });
  377. })
  378. .catch(() => {
  379. this.$message({
  380. type: "info",
  381. message: "已取消删除",
  382. });
  383. });
  384. },
  385. submitFormDraft() {
  386. if (!this.form.presaleStartTime && !this.form.presaleEndTime) {
  387. if (this.form.datePicke) {
  388. this.form.presaleStartTime = moment(
  389. this.form.datePicker[0]
  390. ).valueOf();
  391. this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();
  392. }
  393. }
  394. if (this.form.categoryId?.length > 0) {
  395. this.form.categoryId =
  396. this.form.categoryId[this.form.categoryId.length - 1];
  397. }
  398. // if (this.form.bannerList?.length > 0) {
  399. // this.form.bannerList.shift();
  400. // }
  401. saveGoodsDraft(this.form).then((res) => {
  402. if (res.code == 200) {
  403. this.$message.success(`保存成功!请前往草稿箱查看`);
  404. this.$store.dispatch("tagsView/delView", this.$route); //关闭当前页
  405. this.$router.replace({ path: "/product/product/index" });
  406. }
  407. });
  408. },
  409. async submitForm() {
  410. let basic = await this.$refs.basicRefs.formvalidate();
  411. if (basic) {
  412. let sales = await this.$refs.salesRefs.formvalidate();
  413. if (sales) {
  414. let product = await this.$refs.productRefs.formvalidate();
  415. if (!product) {
  416. return;
  417. }
  418. } else {
  419. return;
  420. }
  421. } else {
  422. return;
  423. }
  424. if (this.form.skuList === "") {
  425. this.$message.error(`商品规格不能为空`);
  426. return;
  427. }
  428. this.btnLading = true;
  429. if (!this.form.presaleStartTime && !this.form.presaleEndTime) {
  430. if (this.form.datePicke) {
  431. this.form.presaleStartTime = moment(
  432. this.form.datePicker[0]
  433. ).valueOf();
  434. this.form.presaleEndTime = moment(this.form.datePicker[1]).valueOf();
  435. }
  436. }
  437. if (this.form.categoryId?.length > 0) {
  438. this.form.categoryId =
  439. this.form.categoryId[this.form.categoryId.length - 1];
  440. }
  441. if (this.form.id) {
  442. if (this.skulist?.length > 0) {
  443. removeSkuBySkuId({ skuIds: this.skulist.toString() }).then(
  444. (res) => {}
  445. );
  446. }
  447. if (this.form.skuList.length < 1 || this.form.skuList === "") {
  448. this.$message.error(`规格不能为空`);
  449. return;
  450. }
  451. updateGoods(this.form).then((res) => {
  452. if (res.code == 200) {
  453. this.btnLading = false;
  454. this.$message.success(`编辑成功!`);
  455. this.$store.dispatch("tagsView/delView", this.$route); //关闭当前页
  456. this.$router.replace({ path: "/product/product/index" });
  457. } else {
  458. this.btnLading = false;
  459. }
  460. });
  461. } else {
  462. publishGoods(this.form).then((res) => {
  463. if (res.code == 200) {
  464. this.btnLading = false;
  465. this.$message.success(`发布成功!`);
  466. this.$store.dispatch("tagsView/delView", this.$route); //关闭当前页
  467. this.$router.replace({ path: "/product/product/index" });
  468. } else {
  469. this.btnLading = false;
  470. }
  471. });
  472. }
  473. },
  474. updateValue(val) {
  475. this.form = { ...this.form, ...val };
  476. this.headerImg = [];
  477. if (val.vid || this.form.vid) {
  478. this.headerImg.push({
  479. type: "video",
  480. src: val.vid ? val.vid : this.form.vid,
  481. sort: 1,
  482. });
  483. }
  484. if (this.form?.bannerList && this.form?.bannerList.length > 0) {
  485. this.form.bannerList.forEach((e, index) => {
  486. this.headerImg.push({
  487. type: "img",
  488. src: e.fileUrl,
  489. sort: index + 4,
  490. });
  491. });
  492. }
  493. this.headerImg.sort((a, b) => a.sort - b.sort); //排序 视频在最前面>封面>商品banner
  494. },
  495. unique(arr) {
  496. const res = new Map();
  497. return arr.filter((arr) => !res.has(arr.src) && res.set(arr.src, 1));
  498. },
  499. },
  500. };
  501. </script>
  502. <style>
  503. .required {
  504. color: red;
  505. }
  506. .el-upload-list__item {
  507. width: 60px !important;
  508. height: 60px !important;
  509. }
  510. .el-upload--picture-card {
  511. width: 80px;
  512. height: 80px;
  513. display: flex;
  514. flex-direction: row;
  515. justify-content: center;
  516. align-items: center;
  517. }
  518. .tips {
  519. font-size: 12px;
  520. color: red;
  521. }
  522. </style>
  523. <style scoped>
  524. .card {
  525. /* height: 85px; */
  526. width: 95%;
  527. background: white;
  528. margin: auto;
  529. border-radius: 10px;
  530. line-height: 30px;
  531. padding: 10px;
  532. }
  533. .spuName {
  534. text-decoration: none;
  535. font-weight: bold;
  536. word-wrap: normal;
  537. font-size: 18px;
  538. color: #333333;
  539. }
  540. .price_group {
  541. color: #ff2f2f;
  542. }
  543. .price {
  544. text-decoration: none;
  545. font-weight: bold;
  546. word-wrap: normal;
  547. font-size: 25px;
  548. color: #ff2f2f;
  549. }
  550. .price_info {
  551. display: flex;
  552. flex-direction: row;
  553. justify-content: space-between;
  554. align-items: center;
  555. }
  556. .ys {
  557. font-size: 14px;
  558. }
  559. </style>