Files
2023-11-14 17:21:03 +08:00

60 lines
1.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @name: index.utli
* @author: kahu4
* @date: 2023-10-31 11:19
* @descriptionindex.utli
* @update: 2023-10-31 11:19
* */
import { ref, computed } from "vue";
import { onShow } from '@dcloudio/uni-app'
import {getCouponList} from "@/api/coupon";
import { tabList } from "@/pages/discountCoupon/index.data";
export function useDiscountCoupon(){
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
*/
async function handleTabsChange(e){
console.log(e)
couponList.value = []
tabCurrent.value = e.index
couponType.value = e.value
await doGetCouponList()
}
/**
* 获取购物车列表
* @returns {Promise<void>}
*/
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
}
}