define({ name: "basic", template: `
基础信息
数字大的排名在前,默认排序方式为创建时间,注意:输入最大数为9位数,只能输入数字
{{firstItem.name}} {{secondItem.name}} {{threeItem.name}} {{optionItem.title}} 添加分类
点击重新上传
建议尺寸: 640 * 640 ,或正方型图片
`, style: ` .goods-image_list { margin-right:20px; } .goods-image_list .upload-boxed { position:relative; } .goods-image_list > div { display:inline-flex; flex-wrap:wrap; column-gap:10px; row-gap:10px; } #basicGoods input::-webkit-outer-spin-button, #basicGoods input::-webkit-inner-spin-button { -webkit-appearance: none; } #basicGoods input[type="number"] { -moz-appearance: textfield; } `, props: { form: { default() { return ; }, }, formKey: { type: String, default: "goods", }, attr_hide:{ default() { return {} } } }, data() { let regular = new RegExp("^[0-9][0-9]*$") let checkoutSort = (rule, value, callback) => { this.sortRegular = true let sort = regular.test(this.form.goods.display_order); if(!sort){ callback(new Error('请输入正整数')); this.sortRegular = false } }; let checkoutTitle = (rule, value, callback) => { this.titleRegular = true if(!this.form.goods.title){ callback(new Error('请输入商品名称')); this.titleRegular = false } }; let checkoutCategory = (rule, value, callback) => { if(!this.attr_hide.hide_category){ let info = true this.categoryList.forEach(item => { item.forEach(el => { if(!el.id){ info = false return } }) }) this.categoryRegular = true if(!info){ callback(new Error('请选择商品分类')); this.categoryRegular = false } }else{ this.categoryRegular = true } }; let checkoutThumb = (rule, value, callback) => { this.thumbRegular = true if(!this.form.goods.thumb){ callback(new Error('请选择商品图片')); this.thumbRegular = false } }; let checkoutVirtualSales = (rule, value, callback) => { let virtualSales = regular.test(this.form.goods.virtual_sales); this.virtualSalesRegular = true if(!virtualSales){ callback(new Error('请输入正整数')); this.virtualSalesRegular = false } }; let checkoutStock = (rule, value, callback) => { let stock = regular.test(this.form.goods.stock); this.stockRegular = true if(!stock){ callback(new Error('请输入正整数')); this.stockRegular = false } }; return { showSelectMaterialPopup: false, formFieldName: "", goodsImagesChangeIndex: null, materialType: "", selNum: "one", select:"open", rules:{ sort:{ validator: checkoutSort}, title:{validator:checkoutTitle}, category:{validator:checkoutCategory}, // goodsSku:{validator:checkoutSku}, thumb:{validator:checkoutThumb}, virtualSales:{validator:checkoutVirtualSales}, stock:{validator:checkoutStock}, }, submitPropertyKeyWhiteList: [], // yesRegular:true, categoryList:[], // 原始值 OriginCategory:[], // 改变后的值 changeCategoryList:[], // 分类值 category_list_box:[], isShow:true, sortRegular:true, titleRegular:true, // skuRegular:true, categoryRegular:true, virtualSalesRegular:true, stockRegular:true, thumbRegular:true, // 提交的数据 threeChildrensIsshow:true, secondChildrensIsshow:true, }; }, mounted() { this.addDefaul() // 设置默认品牌 if(this.form.goods.brand_id === 0){ this.form.goods.brand_id = "" } this.goodsCategoryShow() this.getCategoryValue() }, methods: { // 添加默认值 addDefaul(){ if(JSON.stringify(this.attr_hide) !== '[]'){ if(this.attr_hide.appoint_type){ this.form.goods.type = this.attr_hide.appoint_type } if(this.attr_hide.appoint_need_address){ this.form.goods.need_address = this.attr_hide.appoint_need_address } } if(!this.form.goods.display_order){ this.$set(this.form.goods,"display_order",0) } if(!this.form.goods.category_to_option){ this.$set(this.form.goods,"category_to_option",[{goods_option_id:""}]) } if(!this.form.goods.type){ this.$set(this.form.goods,"type",1) } if(!this.form.goods.need_address){ this.$set(this.form.goods,"need_address",0) } if(!this.form.goods.price){ this.$set(this.form.goods,"price",0) } if(!this.form.goods.market_price){ this.$set(this.form.goods,"market_price",0) } if(!this.form.goods.cost_price){ this.$set(this.form.goods,"cost_price",0) } if(!this.form.goods.weight){ this.$set(this.form.goods,"weight",0) } if(!this.form.goods.volume){ this.$set(this.form.goods,"volume",0) } if(!this.form.goods.reduce_stock_method){ this.$set(this.form.goods,"reduce_stock_method",0) } if(!this.form.goods.withhold_stock){ this.$set(this.form.goods,"withhold_stock",0) } if(!this.form.goods.no_refund){ this.$set(this.form.goods,"no_refund",0) } if(!this.form.goods.cost_price){ this.$set(this.form.goods,"cost_price",0) } if(!this.form.goods.virtual_sales){ this.$set(this.form.goods,"virtual_sales",0) } }, // 商品分类回显 goodsCategoryShow(){ // 判断回显时商品类型是否存在,不存在根据category_level长度添加数据--this.judgeCategoryLevel() // 如果category_level的长度与返回的长度不一致,则不全默认值 if(this.form.goods.category){ this.OriginCategory = JSON.parse(JSON.stringify(this.form.goods.category)) if(this.form.category_level == 3){ this.OriginCategory.forEach(item => { if(item.length === 2){ item.push({ "id": '', "level": 3 }) } }) }else if(this.form.category_level == 2){ this.OriginCategory.forEach(item => { if(item.length === 1){ item.push({ "id": '', "level": 2 }) } }) } }else{ this.judgeCategoryLevel() } if(!this.form.goods.category){ this.isShow = false } if(this.form.goods.category){ if(this.form.goods.category.length){ if(this.form.goods.category[0].length){ for(item of this.form.goods.category){ item.forEach(cateItem => { let id = cateItem.id cateItem.id = cateItem.name cateItem.name = id }) item = item.map(el => ({'id':el.id , 'level':el.level,'name':el.name})) // 判断是否有一级分类 let firstLevel = item.find(threeItem => threeItem.level === 1) if(this.form.category_level * 1 === 1 && !firstLevel){ item.push({'id':'' , 'level':1}) } // 判断是否有二级分类 let secondLevel = item.find(threeItem => threeItem.level === 2) if(this.form.category_level * 1 === 2 && !secondLevel){ item.push({'id':'' , 'level':2}) } // 判断是否有三级分类 let threeLevel = item.find(threeItem => threeItem.level === 3) if(this.form.category_level * 1 === 3 && !threeLevel){ item.push({'id':'' , 'level':3}) } this.categoryList.push(item) this.changeCategoryList = this.categoryList } }else{ this.judgeCategoryLevel() } }else{ this.judgeCategoryLevel() } }else{ this.judgeCategoryLevel() this.changeCategoryList = this.categoryList } }, // 获取分类值 getCategoryValue(){ this.category_list_box = [] this.categoryList.forEach((item,index) => { let filterCategry = [] filterCategry.push({secondCategory:[]}) filterCategry.push({threeCategory:[]}) this.category_list_box.push(filterCategry) }) }, // 判断分类等级 judgeCategoryLevel(){ switch (this.form.category_level * 1){ case 1 : this.categoryList = [[{ "id": '', "level": 1 }]]; this.OriginCategory = this.categoryList break; case 2 : this.categoryList = [[{ "id": '', "level": 1 }, { "id": '', "level": 2 }]]; this.OriginCategory = this.categoryList break; default: this.categoryList = [[{ "id": '', "level": 1 }, { "id": '', "level": 2 }, { "id": '', "level": 3 }]]; this.OriginCategory = this.categoryList break; } }, displaySelectMaterialPopup(fieldName = "thumb", type = 1) { if(fieldName == 'other'){ this.selNum = 'more' }else{ this.selNum = 'one' } this.formFieldName = fieldName; this.showSelectMaterialPopup = !this.showSelectMaterialPopup; this.materialType = String(type); }, selectedMaterial(name, image, imageUrl) { console.log(name,image,imageUrl,"imageUrl*-",this.formFieldName); let originalImageUrl = JSON.parse(JSON.stringify(imageUrl)) if(name == "video"){ this.form.goods.goods_video_link = imageUrl[0].url this.form.goods.goods_video = originalImageUrl[0].attachment } if(name == "video_cover"){ this.form.goods.video_image_link = imageUrl[0].url this.form.goods.video_image = originalImageUrl[0].attachment } if (Array.isArray(imageUrl)) { imageUrl = imageUrl.map((item) => { return item.url; }); } if (this.formFieldName === "other") { if (this.goodsImagesChangeIndex === null) { if(!this.form.goods.thumb_url){ this.$set(this.form.goods,"thumb_url",[]) } for(let item of originalImageUrl){ this.form.goods["thumb_url"].push({ thumb_link:item.url, thumb:item.attachment }); } } else { // this.form.goods["thumb_url"][this.goodsImagesChangeIndex] = imageUrl[0]; this.goodsImagesChangeIndex = null; } } else { this.form.goods[this.formFieldName] = originalImageUrl[0].attachment; if(this.formFieldName == 'thumb') { this.form.goods['thumb_link'] = imageUrl[0] } } }, // 点击图片选中 sureSelectImg(val,id,item){ console.log(val,id,item); // console.log(val,id,item,'点击图片选中'); // if(this.formFieldName == "video_cover"){ // this.form.goods.video_image = item.url // } // if(this.formFieldName == "thumb"){ // this.form.goods[this.formFieldName] = item.url // } }, addCategory() { switch (this.form.category_level * 1){ case 1 : this.categoryList.push([{ "id": '', "level": 1 }]); if(this.isShow){this.OriginCategory.push([{ "id": '', "level": 1 }])} break; case 2 : this.categoryList.push([{ "id": '', "level": 1 }, { "id": '', "level": 2 }]); if(this.isShow){this.OriginCategory.push([{ "id": '', "level": 1 }, { "id": '', "level": 2 }])} break; default: this.categoryList.push([{ "id": '', "level": 1 }, { "id": '', "level": 2 }, { "id": '', "level": 3 }]); if(this.isShow){this.OriginCategory.push([{ "id": '', "level": 1 }, { "id": '', "level": 2 },{ "id": '', "level": 3 }])} break; } this.form.goods.category_to_option.push({'goods_option_id':""}); this.getCategoryValue() }, removeCategory(itemIndex) { this.categoryList.splice(itemIndex, 1); this.category_list_box.splice(itemIndex,1) this.OriginCategory.splice(itemIndex,1) this.form.goods.category_to_option.splice(itemIndex,1); }, validate() { let submitCategoryList = [] this.OriginCategory.forEach(element => { element = element.map(item => { delete item.name }) }) this.OriginCategory.forEach(item =>{ let filterCatrgorys = item.filter((value, index, arr) => { return value.id !== '' }) submitCategoryList.push(filterCatrgorys) }) // 过滤空数组 let filterSubmitCategoryList = [] submitCategoryList.forEach((element,index) => { if(element.length !== 0){ filterSubmitCategoryList.push(element) } }); let obj = { category: filterSubmitCategoryList, status:this.form.goods.status, title:this.form.goods.title, thumb:this.form.goods.thumb, display_order:this.form.goods.display_order } console.log(obj); return obj }, tipValidator(){ if(!this.sortRegular){ this.$message({ message: '请输入排序', type: 'warning' }); return }else if(!this.form.goods.title){ this.$message({ message: '请输入商品名称', type: 'warning' }); return }else if(!this.form.goods.sku){ this.$message({ message: '请填写商品单位', type: 'warning' }); }else if(!this.form.goods.thumb){ this.$message({ message: '请选择商品图片', type: 'warning' }); return }else if(!this.virtualSalesRegular && this.form.goods.virtual_sales !== ''){ this.$message({ message: '请输入第三方销量', type: 'warning' }); return }else if(!this.stockRegular){ this.$message({ message: '请输入库存', type: 'warning' }); return } // if(!this.form.goods.virtual_sales){this.virtualSalesRegular = false } // if(!this.form.goods.stock){this.stockRegular = false } }, // extraDate(){ // return { // 'extra':"额外数据" // } // }, // 监听一级商品分类 btnfirst(value,itemIndex,firstValue){ if(!firstValue){ this.category_list_box[itemIndex].secondCategory = [] this.category_list_box[itemIndex].threeCategory = [] this.categoryList[itemIndex].forEach(item => { item.id = "" }) } this.categoryList[itemIndex].forEach((item,key) => { if(key == 0){ item.id = item.id }else{ item.id = "" } }) // 点击一级分类获取二级分类数据 this.form.category_list.forEach(item => { if(item.id == value){ // this.secondCategory = item.childrens this.category_list_box[itemIndex].secondCategory = item.childrens return } }) this.listenCategory(value,itemIndex,0) }, // 监听二级商品分类 btnChangeSecond(value,itemIndex,secondValue){ let category_list = JSON.parse(JSON.stringify(this.form.category_list)) let secondChildrens = [] if(typeof secondValue.id == "string" && secondValue.id){ this.secondChildrensIsshow = false category_list.forEach((item,index) => { if(item.id == secondValue.name){ secondChildrens.push(...item.childrens) return } }) this.category_list_box[itemIndex].secondCategory = secondChildrens this.secondChildrensIsshow = true } }, btnSecond(value,itemIndex,secondValue){ if(!secondValue){ this.category_list_box[itemIndex].threeCategory = [] } this.categoryList[itemIndex].forEach((item,key) => { if(key === 2){ item.id = '' } }) // 点击二级分类获取三级分类数据 if(this.category_list_box[itemIndex].secondCategory){ this.category_list_box[itemIndex].secondCategory.forEach((item,index) => { if(item.id == value ){ // this.threeCategory = item.childrens this.category_list_box[itemIndex].threeCategory = item.childrens return } }) } this.listenCategory(value,itemIndex,1) }, // 监听三级商品分类 btnChangeThree(value,itemIndex,secondValue,oneValue){ let category_list = JSON.parse(JSON.stringify(this.form.category_list)) let threeChildrens = [] if(typeof secondValue.id == "string" && secondValue.id){ this.threeChildrensIsshow = false category_list.forEach((item,index) => { if(item.id == oneValue.name){ item.childrens.forEach((el,key) => { if(el.id == secondValue.name){ threeChildrens.push(...el.childrens) return } }) return } }) this.category_list_box[itemIndex].threeCategory = threeChildrens this.threeChildrensIsshow = true } }, btnThree(value,itemIndex){ this.listenCategory(value,itemIndex,2) }, listenCategory(value,itemIndex,type){ let info = false this.changeCategoryList[itemIndex].forEach((el,key) => { if(el.id === this.categoryList[itemIndex][key].id){ info = true return } }) if(this.isShow){ if(info){ let categoryBoxList = [] this.OriginCategory[itemIndex].forEach((item,key) => { if(type == 2){ if(key === 2){ item = this.categoryList[itemIndex][key] } }else if(type == 1){ if(key === 2 || key === 1){ item = this.categoryList[itemIndex][key] } }else if(type == 0){ if(key === 2 || key === 1 || key === 0){ item = this.categoryList[itemIndex][key] // item.id = "" } } categoryBoxList.push(item) }) this.OriginCategory[itemIndex] = categoryBoxList }else{ this.OriginCategory[itemIndex] = this.categoryList[itemIndex] } } } }, });