shop-applet/pages/product/addGoodDetail/goodsPrice.vue

425 lines
12 KiB
Vue
Raw Normal View History

2024-04-18 18:02:57 +08:00
<template>
<view class="content">
2024-05-17 11:54:30 +08:00
2024-04-20 14:51:26 +08:00
<view class="card" v-for="(item,index) in attrValue">
2024-04-18 23:59:06 +08:00
<view class="card-head card-li">
2024-04-30 18:57:01 +08:00
<text style="font-size: 32rpx;">规格{{index+1}}</text>
2024-04-20 18:02:16 +08:00
<view class="" style="width: 300rpx;">
2024-04-25 08:40:17 +08:00
<!-- {{formData.attr}} -->
<!-- <u--input placeholder="请输入规格名称" inputAlign='right' v-model="formData.attr[index].value"></u--input> -->
<u--input placeholder="请输入规格名称" inputAlign='right' v-model="item.sku"></u--input>
2024-04-18 23:59:06 +08:00
</view>
</view>
<u-line direction="row" style="margin: 30rpx 0;" color="#ECECEC"></u-line>
2024-04-20 14:51:26 +08:00
<view class="">
2024-05-25 11:19:40 +08:00
<view class="" v-if='isWholeSale == 1 || isWholeSale == 2'
style="display: flex;align-items: center;justify-content: space-between;margin-top: 30rpx;margin-bottom: 20rpx;">
<u--input style="flex: 2; background-color: #F6F6F6;" placeholder="请输入批发价格"
placeholderStyle="font-size:26rpx;color:rgb(192, 196, 204);" v-model="item.wholesale_price"
type='number'></u--input>
2024-04-20 14:51:26 +08:00
<view class="" style="flex: 1;text-align: center;">
/
</view>
2024-04-25 18:09:35 +08:00
<view class="" @click="unitIptClick(index,true)" style="width: 100rpx;flex: 2.4">
<u--input style="background-color: #F6F6F6;pointer-events: none;" readonly placeholder="请输入计量单位"
2024-05-25 11:19:40 +08:00
placeholderStyle="font-size:26rpx;color:rgb(192, 196, 204);"
2024-04-25 18:09:35 +08:00
v-model="item.wholesale_unit_name"></u--input>
</view>
2024-05-22 18:21:10 +08:00
</view>
2024-04-25 18:09:35 +08:00
2024-05-25 11:19:40 +08:00
<view v-if='isWholeSale == 0 || isWholeSale == 2' class=""
style="display: flex;align-items: center;justify-content: space-between;">
<u--input style="flex: 2; background-color: #F6F6F6;" placeholder="请输入零售价格" v-model="item.price"
2024-05-22 18:21:10 +08:00
placeholderStyle="font-size:26rpx;color:rgb(192, 196, 204);" type='number'></u--input>
<view class="" style="flex: 1;text-align: center;">
/
</view>
<view class="" @click="unitIptClick(index,false)" style="width: 100rpx;flex: 2.4">
<u--input readonly style=" background-color: #F6F6F6;pointer-events: none;"
placeholderStyle="font-size:26rpx;color:rgb(192, 196, 204);" placeholder="请输入计量单位"
v-model="item.unit_name"></u--input>
</view>
2024-04-18 23:59:06 +08:00
</view>
</view>
2024-04-19 18:08:04 +08:00
<u-line direction="row" style="margin: 25rpx 0;" color="#ECECEC"></u-line>
2024-04-18 23:59:06 +08:00
<view class=" card-li">
2024-04-19 18:08:04 +08:00
<text style="font-size: 32rpx;">商品库存</text>
2024-04-20 18:02:16 +08:00
<view class="" style="width: 300rpx;">
2024-05-18 19:40:29 +08:00
<u--input type='number' placeholder="请填写库存数量" inputAlign='right' :value="item.stock"
@input="onInput($event,item)"></u--input>
2024-04-18 23:59:06 +08:00
</view>
</view>
2024-04-19 18:08:04 +08:00
<u-line direction="row" style="margin: 25rpx 0;" color="#ECECEC"></u-line>
2024-04-18 23:59:06 +08:00
<view class=" card-li">
2024-04-19 18:08:04 +08:00
<text style="font-size: 32rpx;">条形码</text>
2024-04-20 18:02:16 +08:00
<view class="" style="width: 300rpx;">
2024-04-22 18:05:44 +08:00
<u--input placeholder="请填写商品条形码" inputAlign='right' v-model="item.bar_code"
type='number'></u--input>
2024-04-18 23:59:06 +08:00
</view>
</view>
2024-04-19 18:08:04 +08:00
<u-line direction="row" style="margin: 25rpx 0;" color="#ECECEC"></u-line>
2024-04-18 23:59:06 +08:00
<view class="card-li">
2024-05-16 11:34:36 +08:00
<view style="display: flex;color: #777777;" @click="delFn(index)">
2024-04-18 23:59:06 +08:00
<u-icon name="trash" style='margin-right: 8rpx;'></u-icon>
</view>
<view class="" style="display: flex;align-items: center;">
2024-05-16 18:02:23 +08:00
<u-switch :disabled='attrValue.length==1' v-model="item.is_use" type='primaryy'
activeColor="#38BE41" size="19"></u-switch>
2024-04-19 18:08:04 +08:00
<text style="margin-left: 8rpx;color: #777777;">启用</text>
2024-04-18 23:59:06 +08:00
</view>
2024-04-18 18:02:57 +08:00
</view>
</view>
2024-05-17 11:54:30 +08:00
<view class="">
<u-button icon="plus" text="新增规格" @click="pushFn" class="custom-style" iconColor='#38BE41'></u-button>
</view>
2024-04-20 14:51:26 +08:00
<view class="submit-btn">
<u-button type="primary" shape="circle" text="保存" @click="submit"></u-button>
</view>
2024-04-24 18:11:06 +08:00
<u-popup :show="showPouple" @close="showPouple=false" @open="showPouple=true" :round="10">
<view class="RegularFont" style="padding: 42rpx 40rpx">
<view class="pop-head">
<text v-if='!showCustom' @click='showPouple=false'>取消</text>
<text v-else @click='showCustom=false'>
<u-icon name="arrow-left" size="20"></u-icon>
</text>
<text style="font-size:32rpx ;color:#333333 ;">计量单位</text>
<text v-if='showCustom' @click='addAttr'>确定</text>
<text v-else></text>
</view>
<view style="height: 500rpx;">
<u-transition :show="!showCustom" mode="slide-right">
<view class="goods-leval">
<view class="goods-leval-li" v-for='(item,index) in attrList' :key='index'
@click='choseAttr(item)'>
{{item}}
</view>
<view class="goods-leval-li " style="display: flex;color:#38BE41 ;"
@click="showCustom=true">
<u-icon name="plus" color="#38BE41" style='margin-right: 8rpx;'></u-icon>
</view>
</view>
</u-transition>
<u-transition :show="showCustom" mode="slide-left">
<view class="transition">
<u--textarea v-model="selfAttr" placeholder="请输入计量单位"></u--textarea>
</view>
</u-transition>
</view>
</view>
</u-popup>
2024-04-18 18:02:57 +08:00
</view>
</template>
<script>
2024-04-23 08:45:17 +08:00
import {
formatDate
} from '../../../libs/uniApi'
2024-04-18 23:59:06 +08:00
export default {
data() {
return {
2024-04-24 18:11:06 +08:00
selfAttr: "",
attrList: ['斤',
"公斤",
"吨",
"升",
"个",
"台",
"瓶",
"桶",
"箱",
"袋",
"包",
"盒",
"件",
"罐"
],
showCustom: false, //计量单位自定义
showPouple: false,
unitIndex: 0,
2024-04-20 18:02:16 +08:00
mer_id: "",
isWholeSale: "",
2024-04-24 18:11:06 +08:00
isWhose: false,
2024-04-18 23:59:06 +08:00
text: "",
2024-04-20 14:51:26 +08:00
value: "",
2024-04-20 18:02:16 +08:00
formData: {},
2024-04-23 08:45:17 +08:00
"attrValue": [{
2024-04-23 18:01:32 +08:00
detail: {
2024-04-25 08:40:17 +08:00
' ': '',
2024-04-23 18:01:32 +08:00
},
2024-04-23 08:45:17 +08:00
"price": "",
"unit_name": "",
"wholesale_unit_name": "",
2024-04-23 18:01:32 +08:00
"wholesale_price": '',
2024-04-23 08:45:17 +08:00
"cost": "",
"stock": "",
2024-04-25 08:40:17 +08:00
sku: '',
2024-04-23 08:45:17 +08:00
"ot_price": "",
"procure_price": "",
"bar_code": "",
"weight": "",
"extension_one": "",
"extension_two": "",
2024-04-23 18:01:32 +08:00
uuid: "",
volume: "",
2024-04-23 08:45:17 +08:00
"is_use": 0,
}],
2024-04-23 18:01:32 +08:00
rules: {
price: '单价不能为空',
unit_name: '计量单位不能为空',
wholesale_price: '批发价格不能为空',
wholesale_unit_name: '批发单位不能为空',
2024-04-25 18:09:35 +08:00
stock: '库存不能为空',
2024-04-23 18:01:32 +08:00
}
2024-04-20 14:51:26 +08:00
}
},
methods: {
2024-05-18 19:40:29 +08:00
onInput(event, item) {
if (!/^\d*$/.test(event)) {
event = event.replace(/[^\d]/g, '');
}
item.stock = event;
this.$forceUpdate();
// 更新整数值
},
2024-05-16 11:34:36 +08:00
delFn(index) {
if (this.attrValue.length == 1) {
return this.$util.Tips({
title: "最少保留一个规格"
})
}
this.attrValue.splice(index, 1)
2024-05-20 17:34:52 +08:00
this.formData.attr[0].detail.splice(index, 1)
2024-05-16 11:34:36 +08:00
},
2024-04-24 18:11:06 +08:00
choseAttr(name) {
this.isWhose ?
this.attrValue[this.unitIndex].wholesale_unit_name = name :
this.attrValue[this.unitIndex].unit_name = name;
this.showPouple = false
},
addAttr() {
if (!this.selfAttr) return;
this.attrList.push(this.selfAttr)
this.isWhose ?
this.attrValue[this.unitIndex].wholesale_unit_name = this.attrList[this.attrList.length - 1] :
this.attrValue[this.unitIndex].unit_name = this.attrList[this.attrList.length - 1];
// this.attrValue[this.unitIndex].unit_name = this.attrList[this.attrList.length - 1]
// this.attrValue[this.unitIndex].wholesale_unit_name = this.attrList[this.attrList.length - 1]
this.selfAttr = ''
this.showCustom = false
this.showPouple = false
},
2024-04-25 18:09:35 +08:00
// hide() {
// uni.hideKeyboard()
// },
2024-04-24 18:11:06 +08:00
unitIptClick(index, type) {
this.isWhose = type
this.unitIndex = index
this.showPouple = true
2024-04-25 18:09:35 +08:00
uni.hideKeyboard()
2024-04-24 18:11:06 +08:00
},
2024-04-23 18:01:32 +08:00
pushFn() {
this.attrValue.push({
detail: {
2024-04-25 08:40:17 +08:00
' ': '',
2024-04-23 18:01:32 +08:00
},
"price": "",
"unit_name": "",
"wholesale_unit_name": "",
"wholesale_price": '',
"cost": "",
"stock": "",
2024-04-25 08:40:17 +08:00
sku: '',
2024-04-23 18:01:32 +08:00
"ot_price": "",
"procure_price": "",
"bar_code": "",
"weight": "",
"extension_one": "",
"extension_two": "",
uuid: "",
volume: "",
"is_use": true,
})
2024-04-25 08:40:17 +08:00
// this.formData.attr.push({
// value: '',
// detail: [],
// })
2024-04-23 18:01:32 +08:00
},
2024-04-20 14:51:26 +08:00
submit() {
2024-04-25 08:40:17 +08:00
// 校验
2024-04-23 18:01:32 +08:00
let errList = []
2024-05-25 11:19:40 +08:00
// if (!this.isWholeSale) {
// delete this.rules.wholesale_unit_name
// delete this.rules.wholesale_price
// }
if (this.isWholeSale == 0) { //零售
2024-04-23 18:01:32 +08:00
delete this.rules.wholesale_unit_name
delete this.rules.wholesale_price
2024-05-25 11:19:40 +08:00
} else if (this.isWholeSale == 1) { //批发
delete this.rules.price;
delete this.rules.unit_name;
2024-04-23 18:01:32 +08:00
}
2024-05-25 11:19:40 +08:00
2024-04-23 18:01:32 +08:00
this.attrValue.forEach(item => {
for (let key in this.rules) {
if (!item[key]) {
errList.push(this.rules[key])
}
}
2024-04-25 18:09:35 +08:00
if (this.attrValue.length > 1) {
if (!item['sku']) {
errList.push('规格名称不能为空')
}
}
2024-04-23 18:01:32 +08:00
})
if (errList.length > 0) {
2024-04-25 18:09:35 +08:00
console.log(errList)
2024-04-23 18:01:32 +08:00
uni.$u.toast(errList[0])
return
}
2024-04-25 08:40:17 +08:00
// 校验结束
2024-05-20 17:34:52 +08:00
if (this.formData.attr && this.formData.attr.length > 0)
this.formData.attr[0].detail = [];
2024-04-25 08:40:17 +08:00
this.attrValue.forEach(item => {
2024-05-03 15:03:12 +08:00
typeof(item.detail) == 'object' ?
item.detail[' '] = item.sku: (item.detail = {}, item.detail[' '] = item.sku)
2024-04-25 08:40:17 +08:00
this.formData.attr[0].detail.push(item.sku)
})
2024-04-20 18:02:16 +08:00
this.formData.attrValue = this.attrValue
2024-04-23 08:45:17 +08:00
this.formData.attrValue.forEach(item => {
item.is_use = item.is_use ? '0' : '1'
})
2024-04-20 18:02:16 +08:00
let that = this
2024-04-23 18:01:32 +08:00
this.formData.spec_type = this.formData.attrValue.length > 1 ? '1' : '0'
2024-05-20 17:34:52 +08:00
2024-04-25 08:40:17 +08:00
uni.redirectTo({
2024-05-20 17:34:52 +08:00
url: `/pages/product/addGoodDetail/addGoodDetail?mer_id=${that.mer_id}&&formData=${JSON.stringify(that.formData) }&&showSet=${true}`,
success(res) {
2024-05-21 16:35:54 +08:00
let delta = uni.getStorageSync('delta');
if (delta) delta += 1;
else delta = 2;
uni.setStorageSync('delta', delta);
2024-05-20 17:34:52 +08:00
}
2024-04-20 18:02:16 +08:00
})
2024-04-23 08:45:17 +08:00
},
initFomrData(option) {
if (option.mer_id) {
this.mer_id = option.mer_id
}
if (option.formData) {
this.formData = JSON.parse(option.formData)
}
2024-04-20 14:51:26 +08:00
}
},
onLoad(option) {
2024-05-25 11:19:40 +08:00
this.isWholeSale = this.$store.state.app.userInfo?.mer_info?.wholesale
2024-04-23 08:45:17 +08:00
this.initFomrData(option)
this.attrValue = this.formData.attrValue
this.attrValue.forEach(item => {
item.is_use = !Boolean(Number(item.is_use))
})
if (this.formData.attr.length == 0) {
this.formData.attr.push({
value: '',
detail: [],
2024-04-22 18:05:44 +08:00
})
2024-04-18 23:59:06 +08:00
}
}
}
2024-04-18 18:02:57 +08:00
</script>
<style lang='scss'>
.custom-style {
color: $uni-newTheme-color;
height: 104rpx;
}
.content {
box-sizing: border-box;
padding: 30rpx;
background-color: #F1F1F1;
min-height: 100vh;
position: relative;
font-size: 28rpx;
2024-04-22 18:05:44 +08:00
padding-bottom: 200rpx;
2024-04-19 18:08:04 +08:00
2024-04-18 18:02:57 +08:00
.card {
2024-05-17 11:54:30 +08:00
margin-bottom: 30rpx;
2024-04-18 18:02:57 +08:00
padding: 30rpx 46rpx;
background-color: white;
border-radius: 16rpx 16rpx 16rpx 16rpx;
box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.16);
2024-04-18 23:59:06 +08:00
position: relative;
.card-li {
display: flex;
justify-content: space-between;
align-items: center;
}
2024-04-18 18:02:57 +08:00
}
.card-head::after {
content: '';
position: absolute;
font-size: 32rpx;
2024-04-18 23:59:06 +08:00
left: 20rpx;
width: 8rpx;
2024-04-18 18:02:57 +08:00
height: 32rpx;
2024-04-18 23:59:06 +08:00
top: 50rpx;
background-color: #40AE36;
border-radius: 4rpx 4rpx 4rpx 4rpx;
2024-04-18 18:02:57 +08:00
}
2024-04-20 14:51:26 +08:00
.submit-btn {
position: fixed;
bottom: 50rpx;
width: 670rpx;
}
2024-04-18 18:02:57 +08:00
}
2024-04-24 18:11:06 +08:00
.pop-head {
display: flex;
justify-content: space-between;
color: #20B128;
margin-bottom: 42rpx;
}
.goods-leval {
display: flex;
flex-wrap: wrap;
overflow-y: auto;
.goods-leval-li {
margin-right: 20rpx;
padding: 10rpx 40rpx;
2024-05-25 11:19:40 +08:00
/* height: 60rpx; */
2024-04-24 18:11:06 +08:00
margin-bottom: 20rpx;
border-radius: 36rpx 36rpx 36rpx 36rpx;
background-color: #F1F1F1;
2024-05-25 11:19:40 +08:00
word-break: break-word;
2024-04-24 18:11:06 +08:00
}
.act {
color: #20B128;
background-color: #E8F7E9;
border: 1px solid #20B128;
}
}
2024-04-18 18:02:57 +08:00
</style>