新增营销系统、分销系统、会员功能、门店、提现功能
This commit is contained in:
122
components/canvasShow/basics/coupon/mixin.js
Normal file
122
components/canvasShow/basics/coupon/mixin.js
Normal file
@ -0,0 +1,122 @@
|
||||
import api from '../../config/api'
|
||||
import { funMixin } from '../../config/mixin'
|
||||
import { ref, onMounted } from 'vue';
|
||||
import cookie from '@/utils/cookie'
|
||||
|
||||
export default function (componentContent, typeId, shopId) {
|
||||
const { sendReq, beforeGetData, afterGetData, jumpStore } = funMixin()
|
||||
const couponsData = ref([])
|
||||
|
||||
onMounted(() => {
|
||||
getData()
|
||||
})
|
||||
|
||||
// 获取优惠券列表
|
||||
function getData () {
|
||||
if (
|
||||
componentContent.value.selectedCoupon &&
|
||||
componentContent.value.selectedCoupon.length > 0
|
||||
) {
|
||||
beforeGetData()
|
||||
let _url = `${api.getCoupons}?isPage=2&ids=${componentContent.value.selectedCoupon}`
|
||||
const params = {
|
||||
method: 'GET',
|
||||
url: _url,
|
||||
}
|
||||
sendReq(
|
||||
params,
|
||||
(res) => {
|
||||
afterGetData()
|
||||
couponsData.value = res.data.list
|
||||
},
|
||||
() => {
|
||||
afterGetData()
|
||||
}
|
||||
)
|
||||
} else {
|
||||
couponsData.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// 领取优惠券
|
||||
async function receiveCoupon (item) {
|
||||
var token = cookie.get('accessToken')
|
||||
if (typeof uni !== 'undefined') {
|
||||
if (token) {
|
||||
const params = {
|
||||
url: `${api.takeCoupon}${item.id}`,
|
||||
method: 'GET',
|
||||
}
|
||||
sendReq(
|
||||
params,
|
||||
(res) => {
|
||||
if (res.code !== 0) {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: 'none'
|
||||
})
|
||||
} else {
|
||||
getData()
|
||||
uni.showToast({
|
||||
title: '领取成功',
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
|
||||
},
|
||||
() => {
|
||||
if (res.code !== 0) {
|
||||
uni.showToast({
|
||||
title: res.msg,
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: '请先登录',
|
||||
icon: 'none'
|
||||
})
|
||||
uni.navigateTo({
|
||||
url: '/pages/login/guid'
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (token) {
|
||||
const params = {
|
||||
url: `${api.takeCoupon}${item.id}`,
|
||||
method: 'GET',
|
||||
}
|
||||
sendReq(params).then(res => {
|
||||
ElMessage({
|
||||
message: '领取成功!',
|
||||
type: 'success'
|
||||
})
|
||||
getData()
|
||||
}).catch(res => {
|
||||
if (res.data.code !== '200') {
|
||||
ElMessage({
|
||||
message: res.data.message,
|
||||
type: 'success'
|
||||
})
|
||||
}
|
||||
})
|
||||
} else {
|
||||
ElMessage({
|
||||
message: '请先登录'
|
||||
})
|
||||
// 登录弹框
|
||||
// store.commit('IS_LOGIN', false) // 清除顶部个人中心数据
|
||||
// store.commit('SHOW_LOGIN') // 调用登录弹框
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
componentContent,
|
||||
couponsData,
|
||||
receiveCoupon,
|
||||
jumpStore
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user