You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
263 lines
7.5 KiB
263 lines
7.5 KiB
<!-- 底部菜单--库存--新增商品 -->
|
|
<template>
|
|
<view>
|
|
<view class="formBox">
|
|
<uni-forms ref="form" :modelValue="formData" :rules="rules" labelWidth="85px">
|
|
<uni-forms-item label="商品名称" name="productName" required>
|
|
<uni-easyinput type="text" v-model="formData.productName" placeholder="请输入商品名称" trim="all" />
|
|
</uni-forms-item>
|
|
<uni-forms-item label="商品图片" name="productPicture">
|
|
<view v-if="formData.productPicture !=''">
|
|
<img :src="formData.productPicture" alt="" class="upload-img">
|
|
</view>
|
|
<u-upload :fileList="formData.productPicture" @afterRead="afterRead" @delete="deletePic" name="1" multiple
|
|
:maxCount="1"></u-upload>
|
|
</uni-forms-item>
|
|
<uni-forms-item label="货号" name="productSn" required>
|
|
<uni-easyinput type="text" v-model="formData.productSn" placeholder="请输入货号" trim="all" />
|
|
</uni-forms-item>
|
|
<uni-forms-item label="批发价" name="wholesalePrice" required>
|
|
<uni-easyinput type="digit" v-model="formData.wholesalePrice" placeholder="请输入批发价" trim="all" />
|
|
</uni-forms-item>
|
|
<uni-forms-item label="市场价" name="price" required>
|
|
<uni-easyinput type="digit" v-model="formData.price" placeholder="请输入零售价" trim="all" />
|
|
</uni-forms-item>
|
|
<uni-forms-item label="尾货预警" name="salesWeek" required>
|
|
<!-- <uni-easyinput type="digit" v-model="formData.salesWeek" placeholder="请输入零售价" trim="all" /> -->
|
|
<uni-datetime-picker type="date" :clear-icon="false" v-model="formData.salesWeek" />
|
|
</uni-forms-item>
|
|
<uni-forms-item label="库存预警" name="tailWarn" required>
|
|
<uni-easyinput type="digit" v-model="formData.tailWarn" placeholder="请设置库存预警最低件数" trim="all" />
|
|
</uni-forms-item>
|
|
<uni-forms-item label="分类" name="categoryId" required v-if="dataList == ''">
|
|
<uni-data-select class="uni-data-select" :localdata="categoryList" v-model="formData.categoryId"
|
|
placeholder="请选择分类" @change="categoryChange"></uni-data-select>
|
|
</uni-forms-item>
|
|
<uni-forms-item label="货品简介" name="productIntro">
|
|
<uni-easyinput type="textarea" autoHeight v-model="formData.productIntro" placeholder="请输入货品简介"
|
|
trim="all" />
|
|
</uni-forms-item>
|
|
</uni-forms>
|
|
|
|
<u-button type="primary" @tap.stop="submit()">保存</u-button>
|
|
|
|
</view>
|
|
<!-- <u-modal v-model="show" :content="content"></u-modal> -->
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
fileList1: [],
|
|
formData: {
|
|
productName: '',
|
|
price: '',
|
|
productSn: '',
|
|
wholesalePrice: '',
|
|
productPicture: [],
|
|
productIntro: '',
|
|
categoryId: '',
|
|
salesWeek: '',
|
|
tailWarn: ''
|
|
},
|
|
categoryList: [],
|
|
productId:'',
|
|
arrtList: [],
|
|
arrtChange: [],
|
|
dataList:[],
|
|
rules: {
|
|
categoryId: {
|
|
rules: [{
|
|
required: true,
|
|
errorMessage: '请选择商品分类',
|
|
}, ],
|
|
},
|
|
price: {
|
|
rules: [{
|
|
required: true,
|
|
errorMessage: '请填写市场价',
|
|
}, ],
|
|
},
|
|
wholesalePrice: {
|
|
rules: [{
|
|
required: true,
|
|
errorMessage: '请填写批发价',
|
|
}, ],
|
|
},
|
|
productSn: {
|
|
rules: [{
|
|
required: true,
|
|
errorMessage: '请填写货号',
|
|
}, ],
|
|
},
|
|
productName: {
|
|
rules: [{
|
|
required: true,
|
|
errorMessage: '请填写商品名称',
|
|
}, ],
|
|
},
|
|
tailWarn: {
|
|
rules: [{
|
|
required: true,
|
|
errorMessage: '请填写库存预警天数',
|
|
}, ],
|
|
},
|
|
salesWeek: {
|
|
rules: [{
|
|
required: true,
|
|
errorMessage: '请选择尾货预警天数',
|
|
}, ],
|
|
}
|
|
}
|
|
}
|
|
},
|
|
onLoad(option) {
|
|
if(option.dataList){
|
|
this.dataList = JSON.parse(option.dataList)
|
|
this.formData.productName = this.dataList.productName
|
|
this.formData.price = this.dataList.price
|
|
this.formData.productSn = this.dataList.productSn
|
|
this.formData.wholesalePrice = this.dataList.wholesalePrice
|
|
this.formData.productPicture = this.dataList.productPicture
|
|
this.formData.productIntro = this.dataList.productIntro
|
|
this.formData.categoryId = this.dataList.categoryId
|
|
this.formData.salesWeek = this.dataList.salesWeek
|
|
this.formData.tailWarn = this.dataList.tailWarn
|
|
}
|
|
this.tui.request("/app/productCategory/list", "get", {
|
|
// shopId: 1,
|
|
}, false, true).then((res) => {
|
|
if (res.code == 200) {
|
|
this.categoryList = res.result.map(item => {
|
|
return {
|
|
value: item.id,
|
|
text: item.categoryName
|
|
}
|
|
})
|
|
} else {
|
|
this.tui.toast(res.message)
|
|
}
|
|
})
|
|
},
|
|
methods: {
|
|
// 删除图片
|
|
deletePic(event) {
|
|
this[`fileList${event.name}`].splice(event.index, 1)
|
|
},
|
|
// 新增图片
|
|
async afterRead(event) {
|
|
|
|
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
|
|
let lists = [].concat(event.file)
|
|
if (this.formData.productPicture == undefined) this.formData.productPicture = [];
|
|
let fileListLen = this[`fileList${event.name}`].length
|
|
|
|
lists.map((item) => {
|
|
this[`fileList${event.name}`].push({
|
|
...item,
|
|
status: 'uploading',
|
|
message: '上传中'
|
|
})
|
|
})
|
|
|
|
for (let i = 0; i < lists.length; i++) {
|
|
const result = await this.uploadFilePromise(lists[i].url)
|
|
let item = this[`fileList${event.name}`][fileListLen]
|
|
this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
|
|
status: 'success',
|
|
message: '',
|
|
url: result
|
|
}))
|
|
fileListLen++
|
|
}
|
|
},
|
|
uploadFilePromise(url) {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
let a = uni.uploadFile({
|
|
url: 'https://storage.xenjoyou.com/hiver/upload/file',
|
|
filePath: url,
|
|
name: 'file',
|
|
header: {
|
|
"content-type": "multipart/form-data",
|
|
'accessToken': this.tui.getToken()
|
|
},
|
|
formData: {},
|
|
success: (uploadFileRes) => {
|
|
|
|
let path = JSON.parse(uploadFileRes.data)
|
|
//后端返回的地址,存入图片地址
|
|
this.formData.productPicture = path.result
|
|
}
|
|
});
|
|
})
|
|
},
|
|
categoryChange(e) {
|
|
|
|
},
|
|
// 触发提交表单
|
|
submit() {
|
|
let that = this;
|
|
let url = ''
|
|
this.$refs.form.validate().then(res => {
|
|
if(that.dataList !=''){
|
|
url = '/app/product/edit'
|
|
res.id = that.dataList.id
|
|
}else{
|
|
url = '/app/product/save'
|
|
}
|
|
that.tui.request(url, "post", res, false, false).then((res1) => {
|
|
if (res1.code == 200) {
|
|
uni.navigateBack({
|
|
delta: 2
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
title: "添加失败",
|
|
icon: 'none'
|
|
})
|
|
}
|
|
})
|
|
}).catch(err => {
|
|
|
|
})
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
.formBox {
|
|
margin: 20rpx;
|
|
padding: 20rpx 26rpx;
|
|
border-radius: 14rpx;
|
|
box-shadow: 0px 1px 10px 2px #e2e2e2;
|
|
background-color: #fff;
|
|
|
|
.uni-data-select {
|
|
width: 100%;
|
|
}
|
|
|
|
.attrs {
|
|
text {
|
|
display: inline-block;
|
|
border: 1px solid $u-primary;
|
|
padding: 7px 20rpx;
|
|
margin: 20rpx;
|
|
background-color: #fff;
|
|
color: $u-primary;
|
|
}
|
|
|
|
.checkedText {
|
|
background-color: $u-primary;
|
|
color: #fff;
|
|
}
|
|
}
|
|
}
|
|
.upload-img{
|
|
width: 160rpx;
|
|
height: 160rpx;
|
|
}
|
|
</style>
|