product.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import { productCouponListApi } from '@/api/product';
  2. import { defaultObj } from '@/views/product/creatProduct/default';
  3. export default {
  4. data() {
  5. return {
  6. headTab: [
  7. { tit: '商品信息', name: '1' },
  8. { tit: '规格库存', name: '2' },
  9. { tit: '商品详情', name: '3' },
  10. { tit: '其他设置', name: '4' },
  11. ],
  12. formValidate: Object.assign({}, defaultObj),
  13. attrInfo: {},
  14. };
  15. },
  16. methods: {
  17. getData(res, type) {
  18. let info = res;
  19. this.formValidate.content = '';
  20. this.formValidate = {
  21. ...info,
  22. image: this.$selfUtil.setDomain(info.image),
  23. sliderImages: JSON.parse(info.sliderImage),
  24. cateIds: info.cateId ? info.cateId.split(',') : [], // 商品分类id
  25. sort: info.sort ? info.sort : 0,
  26. attrList: info.attrList ? info.attrList : [],
  27. attrValueList: info.attrValueList ? info.attrValueList : [],
  28. isSub: info.isSub ? info.isSub : false,
  29. isHot: info.isHot ? info.isHot : false,
  30. content: info.content ? this.$selfUtil.replaceImgSrcHttps(info.content) : '',
  31. id: info.id ? info.id : 0,
  32. coupons: info.coupons ? info.coupons : [],
  33. couponIds: info.couponIds ? info.couponIds : [],
  34. type: info.type ? info.type : Number(this.$route.params.productType),
  35. guaranteeIdsList: info.guaranteeIds ? info.guaranteeIds.split(',').map(Number) : [], //保障服务
  36. isPaidMember: info.isPaidMember ? info.isPaidMember : false,
  37. deliveryMethodList: info.deliveryMethod ? info.deliveryMethod.split(',') : ['1'],
  38. systemFormId: info.systemFormId ? info.systemFormId : null,
  39. refundSwitch: type === 'add' ? info.refundSwitch : true,
  40. // categoryId: info.categoryId ? info.categoryId : '',
  41. // brandId: info.brandId ? info.brandId : ''
  42. };
  43. this.htmlKey++;
  44. this.labelarr = info.keyword ? info.keyword.split(',') : [];
  45. if (this.formValidate.categoryId) {
  46. this.getbrandList();
  47. this.brandList.push({ name: '其他', id: 0 });
  48. }
  49. if (this.formValidate.couponIds && this.formValidate.couponIds.length) {
  50. productCouponListApi().then((res) => {
  51. let ids = this.formValidate.couponIds.toString();
  52. let arr = res;
  53. let obj = {};
  54. for (let i in arr) {
  55. obj[arr[i].id] = arr[i];
  56. }
  57. let strArr = ids.split(',');
  58. let newArr = [];
  59. for (let item of strArr) {
  60. if (obj[item]) {
  61. newArr.push(obj[item]);
  62. }
  63. }
  64. this.$set(this.formValidate, 'coupons', newArr); //在编辑回显时,让返回数据中的优惠券id,通过接口匹配显示,
  65. });
  66. }
  67. let imgs = JSON.parse(info.sliderImage);
  68. let imgss = [];
  69. Object.keys(imgs).map((i) => {
  70. imgss.push(this.$selfUtil.setDomain(imgs[i]));
  71. });
  72. this.formValidate.sliderImages = [...imgss];
  73. if (this.getFileType(this.formValidate.sliderImages[0]) == 'video') {
  74. //如果返回数据轮播图的第一张是视频,就将其赋值给videoLink做渲染,同时将其在轮播图中删除
  75. this.$set(this, 'videoLink', this.formValidate.sliderImages[0]);
  76. this.formValidate.sliderImages.splice(0, 1);
  77. }
  78. if (info.specType) {
  79. if (info.attrValueList) {
  80. info.attrValueList.forEach((val) => {
  81. val.image = this.$selfUtil.setDomain(val.image);
  82. val.attrValueShow = JSON.parse(val.attrValue);
  83. val.attr_arr = val.sku.split(',');
  84. val.brokerage = val.brokerage || 0;
  85. val.brokerageTwo = val.brokerageTwo || 0;
  86. val.vipPrice = val.vipPrice || 0;
  87. });
  88. this.ManyAttrValue = [...this.oneFormBatch, ...info.attrValueList];
  89. } else {
  90. if (this.formValidate.attrList.length) {
  91. this.oneFormBatch[0].image = this.$selfUtil.setDomain(info.image);
  92. }
  93. }
  94. } else {
  95. this.OneattrValue = info.attrValueList;
  96. }
  97. },
  98. // 点击商品图
  99. modalPicTap(tit, num, i, status) {
  100. const _this = this;
  101. if (_this.isDisabled) return;
  102. this.$modalUpload(
  103. function (img) {
  104. if (!img) return;
  105. if (tit === '1' && !num) {
  106. _this.formValidate.image = img[0].sattDir;
  107. _this.OneattrValue[0].image = img[0].sattDir;
  108. }
  109. if (tit === '2' && !num) {
  110. if (img.length > 10) return this.$message.warning('最多选择10张图片!');
  111. if (img.length + _this.formValidate.sliderImages.length > 10)
  112. return this.$message.warning('最多选择10张图片!');
  113. img.map((item) => {
  114. _this.formValidate.sliderImages.push(item.sattDir);
  115. });
  116. }
  117. if (tit === '1' && num === 'dan') {
  118. _this.OneattrValue[0].image = img[0].sattDir;
  119. }
  120. if (tit === '1' && num === 'duo') {
  121. _this.ManyAttrValue[i].image = img[0].sattDir;
  122. }
  123. if (tit === '1' && num === 'pi') {
  124. _this.oneFormBatch[0].image = img[0].sattDir;
  125. }
  126. },
  127. tit,
  128. 'content',
  129. );
  130. },
  131. // 移动
  132. handleDragStart(e, item) {
  133. if (!this.isDisabled) this.dragging = item;
  134. },
  135. handleDragEnd(e, item) {
  136. if (!this.isDisabled) this.dragging = null;
  137. },
  138. handleDragOver(e) {
  139. if (!this.isDisabled) e.dataTransfer.dropEffect = 'move';
  140. },
  141. // 移动关键代码,包含轮播图、规格
  142. handleDragEnter(e, item, index) {
  143. if (!this.isDisabled) {
  144. e.dataTransfer.effectAllowed = 'move';
  145. if (item === this.dragging) {
  146. return;
  147. }
  148. let newItems = [];
  149. newItems = [...this.formValidate.sliderImages];
  150. const src = newItems.indexOf(this.dragging);
  151. const dst = newItems.indexOf(item);
  152. newItems.splice(dst, 0, ...newItems.splice(src, 1));
  153. this.formValidate.sliderImages = newItems;
  154. }
  155. },
  156. },
  157. };