|
|
@@ -73,6 +73,7 @@ const attrs_value = reactive<
|
|
|
suk: '默认',
|
|
|
image: [],
|
|
|
stock: 0,
|
|
|
+ detail: {},
|
|
|
price: 0,
|
|
|
ot_price: 0,
|
|
|
cost: 0
|
|
|
@@ -147,7 +148,6 @@ const rules = reactive({
|
|
|
trigger: 'change',
|
|
|
required: true,
|
|
|
validator: (_, val, callback) => {
|
|
|
- console.log(val, formData.slider_image, 'val')
|
|
|
if (!val || val.length === 0) {
|
|
|
callback(new Error('请选择轮播图片'))
|
|
|
} else {
|
|
|
@@ -248,8 +248,6 @@ const save = async (formEl: FormInstance | undefined) => {
|
|
|
if (valid) {
|
|
|
// 将分类ID转换为数组形式,以便后续处理
|
|
|
const cateIds: number[] = Array.from(flattenCateIds(formData.cate_ids)).map((re) => re)
|
|
|
- console.log(cateIds, 'cateIds')
|
|
|
-
|
|
|
// 构建要保存的商品数据对象
|
|
|
const data: goodsData = {
|
|
|
store_id: formData.store_id,
|
|
|
@@ -280,8 +278,57 @@ const save = async (formEl: FormInstance | undefined) => {
|
|
|
}
|
|
|
// 多规格商品处理
|
|
|
if (formData.spec_type == 1) {
|
|
|
- data.attrs_value = productAttrList.value.value.map((res) => {
|
|
|
- return res
|
|
|
+ try {
|
|
|
+ for (let i = 0; i < productAttrList.value.value.length; i++) {
|
|
|
+ const item = productAttrList.value.value[i]
|
|
|
+ if (item.pic.length == 0) {
|
|
|
+ return ElMessage.error('商品图片不能为空')
|
|
|
+ }
|
|
|
+ if (isNaN(item.price)) {
|
|
|
+ return ElMessage.error('请输入正确的商品价格')
|
|
|
+ }
|
|
|
+ if (item.price * 1 <= 0) {
|
|
|
+ return ElMessage.error('商品价格必须大于0')
|
|
|
+ }
|
|
|
+ if (item.stock * 1 <= 0) {
|
|
|
+ return ElMessage.error('商品库存必须大于0')
|
|
|
+ }
|
|
|
+ if (item.ot_price * 1 <= 0) {
|
|
|
+ return ElMessage.error('商品原价必须大于0')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error: any) {
|
|
|
+ return ElMessage.error(error.message)
|
|
|
+ }
|
|
|
+ const keyList = getKeyList()
|
|
|
+ data.attrs_value = productAttrList.value.value.map((res): attrsValue => {
|
|
|
+ const suk: any[] = []
|
|
|
+ for (const key in res.detail) {
|
|
|
+ suk.push(res.detail[key])
|
|
|
+ }
|
|
|
+ const item = {
|
|
|
+ suk: suk.join(','),
|
|
|
+ image: res.pic[0],
|
|
|
+ stock: res.stock,
|
|
|
+ price: res.price,
|
|
|
+ ot_price: res.ot_price,
|
|
|
+ cost: res.cost,
|
|
|
+ detail: res.detail
|
|
|
+ }
|
|
|
+ if (keyList.length > 0) {
|
|
|
+ for (let i = 0; i < keyList.length; i++) {
|
|
|
+ const key = keyList[i]
|
|
|
+ item[key] = res[key]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return item
|
|
|
+ })
|
|
|
+
|
|
|
+ data.attrs = actionAttrs.map((re) => {
|
|
|
+ return {
|
|
|
+ attr_name: re.value,
|
|
|
+ attr_values: re.detail
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
try {
|
|
|
@@ -312,10 +359,20 @@ const save = async (formEl: FormInstance | undefined) => {
|
|
|
} catch (error) {
|
|
|
console.log(error)
|
|
|
} finally {
|
|
|
- console.log(data)
|
|
|
+ // console.log(data)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+const getKeyList = () => {
|
|
|
+ const keyList: string[] = []
|
|
|
+ for (let i = 0; i < productAttrList.value.header.length; i++) {
|
|
|
+ const item = productAttrList.value.header[i]
|
|
|
+ if (item.key) {
|
|
|
+ keyList.push(item.key)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return keyList
|
|
|
+}
|
|
|
const loadingData = ref(false)
|
|
|
onMounted(async () => {
|
|
|
//加载商品规格
|
|
|
@@ -358,9 +415,40 @@ onMounted(async () => {
|
|
|
attrs_value.suk = values.suk
|
|
|
attrs_value.image = [values.image]
|
|
|
}
|
|
|
- // if(formData.spec_type == 1){
|
|
|
-
|
|
|
- // }
|
|
|
+ if (formData.spec_type == 1) {
|
|
|
+ const atrs = res.data.productAttr.map((ree): productRuleValue => {
|
|
|
+ return {
|
|
|
+ attrHidden: '',
|
|
|
+ detail: ree.attr_values,
|
|
|
+ detailValue: '',
|
|
|
+ value: ree.attr_name
|
|
|
+ }
|
|
|
+ })
|
|
|
+ actionAttrs.push(...atrs)
|
|
|
+ await attrsConfirm('header')
|
|
|
+ const keyList = getKeyList()
|
|
|
+ productAttrList.value.value = res.data.productValue.map((ree): AttrBaseItem => {
|
|
|
+ const item = {
|
|
|
+ pic: ree.image ? [ree.image] : [],
|
|
|
+ price: ree.price,
|
|
|
+ cost: ree.cost,
|
|
|
+ ot_price: ree.ot_price,
|
|
|
+ stock: ree.stock,
|
|
|
+ detail: ree.detail,
|
|
|
+ volume: ree.volume,
|
|
|
+ bar_code: ree.bar_code,
|
|
|
+ weight: ree.weight
|
|
|
+ }
|
|
|
+ if (keyList.length > 0) {
|
|
|
+ for (let i = 0; i < keyList.length; i++) {
|
|
|
+ const key = keyList[i]
|
|
|
+ item[key] = ree[key]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return item
|
|
|
+ })
|
|
|
+ }
|
|
|
+ //加载门店
|
|
|
getStore('', data.store_id)
|
|
|
} catch (error) {
|
|
|
console.log(error, 'error')
|
|
|
@@ -432,7 +520,6 @@ const attrBase = reactive<AttrBaseItem[]>([
|
|
|
bar_code: '', //产品编号
|
|
|
cost: 0, //成本价
|
|
|
detail: {},
|
|
|
- integral: 0, //积分
|
|
|
ot_price: 0, //原价
|
|
|
pic: [], //图片
|
|
|
price: 0, //售价
|
|
|
@@ -445,7 +532,7 @@ const attrBase = reactive<AttrBaseItem[]>([
|
|
|
const productAttrList = ref<{
|
|
|
attr: any[]
|
|
|
header: any[]
|
|
|
- value: any[]
|
|
|
+ value: AttrBaseItem[]
|
|
|
}>({
|
|
|
attr: [],
|
|
|
header: [],
|
|
|
@@ -506,17 +593,22 @@ const addAttrItem = (tag: productRuleValue) => {
|
|
|
/**
|
|
|
* 生成多规格填写列表
|
|
|
*/
|
|
|
-const attrsConfirm = async () => {
|
|
|
+const attrsConfirm = async (header?: string) => {
|
|
|
const { data } = await getAttrSelectList(formData.id || 0, actionAttrs)
|
|
|
- const attrs = {
|
|
|
- attr: data.attr,
|
|
|
- header: data.header,
|
|
|
- value: data.value.map((re) => {
|
|
|
- re.pic = re.pic ? [re.pic] : []
|
|
|
- return re
|
|
|
- })
|
|
|
+ if (header == 'header') {
|
|
|
+ productAttrList.value.header = data.header
|
|
|
+ } else {
|
|
|
+ const attrs = {
|
|
|
+ attr: data.attr,
|
|
|
+ header: data.header,
|
|
|
+ value: data.value.map((re) => {
|
|
|
+ re.pic = re.pic ? [re.pic] : []
|
|
|
+ return re
|
|
|
+ })
|
|
|
+ }
|
|
|
+ productAttrList.value = attrs
|
|
|
}
|
|
|
- productAttrList.value = attrs
|
|
|
+ return true
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -549,7 +641,6 @@ const initAttrBase = () => {
|
|
|
bar_code: '', //产品编号
|
|
|
cost: 0, //成本价
|
|
|
detail: {},
|
|
|
- integral: 0, //积分
|
|
|
ot_price: 0, //原价
|
|
|
pic: [], //图片
|
|
|
price: 0, //售价
|
|
|
@@ -567,7 +658,6 @@ const batchSet = () => {
|
|
|
value[i].pic = attrBase[0].pic
|
|
|
value[i].bar_code = attrBase[0].bar_code
|
|
|
value[i].cost = attrBase[0].cost
|
|
|
- value[i].integral = attrBase[0].integral
|
|
|
value[i].price = attrBase[0].price
|
|
|
value[i].ot_price = attrBase[0].ot_price
|
|
|
value[i].stock = attrBase[0].stock
|
|
|
@@ -577,9 +667,9 @@ const batchSet = () => {
|
|
|
}
|
|
|
const upImageButtomRef = useTemplateRef('upImageButtomRef')
|
|
|
|
|
|
-const selectPic = ref<string[]>([])
|
|
|
-const selectPicIndex = ref(0)
|
|
|
-const selectPicObj = ref('header')
|
|
|
+const selectPic = ref<string[]>([]) //选中的图片
|
|
|
+const selectPicIndex = ref(0) //上传图片选择对象
|
|
|
+const selectPicObj = ref('header') //上传图片类型
|
|
|
|
|
|
/**
|
|
|
* 点击上传图片回调函数
|
|
|
@@ -856,11 +946,6 @@ const changePic = (pic: string[]) => {
|
|
|
<ElInput type="number" v-model="row.price" />
|
|
|
</template>
|
|
|
</ElTableColumn>
|
|
|
- <!-- <ElTableColumn prop="integral" label="积分">
|
|
|
- <template #default="{ row }">
|
|
|
- <ElInput type="number" v-model="row.integral" />
|
|
|
- </template>
|
|
|
- </ElTableColumn> -->
|
|
|
<ElTableColumn prop="cost" label="成本价">
|
|
|
<template #default="{ row }">
|
|
|
<ElInput type="number" v-model="row.cost" />
|
|
|
@@ -878,7 +963,7 @@ const changePic = (pic: string[]) => {
|
|
|
<ElInput type="number" v-model="row.stock" />
|
|
|
</template>
|
|
|
</ElTableColumn>
|
|
|
- <ElTableColumn prop="bar_code" label="产品编号">
|
|
|
+ <!-- <ElTableColumn prop="bar_code" label="产品编号">
|
|
|
<template #default="{ row }">
|
|
|
<ElInput v-model="row.bar_code" />
|
|
|
</template>
|
|
|
@@ -892,7 +977,7 @@ const changePic = (pic: string[]) => {
|
|
|
<template #default="{ row }">
|
|
|
<ElInput v-model="row.volume" />
|
|
|
</template>
|
|
|
- </ElTableColumn>
|
|
|
+ </ElTableColumn> -->
|
|
|
<ElTableColumn fixed="right" label="操作" width="140px">
|
|
|
<BaseButton link type="primary" @click="batchSet"> 批量设置 </BaseButton>
|
|
|
<ElDivider direction="vertical" />
|