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.
262 lines
7.9 KiB
262 lines
7.9 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">
|
|
<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
|
|
:maxCount="10"></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>
|
|
<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(ret)">保存</u-button>
|
|
<kk-printer ref="kkprinter" :bufferData="bufferData" @onPrint="onPrint"></kk-printer>
|
|
</view>
|
|
<!-- <u-modal v-model="show" :content="content"></u-modal> -->
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
import util from '@/components/kk-printer/utils/util.js';
|
|
import * as blesdk from '@/components/kk-printer/utils/bluetoolth.js';
|
|
import kkPrinter from '@/components/kk-printer/index.vue';
|
|
export default {
|
|
data() {
|
|
return {
|
|
fileList1: [],
|
|
// 表单数据
|
|
formData: {
|
|
productName: '',
|
|
price: '',
|
|
productSn: '',
|
|
wholesalePrice: '',
|
|
// classification: '',
|
|
productPicture: '',
|
|
productIntro: '',
|
|
categoryId: '',
|
|
salesWeek: '',
|
|
tailWarn: ''
|
|
},
|
|
categoryList: [],
|
|
arrtList: [],
|
|
arrtChange: [],
|
|
bufferData: '',
|
|
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: '请选择尾货预警天数',
|
|
}, ],
|
|
}
|
|
}
|
|
}
|
|
},
|
|
components: {
|
|
kkPrinter
|
|
},
|
|
onShow() {
|
|
let that = this
|
|
uni.$on('classForm', function(data) {
|
|
that.formData.classification = data
|
|
})
|
|
},
|
|
onLoad() {
|
|
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) {
|
|
console.log(event);
|
|
// 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
|
|
let lists = [].concat(event.file)
|
|
if (this.fileList1 == undefined) this.fileList1 = [];
|
|
let fileListLen = this[`fileList${event.name}`].length
|
|
console.log(lists, 'lists');
|
|
lists.map((item) => {
|
|
this[`fileList${event.name}`].push({
|
|
...item,
|
|
status: 'uploading',
|
|
message: '上传中'
|
|
})
|
|
})
|
|
console.log(this.fileList1);
|
|
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) {
|
|
console.log(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) => {
|
|
console.log("这里", uploadFileRes)
|
|
let path = JSON.parse(uploadFileRes.data)
|
|
//后端返回的地址,存入图片地址
|
|
this.formData.productPicture = path.result
|
|
}
|
|
});
|
|
})
|
|
},
|
|
categoryChange(e) {
|
|
|
|
},
|
|
// 触发提交表单
|
|
submit() {
|
|
this.$refs.form.validate().then(res => {
|
|
this.tui.request("/app/product/save", "post", res, false, false).then((res1) => {
|
|
if (res1.code == 200) {
|
|
uni.navigateBack({
|
|
delta: 1
|
|
})
|
|
} else {
|
|
uni.showToast({
|
|
title: "添加失败",
|
|
icon: 'none'
|
|
})
|
|
}
|
|
})
|
|
}).catch(err => {
|
|
console.log('表单错误信息:', err);
|
|
})
|
|
},
|
|
onPrint(opt) {
|
|
//快递单600*1040 入库单440*320
|
|
let strCmd = blesdk.CreatCPCLPage(440, 320, 1, 0);
|
|
strCmd += blesdk.addCPCLText('0', '30', '24', '0', 0, '商品名:女装小西裤')
|
|
strCmd += blesdk.addCPCLText('0', '80', '24', '0', 0, '货 号:NK20231012001')
|
|
strCmd += blesdk.addCPCLText('0', '130', '24', '0', 0, '供应商:杭州春雨服饰')
|
|
strCmd += blesdk.addCPCLText('0', '180', '24', '0', 0, '批发价:56.00')
|
|
strCmd += blesdk.addCPCLText('0', '230', '24', '0', 0, '零售价:99.00')
|
|
strCmd += blesdk.addCPCLQRCode(260, 170, 'H', '1', 6, '1694621564429623297') //二维码
|
|
strCmd += blesdk.addCPCLLocation(0); //对齐指令 0-左对齐 1-右对齐 2-居中
|
|
strCmd += blesdk.addCPCLPrint();
|
|
this.bufferData = strCmd;
|
|
},
|
|
}
|
|
}
|
|
</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;
|
|
}
|
|
}
|
|
}
|
|
</style>
|