立减金

This commit is contained in:
zhangguoping 2024-09-02 19:44:05 +08:00
parent fb3024396f
commit e574bfff15
1 changed files with 55 additions and 16 deletions

View File

@ -161,7 +161,7 @@
</template>
<script lang="ts">
import "./index.scss";
import { DETAIL_QUERY, EXCHANGE } from "@/router/api";
import { DETAIL_QUERY, EXCHANGE, ORDER_QUERY } from "@/router/api";
let goodsDetail = 0,
goodsCount = 0;
@ -186,20 +186,25 @@ export default {
},
};
},
async created() {
this.goodsID = localStorage.getItem("id") || 810;
const { code, data } = await DETAIL_QUERY({ id: this.goodsID });
if (code === 200) {
Object.assign(this.info, data.info, {
time_limit: data.info.time_limit
? JSON.parse(data.info.time_limit)
: {},
card_type: data.info.card_type || ["1"],
});
Object.assign(this.goods, data.goods);
}
created() {
this.getData();
},
methods: {
async getData() {
this.goodsID = localStorage.getItem("id") || 810;
const { code, data } = await DETAIL_QUERY({ id: this.goodsID });
if (code === 200) {
Object.assign(this.info, data.info, {
time_limit: data.info.time_limit
? JSON.parse(data.info.time_limit)
: {},
card_type: data.info.card_type
? JSON.parse(data.info.card_type)
: ["1"],
});
Object.assign(this.goods, data.goods);
}
},
cardType(val: any[]) {
return val
.map((item) => {
@ -238,9 +243,43 @@ export default {
name: "123",
};
const res = await EXCHANGE(params);
// if(res.code === 200) {
// }
if (res.code === 200 && res.data.length) {
const data = res.data[0];
if (data.code === 0) {
// window.location.href = data.path;
self.orderPolling();
} else {
showToast(data.message);
}
// res.data.forEach(item => {
// if(item.id === self.goodsID && item.code != 0) {
// showToast(self.message)
// }
// })
} else {
showToast(res.message);
}
},
async orderPolling() {
const that = this;
const params = {
key: localStorage.getItem("key"),
id: [localStorage.getItem("id")],
};
const res = await ORDER_QUERY();
if (res && res.code === 200) {
if (res.data.status === 2) {
return await this.getData();
} else {
setTimeout(() => {
that.orderPolling();
}, 3000);
}
} else {
setTimeout(() => {
that.orderPolling();
}, 3000);
}
},
/* 公众号领取 */