diff --git a/src/views/product/add_shop.vue b/src/views/product/add_shop.vue index bd8a360..339dc87 100644 --- a/src/views/product/add_shop.vue +++ b/src/views/product/add_shop.vue @@ -1,11 +1,22 @@ @@ -316,13 +587,21 @@ - + - 确定 + 确定 取消 - + 取 消 - 确 定 + 确 定 - + - + @@ -386,10 +696,10 @@ import { tbProductPost, tbProductSpecGet, tbProductGetDetail, - tbProductPut + tbProductPut, } from "@/api/shop"; import addUnit from "./components/addUnit"; -import addImg from './components/addImages.vue' +import addImg from "./components/addImages.vue"; import addClassify from "./components/addClassify"; import shopList from "@/components/shopList"; import groupTypeList from "@/components/groupTypeList"; @@ -406,7 +716,8 @@ export default { uploadImg, shopList, groupTypeList, - Editor, addImg + Editor, + addImg, }, data() { const validatordateUsed = (rule, value, callback) => { @@ -435,9 +746,9 @@ export default { firstShared: undefined, barCode: `${localStorage.getItem("shopId")}${dayjs().valueOf()}`, isGrounding: 1, - productId: this.$route.query.goods_id ? this.$route.query.goods_id : '', + productId: this.$route.query.goods_id ? this.$route.query.goods_id : "", shopId: localStorage.getItem("shopId"), - suit: 0 + suit: 0, }, tableAddShopIndex: null, isEditor: false, @@ -447,7 +758,7 @@ export default { id: "", typeEnum: "normal", name: "", - shortTitle: "",//商品介绍 + shortTitle: "", //商品介绍 unitId: "", unitName: "", categoryId: "", // 商品分类id @@ -479,70 +790,72 @@ export default { marketPriceInfo: "", platformTips: "", refundPolicy: "", - usageRules: "" - } + usageRules: "", + }, }, imgList: [], rules: { typeEnum: [ { - required: true - } + required: true, + }, ], name: [ { required: true, trigger: "blur", - message: "请输入商品名称" - } + message: "请输入商品名称", + }, + ], + unitId: [ + { + required: true, + trigger: "change", + message: "请选择单位", + }, ], - unitId: [{ - required: true, - trigger: "change", - message: "请选择单位" - }], categoryId: [ { required: true, trigger: "change", - message: "请选择商品分类" - } + message: "请选择商品分类", + }, ], groupCategoryId: [ { required: true, trigger: "change", - message: "请选择团购券分类" - } + message: "请选择团购券分类", + }, ], "notices.dateUsed": [ { required: true, trigger: "blur", - message: "请输入使用日期说明" - } + message: "请输入使用日期说明", + }, ], "notices.availableTime": [ { required: true, trigger: "blur", - message: "请输入可用时间说明" - } + message: "请输入可用时间说明", + }, ], "notices.bookingType": [ { required: true, trigger: "blur", - message: "请输入预约方式" - } + message: "请输入预约方式", + }, ], "notices.refundPolicy": [ { required: true, trigger: "blur", - message: "请输入退款说明" - } - ] + message: "请输入退款说明", + }, + ], }, units: [], categorys: [], @@ -550,8 +863,8 @@ export default { showBatchModal: false, batchNumberKey: "", batchNumberForm: { - batchNumber: 0 - } + batchNumber: 0, + }, }; }, mounted() { @@ -564,9 +877,14 @@ export default { } }, methods: { + uploadImgSucess(res, item) { + console.log(res); + console.log(item); + item.coverImg = res[0]; + }, successEvent(d) { this.form.images.push(d[0].url); - this.imgList.push(d[0]) + this.imgList.push(d[0]); // if (this.$refs.uploadImg.fileList.length < 9) { // d.forEach(item => { // item.uid = item.id @@ -584,27 +902,27 @@ export default { }, priceFormat(item, key) { const messageheight = 48; - const offset = window.innerHeight / 2 - (messageheight / 2) - 100 + const offset = window.innerHeight / 2 - messageheight / 2 - 100; this.$nextTick(() => { const min = 0; const max = 100000000; - const newval = formatPrice(item[key], min, max, true) - console.log(newval) - if (typeof newval !== 'number') { - item[key] = newval.value + const newval = formatPrice(item[key], min, max, true); + console.log(newval); + if (typeof newval !== "number") { + item[key] = newval.value; this.$message({ offset, message: `请输入${min}到${max}范围内的数字`, - type: "error" + type: "error", }); } else { - item[key] = newval + item[key] = newval; } - }) + }); }, deleteEvent(d) { - let index = this.imgList.findIndex(ele => ele.url == d.url) + let index = this.imgList.findIndex((ele) => ele.url == d.url); this.imgList.splice(index, 1); }, // 删除分组商品 @@ -623,7 +941,7 @@ export default { } }, selectUnitt(e) { - this.form.unitName = this.units.find(item => item.id == e).name; + this.form.unitName = this.units.find((item) => item.id == e).name; }, // 批量修改规格 batchNumber(key) { @@ -632,13 +950,13 @@ export default { }, // 确认批量修改规格 batchNumberFormConfirm() { - console.log(this.form.skuList) + console.log(this.form.skuList); this.form.skuList.map((item, index) => { //解决vue2列表数据更新视图未变化问题 - let newitem = { ...item } + let newitem = { ...item }; newitem[this.batchNumberKey] = this.batchNumberForm.batchNumber; - this.$set(this.form.skuList, index, { ...newitem }) + this.$set(this.form.skuList, index, { ...newitem }); // item[this.batchNumberKey] = this.batchNumberForm.batchNumber; }); this.showBatchModal = false; @@ -651,7 +969,7 @@ export default { // 赋值商品类型 this.changeTypeEnum( - this.shopTypes.findIndex(item => item.typeEnum == res.typeEnum) + this.shopTypes.findIndex((item) => item.typeEnum == res.typeEnum) ); this.specTableHeaders = JSON.parse(res.specTableHeaders); this.selectSpec = JSON.parse(res.selectSpec); @@ -661,9 +979,9 @@ export default { // url: item // }; // }); - this.imgList = res.images.map(item => { + this.imgList = res.images.map((item) => { return { - url: item + url: item, }; }); this.form = res; @@ -693,8 +1011,8 @@ export default { // 提交 submitHandle() { - console.log(this.form.skuList) - const hasUndefined = this.form.skuList.some(obj => { + console.log(this.form.skuList); + const hasUndefined = this.form.skuList.some((obj) => { for (const key in obj) { if (obj[key] === undefined) { return true; // 如果找到undefined,立即停止搜索并返回true @@ -705,25 +1023,22 @@ export default { // 停止执行下面的数据 if (hasUndefined) { this.$message({ - message: '请完善规格属性的参数!', - type: 'warning' + message: "请完善规格属性的参数!", + type: "warning", }); return false; } - - this.imgList.forEach(ele => { - arr.push(ele.url) - }) - let arr = [] - this.imgList.forEach(ele => { - arr.push(ele.url) - }) - this.$refs.formRef.validate(async faild => { + let arr = []; + this.imgList.forEach((ele) => { + arr.push(ele.url); + }); + this.$refs.formRef.validate(async (faild) => { try { if (faild) { this.loading = true; - this.form.images = arr - this.form.lowPrice = this.form.skuList.length && this.form.skuList[0].salePrice; + this.form.images = arr; + this.form.lowPrice = + this.form.skuList.length && this.form.skuList[0].salePrice; this.form.coverImg = this.form.images[0]; this.form.selectSpec = JSON.stringify(this.selectSpec); this.form.specTableHeaders = JSON.stringify(this.specTableHeaders); @@ -736,7 +1051,7 @@ export default { this.$notify({ title: "成功", message: `${this.form.id ? "编辑" : "添加"}成功`, - type: "success" + type: "success", }); this.$router.back(); this.loading = false; @@ -754,7 +1069,7 @@ export default { }, // 分组选择商品 selectShopRes(res) { - let arr = res.map(item => { + let arr = res.map((item) => { item.groupNum = 1; return item; }); @@ -765,7 +1080,7 @@ export default { this.form.groupSnap.push({ title: "", goods: [...arr], - number: 1 + number: 1, }); } @@ -794,7 +1109,6 @@ export default { }, // 删除突破按 uploadRemove(arr) { - this.form.images = arr; }, // 选择规格属性 @@ -811,12 +1125,12 @@ export default { let arr = []; for (let val of item.selectSpecResult) { arr.push({ - [item.name]: val + [item.name]: val, }); } skuSnap.push({ name: item.name, - value: item.selectSpecResult.join(",") + value: item.selectSpecResult.join(","), }); bodys.push(arr); } @@ -829,7 +1143,7 @@ export default { const m = { coverImg: "", - ...this.defaultSku + ...this.defaultSku, }; for (let item of arr) { @@ -846,7 +1160,7 @@ export default { specSnap: specSnap.join(","), ...m, ...obj, - barCode: `${dayjs().valueOf()}${RandomNumBoth(1, 9999)}` + barCode: `${dayjs().valueOf()}${RandomNumBoth(1, 9999)}`, }); } else { let specSnap = []; @@ -857,14 +1171,14 @@ export default { specSnap: specSnap.join(","), ...m, ...item, - barCode: `${dayjs().valueOf()}${RandomNumBoth(1, 9999)}` + barCode: `${dayjs().valueOf()}${RandomNumBoth(1, 9999)}`, }); } } if (this.originSkuList.length) { - this.form.skuList = newarr.map(item => { - this.originSkuList.map(val => { + this.form.skuList = newarr.map((item) => { + this.originSkuList.map((val) => { if (item.specSnap == val.specSnap) { for (let key in val) { item[key] = val[key]; @@ -892,8 +1206,8 @@ export default { if (arr.length < 2) return arr[0] || []; return [].reduce.call(arr, (col, set) => { let res = []; - col.forEach(c => { - set.forEach(s => { + col.forEach((c) => { + set.forEach((s) => { let t = [].concat(Array.isArray(c) ? c : [c]); t.push(s); res.push(t); @@ -911,7 +1225,7 @@ export default { i++; headers.push({ label: item.name, - value: item.name + value: item.name, }); } } @@ -922,7 +1236,7 @@ export default { selectSpecHandle(e) { this.isEditor = false; const selectSpec = JSON.parse( - JSON.stringify(this.specList.find(item => item.id == e).specList) + JSON.stringify(this.specList.find((item) => item.id == e).specList) ); for (let item in selectSpec) { selectSpec[item].selectSpecResult = []; @@ -937,10 +1251,10 @@ export default { shopId: localStorage.getItem("shopId"), sort: "id", page: 0, - size: 100 + size: 100, }); this.specList = res.content; - } catch (error) { } + } catch (error) {} }, // 获取单位 async tbShopUnit() { @@ -949,10 +1263,10 @@ export default { shopId: localStorage.getItem("shopId"), sort: "id", page: 0, - size: 100 + size: 100, }); this.units = res.content; - } catch (error) { } + } catch (error) {} }, // 商品分类列表 async tbShopCategoryGet() { @@ -961,19 +1275,19 @@ export default { shopId: localStorage.getItem("shopId"), sort: "id", page: 0, - size: 100 + size: 100, }); let categorys = []; for (let item of res.content) { categorys.push({ name: `|----${item.name}`, - id: item.id + id: item.id, }); if (item.childrenList.length) { for (let val of item.childrenList) { categorys.push({ name: `|----|----${val.name}`, - id: val.id + id: val.id, }); } } @@ -982,8 +1296,8 @@ export default { } catch (error) { console.log("商品分类列表", error); } - } - } + }, + }, }; @@ -1068,7 +1382,7 @@ export default { z-index: 10; } -.showStyle:hover>.buttonstyle { +.showStyle:hover > .buttonstyle { display: block; }