修改在已有秒杀商品情况下添加新的秒杀商品 数据保存错误问题

master
pikachu 2021-08-16 19:54:18 +08:00
parent f33efac045
commit db919a57f3
1 changed files with 293 additions and 265 deletions

View File

@ -74,7 +74,7 @@
v-if="row.promotionApplyStatus == 'REFUSE'"
@click="showReason(row.failReason)"
class="reason"
>拒绝原因</span
>拒绝原因</span
>
<Badge
status="error"
@ -99,7 +99,8 @@
size="small"
ghost
@click="delGoods(index, row)"
>删除</Button
>删除
</Button
>
</template>
</Table>
@ -114,7 +115,8 @@
:loading="submitLoading"
v-if="promotionStatus === 'NEW'"
@click="save"
>提交</Button
>提交
</Button
>
</Row>
</Card>
@ -126,279 +128,305 @@
</div>
</template>
<script>
import {
seckillGoodsList,
seckillDetail,
setSeckillGoods,
delSeckillGoods
} from "@/api/promotion.js";
import skuSelect from "@/views/lili-dialog";
export default {
components: {
skuSelect,
},
data() {
return {
promotionStatus: "", //
loading: false, //
searchForm: {
//
pageNumber: 0, //
pageSize: 1000, //
},
tabIndex: 0, //
submitLoading: false, //
selectList: [], //
selectCount: 0, //
data: [{}], //
columns: [
{
title: "活动名称",
key: "promotionName",
minWidth: 120,
},
{
title: "活动开始时间",
key: "startTime",
},
{
title: "报名截止时间",
slot: "applyEndTime",
},
{
title: "时间场次",
slot: "hours",
},
],
goodsColumns: [
{
title: "商品名称",
key: "goodsName",
minWidth: 120,
},
{
title: "商品价格",
slot: "originalPrice",
minWidth: 50,
},
{
title: "库存",
slot: "quantity",
minWidth: 40,
},
{
title: "活动价格",
slot: "price",
minWidth: 50,
},
{
title: "状态",
slot: "promotionApplyStatus",
minWidth: 30,
},
{
title: "操作",
slot: "action",
minWidth: 50,
},
],
goodsList: [] //
};
},
methods: {
//
closeCurrentPage() {
this.$store.commit("removeTag", "seckill-goods");
localStorage.storeOpenedList = JSON.stringify(
this.$store.state.app.storeOpenedList
);
this.$router.go(-1);
},
//
save() {
import {
seckillGoodsList,
seckillDetail,
setSeckillGoods,
delSeckillGoods
} from "@/api/promotion.js";
import skuSelect from "@/views/lili-dialog";
let list = JSON.parse(JSON.stringify(this.goodsList));
let params = {
seckillId: this.$route.query.id,
applyVos: [],
export default {
components: {
skuSelect,
},
data() {
return {
promotionStatus: "", //
loading: false, //
searchForm: {
//
pageNumber: 0, //
pageSize: 1000, //
},
tabIndex: 0, //
submitLoading: false, //
selectList: [], //
selectCount: 0, //
data: [{}], //
columns: [
{
title: "活动名称",
key: "promotionName",
minWidth: 120,
},
{
title: "活动开始时间",
key: "startTime",
},
{
title: "报名截止时间",
slot: "applyEndTime",
},
{
title: "时间场次",
slot: "hours",
},
],
goodsColumns: [
{
title: "商品名称",
key: "goodsName",
minWidth: 120,
},
{
title: "商品价格",
slot: "originalPrice",
minWidth: 50,
},
{
title: "库存",
slot: "quantity",
minWidth: 40,
},
{
title: "活动价格",
slot: "price",
minWidth: 50,
},
{
title: "状态",
slot: "promotionApplyStatus",
minWidth: 30,
},
{
title: "操作",
slot: "action",
minWidth: 50,
},
],
goodsList: [] //
};
list.forEach((e, index) => {
e.list.forEach((i) => {
// if(e.id) delete e.id
params.applyVos.push(i);
});
});
this.submitLoading = true;
setSeckillGoods(params).then((res) => {
this.submitLoading = false;
if (res && res.success) {
this.$Message.success("提交活动商品成功");
this.closeCurrentPage();
}
});
},
//
init() {
this.getSeckillMsg();
},
//
clearSelectAll() {
this.$refs.table.selectAll(false);
},
//
changeSelect(e) {
this.selectList = e;
this.selectCount = e.length;
},
methods: {
//
closeCurrentPage() {
this.$store.commit("removeTag", "seckill-goods");
localStorage.storeOpenedList = JSON.stringify(
this.$store.state.app.storeOpenedList
);
this.$router.go(-1);
},
//
save() {
getDataList() {
//
this.loading = true;
this.searchForm.seckillId = this.$route.query.id;
// 1:00
let hours = this.unixHours(this.data[0].hours);
hours.forEach((e) => {
this.goodsList.push({
hour: e,
list: [],
});
});
seckillGoodsList(this.searchForm).then((res) => {
this.loading = false;
if (res.success && res.result) {
let data = res.result.records;
// '1'
let noFilterhours = this.data[0].hours.split(",");
if (data.length) {
noFilterhours.forEach((e, index) => {
data.forEach((i) => {
if (i.timeLine == e) {
this.goodsList[index].list.push(i);
}
});
});
}
}
});
},
let list = JSON.parse(JSON.stringify(this.goodsList));
getSeckillMsg() {
//
seckillDetail(this.$route.query.id).then((res) => {
if (res.success && res.result) {
this.data = [];
this.data.push(res.result);
this.promotionStatus = res.result.promotionStatus;
this.getDataList();
}
});
},
delGoods(index, row) {
//
if (row.promotionApplyStatus === 'PASS') {
const params = {
seckillId: row.seckillId,
id: row.id
}
delSeckillGoods(params).then(res => {
if (res.success) {
this.goodsList[this.tabIndex].list.splice(index, 1);
this.$Message.success("删除成功!");
}
})
} else {
this.goodsList[this.tabIndex].list.splice(index, 1);
this.$Message.success("删除成功!");
}
},
selectedGoodsData(item) {
//
let list = [];
console.log(item);
item.forEach((e) => {
list.push({
goodsName: e.goodsName,
price: e.price,
originalPrice: e.price,
promotionApplyStatus: e.promotionApplyStatus || '',
quantity: e.quantity,
console.warn(list)
let params = {
seckillId: this.$route.query.id,
storeId: e.storeId,
storeName: e.storeName,
skuId: e.id,
timeLine: this.data[0].hours.split(",")[this.tabIndex],
applyVos: [],
};
list.forEach((e, index) => {
e.list.forEach((i) => {
// if(e.id) delete e.id
params.applyVos.push(i);
});
});
});
this.submitLoading = true;
this.goodsList[this.tabIndex].list = list;
this.$nextTick(()=> {
this.$forceUpdate()
})
},
openSkuList() { //
this.$refs.skuSelect.open("goods");
let data = JSON.parse(JSON.stringify(this.goodsList[this.tabIndex].list))
data.forEach(e => {
e.id = e.skuId
})
this.$refs.skuSelect.goodsData = data;
},
unixDate(time) {
//
return this.$options.filters.unixToDate(new Date(time) / 1000);
},
unixHours(item) {
if (item) {
//
let hourArr = item.split(",");
for (let i = 0; i < hourArr.length; i++) {
hourArr[i] += ":00";
console.log(list)
setSeckillGoods(params).then((res) => {
this.submitLoading = false;
if (res && res.success) {
this.$Message.success("提交活动商品成功");
this.closeCurrentPage();
}
});
},
//
init() {
this.getSeckillMsg();
},
//
clearSelectAll() {
this.$refs.table.selectAll(false);
},
//
changeSelect(e) {
this.selectList = e;
this.selectCount = e.length;
},
getDataList() {
//
this.loading = true;
this.searchForm.seckillId = this.$route.query.id;
// 1:00
let hours = this.unixHours(this.data[0].hours);
hours.forEach((e) => {
this.goodsList.push({
hour: e,
list: [],
});
});
seckillGoodsList(this.searchForm).then((res) => {
this.loading = false;
if (res.success && res.result) {
let data = res.result.records;
// '1'
let noFilterhours = this.data[0].hours.split(",");
if (data.length) {
noFilterhours.forEach((e, index) => {
data.forEach((i) => {
if (i.timeLine == e) {
this.goodsList[index].list.push(i);
}
});
});
}
}
});
},
getSeckillMsg() {
//
seckillDetail(this.$route.query.id).then((res) => {
if (res.success && res.result) {
this.data = [];
this.data.push(res.result);
this.promotionStatus = res.result.promotionStatus;
this.getDataList();
}
});
},
delGoods(index, row) {
//
if (row.promotionApplyStatus === 'PASS') {
const params = {
seckillId: row.seckillId,
id: row.id
}
delSeckillGoods(params).then(res => {
if (res.success) {
this.goodsList[this.tabIndex].list.splice(index, 1);
this.$Message.success("删除成功!");
}
})
} else {
this.goodsList[this.tabIndex].list.splice(index, 1);
this.$Message.success("删除成功!");
}
return hourArr;
},
selectedGoodsData(item) {
//
item.forEach((e) => {
if(this.goodsList[this.tabIndex].list.length == 0){
this.goodsList[this.tabIndex].list.push({
goodsName: e.goodsName,
price: e.price,
originalPrice: e.price,
promotionApplyStatus: e.promotionApplyStatus || '',
quantity: e.quantity,
seckillId: this.$route.query.id,
storeId: e.storeId,
storeName: e.storeName,
skuId: e.id,
timeLine: this.data[0].hours.split(",")[this.tabIndex],
});
}else{
this.goodsList[this.tabIndex].list.forEach(goods => {
if (e.id != goods.skuId) {
this.goodsList[this.tabIndex].list.push(
{
goodsName: e.goodsName,
price: e.price,
originalPrice: e.price,
promotionApplyStatus: e.promotionApplyStatus || '',
quantity: e.quantity,
seckillId: this.$route.query.id,
storeId: e.storeId,
storeName: e.storeName,
skuId: e.id,
timeLine: this.data[0].hours.split(",")[this.tabIndex],
}
)
}
})
}
})
this.$nextTick(() => {
this.$forceUpdate()
})
},
openSkuList() { //
this.$refs.skuSelect.open("goods");
let data = JSON.parse(JSON.stringify(this.goodsList[this.tabIndex].list))
data.forEach(e => {
e.id = e.skuId
})
this.$refs.skuSelect.goodsData = data;
},
unixDate(time) {
//
return this.$options.filters.unixToDate(new Date(time) / 1000);
},
unixHours(item) {
if (item) {
//
let hourArr = item.split(",");
for (let i = 0; i < hourArr.length; i++) {
hourArr[i] += ":00";
}
return hourArr;
}
return [];
},
//
promotionApplyStatus(key) {
switch (key) {
case "APPLY":
return "申请";
case "PASS":
return "通过";
case "REFUSE":
return "拒绝";
default:
return "未申请";
}
},
//
showReason(reason) {
this.$Modal.info({
title: "拒绝原因",
content: reason,
});
},
},
mounted() {
this.init();
},
// keepAlivetrue
beforeRouteLeave(to, from, next) {
if (to.name === 'seckill') {
to.meta.keepAlive = true
}
return [];
},
//
promotionApplyStatus(key) {
switch (key) {
case "APPLY":
return "申请";
case "PASS":
return "通过";
case "REFUSE":
return "拒绝";
default:
return "未申请";
}
},
//
showReason(reason) {
this.$Modal.info({
title: "拒绝原因",
content: reason,
});
},
},
mounted() {
this.init();
},
// keepAlivetrue
beforeRouteLeave(to, from, next){
if(to.name === 'seckill') {
to.meta.keepAlive = true
next()
}
next()
}
};
};
</script>
<style lang="scss" scoped>
.operation {
margin: 10px 0;
}
.reason {
cursor: pointer;
color: #2d8cf0;
font-size: 12px;
}
.operation {
margin: 10px 0;
}
.reason {
cursor: pointer;
color: #2d8cf0;
font-size: 12px;
}
</style>