提交 8dd826bf authored 作者: huaxinzhu's avatar huaxinzhu

1、添加商品-商品信息页面以及校验

上级 e3d51d21
<template>
<div class="goods-info">
<el-form :model="goodsInfoForm" :rules="rules" ref="goodsInfoForm" label-width="120px" class="demo-goodsInfoForm">
<el-form-item label="商品分类:">
<span class="type-text-span">{{ categoryStr }}</span><el-link class="edit-type-span el-icon-edit" :underline="false">修改所在类目</el-link>
<el-form :model="goodsInfoForm" :rules="goodsInfoRules" ref="goodsInfoForm" label-width="150px" class="demo-goodsInfoForm" size="small">
<el-form-item label="商品分类:" prop="categoryStr">
<el-input style="width:400px;" v-model="goodsInfoForm.categoryStr" :disabled="true"></el-input>
<!-- <span class="type-text-span">{{ goodsInfoForm.categoryStr }}</span>-->
<el-link class="edit-type-span el-icon-edit" type="primary" :underline="false" @click="editType">修改所在类目</el-link>
<span class="tip-span">该商品所在类目须支持七天无理由退货</span>
</el-form-item>
<el-form-item label='商品标题:' prop="goodsName">
<el-input v-model="goodsInfoForm.goodsName" placeholder="请输入商品标题" style="width:400px;"></el-input>
<span class="tip-span ml20">商品名称限制在30字以内,不要填写与商品无关的词</span>
</el-form-item>
<el-form-item label="商品产地:" prop="producingArea">
<el-select v-model="goodsInfoForm.producingArea" placeholder="请选择商品产地" style="width: 400px;">
<el-option
v-for="item in areaOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="商品发货地:" prop="fhd">
<el-select v-model="goodsInfoForm.fhd" placeholder="请选择商品发货地" style="width: 400px;">
<el-option
v-for="item in areaOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="所属品牌:" prop="goodsBrand">
<el-select v-model="goodsInfoForm.goodsBrand" placeholder="请选择商品品牌" style="width: 400px;">
<el-option
v-for="item in brandOptions"
:key="item.id"
:label="item.brand_cn"
:value="item.id"
></el-option>
</el-select>
<el-link class="edit-type-span el-icon-plus" type="primary" :underline="false" @click="toBrand">新增品牌</el-link>
</el-form-item>
<el-form-item label='市场参考价链接:'>
<el-input v-model="goodsInfoForm.lj" placeholder="请输入京东或者淘宝的商品链接" style="width:400px;"></el-input>
</el-form-item>
<el-form-item label='商品编码:'>
<el-input v-model="goodsInfoForm.spbm" placeholder="请输入商品编码(非必须)" style="width:400px;"></el-input>
</el-form-item>
<el-form-item label="商品图片:" prop="sptp">
<span class="tip-span" style="display: block;line-height: 34px;">商品图片最多上传9张,默认第一张为主图 <span>单张图片需限制在2M以内,可上传png、jpg格式,尺寸要求为正方形</span></span>
<el-upload
class="upload-img"
list-type="picture-card"
action="#"
:limit="1"
:on-exceed="limitImg9"
:http-request="uploadGoodsImg"
:on-preview="handlePictureCardPreview"
:on-remove="handleRemove"
:file-list="goodsImgFileList"
><i class="el-icon-plus" />
</el-upload>
<el-dialog :visible.sync="goodsImgVisible">
<img width="100%" :src="goodsImgUrlDialog" alt="">
</el-dialog>
</el-form-item>
</el-form>
<!-- 修改 商品分类目录 -->
<el-dialog
v-loading="loadingSSQ"
class="add-workorder-dialog"
title="修改商品分类"
:visible.sync="editGoodsTypeDialog"
:destroy-on-close="true"
:before-close="cancelType"
width="60%"
center
>
<!-- <p>当前所选类目:<span></span></p>-->
<el-cascader-panel v-show="editGoodsTypeDialog" v-model="SSQGoodsList" :props='goodsprops' @change="SSQGoodsChange" ref="ssqGoodsCascader"></el-cascader-panel>
<span slot="footer" class="dialog-footer">
<el-button @click="cancelType" size="mini">取 消</el-button>
<el-button type="primary" @click="saveType" size="mini">确 定</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import {
GetCategory,
GetFreight,
UploadImg
} from '@/api/module/goods'
import {getBrandsInf} from '@/api/module/brand/brand'
import { GetCategory, GetFreight, UploadImg } from '@/api/module/goods'
import { getAreaList } from '@/api/module/retreat/address';
import { getBrandsInf } from '@/api/module/brand/brand'
export default {
name: 'goods',
props: {
......@@ -32,56 +119,49 @@
}
};
return {
categoryStr: '',
/*------------------------------*/
//loading: false,
// categoryStr: '',
goodsInfoDataClone: {},
areaOptions: [], // 地址 省
brandOptions: [], // 商品品牌
goodsInfoForm: {
outGoodsId: '',
value: [],
goodsId: 0,
categoryStr: '', // 商品分类 地址拼接
categoryList: [],
goodsName: '',
scPrice: '',
price: "", //市场价 单位分
goodsNowStock: "",
producingArea: '',
weight: '',
unit: '', //单位
goodsBrand: '', //品牌
resource: '1',
categoryId: 0,
freightId: 310, //运费模板ID
wlPrice: '',
pywlPrice: '',
jsPrice: '', //协议价
Delayompensate: "",
aftersaleTime: '7',
mark: '',
serviceagsTags: [],
description: ''
producingArea: [], // 产地
fhd: [], // 发货地
goodsBrand: [], // 品牌
sptp: '' // 商品图片
},
rules: {
goodsInfoRules: {
categoryStr: [{required: true, message: '商品分类不能为空', trigger: 'blur'},],
goodsName: [
{required: true, message: '请输入商品名称', trigger: 'blur'},
{min: 3, max: 50, message: '长度在 3 到 50 个字符', trigger: 'blur'}
{min: 3, max: 30, message: '商品标题限制在30字以内', trigger: 'blur'}
],
categoryId: [{required: true, message: '请选择商品分类', validator: categoryIdCheck}],
price: [{required: true, message: '请填写指导售价', trigger: 'blur'}],
jsPrice: [{required: true, message: '请填写结算售价', trigger: 'blur'}],
scPrice: [{required: true, message: '请填写市场原价', trigger: 'blur'}],
goodsNowStock: [
{required: true, message: '商品库存不能为空', trigger: 'blur'},
{type: 'number', message: '商品库存要填写数字'},
],
unit: [{required: true, message: '商品单位不能为空', trigger: 'blur'}],
goodsBrand: [{required: true, message: '商品品牌不能为空', trigger: 'change'}]
producingArea:[{required: true, message: '请选择商品产地', trigger: 'change'}],
fhd: [{required: true, message: '请选择商品发货地', trigger: 'change'}],
goodsBrand: [{required: true, message: '请选择商品品牌', trigger: 'change'}],
sptp: [{required: true, message: '请选择商品分类', validator: categoryIdCheck}]
},
// 运费模板列表
freightList: [],
options1: [],
goodsImgFileList: [], // 商品图片地址 集合list
goodsImgVisible: false, // 图片能否预览
goodsImgUrlDialog: '',
/* 修改 商品分类 */
loadingSSQ: false,
editGoodsTypeDialog: false,
SSQGoodsList: [], // 省市区 子组件goods的
goodsprops: {
expandTrigger: 'click',
lazy: true,
lazyLoad: this.lazyLoad,
value: "id",
label: 'name',
leaf: 'leaf'
},
}
} // return end
},
components: {},
watch: {
......@@ -93,198 +173,145 @@
// },
},
created() {
// 深拷贝一份最开始的数据,为初始化准备
this.goodsInfoDataClone = this.deepClone(this.goodsinfodata);
this.goodsInfoForm = this.goodsinfodata
// console.log("父组件传过来的",this.goodsinfodata)
// console.log("1111",this.goodsInfoForm)
// 获取 省
this.getArea();
// 获取 商品品牌
this.getBrands();
},
mounted() {
this.getCategory();
this.getFreight();
this.getBrands();
// this.getCategory();
// this.getFreight();
// this.getBrands();
},
methods: {
fileChange(e){
const list = this.$refs.file.files;
console.log(list)
this.indexall = list.length
this.uplonds()
},
uplonds(){
this.getBase64(this.$refs.file.files[this.index]).then((res) => {
let result = res.split(",");
this.Base64img = result[1];
let data = {"image": this.Base64img}
this.quillUpdateImg = true;
UploadImg(data).then(res => {
if (res && res.data.code == 1) {
this.index++
this.goodsInfoFormdialogImageUrl.push({'url': res.data.data.imageUrl});
this.$message({ message:'上传成功',type:'success'});
// 获取富文本组件实例
let quill = this.$refs.myTextEditor.quill;
let length = quill.getSelection().index;
// 插入图片 res.data.url为服务器返回的图片地址
quill.insertEmbed(length, 'image', res.data.data.imageUrl)
// 调整光标到最后
quill.setSelection(length + 1)
if(this.index<this.indexall){
this.uplonds()
}else{
this.index = 0
this.quillUpdateImg = false;
}
// 获取 省
getArea() {
let limboNode = {
pid: 0
};
getAreaList(limboNode).then( res=> {
if(res.data) {
this.areaOptions = res.data;
}else {
this.$message({ message:'上传失败,请重新上传',type:'error'});
this.quillUpdateImg = false;
this.areaOptions = [];
}
})
});
},
/*************************/
// 上传图片前
beforeUploadEdit(res, file) {
// 显示loading动画
this.quillUpdateImg = true
},
// 上传图片成功
uploadSectionFile(param, file, fileList) {
this.getBase64(param.file).then((res) => {
let result = res.split(",");
this.Base64img = result[1];
let data = {"image": this.Base64img}
this.quillUpdateImg = true;
UploadImg(data).then(res => {
if (res && res.data.code == 1) {
this.goodsInfoFormdialogImageUrl.push({'url': res.data.data.imageUrl});
this.$message({ message:'上传成功',type:'success'});
// 获取富文本组件实例
let quill = this.$refs.myTextEditor.quill;
let length = quill.getSelection().index;
// 插入图片 res.data.url为服务器返回的图片地址
quill.insertEmbed(length, 'image', res.data.data.imageUrl)
// 调整光标到最后
quill.setSelection(length + 1)
// 获取 商品品牌
getBrands() {
getBrandsInf().then( res => {
if(res.data) {
this.brandOptions = res.data.data;
}else {
this.$message({ message:'上传失败,请重新上传',type:'error'});
this.brandOptions = [];
}
this.quillUpdateImg = false;
})
});
/*-----*/
},
// 图片转换为 base64
getBase64(file) {
return new Promise(function (resolve, reject) {
let reader = new FileReader();
let imgResult = "";
reader.readAsDataURL(file);
reader.onload = function () {
imgResult = reader.result;
};
reader.onerror = function (error) {
reject(error);
};
reader.onloadend = function () {
resolve(imgResult);
};
});
/* 修改 商品分类 类目 */
editType() {
this.SSQGoodsList = [];
this.editGoodsTypeDialog = true;
this.SSQGoodsList = this.goodsInfoForm.categoryList
console.log(222,this.SSQGoodsList);
},
/*************************/
// 服务标签 中,7天退换和不可退换只能2选一
serviceSingleChange(id) {
let index4 = this.serviceagsTags.indexOf(4);
let index3 = this.serviceagsTags.indexOf(3);
if(id == 3) {
if( index4 > -1) {
this.serviceagsTags.splice(index4,1)
}
lazyLoad(node, resolve) {
this.getSSQArea(node, resolve);
},
getSSQArea(node, resolve) {
const level = node.level;
let limboNode = {};
if(level === 0) {
//debugger
limboNode = {pid: 0}
}
if(id == 4) {
if( index3 > -1) {
this.serviceagsTags.splice(index3,1)
if(level === 1) {
//debugger
limboNode = { pid: node.value };
}
if(level === 2) {
limboNode = { pid: node.value };
}
},
// 运费模板类型,change事件
freightIdTypeChange(val) {
// 0 单独运费 1 是运费模板
if(val === '1') {
if(this.goodsInfoForm.freightId == 0) {
this.goodsInfoForm.freightId = "全国包邮通用模板";
//this.loadingSSQ = true;
getAreaList(limboNode).then(res => {
let result = {};
if (level === 0) {
result = res.data
result.forEach(item => {
item.value = item.id;
item.label = item.name;
item.children=[];
item.leaf = 0; // 可以控制 是否有下级 值为true都不行,必须等于0
})
}
if (level === 1) {
result = res.data
result.forEach(item => {
item.value = item.id;
item.label = item.name
item.children=[];
//这句代码表示当点击最后一级的时候 label后面不会转圈圈 并把相关值赋值到选择器上
item.leaf = 0
})
}
},
// 获取品牌信息
getBrands() {
getBrandsInf().then(res => {
if (res.data.data) {
this.brandOtions = res.data.data;
if (level === 2) {
result = res.data
result.forEach(item => {
item.value = item.id;
item.label = item.name
item.leaf = 1;
})
}
resolve(result)
//this.loadingSSQ = false;
});
},
// 获取 商品分类 信息
getCategory() {
GetCategory({}).then(response => {
this.options1 = response.data.data;
});
SSQGoodsChange(value) {
//this.SSQGoodsList = value;
},
// 运费模板
getFreight() {
GetFreight(this.queryParams).then(response => {
this.freightList = response.data
});
// 确认 修改 商品分类
saveType() {
},
handleChange(value) {
this.goodsInfoForm.categoryId = value[value.length - 1]
// 取消 修改 商品分类
cancelType() {
this.editGoodsTypeDialog = false;
},
setTreeData(arr) {
// 删除所有 children,以防止多次调用
arr.forEach(function (item) {
delete item.children;
});
let map = {}; // 构建map
arr.forEach(i => {
map[i.third_id] = i; // 构建以third_id为键 当前数据为值
});
let treeData = [];
arr.forEach(child => {
const mapItem = map[child.parent_id]; // 判断当前数据的parent_id是否存在map中
if (mapItem) { // 存在则表示当前数据不是最顶层数据
// 注意: 这里的map中的数据是引用了arr的它的指向还是arr,当mapItem改变时arr也会改变,踩坑点
(mapItem.children || (mapItem.children = [])).push(child); // 这里判断mapItem中是否存在children, 存在则插入当前数据, 不存在则赋值children为[]然后再插入当前数据
} else { // 不存在则是组顶层数据
treeData.push(child);
// 上传 商品图片,限制 9 张
limitImg9() {
this.$message({ message: '最多上传9张图片', type: 'warning' })
},
// 上传 商品图片
uploadGoodsImg(param) {
this.getBase64(param.file).then( res => {
let result = res.split(",");
this.Base64img = result[1];
let data = {"image":this.Base64img};
//console.log(213,data);
UploadImg(data).then( res=> {
console.log(217,res);
let urlObj = {'url': ''};
if(res.data) {
urlObj.url = res.data.data.imageUrl;
this.goodsImgFileList.push(urlObj);
this.$message({type:'success',message:'图片上传成功'});
// 只清除一次,不浪费哦
if(this.goodsImgFileList.length < 1) {
this.$refs.goodsInfoForm.clearValidate('sptp');
}
}
});
return treeData;
},
onEditorChange({editor, html, text}) {
this.content = html;
//console.log(315,this.content);
},
// 商品品牌 向后台传入 name
goodsBrandChange(indexId) {
let obj = {};
obj = this.brandOtions.find((item)=>{//这里的userList就是上面遍历的数据源
return item.id === indexId;//筛选出匹配数据
});
this.goodsInfoForm.goodsBrand = obj.brand_cn;
},
// 维护品牌
toBrand() {
this.$router.push({path: '/system/shop/brand'});
},
resetGoodsInfForm(formName) {
this.$refs[formName].resetFields();
// 详情描述,重置
this.content = '';
// 服务标签
this.serviceagsTags = [];
//console.log("重置后的数据:",this.goodsInfoForm);
},
// 商品信息 子组件 form表单校验
// 商品信息 子组件 form表单校验, 在父组件中被调用
validateGoodsInfForm () {
let flag = null
this.$refs['goodsInfoForm'].validate(valid => {
......@@ -296,23 +323,78 @@
})
return flag
},
selectTm(indexId) {
// 商品图片 预览
handlePictureCardPreview(file) {
this.goodsImgUrlDialog = file.url;
this.goodsImgVisible = true;
},
// 删除 商品图片
handleRemove(file) {
for (let i = 0; i < this.goodsImgFileList.length; i++) {
if (file.uid === this.goodsImgFileList[i].uid) {
this.goodsImgFileList.splice(i, 1)
}
}
if(this.goodsImgFileList.length === 0) {
this.$refs.goodsInfoForm.validateField('sptp')
}else {
this.$refs.goodsInfoForm.clearValidate('sptp');
}
},
// 维护品牌
toBrand() {
this.$router.push({path: '/system/shop/brand'});
},
}
// 通用 方法
// 图片转换为 base64
getBase64(file) {
return new Promise(function (resolve, reject) {
let reader = new FileReader();
let imgResult = "";
reader.readAsDataURL(file);
reader.onload = function () {
imgResult = reader.result;
};
reader.onerror = function (error) {
reject(error);
};
reader.onloadend = function () {
resolve(imgResult);
};
});
},
} // methods end
}
</script>
<style scoped>
ul {
padding: 0;
}
.goods-info {
padding: 15px 0px;
margin-top: 18px;
}
.type-text-span {
display: inline-block;
width: 300px;
width: 400px;
/*margin: 0 20px 0;*/
}
.edit-type-span {
display: inline-block;
cursor: pointer;
margin: 0 20px;
}
/* 一般提示性文字 */
.tip-span {
color: #909399;
font-size: 12px;
}
/deep/.el-form-item {
margin-bottom: 20px;
}
</style>
......@@ -10,15 +10,15 @@
<p class="goods-type-tip">为商品设置正确的类目,能让商品快速的被搜索到</p>
</div>
<div class="goods-type-options" v-loading="loading">
<el-cascader-panel v-model="SSQList" :props='props' @change="SSQChange" ref="ssqCascader" @blur="handleAddressFun"></el-cascader-panel>
<el-cascader-panel v-model="SSQList" :props='props' @change="SSQChange" ref="ssqCascader"></el-cascader-panel>
</div>
<el-button type="primary" class="next-step" :disabled="isNextStep" @click="nextStep">下一步</el-button>
</div>
</el-card>
<!-- 选择商品类目 end -->
<!-- 添加商品 start -->
<el-card class="box-card good-details-body" v-show="isShowGoodsDetails">
<div class="floor-nav" id="floorNavList" :class="{'is-fixed': isFixed}">
<el-card class="box-card good-details-body" v-if="isShowGoodsDetails">
<div class="floor-nav" id="floorNavList">
<ul class="nav-list">
<li class="nav-list-item" :class="{'floor-item-active': isFIActive === index}" v-for="(item, index) in floorNav" :key="item.id" @click="setFloorNavMountClick(index)">{{ item.name }}</li>
</ul>
......@@ -27,7 +27,7 @@
<div class="floor-item">
<div class="floor-item-box">
<p class="card-header-title floor-item-box-title"><span class="blue-block-goods blue-block-goods-title"></span>商品信息</p>
<Goodsinfomation ref="GoodsInfo" :goodsinfodata='goodsinfodata'/>
<Goodsinfomation ref="goodsInfo" :goodsinfodata='goodsinfodata'/>
</div>
</div>
......@@ -53,7 +53,7 @@
</div>
</div>
<div class="submit-cont">
<el-button type="primary" style="padding: 10px 30px;">提 交</el-button>
<el-button type="primary" style="padding: 10px 30px;" @click="save">提 交</el-button>
</div>
</el-card>
<!-- 添加商品 end -->
......@@ -79,12 +79,10 @@
leaf: 'leaf'
},
isNextStep: true,
isFixed: false,
scrollHeight: 0,
isShowGoodsDetails: false,
isFIActive: 0,
/**/
floorNav: [ // 自定义左侧楼层数
floorNav: [
{ id: 1, name: '商品信息' },
{ id: 2, name: '商品规格' },
{ id: 3, name: '商品售价' },
......@@ -92,7 +90,10 @@
{ id: 5, name: '售后及服务' },
],
/* 商品信息 */
goodsinfodata: {}
goodsinfodata: {
categoryList: [],
categoryStr: ''
}
}
},
components: {
......@@ -177,22 +178,20 @@
this.loading = false;
});
},
// handleAddressFun: function(e,form,this.ssqStr){
// // thsAreaCode = this.form.areaCode // 注意1:获取value值
// thsAreaCode = this.$refs['ssqCascader'].currentLabels //注意2: 获取label值
// console.log(thsAreaCode) // 注意3: 最终结果是个一维数组对象
//
// },
// 添加商品后,下一步 操作
nextStep() {
// 注意数据格式 [1,2,3] 数组,且里面是数字类型
// let a1 = []
// a1.push(this.SSQList[0]);
//let fuck1 = this.$refs['ssqCascader'].getCheckedNodes(this.SSQList)
// console.log(111,this.SSQList);
//console.log(222,fuck1);
let ssqLabelList = this.$refs['ssqCascader'].getCheckedNodes()[0].pathLabels;
this.goodsinfodata.categoryList = this.SSQList;
this.goodsinfodata.categoryStr = ssqLabelList[0] + '/' + ssqLabelList[1] + '/' + ssqLabelList[2];
this.isShowGoodsDetails = true;
},
//
save() {
let isGoodInfMsg = this.$refs['goodsInfo'].validateGoodsInfForm();
},
/* 添加商品详细 */
/* 设置楼层导航事件驱动方法* @params Number index 楼层下标 */
setFloorNavMountClick(index) {
......@@ -202,8 +201,8 @@
floor_offsetTop = floor_item[index].offsetTop - floor_item[0].offsetTop,
window_scrollTop = this.$refs.scrollview.scrollTop,
timer = {
step: 50,
times: 15,
step: 45,
times: 18,
FLOOR_OFFSETTOP: floor_offsetTop
}
if (window_scrollTop > floor_offsetTop) {
......@@ -214,7 +213,6 @@
_this.setFloorScrollArrowDown(timer)
}
},
/* 设置楼层向上滚动* @params Object timer 定时器配置 */
setFloorScrollArrowUp(timer) {
//debugger
......
......@@ -793,7 +793,9 @@
// 订单导出
handleExport(row) {
const rowIds = this.ids;
let query = {page: 1, limit: 100}
//console.log(777,rowIds);
let query = {page: 1, limit: 100};
// return
exportOrder(query).then(res => {
if(res.code === 1) {
const link = document.createElement('a');
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论