代码更新
This commit is contained in:
@@ -15,31 +15,17 @@
|
||||
</uni-data-picker>
|
||||
</view>
|
||||
</view>
|
||||
<!-- <view class="border-top-0">
|
||||
<uni-forms-item label="选择规格" required name="categoryId">
|
||||
<uni-data-picker :clear-icon="false" @change="specIdChange"
|
||||
:map="{text:'name',value:'id'}" placeholder="请选择规格" popup-title="请选择规格"
|
||||
:localdata="FormData.specList" v-model="FormData.specId">
|
||||
</uni-data-picker>
|
||||
</uni-forms-item>
|
||||
</view> -->
|
||||
|
||||
<view class=" ">
|
||||
<view class="u-m-t-32" v-for="(item,index) in FormData.selectSpec" :key="index">
|
||||
<view class="u-m-t-32" v-for="(item,index) in FormData.selectSpecInfo" :key="index">
|
||||
<view class="font-bold">
|
||||
{{item.name}}
|
||||
</view>
|
||||
<view class="u-m-t-16">
|
||||
<!-- <up-checkbox-group :labelSize="12" :size="14" :activeColor="color.ColorMain"
|
||||
shape="circle" v-model="item.selectSpecResult" placement="row"
|
||||
@change="createResult">
|
||||
<up-checkbox :customStyle="{marginRight: '60rpx',marginBottom:'16rpx'}"
|
||||
v-for="(item, index) in item.value" :key="index" :label="item.text"
|
||||
:name="item.value">
|
||||
</up-checkbox>
|
||||
</up-checkbox-group> -->
|
||||
|
||||
|
||||
<uni-data-checkbox @change="createResult" multiple :selectedColor="color.ColorMain"
|
||||
v-model="item.selectSpecResult" :localdata="item.value">
|
||||
v-model="item.selectSpecResult" :localdata="item.children">
|
||||
</uni-data-checkbox>
|
||||
|
||||
</view>
|
||||
@@ -106,29 +92,13 @@
|
||||
:inputBorder="inputBorder" v-model="item.skus.originPrice" type="digit"
|
||||
placeholder="请输入原价(元)" />
|
||||
</uni-forms-item>
|
||||
<uni-forms-item label="起售数量" required name="suit">
|
||||
<uni-easyinput @blur="priceFormat(item.skus,'suit')" :paddingNone="inputPaddingNone"
|
||||
<uni-forms-item label="起售数量" required name="suitNum">
|
||||
<uni-easyinput @blur="priceFormat(item.skus,'suitNum')" :paddingNone="inputPaddingNone"
|
||||
:placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
|
||||
v-model="item.skus.suit" type="digit" placeholder="请输入起售数量" />
|
||||
v-model="item.skus.suitNum" type="digit" placeholder="请输入起售数量" />
|
||||
</uni-forms-item>
|
||||
<!-- <view class="u-relative">
|
||||
<uni-forms-item label="库存数量" required>
|
||||
<uni-easyinput :disabled="disabledStock"
|
||||
@blur="priceFormat(item.skus,'stockNumber')" :paddingNone="inputPaddingNone"
|
||||
:placeholderStyle="placeholderStyle" :inputBorder="inputBorder"
|
||||
v-model="item.skus.stockNumber" type="digit" placeholder="请输入库存数量" />
|
||||
</uni-forms-item>
|
||||
<view class="u-absolute position-all" v-if="disabledStock"
|
||||
@click="canEditGoodsStock(true)">
|
||||
</view>
|
||||
</view> -->
|
||||
|
||||
|
||||
<uni-forms-item label="分销金额" required>
|
||||
<uni-easyinput @blur="priceFormat(item.skus,'firstShared')"
|
||||
:paddingNone="inputPaddingNone" :placeholderStyle="placeholderStyle"
|
||||
:inputBorder="inputBorder" v-model="item.skus.firstShared" type="digit"
|
||||
placeholder="请输入分销金额" />
|
||||
</uni-forms-item>
|
||||
<uni-forms-item label="商品条码" required>
|
||||
<view class="bg-gray u-flex u-col-center u-col-center u-p-l-24" style="height: 72rpx;background: #F6F6F6;border-radius: 8rpx ;">
|
||||
<uni-easyinput disabled :paddingNone="inputPaddingNone"
|
||||
@@ -171,48 +141,178 @@
|
||||
</view>
|
||||
</template>
|
||||
<script setup>
|
||||
import {
|
||||
getSafeBottomHeight
|
||||
} from '@/commons/utils/safe-bottom.js'
|
||||
import {
|
||||
formatPrice
|
||||
} from "@/commons/utils/format.js";
|
||||
import { reactive, nextTick, ref, watch } from 'vue';
|
||||
import { onLoad, onReady, onShow } from '@dcloudio/uni-app';
|
||||
import { getSafeBottomHeight } from '@/commons/utils/safe-bottom.js'
|
||||
import { formatPrice } from "@/commons/utils/format.js";
|
||||
import popFastEdit from "./components/fast-edit.vue"
|
||||
import infoBox from '@/commons/utils/infoBox.js'
|
||||
import dayjs from "dayjs";
|
||||
import go from '@/commons/utils/go.js';
|
||||
import color from '@/commons/color.js';
|
||||
import {
|
||||
$types,
|
||||
$defaultSku
|
||||
} from '@/commons/goodsData.js'
|
||||
import {
|
||||
$productSpec
|
||||
} from '@/http/yskApi/goods.js';
|
||||
import {
|
||||
onLoad,
|
||||
onReady,
|
||||
onShow
|
||||
} from '@dcloudio/uni-app';
|
||||
import {
|
||||
onMounted,
|
||||
reactive,
|
||||
nextTick,
|
||||
ref,
|
||||
onBeforeMount,
|
||||
watch
|
||||
} from 'vue';
|
||||
import {
|
||||
hasPermission
|
||||
} from '@/commons/utils/hasPermission.js';
|
||||
import { $defaultSku } from '@/commons/goodsData.js'
|
||||
|
||||
import { hasPermission } from '@/commons/utils/hasPermission.js';
|
||||
import { getSpecList,delSpec } from '@/api/product.js'
|
||||
|
||||
|
||||
//上个页面传来的参数
|
||||
let option = {}
|
||||
const FormData = reactive({
|
||||
specId: '',
|
||||
specItem: '',
|
||||
specAllList: [],
|
||||
result: [],
|
||||
selectSpecInfo: [],
|
||||
})
|
||||
|
||||
//表单验证
|
||||
const rules = {
|
||||
salePrice: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '售价必填'
|
||||
}]
|
||||
},
|
||||
memberPrice: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '会员价必填'
|
||||
}]
|
||||
},
|
||||
costPrice: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '成本价必填'
|
||||
}]
|
||||
},
|
||||
originPrice: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '原价必填'
|
||||
}]
|
||||
},
|
||||
suitNum: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '起售数量必填'
|
||||
},
|
||||
{
|
||||
validateFunction: function(rule, value, data, callback) {
|
||||
if (value < 1) {
|
||||
callback('起售数量至少为1个')
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
let bottomHeight = ref(100)
|
||||
|
||||
const inputPaddingNone = ref(true)
|
||||
const form = ref(null)
|
||||
const formRefs = ref([]);
|
||||
const originSpecMap = {}
|
||||
|
||||
let emitName = ''
|
||||
|
||||
onReady(() => {
|
||||
getSafeBottomHeight('safe-bottom').then(res => {
|
||||
console.log(res);
|
||||
bottomHeight.value = res
|
||||
})
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
canEditGoodsStock()
|
||||
})
|
||||
|
||||
onLoad(opt => {
|
||||
Object.assign(option, opt)
|
||||
const obj = uni.getStorageSync('guige')
|
||||
getTbProductSpec(obj)
|
||||
if (opt && JSON.stringify(opt) !== '{}' && opt.emitName) {
|
||||
emitName = opt.emitName
|
||||
}
|
||||
|
||||
})
|
||||
function triggerEvent(emitName, data) {
|
||||
if (emitName) {
|
||||
uni.$emit(emitName, data)
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 获取规格数据
|
||||
*/
|
||||
function getTbProductSpec(obj) {
|
||||
getSpecList({name: ''}).then(res => {
|
||||
FormData.specAllList = res;
|
||||
FormData.specAllList.map(item => {
|
||||
item.children.map(spe => {
|
||||
spe.children.map(v => {
|
||||
if (obj && JSON.stringify(obj) !== '{}') {
|
||||
spe.selectSpecResult = []
|
||||
for (var oe in obj.selectSpecInfo) {
|
||||
|
||||
if ( spe.name == oe ) {
|
||||
spe.selectSpecResult = obj.selectSpecInfo[oe]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
spe.selectSpecResult = []
|
||||
}
|
||||
v.text = v.name
|
||||
v.value = v.name
|
||||
})
|
||||
})
|
||||
});
|
||||
if (obj && JSON.stringify(obj) !== '{}') {
|
||||
FormData.specAllList.map(item=>{
|
||||
if( item.id == obj.specId ){
|
||||
obj.selectSpecInfo = item.children
|
||||
}
|
||||
})
|
||||
}
|
||||
FormData.specList = res.map(item => {
|
||||
return {
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
}
|
||||
})
|
||||
if (obj && JSON.stringify(obj) !== '{}') {
|
||||
// console.log(obj.selectSpecInfo);
|
||||
Object.assign(FormData, obj)
|
||||
for (let i of obj.result) {
|
||||
const key = returnSpecSnap(i.names)
|
||||
originSpecMap[key] = i
|
||||
}
|
||||
nextTick(() => {
|
||||
FormData.result = obj.result
|
||||
})
|
||||
}
|
||||
console.log(FormData)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则选择
|
||||
* @param {Object} e
|
||||
*/
|
||||
function specIdChange(e) {
|
||||
|
||||
const item = FormData.specAllList.find(v => v.id === FormData.specId)
|
||||
FormData.selectSpecInfo = (item.children || [])
|
||||
console.log(item)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const refFiles = ref([]);
|
||||
const imageStyles = reactive({
|
||||
width: 82,
|
||||
@@ -250,38 +350,38 @@
|
||||
},
|
||||
{
|
||||
text: '起售数量',
|
||||
key: 'suit',
|
||||
key: 'suitNum',
|
||||
value: ''
|
||||
},
|
||||
{
|
||||
text: '库存数量',
|
||||
key: 'stockNumber',
|
||||
value: ''
|
||||
},
|
||||
{
|
||||
text: '分销金额',
|
||||
key: 'firstShared',
|
||||
value: ''
|
||||
}
|
||||
],
|
||||
sel: ''
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* 批量修改打开
|
||||
*/
|
||||
function fastEditShow() {
|
||||
fastEdit.show = true
|
||||
}
|
||||
//上个页面传来的参数
|
||||
let option = {}
|
||||
|
||||
|
||||
|
||||
//number类型数据限制
|
||||
|
||||
/**
|
||||
* number类型数据限制
|
||||
* @param {Object} item
|
||||
* @param {Object} key
|
||||
*/
|
||||
function priceFormat(item, key) {
|
||||
nextTick(() => {
|
||||
let min = 0;
|
||||
let max = 100000000;
|
||||
console.log(item[key]);
|
||||
if (key == 'suit') {
|
||||
if (key == 'suitNum') {
|
||||
min = 1
|
||||
}
|
||||
const newval = formatPrice(item[key], min, max, true)
|
||||
@@ -298,7 +398,10 @@
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 批量修改监听
|
||||
* @param {Object} arr
|
||||
*/
|
||||
function updateSkuKey(arr) {
|
||||
for (let i in FormData.result) {
|
||||
const sku = FormData.result[i].skus
|
||||
@@ -312,21 +415,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
const inputPaddingNone = ref(true)
|
||||
const form = ref(null)
|
||||
const originSpecMap = {}
|
||||
const FormData = reactive({
|
||||
specId: '',
|
||||
specItem: '',
|
||||
result: [],
|
||||
selectSpec: [],
|
||||
})
|
||||
|
||||
|
||||
//表单相关事件
|
||||
function changeResultCover(val, index) {
|
||||
FormData.result[index].coverImg = val
|
||||
console.log(FormData.result[index]);
|
||||
}
|
||||
const formRefs = ref([]);
|
||||
//绑定表单元素
|
||||
function setFormRef(index) {
|
||||
formRefs.value[index] = null;
|
||||
@@ -346,7 +440,6 @@
|
||||
const inputBorder = ref(false)
|
||||
|
||||
//生成笛卡尔集
|
||||
|
||||
function combineSpecs(specs) {
|
||||
if (specs.length === 0) {
|
||||
return [
|
||||
@@ -366,9 +459,7 @@
|
||||
};
|
||||
const defaultSku = reactive({
|
||||
...$defaultSku,
|
||||
shopId: uni.getStorageSync('shopId'),
|
||||
coverImg: '',
|
||||
productId: option.productId,
|
||||
barCode: `${uni.getStorageSync("shopId")}${dayjs().valueOf()}`
|
||||
})
|
||||
|
||||
@@ -376,43 +467,33 @@
|
||||
const randomNumber = Math.floor(Math.random() * 1000)
|
||||
return {
|
||||
...defaultSku,
|
||||
productId: option.productId,
|
||||
barCode: `${uni.getStorageSync("shopId")}${dayjs().valueOf()-randomNumber}`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 选择规格属性
|
||||
*/
|
||||
function createResult() {
|
||||
let arr = []
|
||||
// for(let i in FormData.selectSpec){
|
||||
// const selectSpecResult=FormData.selectSpec[i].selectSpecResult
|
||||
// if(selectSpecResult.length>0){
|
||||
// arr.push({
|
||||
// value: selectSpecResult,
|
||||
// name: FormData.selectSpec[i].name
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
for (let k of FormData.selectSpec) {
|
||||
for (let k of FormData.selectSpecInfo) {
|
||||
if (k.selectSpecResult.length) {
|
||||
console.log(k.selectSpecResult.length);
|
||||
arr.push({
|
||||
value: k.selectSpecResult,
|
||||
name: k.name
|
||||
})
|
||||
}
|
||||
}
|
||||
console.log(arr);
|
||||
const spes = combineSpecs(arr)
|
||||
console.log(spes);
|
||||
const result = spes.filter(v => {
|
||||
return !Array.isArray(v)
|
||||
}).map(v => {
|
||||
const specSnap = returnSpecSnap(v)
|
||||
const data = originSpecMap[specSnap]
|
||||
const specInfo = returnSpecSnap(v)
|
||||
const data = originSpecMap[specInfo]
|
||||
const skus = returnDefaultSku()
|
||||
const newdata = {
|
||||
names: v,
|
||||
specSnap,
|
||||
specInfo,
|
||||
skus
|
||||
}
|
||||
return data || newdata
|
||||
@@ -422,84 +503,6 @@
|
||||
|
||||
|
||||
|
||||
function specIdChange(e) {
|
||||
console.log(e);
|
||||
const item = FormData.specList.find(v => v.id === FormData.specId)
|
||||
FormData.selectSpec = (item.specList || [])
|
||||
|
||||
}
|
||||
//获取规格数据
|
||||
function getTbProductSpec() {
|
||||
$productSpec.get({
|
||||
page: 0,
|
||||
size: 200,
|
||||
sort: "id"
|
||||
}).then(res => {
|
||||
FormData.specList = res.content.map(item => {
|
||||
return {
|
||||
...item,
|
||||
specList: item.specList.map(spe => {
|
||||
return {
|
||||
...spe,
|
||||
selectSpecResult: [],
|
||||
value: spe.value.map(v => {
|
||||
return {
|
||||
text: v,
|
||||
value: v
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
//表单验证
|
||||
const rules = {
|
||||
salePrice: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '售价必填'
|
||||
}]
|
||||
},
|
||||
memberPrice: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '会员价必填'
|
||||
}]
|
||||
},
|
||||
costPrice: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '成本价必填'
|
||||
}]
|
||||
},
|
||||
originPrice: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '原价必填'
|
||||
}]
|
||||
},
|
||||
suit: {
|
||||
rules: [{
|
||||
required: true,
|
||||
errorMessage: '起售数量必填'
|
||||
},
|
||||
{
|
||||
validateFunction: function(rule, value, data, callback) {
|
||||
if (value < 1) {
|
||||
callback('起售数量至少为1个')
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//页面滚动到最底部
|
||||
@@ -514,23 +517,12 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let emitName = ''
|
||||
|
||||
function triggerEvent(emitName, data) {
|
||||
if (emitName) {
|
||||
uni.$emit(emitName, data)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//生成name
|
||||
function returnSpecSnap(names) {
|
||||
const specSnap = Object.keys(names).reduce((prve, cur) => {
|
||||
const specInfo = Object.keys(names).reduce((prve, cur) => {
|
||||
return prve + names[cur] + ','
|
||||
}, '')
|
||||
return specSnap.substring(0, specSnap.length - 1)
|
||||
return specInfo.substring(0, specInfo.length - 1)
|
||||
}
|
||||
// 允许修改商品库存
|
||||
let disabledStock = ref(false)
|
||||
@@ -545,34 +537,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
onShow(() => {
|
||||
canEditGoodsStock()
|
||||
})
|
||||
|
||||
onLoad(opt => {
|
||||
Object.assign(option, opt)
|
||||
getTbProductSpec()
|
||||
const obj = uni.getStorageSync('guige')
|
||||
if (obj && JSON.stringify(obj) !== '{}') {
|
||||
console.log(obj.selectSpec);
|
||||
option.productId = opt.productId
|
||||
Object.assign(FormData, obj)
|
||||
for (let i of obj.result) {
|
||||
const key = returnSpecSnap(i.names)
|
||||
originSpecMap[key] = i
|
||||
}
|
||||
nextTick(() => {
|
||||
FormData.result = obj.result
|
||||
console.log(FormData.result);
|
||||
})
|
||||
}
|
||||
console.log(opt);
|
||||
if (opt && JSON.stringify(opt) !== '{}' && opt.emitName) {
|
||||
emitName = opt.emitName
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
function emitspecificationsSave() {
|
||||
// emitspecificationsSave 触发规格保存事件将数据给到添加商品页面
|
||||
// guigeEdit 触发规格保存事件将数据给到添加规格页面
|
||||
@@ -613,7 +578,7 @@
|
||||
//判断验证是否通过
|
||||
console.log('pass');
|
||||
const item = FormData.specList.find(v => v.id === FormData.specId)
|
||||
FormData.specsInfoName = item ? item.name : ''
|
||||
FormData.specName = item ? item.name : ''
|
||||
console.log(FormData);
|
||||
emitspecificationsSave()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user