|
@@ -21,7 +21,7 @@
|
|
|
<u-form-item label="商品描述" prop="content" required borderBottom ref="item1">
|
|
|
<u--input v-model="form.content" placeholder="请输入" border="none"></u--input>
|
|
|
</u-form-item>
|
|
|
- <u-form-item label="商品图片" prop="" required borderBottom ref="item1">
|
|
|
+ <u-form-item label="商品图片" prop="goodsFiles" required borderBottom ref="item1">
|
|
|
<zj-upload key="cp" @getFiles="getFiles" :fileList="fileList" :count="9" />
|
|
|
</u-form-item>
|
|
|
<u-form-item style="" labelPosition="left" required label="商品分类" prop="categoryId" borderBottom ref="item1">
|
|
@@ -160,6 +160,7 @@ export default {
|
|
|
content: '',
|
|
|
categoryName: '',
|
|
|
categoryId: '',
|
|
|
+ goodsFiles:[],
|
|
|
lng: '',
|
|
|
lat: '',
|
|
|
address: '',
|
|
@@ -190,6 +191,19 @@ export default {
|
|
|
message: '必传',
|
|
|
trigger: ['change', 'blur']
|
|
|
}],
|
|
|
+ goodsFiles: [{
|
|
|
+ // 自定义验证函数,见上说明
|
|
|
+ validator: (rule, value, callback) => {
|
|
|
+ // 上面有说,返回true表示校验通过,返回false表示不通过
|
|
|
+ if(value.length){
|
|
|
+ return true;
|
|
|
+ }else{
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ message: '必传',
|
|
|
+ trigger: ['change', 'blur']
|
|
|
+ }],
|
|
|
address: [{
|
|
|
required: true,
|
|
|
message: '必传',
|
|
@@ -230,14 +244,13 @@ export default {
|
|
|
categoryList: [],
|
|
|
dictList: [],
|
|
|
fileList: [],
|
|
|
- fileurl: [],
|
|
|
content: '',
|
|
|
type: '',
|
|
|
goodsId: ''
|
|
|
}
|
|
|
},
|
|
|
onReady() {
|
|
|
- //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
|
|
|
+ // 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
|
|
|
// this.$refs.form.setRules(this.rules)
|
|
|
},
|
|
|
onLoad() {
|
|
@@ -259,7 +272,14 @@ export default {
|
|
|
handler(nl) {
|
|
|
this.$refs.form.clearValidate('address')
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ 'form.goodsFiles': {
|
|
|
+ handler(nl) {
|
|
|
+ if(nl.length){
|
|
|
+ this.$refs.form.clearValidate('goodsFiles')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
},
|
|
|
methods: {
|
|
|
getParams(value){
|
|
@@ -276,12 +296,12 @@ export default {
|
|
|
id: this.goodsId
|
|
|
})
|
|
|
.then(res => {
|
|
|
- console.log(res)
|
|
|
this.form = {
|
|
|
title: res.data.title,
|
|
|
content: res.data.content,
|
|
|
categoryName: res.data.categoryName,
|
|
|
categoryId: res.data.categoryId,
|
|
|
+ goodsFiles:[],
|
|
|
lng: res.data.lng,
|
|
|
lat: res.data.lat,
|
|
|
address: res.data.address,
|
|
@@ -297,9 +317,8 @@ export default {
|
|
|
goodsCreateTime: res.data.goodsCreateTime
|
|
|
}
|
|
|
this.fileList = res.data.goodsFiles.map(v => v.imgUrl)
|
|
|
- this.fileurl = []
|
|
|
res.data.goodsFiles.forEach(v => {
|
|
|
- this.fileurl.push({
|
|
|
+ this.form.goodsFiles.push({
|
|
|
imgUrl: v.imgUrl
|
|
|
})
|
|
|
})
|
|
@@ -317,9 +336,9 @@ export default {
|
|
|
.catch(() => {})
|
|
|
},
|
|
|
getFiles(value) {
|
|
|
- this.fileurl = []
|
|
|
+ this.form.goodsFiles = []
|
|
|
value.forEach(v => {
|
|
|
- this.fileurl.push({
|
|
|
+ this.form.goodsFiles.push({
|
|
|
imgUrl: v
|
|
|
})
|
|
|
})
|
|
@@ -332,10 +351,7 @@ export default {
|
|
|
this.disabled = true
|
|
|
this.form.categoryName =
|
|
|
this.categoryList.find(v => v.categoryId === this.form.categoryId)?.categoryName ?? ''
|
|
|
- let params = {
|
|
|
- ...this.form,
|
|
|
- goodsFiles: this.fileurl
|
|
|
- }
|
|
|
+ let params = this.form
|
|
|
this.$toast('正在发布中,请稍后')
|
|
|
setTimeout(() => {
|
|
|
let path = '/goods/add'
|
|
@@ -355,6 +371,7 @@ export default {
|
|
|
content: '',
|
|
|
categoryName: '',
|
|
|
categoryId: '',
|
|
|
+ goodsFiles:[],
|
|
|
lng: '',
|
|
|
lat: '',
|
|
|
address: '',
|