平板端快衣店
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.
 
 
 
 
 

778 lines
20 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" @blur="getSnIsRepeat" placeholder="请输入货号" trim="all" />
</uni-forms-item>
<uni-forms-item label="批发价" name="wholesalePrice">
<!-- <uni-easyinput type="digit" v-model="formData.wholesalePrice" placeholder="请输入批发价" trim="all" /> -->
<input type="digit" class="content-input" v-model="formData.wholesalePrice" @focus="obtainPrice($event,'wholesalePrice')" @blur="changessPrice($event,'wholesalePrice')" placeholder="请输入批发价">
</uni-forms-item>
<uni-forms-item label="分类" name="categoryId" v-if="dataList == ''">
<!-- <uni-data-select class="uni-data-select" :localdata="categoryList" v-model="formData.categoryId"
placeholder="请选择分类" @change="categoryChange(formData.categoryId)"></uni-data-select> -->
<view class="content-list">
<view class="list-val">
<input type="text" placeholder="请选择分类" disabled :value="typeItem.categoryName"
style="border-bottom: 1px solid #fff;text-align: center;"
@tap="goGategoryLow">
<uni-icons type="right" size="16"
style="margin-left: 40rpx;line-height: 70rpx;"></uni-icons>
</view>
</view>
</uni-forms-item>
<uni-forms-item label="添加规格" name="categoryId" v-if="dataList == ''">
<!-- <uni-data-select class="uni-data-select" :localdata="categoryList" v-model="formData.categoryId"
placeholder="请选择分类" @change="categoryChange(formData.categoryId)"></uni-data-select> -->
<view class="content-list">
<view class="list-val">
<input type="text" placeholder="点击选择规格" disabled
style="border-bottom: 1px solid #fff;text-align: center;"
@tap="ejectRuleSelect">
<!-- <uni-icons type="right" size="16"
style="margin-left: 40rpx;line-height: 70rpx;"></uni-icons> -->
</view>
</view>
</uni-forms-item>
<uni-forms-item label="商品条码" name="barcode">
<uni-easyinput type="text" v-model="formData.barcode" placeholder="可以扫码商品条码添加" trim="all" />
<u-icon name="camera" size="36" @tap.stop='scanCodeAdd'></u-icon>
</uni-forms-item>
<uni-forms-item label="市场价" name="price">
<!-- <uni-easyinput type="digit" v-model="formData.price" placeholder="请输入零售价" trim="all" /> -->
<input type="digit" class="content-input" v-model="formData.price" @focus="obtainPrice($event,'price')" @blur="changessPrice($event,'price')" placeholder="请输入零售价">
</uni-forms-item>
<uni-forms-item label="尾货预警" name="salesWeek">
<!-- <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">
<uni-easyinput type="digit" v-model="formData.tailWarn" placeholder="请设置库存预警最低件数" trim="all" />
</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>
<view v-if="type == 'edit'" style="display: flex;">
<button @tap.stop="submit()" style="width: 95%;">保存</button>
</view>
<view v-else>
<button @tap.stop="submit()">保存</button>
</view>
</view>
<!-- 添加分类弹出层 -->
<uni-popup ref="addTypeDialog" background-color="#fff">
<view class="add-popup-content">
<view class="add-popup-title">
<text>添加规格</text>
<uni-icons @tap='close' type="closeempty" color='red' size="16"
style="height:40rpx;line-height: 40rpx;position: absolute !important;bottom:0;right: 30rpx;"></uni-icons>
</view>
<view class="add-popup-container">
<!-- <view>
<text style="color:red;font-size:22rpx;">*您可以点击默认项快捷添加分类,如没有想要的快捷项,可以手动输入</text>
</view> -->
<!-- <input type="text" v-model="typeText" style="width: 100%;border: 1px solid #eee;height: 80rpx;padding-left: 20rpx;margin:20rpx 0;font-size: 25rpx;line-height: 80rpx;"
placeholder="请输入分类名称"> -->
<ul>
<li v-for="(item,index) in defaultList" :key="index">
<view class="title-fur">
<view class="name">{{item.name}}</view>
<u-icon size="20" name="plus" color="#5fd9ee"
@tap="toggle(index) "></u-icon>
</view>
<view class="content-fur">
<view class="content-low" :class="item1.checked?'checked':''" v-for="(item1,index1) in item.list" :key="index1"
@tap.stop="addMultipleType(item,item1.value,index1)">{{item1.value}}</view>
</view>
</li>
</ul>
<view class="add-popup-bottom">
<view class="add-popup-btn" @tap="dialogInputConfirm()">确认</view>
</view>
</view>
</view>
</uni-popup>
<!-- <u-modal v-model="show" :content="content"></u-modal> -->
</view>
</template>
<script>
export default {
data() {
return {
fileList1: [],
formData: {
productName: '',
price: 0,
productSn: '',
wholesalePrice: 0,
productPicture: '',
productIntro: '',
categoryId: '',
salesWeek: '',
tailWarn: '',
barcode:''
},
defaultList:[{
name:'颜色',
list:[{
value:'均色',
checked:false,
},{
value:'白色',
checked:false,
},{
value:'黑色',
checked:false,
},{
value:'浅蓝',
checked:false,
},{
value:'蓝色',
checked:false,
},{
value:'灰色',
checked:false,
},{
value:'咖色',
checked:false,
},{
value:'紫色',
checked:false,
},{
value:'红色',
checked:false,
},{
value:'米色',
checked:false,
}]
},{
name:'尺码',
list:[{
value:'均码',
checked:false,
},{
value:'XS码',
checked:false
},{
value:'S码',
checked:false,
},{
value:'M码',
checked:false,
},{
value:'L码',
checked:false,
},{
value:'XL码',
checked:false,
},{
value:'2XL码',
checked:false,
},{
value:'3XL码',
checked:false,
},{
value:'4XL码',
checked:false,
},{
value:'25码',
checked:false
},{
value:'26码',
checked:false
},{
value:'27码',
checked:false
},{
value:'28码',
checked:false
},{
value:'29码',
checked:false
},{
value:'30码',
checked:false
},{
value:'31码',
checked:false
},{
value:'32码',
checked:false
},{
value:'33码',
checked:false
},{
value:'34码',
checked:false
},{
value:'35码',
checked:false
},{
value:'36码',
checked:false
},{
value:'37码',
checked:false
},{
value:'38码',
checked:false
},{
value:'39码',
checked:false
},{
value:'40码',
checked:false
},{
value:'41码',
checked:false
},{
value:'42码',
checked:false
},{
value:'43码',
checked:false
},{
value:'44码',
checked:false
},{
value:'45码',
checked:false
}]
}],
categoryList: [],
productId:'',
arrtList: [],
typeItem:{},
arrtChange: [],
categoryId:'',
dataList:[],
type:'add',
multipleList:[],
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: '请选择尾货预警天数',
// }, ],
// }
}
}
},
onShow(){
let that = this;
this.typeItem = JSON.parse(JSON.stringify(this.typeItem)) || ''
if(this.typeItem){
this.formData.categoryId = this.typeItem.id
}
},
onLoad(option) {
if(option.dataList){
this.type = 'edit'
this.dataList = JSON.parse(option.dataList)
this.formData.productName = this.dataList.productName
this.formData.barcode = this.dataList.barcode
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.getGategoryList()
},
methods: {
//初始化获取分类列表
getGategoryList() {
this.tui.request("/app/productCategory/list", "get", {
// shopId: 1,
}, false, true).then((res) => {
if (res.code == 200) {
if(res.result.length > 0){
this.typeItem = res.result[0]
this.formData.categoryId = this.typeItem.id
}
} else {
this.tui.toast(res.message)
}
}).catch((res) => {})
},
// 删除图片
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++
}
},
obtainPrice(e,type,num){
console.log("获得焦点")
this.linshiPrice = e.target.value
if(type=='price'){
this.formData.price = ''
}else if(type=='wholesalePrice'){
this.formData.wholesalePrice = ''
}
},
dialogInputConfirm(e) {
let that = this;
if(that.multipleList == ''){
that.multipleList = [{
attributeName:'颜色',
productAttributeValueVoList:[{
checked: true,
value: "均色"
}]
},{
attributeName:'尺码',
productAttributeValueVoList:[{
checked: true,
value: "均码"
}]
}]
}else{
for(let i=0;i<that.multipleList.length;i++){
if(that.multipleList[i].productAttributeValueVoList == ''){
if(that.multipleList[i].attributeName == '颜色'){
that.multipleList[i].productAttributeValueVoList = [{
checked: true,
value: "均色"
}]
}else{
that.multipleList[i].productAttributeValueVoList = [{
checked: true,
value: "均码"
}]
}
}else{
if(that.multipleList.length != 2){
if(that.multipleList[i].attributeName == '颜色'){
let data = {
attributeName:'尺码',
productAttributeValueVoList:[{
checked: true,
value: "均码"
}]
}
that.multipleList.push(data)
}else{
let data = {
attributeName:'颜色',
productAttributeValueVoList:[{
checked: true,
value: "均码"
}]
}
that.multipleList.push(data)
}
}
}
}
}
for(var i=0;i<that.defaultList.length;i++){
for(var m=0;m<that.defaultList[i].list.length;m++){
that.defaultList[i].list[m].checked = false
}
}
console.log('multipleList',that.multipleList)
that.$refs.addTypeDialog.close()
},
changessPrice(e,type) {
if(type == 'price'){
if(this.linshiPrice == e.target.value){
this.formData.price = e.target.value
}else{
if(e.target.value == ''){
this.formData.price = this.linshiPrice
}else{
this.formData.price = e.target.value
}
}
}else{
if(this.linshiPrice == e.target.value){
this.formData.wholesalePrice = e.target.value
}else{
if(e.target.value == ''){
this.formData.wholesalePrice = this.linshiPrice
}else{
this.formData.wholesalePrice = e.target.value
}
}
}
},
uploadFilePromise(url) {
return new Promise((resolve, reject) => {
let a = uni.uploadFile({
url: 'https://dev.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) {
this.categoryId = e
},
//货号是否重复
getSnIsRepeat(){
this.tui.request('/app/product/getByProductSn', "post", {
productSn:this.formData.productSn
}, false, true).then((res1) => {
if (res1.code == 200) {
if(res1.result != ''){
this.tui.toast('当前货号已被商品:“'+res1.result[0].productName+'”占用,请重新输入')
this.formData.productSn = ''
}
}
})
},
ejectRuleSelect(){
this.$refs.addTypeDialog.open('bottom')
},
// 触发提交表单
submit() {
let that = this;
let url = ''
this.$refs.form.validate().then(res => {
if(that.dataList !=''){
url = '/app/product/edit'
this.formData.id = that.dataList.id
}else{
url = '/app/product/save'
this.formData.purchasePrice = 0
}
if(res.productPicture == ''){
res.productPicture = ''
}
that.tui.request(url, "post", this.formData, false, false).then((res1) => {
if (res1.code == 200) {
uni.navigateBack({
delta: 1
})
} else {
uni.showToast({
title: "添加失败",
icon: 'none'
})
}
})
}).catch(err => {
})
},
//跳转分类页
goGategoryLow() {
uni.navigateTo({
url: '/package1/inventory/gategory'
})
},
scanCodeAdd() {
let that = this;
uni.scanCode({
scanType: ['barCode'],
success: (res) => {
that.tui.request('/app/product/getByBarcode', "post", {
barcode:res.result
}, false, true).then((res1) => {
if (res1.code == 200) {
if(res1.result != ''){
that.tui.toast('当前条码已被商品:“'+res1.result[0].productName+'”占用,请重新输入')
}else{
that.formData.barcode = res.result;
}
}
})
},
fail: (res) => {
uni.showToast({
title: '扫描失败',
icon: 'none'
})
}
})
},
//选择多个规格保存
addMultipleType(item,item1,index){
item.list[index].checked = !item.list[index].checked
var list = []
if(this.multipleList == ''){
list.push(item.list[index])
var data = {
attributeName:item.name,
productAttributeValueVoList: list
}
this.multipleList.push(data)
}else{
for(var i=0;i<this.multipleList.length;i++){
if(this.multipleList[i].attributeName == item.name){ //同种分类
for(var m=0;m<this.multipleList[i].productAttributeValueVoList.length;m++){
if(this.multipleList[i].productAttributeValueVoList[m].value == item.list[index].value){ //规格相同
this.multipleList[i].productAttributeValueVoList.splice(m,1)
return;
}else{ //规格不同
if(m+1 == this.multipleList[i].productAttributeValueVoList.length){
this.multipleList[i].productAttributeValueVoList.push(item.list[index])
return;
}
}
}
}else{ //不同分类
if(this.multipleList.length == i+1){
list.push(item.list[index])
var data = {
attributeName:item.name,
productAttributeValueVoList: list
}
this.multipleList.push(data)
return;
}
}
}
}
},
}
}
</script>
<style lang="scss">
.list-val {
width: 486rpx;
height: 70rpx;
line-height: 70rpx;
}
.list-val input {
width: 400rpx;
height: 70rpx;
display: inline-block;
line-height: 70rpx;
text-align: left !important;
padding-left: 20rpx;
float: left;
font-size: 25rpx;
}
.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;
}
.checked{
background: #60F3FF !important;
color: #fff !important;
border-radius: 5px !important;
}
.content-list {
height: 70rpx;
border: 1px solid #eee;
}
button{
height: 90rpx;
line-height: 90rpx;
font-size: 36rpx;
color: #fff;
background: #5fd9ee;
border-radius: 10px;
}
.content-input {
width: auto;
position: relative;
overflow: hidden;
flex: 1;
line-height: 1;
font-size: 14px;
height: 35px;
border: 2px solid #eee;
padding-left: 20rpx;
border-radius: 5px;
}
.add-popup-content {
align-items: center;
justify-content: center;
padding: 15px;
width: 100%;
height: 1050rpx;
background-color: #fff;
}
.add-popup-title {
font-size: 36rpx;
font-weight: bold;
text-align: center;
position: relative;
}
.add-popup-container {
margin-top: 20rpx;
}
.add-popup-bottom {
display: flex;
height: 80rpx;
color: #fff;
line-height: 80rpx;
margin-top: 50rpx;
}
.add-popup-btn {
flex: 1;
text-align: center;
background: linear-gradient(90deg, #60F3FF, #088FEB);
}
.title-fur {
width: 95%;
height: 70rpx;
margin: 0 auto;
border-bottom: 1px solid #eee;
.name {
font-size: 30rpx;
width: 90%;
float: left;
height: 70rpx;
line-height: 70rpx;
}
}
.content-fur {
padding-bottom: 25rpx;
}
.content-low {
width: auto;
border: 1px solid #eee;
display: inline-block;
min-width: 90rpx;
padding: 5rpx;
font-size: 35rpx;
text-align: center;
color: #777;
margin: 20rpx 0 0 20rpx;
border-radius: 5px;
}
</style>