|
|
@ -1,12 +1,10 @@ |
|
|
import { |
|
|
|
|
|
axios |
|
|
|
|
|
} from '../../js/libs' |
|
|
|
|
|
const app = getApp() |
|
|
|
|
|
|
|
|
import { axios } from "../../js/libs"; |
|
|
|
|
|
const app = getApp(); |
|
|
|
|
|
|
|
|
Page({ |
|
|
Page({ |
|
|
data: { |
|
|
data: { |
|
|
showModal: false, |
|
|
showModal: false, |
|
|
shareTitle: '', |
|
|
|
|
|
|
|
|
shareTitle: "", |
|
|
mall: null, |
|
|
mall: null, |
|
|
userCouponNum: 0, |
|
|
userCouponNum: 0, |
|
|
mallCode: null, |
|
|
mallCode: null, |
|
|
@ -14,174 +12,148 @@ Page({ |
|
|
refresherTriggered: false, |
|
|
refresherTriggered: false, |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
async onLoad({ |
|
|
|
|
|
q |
|
|
|
|
|
}) { |
|
|
|
|
|
|
|
|
async onLoad({ q }) { |
|
|
if (q) { |
|
|
if (q) { |
|
|
const { |
|
|
|
|
|
mallCode, |
|
|
|
|
|
couponCode |
|
|
|
|
|
} = decodeURIComponent(q).split('?').pop().replace('q=', '').split('&').map(kv => kv.split('=')).reduce((acc, nxt) => Object.assign(acc, { |
|
|
|
|
|
[nxt[0]]: nxt[1] |
|
|
|
|
|
}), {}) |
|
|
|
|
|
|
|
|
const { mallCode, couponCode } = decodeURIComponent(q) |
|
|
|
|
|
.split("?") |
|
|
|
|
|
.pop() |
|
|
|
|
|
.replace("q=", "") |
|
|
|
|
|
.split("&") |
|
|
|
|
|
.map((kv) => kv.split("=")) |
|
|
|
|
|
.reduce( |
|
|
|
|
|
(acc, nxt) => |
|
|
|
|
|
Object.assign(acc, { |
|
|
|
|
|
[nxt[0]]: nxt[1], |
|
|
|
|
|
}), |
|
|
|
|
|
{} |
|
|
|
|
|
); |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
mallCode, |
|
|
mallCode, |
|
|
couponCode |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
couponCode, |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
const db = wx.cloud.database() |
|
|
|
|
|
|
|
|
const db = wx.cloud.database(); |
|
|
const { |
|
|
const { |
|
|
data: { |
|
|
|
|
|
value: shareTitle |
|
|
|
|
|
} |
|
|
|
|
|
} = await db.collection('config').doc('shareTitle').get() |
|
|
|
|
|
|
|
|
data: { value: shareTitle }, |
|
|
|
|
|
} = await db.collection("config").doc("shareTitle").get(); |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
shareTitle |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
getLocation() { |
|
|
|
|
|
return new Promise(resolve => { |
|
|
|
|
|
wx.getLocation({ |
|
|
|
|
|
type: 'wgs84', |
|
|
|
|
|
success: resolve |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
shareTitle, |
|
|
|
|
|
}); |
|
|
}, |
|
|
}, |
|
|
async refreshList() { |
|
|
async refreshList() { |
|
|
const mall = this.data.mall |
|
|
|
|
|
const { |
|
|
|
|
|
coupons, |
|
|
|
|
|
} = getApp() |
|
|
|
|
|
|
|
|
const mall = this.data.mall; |
|
|
|
|
|
const { coupons } = getApp(); |
|
|
if (mall) { |
|
|
if (mall) { |
|
|
const codes = await coupons.getMallCodes(mall.code) |
|
|
|
|
|
mall.coupons = codes |
|
|
|
|
|
|
|
|
const codes = await coupons.getMallCodes(mall.code); |
|
|
|
|
|
mall.coupons = codes; |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
mall |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
mall, |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
refresherTriggered: false |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
refresherTriggered: false, |
|
|
|
|
|
}); |
|
|
}, |
|
|
}, |
|
|
async onShow() { |
|
|
async onShow() { |
|
|
const { |
|
|
|
|
|
malls, |
|
|
|
|
|
coupons, |
|
|
|
|
|
} = getApp() |
|
|
|
|
|
|
|
|
const { malls, coupons } = getApp(); |
|
|
|
|
|
|
|
|
const mall = this.data.mallCode ? await malls.getMallByCode(this.data.mallCode) : await malls.getCurrentMall() |
|
|
|
|
|
const mallCode = this.data.mallCode |
|
|
|
|
|
|
|
|
const mall = this.data.mallCode |
|
|
|
|
|
? await malls.getMallByCode(this.data.mallCode) |
|
|
|
|
|
: await malls.getCurrentMall(); |
|
|
|
|
|
const mallCode = this.data.mallCode; |
|
|
if (this.data.mallCode) { |
|
|
if (this.data.mallCode) { |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
mallCode: null |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
mallCode: null, |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!mall.coupons) { |
|
|
if (!mall.coupons) { |
|
|
const codes = await coupons.getMallCodes(mall.code, mall.name) |
|
|
|
|
|
mall.coupons = codes |
|
|
|
|
|
|
|
|
const codes = await coupons.getMallCodes(mall.code, mall.name); |
|
|
|
|
|
mall.coupons = codes; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
this.setData({ |
|
|
mall |
|
|
|
|
|
}) |
|
|
|
|
|
const userCodes = await coupons.getUserCodes(-1) |
|
|
|
|
|
|
|
|
mall, |
|
|
|
|
|
}); |
|
|
|
|
|
const userCodes = await coupons.getUserCodes(-1); |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
userCouponNum: userCodes.length |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
userCouponNum: userCodes.length, |
|
|
|
|
|
}); |
|
|
if (this.data.couponCode) { |
|
|
if (this.data.couponCode) { |
|
|
|
|
|
|
|
|
this.doShowQrcodeModal({ |
|
|
this.doShowQrcodeModal({ |
|
|
mallCode, |
|
|
mallCode, |
|
|
couponCode: this.data.couponCode |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
couponCode: this.data.couponCode, |
|
|
|
|
|
}); |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
couponCode: null |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
couponCode: null, |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
async doShowQrcodeModal({ |
|
|
|
|
|
mallCode, |
|
|
|
|
|
couponCode |
|
|
|
|
|
}) { |
|
|
|
|
|
const { |
|
|
|
|
|
getOpenid, |
|
|
|
|
|
} = getApp() |
|
|
|
|
|
wx.showLoading() |
|
|
|
|
|
|
|
|
async doShowQrcodeModal({ mallCode, couponCode }) { |
|
|
|
|
|
const { getOpenid } = getApp(); |
|
|
|
|
|
wx.showLoading(); |
|
|
try { |
|
|
try { |
|
|
const openid = await getOpenid() |
|
|
|
|
|
await axios.get('/Api/Coupon/GetCoupon', { |
|
|
|
|
|
|
|
|
const openid = await getOpenid(); |
|
|
|
|
|
await axios.get("/Api/Coupon/GetCoupon", { |
|
|
couponCode, |
|
|
couponCode, |
|
|
mallCode, |
|
|
mallCode, |
|
|
"userCode": openid |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
userCode: openid, |
|
|
|
|
|
}); |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
couponName: '直播券', |
|
|
|
|
|
showModal: true |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
couponName: "直播券", |
|
|
|
|
|
showModal: true, |
|
|
|
|
|
}); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
wx.showToast({ |
|
|
wx.showToast({ |
|
|
icon: 'none', |
|
|
|
|
|
|
|
|
icon: "none", |
|
|
title: JSON.stringify(error), |
|
|
title: JSON.stringify(error), |
|
|
}) |
|
|
|
|
|
|
|
|
}); |
|
|
} finally { |
|
|
} finally { |
|
|
wx.hideLoading() |
|
|
|
|
|
|
|
|
wx.hideLoading(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
async doShowModal({ |
|
|
|
|
|
detail: { |
|
|
|
|
|
code |
|
|
|
|
|
} |
|
|
|
|
|
}) { |
|
|
|
|
|
const { |
|
|
|
|
|
getOpenid, |
|
|
|
|
|
coupons |
|
|
|
|
|
} = getApp() |
|
|
|
|
|
wx.showLoading() |
|
|
|
|
|
|
|
|
async doShowModal({ detail: { code } }) { |
|
|
|
|
|
const { getOpenid, coupons } = getApp(); |
|
|
|
|
|
wx.showLoading(); |
|
|
try { |
|
|
try { |
|
|
const openid = await getOpenid() |
|
|
|
|
|
const coupon = coupons.get(code) |
|
|
|
|
|
await axios.get('/Api/Coupon/GetCoupon', { |
|
|
|
|
|
"couponCode": coupon.code, |
|
|
|
|
|
"mallCode": coupon.mallCode, |
|
|
|
|
|
"userCode": openid |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
const openid = await getOpenid(); |
|
|
|
|
|
const coupon = coupons.get(code); |
|
|
|
|
|
await axios.get("/Api/Coupon/GetCoupon", { |
|
|
|
|
|
couponCode: coupon.code, |
|
|
|
|
|
mallCode: coupon.mallCode, |
|
|
|
|
|
userCode: openid, |
|
|
|
|
|
}); |
|
|
coupons.set({ |
|
|
coupons.set({ |
|
|
...coupon, |
|
|
...coupon, |
|
|
received: true |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
received: true, |
|
|
|
|
|
}); |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
mall: { |
|
|
mall: { |
|
|
...this.data.mall, |
|
|
...this.data.mall, |
|
|
coupons: [...this.data.mall.coupons] |
|
|
|
|
|
|
|
|
coupons: [...this.data.mall.coupons], |
|
|
}, |
|
|
}, |
|
|
couponName: '优惠券', |
|
|
|
|
|
showModal: true |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
couponName: "优惠券", |
|
|
|
|
|
showModal: true, |
|
|
|
|
|
}); |
|
|
} catch (error) { |
|
|
} catch (error) { |
|
|
wx.showToast({ |
|
|
wx.showToast({ |
|
|
icon: 'none', |
|
|
|
|
|
|
|
|
icon: "none", |
|
|
title: JSON.stringify(error), |
|
|
title: JSON.stringify(error), |
|
|
}) |
|
|
|
|
|
|
|
|
}); |
|
|
} finally { |
|
|
} finally { |
|
|
wx.hideLoading() |
|
|
|
|
|
|
|
|
wx.hideLoading(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
hideModal() { |
|
|
hideModal() { |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
showModal: false |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
showModal: false, |
|
|
|
|
|
}); |
|
|
}, |
|
|
}, |
|
|
onShareAppMessage() { |
|
|
onShareAppMessage() { |
|
|
return { |
|
|
return { |
|
|
title: this.data.shareTitle, |
|
|
title: this.data.shareTitle, |
|
|
path: "pages/index/index", |
|
|
path: "pages/index/index", |
|
|
imageUrl: "./shareImg.png" |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
imageUrl: "./shareImg.png", |
|
|
|
|
|
}; |
|
|
|
|
|
}, |
|
|
|
|
|
}); |
|
|
|