web-retail-admin/src/views/goodsManage/goodsRelease/ggmx.vue

918 lines
28 KiB
Vue

<!--
* @Descripttion:
* @version:
* @Author: kBank
* @Date: 2022-11-04 09:04:48
-->
<!--
* @Descripttion:
* @version:
* @Author: kBank
* @Date: 2022-11-02 17:07:29
-->
<template>
<div class="ggmx">
<div class="tit">{{ '规格明细' }}</div>
<div v-for="(item, index) in goodList" :key="index" class="goodsAll">
<div class="goods_t">
<div class="goods_tit">
<div class="goods_tit_1">{{ item.productName }}</div>
<div class="goods_tit_2">
{{ '产品编码' }}:{{ item.productCode }}
</div>
<div class="goods_tit_3">({{ item.isGift ? "销售" : "赠品" }})</div>
</div>
<div class="goods_btm">
<el-form label-width="auto">
<el-form-item
v-for="(child, cindex) in item.specsTypeData"
:key="cindex"
:label="child.typeName"
>
<el-checkbox-group v-model="item.checked">
<el-checkbox
v-for="(sld, sindex) in child.specsList"
:key="sld.specsId"
:label="sld.specsId"
@change="
getCheckBox(
$event,
item.productId,
child.pkId,
sld,
item.isGift
)
"
>{{ sld.value }}</el-checkbox>
</el-checkbox-group>
</el-form-item>
</el-form>
</div>
</div>
<div v-show="item.allSel" class="goods_b">
<div class="pl">
<el-row type="flex" justify="end" :gutter="20">
<el-col :span="2">
<div style="line-height: 40px">{{ '批量处理' }}</div>
</el-col>
<el-col :span="2">
<el-input
v-model="item.price"
clearable
size="medium"
:placeholder="'产品价格'"
/>
</el-col>
<el-col v-if="specialArea == 31" :span="2">
<el-input
v-model="item.vipPrice"
clearable
size="medium"
placeholder="会员价"
/>
</el-col>
<el-col v-if="specialArea == 31" :span="2">
<el-input
v-model="item.retailPriced"
clearable
size="medium"
placeholder="零售价"
/>
</el-col>
<el-col :span="2">
<el-input
v-model="item.integral"
clearable
size="medium"
:placeholder="'产品业绩'"
/>
</el-col>
<el-col :span="2">
<el-input
v-model="item.assAchieve"
clearable
size="medium"
:placeholder="specialArea == 40 ? 'EV' : 'BV'"
/>
</el-col>
<el-col :span="2">
<el-select v-model="item.sj" size="medium">
<el-option
v-for="item in agreeList"
:key="item.val"
:label="item.text"
:value="item.val"
/>
</el-select>
</el-col>
<!-- <el-col :span="2">
<el-select clearable v-model="item.xs">
<el-option v-for="item in agreeList"
:key="item.val"
:label="item.text"
:value="item.val"></el-option>
</el-select>
</el-col> -->
<el-col :span="3">
<el-button
type="primary"
@click="plcz(item.productId, item.isGift)"
>{{ '批量操作' }}</el-button>
</el-col>
</el-row>
</div>
<!-- <div class="goods_t"></div> -->
<el-table
ref="multipleTable"
:data="item.showList"
style="width: 100%"
:header-cell-style="{ background: '#EEEEEE' }"
:row-class-name="tableRowClassName"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" />
<el-table-column
align="center"
width="200"
prop="productCover"
label="产品图片"
>
<template slot-scope="scope">
<!-- <img class="bgImg"
:src="scope.row.productCover"
alt="" /> -->
<imageUpload v-model="scope.row.specCover" />
</template>
</el-table-column>
<el-table-column
align="center"
prop="productName"
:label="'产品名称'"
/>
<el-table-column
v-for="(ctm, index) in item.titName"
:key="index"
:label="ctm"
align="center"
>
<template slot-scope="scope">
<div v-show="index == 0">{{ scope.row.value0 }}</div>
<div v-show="index == 1">{{ scope.row.value1 }}</div>
<div v-show="index == 2">{{ scope.row.value2 }}</div>
<div v-show="index == 3">{{ scope.row.value3 }}</div>
<div v-show="index == 4">{{ scope.row.value4 }}</div>
<div v-show="index == 5">{{ scope.row.value5 }}</div>
</template>
</el-table-column>
<el-table-column align="center" prop="retailPriceTmp" label="划线价" />
<el-table-column align="center" prop="quantity" label="数量" />
<el-table-column
align="center"
prop="productPrice"
:label="'产品金额'"
>
<template slot-scope="scope">
<el-input
v-model="scope.row.productPrice"
clearable
size="medium"
:placeholder="'请输入'"
/>
</template>
</el-table-column>
<el-table-column
v-if="specialArea == 31"
align="center"
prop="vipPrice"
label="会员价"
>
<template slot-scope="scope">
<el-input
v-model="scope.row.vipPrice"
clearable
size="medium"
:placeholder="'请输入'"
/>
</template>
</el-table-column>
<el-table-column
v-if="specialArea == 31"
align="center"
prop="retailPrice"
label="零售价"
>
<template slot-scope="scope">
<el-input
v-model="scope.row.retailPrice"
clearable
size="medium"
:placeholder="'请输入'"
/>
</template>
</el-table-column>
<el-table-column
align="center"
prop="productAchieve"
label="*产品业绩/PV($)"
>
<template slot-scope="scope">
<el-input
v-model="scope.row.productAchieve"
clearable
size="medium"
:placeholder="'请输入'"
/>
</template>
</el-table-column>
<el-table-column
align="center"
prop="assAchieve"
:label="specialArea == 40 ? 'EV($)' : 'BV'"
>
<template slot-scope="scope">
<el-input
v-model="scope.row.assAchieve"
clearable
size="medium"
:placeholder="'请输入'"
/>
</template>
</el-table-column>
<el-table-column
align="center"
prop="isPutOn"
:label="'上架状态'"
>
<template slot-scope="scope">
<el-select v-model="scope.row.isPutOn" size="medium">
<el-option
v-for="item in agreeList"
:key="item.val"
:label="item.text"
:value="item.val"
/>
</el-select>
</template>
</el-table-column>
<!-- <el-table-column align="center"
prop="code"
label="编码">
<template slot-scope="scope">
<el-input clearable v-model="scope.row.code"
placeholder="请输入编码"></el-input>
</template>
</el-table-column> -->
<!-- <el-table-column align="center"
prop="status"
:label="'销售状态'">
<template slot-scope="scope">
<el-select clearable v-model="scope.row.status">
<el-option v-for="item in agreeList"
:key="item.val"
:label="item.text"
:value="item.val"></el-option>
</el-select>
</template>
</el-table-column> -->
</el-table>
</div>
</div>
</div>
</template>
<script>
import { getProductSpecsIsGift } from '@/api/product.js'
// import SkuForm from 'vue-sku-form'
import { mapGetters } from 'vuex'
import ImageUpload from '@/components/ImageUpload'
export default {
name: 'Ggmx',
components: {
// SkuForm,
ImageUpload
},
computed: {
...mapGetters(['productIds'])
},
watch: {
goodList: {
handler(newVal, oldVal) {
// console.log('%c [ newVal ]-193', 'font-size:13px; background:#55e8eb; color:#99ffff;', newVal)
this.$emit('getGoodList', newVal, this.copyArr)
// this.fixThing()
},
deep: true // 加这个属性,深度监听
}
},
data() {
return {
uploadUrl: process.env.VUE_APP_BASE_API + '/manage/upload', // 上传的图片服务器地址
agreeList: [
{
text: '允许',
val: 0
},
{
text: '禁止',
val: 1
}
],
form: {
specsList: [],
price: '',
productAchieve: '',
sj: '',
xs: '',
integral: '',
assAchieve: ''
},
// 批量操作选中数据
selCheckList: [],
// productIds: [],
goodList: [
{
checked: []
}
],
allData: [],
copyArr: [],
specialArea: ''
}
},
mounted() {
// this.getData()
},
methods: {
getSpecial(val) {
this.specialArea = val
},
// getInput() {
// console.log(
// '%c [ this.goodList ]-221',
// 'font-size:13px; background:#22dbd8; color:#66ffff;',
// this.goodList
// )
// this.goodList.forEach((aTem) => {
// aTem.showList.forEach((sTem) => {
// console.log('%c [ sTem ]-226', 'font-size:13px; background:#906a44; color:#d4ae88;', sTem)
// })
// })
// },
// 单选时组装数组
getCheckBox(check, goodsId, pkId, sld, isGift) {
// console.log(
// '%c [ pkId ]-251',
// 'font-size:13px; background:#faa398; color:#ffe7dc;',
// pkId
// )
// console.log(
// '%c [ check ]-251',
// 'font-size:13px; background:#a31ffb; color:#e763ff;',
// check
// )
if (check) {
this.allData.forEach((aTem) => {
if (aTem.productId == goodsId && aTem.isGift == isGift) {
aTem.titName = []
aTem.selList.forEach((sTem, sIex) => {
if (sTem.selData.indexOf(sTem.typeName) == -1) {
aTem.titName.push(sTem.typeName)
}
if (sTem.pkId == pkId && sTem.selData.indexOf(sld) == -1) {
sTem.selData.push(
Object.assign(
{},
{
productCode: aTem.productCode,
productCover: aTem.productCover,
productId: aTem.productId,
isGift: aTem.isGift,
productName: aTem.productName
},
{ typeName: sTem.typeName, pkId: sTem.pkId },
sld
)
)
}
})
}
})
} else {
this.allData.forEach((aTem) => {
if (aTem.productId == goodsId && aTem.isGift == isGift) {
aTem.selList.forEach((sTem, sIex) => {
if (sTem.pkId == pkId) {
sTem.selData.splice(
sTem.selData.findIndex(
(sstem) => sstem.specsId === sld.specsId
),
1
)
}
})
}
})
}
// this.allData
// console.log(
// '%c [ this.allData ]-305',
// 'font-size:13px; background:#64aee9; color:#a8f2ff;',
// this.allData
// )
this.pushArr(goodsId, isGift)
},
// 把组装好的数组放入大数组去笛卡尔
pushArr(goodsId, isGift) {
this.allData.forEach((aTem) => {
if (aTem.productId == goodsId && aTem.isGift == isGift) {
aTem.checkList = []
aTem.selList.forEach((sTem, sIex) => {
aTem.checkList.push(sTem.selData)
})
}
})
this.runFunc(goodsId, isGift)
},
// 笛卡尔重组
runFunc(goodsId, isGift) {
this.allData.forEach((aTem) => {
if (aTem.productId == goodsId && aTem.isGift == isGift) {
aTem.checkList = this.calcDescartes(aTem.checkList)
}
})
this.goodList.forEach((item) => {
if (item.productId == goodsId && item.isGift == isGift) {
item.checkList = []
this.allData.forEach((aTem) => {
if (aTem.productId == goodsId && aTem.isGift == isGift) {
aTem.checkList.forEach((cTem) => {
if (item.pkId == aTem.pkid) {
item.checkList.push(cTem)
item.titName = aTem.titName
}
})
}
})
}
})
this.goodList.forEach((item, fdex) => {
if (item.productId == goodsId && item.isGift == isGift) {
item.showList = []
item.checkList.forEach((ctem, cdex) => {
ctem.assn = {}
ctem.waresSpecsList = []
if (ctem.forEach) {
ctem.forEach((cld, index) => {
this.$set(
this.goodList[fdex].checkList[cdex],
'productPrice',
''
)
this.$set(this.goodList[fdex].checkList[cdex], 'vipPrice', '')
this.$set(
this.goodList[fdex].checkList[cdex],
'retailPrice',
''
)
// this.$set(this.goodList[fdex].checkList[cdex], 'code', '')
this.$set(this.goodList[fdex].checkList[cdex], 'isPutOn', 0)
this.$set(
this.goodList[fdex].checkList[cdex],
'productAchieve',
''
)
this.$set(
this.goodList[fdex].checkList[cdex],
'assAchieve',
''
)
cld.productPrice = ''
cld.retailPrice = ''
cld.vipPrice = ''
cld.productAchieve = ''
cld.assAchieve = ''
cld.isPutOn = 0
cld.status = ''
cld.pkProduct = cld.productId
cld.quantity = item.quantity
cld.retailPriceTmp = item.retailPriceTmp
cld.isGift = cld.isGift
ctem.waresSpecsList.push({
pkSpecs: cld.specsId,
pkSpecsType: cld.pkSpecsType
})
if (index == 0) {
cld.value0 = cld.value
cld.pkId0 = cld.pkId
cld.specsId0 = cld.specsId
cld.typeName0 = cld.typeName
cld.pkSpecsType0 = cld.pkSpecsType
}
if (index == 1) {
cld.value1 = cld.value
cld.pkId1 = cld.pkId
cld.specsId1 = cld.specsId
cld.typeName1 = cld.typeName
cld.pkSpecsType1 = cld.pkSpecsType
}
if (index == 2) {
cld.value2 = cld.value
cld.pkId2 = cld.pkId
cld.specsId2 = cld.specsId
cld.typeName2 = cld.typeName
cld.pkSpecsType2 = cld.pkSpecsType
}
if (index == 3) {
cld.value3 = cld.value
cld.pkId3 = cld.pkId
cld.specsId3 = cld.specsId
cld.typeName3 = cld.typeName
cld.pkSpecsType3 = cld.pkSpecsType
}
if (index == 4) {
cld.value4 = cld.value
cld.pkId4 = cld.pkId
cld.specsId4 = cld.specsId
cld.typeName4 = cld.typeName
cld.pkSpecsType4 = cld.pkSpecsType
}
if (index == 5) {
cld.value5 = cld.value
cld.pkId5 = cld.pkId
cld.specsId5 = cld.specsId
cld.typeName5 = cld.typeName
cld.pkSpecsType5 = cld.pkSpecsType
}
item.showList.push(
Object.assign(ctem.assn, cld, {
waresSpecsList: ctem.waresSpecsList
})
)
// item.showList[cdex].waresSpecsList.push(cld.waresSpecs)
})
} else {
ctem.waresSpecsList = [
{
pkSpecs: ctem.specsId,
pkSpecsType: ctem.pkSpecsType
}
]
this.$set(
this.goodList[fdex].checkList[cdex],
'productPrice',
''
)
this.$set(this.goodList[fdex].checkList[cdex], 'retailPrice', '')
this.$set(this.goodList[fdex].checkList[cdex], 'vipPrice', '')
// this.$set(this.goodList[fdex].checkList[cdex], 'code', '')
this.$set(this.goodList[fdex].checkList[cdex], 'isPutOn', 0)
this.$set(this.goodList[fdex].checkList[cdex], 'assAchieve', 0)
this.$set(
this.goodList[fdex].checkList[cdex],
'productAchieve',
0
)
// this.$set(this.goodList[index].checkList[cdex], 'productPrice', '')
// this.$set(this.goodList[index].checkList[cdex], 'productPrice', '')
// this.$set(item.checkList, ctem.integral, '')
// this.$set(item.checkList, ctem.isPutOn, '')
// this.$set(item.checkList, ctem.status, '')
ctem.pkProduct = ctem.productId
ctem.quantity = item.quantity
ctem.retailPriceTmp = item.retailPriceTmp
ctem.isGift = ctem.isGift
ctem.value0 = ctem.value
ctem.pkId0 = ctem.pkId
ctem.specsId0 = ctem.specsId
ctem.typeName0 = ctem.typeName
ctem.pkSpecsType0 = ctem.pkSpecsType
item.showList.push(ctem)
}
})
}
})
this.goodList.forEach((item) => {
if (item.productId == goodsId && item.isGift == isGift) {
item.showList = this.unique(item.showList)
if (item.showList.length > 0 && item.showList[0].pkId0) {
item.allSel = true
} else {
item.allSel = false
}
}
})
this.goodList.forEach((item) => {
item.sj = this.agreeList[0].val
if (item.showList) {
item.showList.forEach((cld) => {
cld.specsIdList = [
cld.specsId0,
cld.specsId1,
cld.specsId2,
cld.specsId3,
cld.specsId4,
cld.specsId5
].filter(Boolean)
})
}
})
this.copyArr = JSON.parse(JSON.stringify(this.allData))
this.$forceUpdate()
},
// // 传参格式
// fixThing() {
// let waresSpecsSkuList = []
// this.goodList.forEach((item) => {
// waresSpecsSkuList.push(...item.showList)
// })
// console.log(
// '%c [ waresSpecsSkuList ]-457',
// 'font-size:13px; background:#2fda2e; color:#73ff72;',
// waresSpecsSkuList
// )
// },
// 数组对象去重
unique(arr) {
for (var i = 0; i < arr.length; i++) {
// 首次遍历数组
for (var j = i + 1; j < arr.length; j++) {
// 再次遍历数组
if (arr[i] == arr[j]) {
// 判断连个值是否相等
arr.splice(j, 1) // 相等删除后者
j--
}
}
}
return arr
},
calcDescartes(array) {
// if (array.length < 2) return array[0] || []
return array.reduce((total, currentValue) => {
const res = []
// if (total.length == 0) {
// res.push([cv])
// }
total.forEach((t) => {
if (currentValue.length > 0) {
currentValue.forEach((cv) => {
if (t instanceof Array)
// 或者使用 Array.isArray(t)
{ res.push([...t, cv]) } else res.push([t, cv])
})
} else {
res.push([t])
}
})
return res
})
},
handleSelectionChange(val) {
this.selCheckList = val
},
plcz(productId, isGift) {
this.goodList.forEach((item, index) => {
this.selCheckList.forEach((cld, cndx) => {
if (item.showList) {
item.showList.forEach((sld, sndex) => {
if (
item.productId == productId &&
item.isGift == isGift &&
sld.specsIdList.sort().toString() ==
cld.specsIdList.sort().toString()
) {
if (item.price) {
sld.productPrice = item.price
this.$set(
this.goodList[index].showList[sndex],
'productPrice',
item.price
)
this.$forceUpdate()
}
if (item.retailPriced) {
sld.retailPrice = item.retailPriced
this.$set(
this.goodList[index].showList[sndex],
'retailPrice',
item.retailPriced
)
this.$forceUpdate()
}
if (item.vipPrice) {
sld.vipPrice = item.vipPrice
this.$set(
this.goodList[index].showList[sndex],
'vipPrice',
item.vipPrice
)
this.$forceUpdate()
}
if (item.integral) {
sld.productAchieve = item.integral
this.$set(
this.goodList[index].showList[sndex],
'productAchieve',
item.integral
)
this.$forceUpdate()
}
if (item.assAchieve) {
sld.assAchieve = item.assAchieve
this.$set(
this.goodList[index].showList[sndex],
'assAchieve',
item.assAchieve
)
this.$forceUpdate()
}
if (item.productAchieve) {
sld.productAchieve = item.productAchieve
}
if (item.sj != '' || item.sj != undefined) {
// console.log(
// '%c [ item.sj ]-555',
// 'font-size:13px; background:#2d4cc6; color:#7190ff;',
// item.sj
// )
sld.isPutOn = item.sj
this.$set(
this.goodList[index].showList[sndex],
'isPutOn',
item.sj
)
this.$forceUpdate()
}
if (item.xs) {
sld.status = item.xs
}
// this.$set(this.goodList[index].showList[sndex], isPutOn, item.sj)
}
this.$set(this.goodList[index].showList, sndex, sld)
})
}
// if (item.productId == productId) {
// if (item.price != '') {
// cld.price = item.price
// }
// if (item.integral != '') {
// cld.integral = item.integral
// }
// if (item.sj != '') {
// cld.isPutOn = item.sj
// }
// if (item.xs != '') {
// cld.status = item.xs
// }
// }
})
})
// this.selCheckList
// console.log(this.$refs.multipleTable)
// this.$set('this','goodList',this.goodList)
this.$forceUpdate()
this.$nextTick(() => {
for (var i = 0; i < this.$refs.multipleTable.length; i++) {
this.$refs.multipleTable[i].clearSelection()
}
})
},
compareArrays(arr1, arr2) {
if (arr1.length !== arr2.length) {
return false
}
for (let i = 0; i < arr1.length; i++) {
if (arr1[i] !== arr2[i]) {
return false
}
}
return true
},
getData(data, specialArea) {
this.specialArea = specialArea
if (this.productIds.length > 0) {
const a = this.compareArrays(this.productIds, data)
if (a) {
} else {
this.getList(data)
this.$store.commit('settings/GGMX_SETTING', data)
}
} else {
this.getList(data)
this.$store.commit('settings/GGMX_SETTING', data)
}
},
getList(data) {
getProductSpecsIsGift({ productGiftList: data }).then((res) => {
const arr = res.data
// 获取数据重组数组
const allData = []
arr.forEach((item, index) => {
item.checked = []
allData.push({
productId: item.productId,
productCode: item.productCode,
productCover: item.productCover,
productName: item.productName,
selList: [],
isGift: item.isGift
})
item.specsTypeData.forEach((cld) => {
allData[index].selList.push({
pkId: cld.pkId,
typeName: cld.typeName,
selData: []
})
})
})
this.allData = allData
this.goodList = arr
})
},
tableRowClassName({ row, rowIndex }) {
if (rowIndex % 2 == 1) {
return 'warning-row'
} else if (rowIndex % 2 == 0) {
return 'success-row'
}
return ''
}
}
}
</script>
<style scoped lang="scss">
::v-deep .el-form-item {
margin-bottom: 0;
}
.ggmx {
margin-left: -20px;
.goodsAll {
padding: 0 20px;
.goods_t {
margin-bottom: 20px;
background: #ffffff;
box-shadow: 0px 1px 20px 0px rgba(#ccc, 0.3);
border-radius: 8px;
.goods_tit {
display: flex;
padding: 20px;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
.goods_tit_1 {
font-size: 14px;
font-weight: bold;
color: #333333;
margin-right: 40px;
}
.goods_tit_2 {
font-size: 14px;
color: #666666;
}
.goods_tit_3 {
font-size: 14px;
color: #aa3931;
margin-left: 20px;
}
}
.goods_btm {
padding: 0 20px;
}
}
}
}
.tit {
font-size: 14px;
font-weight: bold;
color: #333333;
padding: 10px 20px 0 20px;
border-left: 5px solid #4391fd;
margin-bottom: 9px;
}
.bgImg {
width: 48px;
height: 48px;
}
.pl {
margin-bottom: 20px;
}
.goods_b {
margin-bottom: 30px;
}
// ::v-deep .el-table .cell{
// overflow: auto;
// }
::v-deep .el-input__suffix {
top: -3px;
}
::v-deep .el-select .el-input__suffix {
top: 5px;
}
</style>