2023-11-14 17:21:03 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* @name: index.utli
|
|
|
|
|
|
* @author: kahu4
|
|
|
|
|
|
* @date: 2023-10-31 11:19
|
|
|
|
|
|
* @description:index.utli
|
|
|
|
|
|
* @update: 2023-10-31 11:19
|
|
|
|
|
|
* */
|
2024-02-08 21:01:37 +08:00
|
|
|
|
import { computed, ref } from "vue";
|
2023-11-14 17:21:03 +08:00
|
|
|
|
import { onShow } from '@dcloudio/uni-app'
|
2024-02-08 21:01:37 +08:00
|
|
|
|
import { getCouponList } from "@/api/coupon";
|
2023-11-14 17:21:03 +08:00
|
|
|
|
import { tabList } from "@/pages/discountCoupon/index.data";
|
|
|
|
|
|
|
2024-02-08 21:01:37 +08:00
|
|
|
|
export function useDiscountCoupon() {
|
2023-11-14 17:21:03 +08:00
|
|
|
|
const tabCurrent = ref(0) // tab选中
|
|
|
|
|
|
const couponType = ref(1) // 1、可使用,2、已使用,3、已失效
|
|
|
|
|
|
const couponListLoading = ref(false)
|
|
|
|
|
|
const couponList = ref([])
|
|
|
|
|
|
const showEmpty = computed(() => couponList.value.length <= 0)
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* tab发生改变
|
|
|
|
|
|
* @param e
|
|
|
|
|
|
*/
|
2024-02-08 21:01:37 +08:00
|
|
|
|
async function handleTabsChange(e) {
|
2023-11-14 17:21:03 +08:00
|
|
|
|
console.log(e)
|
|
|
|
|
|
couponList.value = []
|
|
|
|
|
|
tabCurrent.value = e.index
|
|
|
|
|
|
couponType.value = e.value
|
|
|
|
|
|
await doGetCouponList()
|
|
|
|
|
|
}
|
2024-02-08 21:01:37 +08:00
|
|
|
|
|
2023-11-14 17:21:03 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取购物车列表
|
|
|
|
|
|
*/
|
|
|
|
|
|
async function doGetCouponList() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
couponListLoading.value = true
|
|
|
|
|
|
const res = await getCouponList(couponType.value)
|
|
|
|
|
|
couponList.value = res
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
couponListLoading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
onShow(async () => {
|
|
|
|
|
|
await doGetCouponList()
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
tabList,
|
|
|
|
|
|
tabCurrent,
|
|
|
|
|
|
handleTabsChange,
|
|
|
|
|
|
showEmpty,
|
|
|
|
|
|
couponListLoading,
|
|
|
|
|
|
couponList,
|
|
|
|
|
|
doGetCouponList
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|