|
@@ -1,4 +1,4 @@
|
|
|
-import { defineComponent, onMounted, reactive, ref } from 'vue'
|
|
|
+import { defineComponent, onMounted, reactive, ref, watch } from 'vue'
|
|
|
import styles from './index.module.less'
|
|
|
import { Cell, CellGroup, Checkbox, Icon, Image } from 'vant'
|
|
|
import activeButtonIcon from '@common/images/icon_checkbox.png'
|
|
@@ -30,16 +30,23 @@ export default defineComponent({
|
|
|
type: String,
|
|
|
default: ''
|
|
|
},
|
|
|
+ orderGoodsType: {
|
|
|
+ type: Array,
|
|
|
+ default: () => []
|
|
|
+ },
|
|
|
/** 实际需要支付金额 */
|
|
|
actualPrice: {
|
|
|
type: Number,
|
|
|
default: 0
|
|
|
}
|
|
|
},
|
|
|
- emits: ['confirm'],
|
|
|
+ /** confirm 选择畅学卡, confirmOnlyDiscount 在有效期内,直接抵扣 */
|
|
|
+ emits: ['confirm', 'confirmOnlyDiscount'],
|
|
|
setup(props, { emit }) {
|
|
|
- //
|
|
|
+ // 是否显示畅学卡
|
|
|
const isDisplay = ref(false)
|
|
|
+ const isDiscountApply = ref(false) // 畅学卡是否在有效期内
|
|
|
+ const productType = ref<any[]>([])
|
|
|
const checked = ref(false)
|
|
|
const params = reactive({
|
|
|
discountPrice: 0 as any, // 优惠的金额,
|
|
@@ -54,15 +61,18 @@ export default defineComponent({
|
|
|
vipType: 'DISCOUNT'
|
|
|
})
|
|
|
|
|
|
+ // watch(() => props.orderGoodsType, () => {
|
|
|
+ // console.log('watch ---- ')
|
|
|
+ // productChange()
|
|
|
+ // })
|
|
|
+
|
|
|
// 格式化显示
|
|
|
const formatShowTime = () => {
|
|
|
- console.log(props.actualPrice, 'actualPrice')
|
|
|
if(checked.value) {
|
|
|
params.discountPrice = (
|
|
|
props.actualPrice -
|
|
|
(props.actualPrice * discountDetail.value.discountRate / 100)
|
|
|
).toFixed(2)
|
|
|
- // discountEndTime
|
|
|
const users = state.user.data
|
|
|
const startTime = users.discountEndTime || new Date()
|
|
|
let endTime = dayjs(new Date()).format('YYYY-MM-DD')
|
|
@@ -96,6 +106,29 @@ export default defineComponent({
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ const onDiscountChange2 = () => {
|
|
|
+ checked.value = true
|
|
|
+ formatShowTime()
|
|
|
+
|
|
|
+ emit("confirmOnlyDiscount", {
|
|
|
+ checked: checked.value,
|
|
|
+ discountPrice: params.discountPrice,
|
|
|
+ ...discountDetail.value
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ const productChange = (productType) => {
|
|
|
+ // 判断是否需要购买畅学卡
|
|
|
+ let status = false
|
|
|
+ props.orderGoodsType.forEach((item: any) => {
|
|
|
+
|
|
|
+ if (productType.includes(item)) {
|
|
|
+ status = true
|
|
|
+ }
|
|
|
+ })
|
|
|
+ isDisplay.value = status
|
|
|
+ }
|
|
|
+
|
|
|
const __init = async () => {
|
|
|
const { data } = await request.get(
|
|
|
`${state.platformApi}/memberPriceSettings/getDiscount`
|
|
@@ -108,11 +141,16 @@ export default defineComponent({
|
|
|
vipType: data.vipType
|
|
|
}
|
|
|
const productType = data.productType ? data.productType.split(',') : []
|
|
|
- // 判断是否需要购买畅学卡
|
|
|
- if (productType.includes(props.orderType)) {
|
|
|
- isDisplay.value = true
|
|
|
- } else {
|
|
|
- isDisplay.value = false
|
|
|
+ productType.value = productType
|
|
|
+ productChange(productType)
|
|
|
+
|
|
|
+ const users = state.user.data
|
|
|
+ const nowTime = dayjs()
|
|
|
+ const endTime = users.discountEndTime || new Date()
|
|
|
+ console.log(endTime, 'endTime', users, nowTime)
|
|
|
+ if(dayjs(nowTime).isBefore(dayjs(endTime))) {
|
|
|
+ isDiscountApply.value = true
|
|
|
+ onDiscountChange2()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -120,7 +158,7 @@ export default defineComponent({
|
|
|
return () =>
|
|
|
isDisplay.value ? (
|
|
|
<div class={styles.addDiscount}>
|
|
|
- <CellGroup class={['mb12', styles.cellGroup]} border={false}>
|
|
|
+ {!isDiscountApply.value ? <><CellGroup class={['mb12', styles.cellGroup]} border={false}>
|
|
|
<Cell
|
|
|
center
|
|
|
class={styles.selectDiscount}
|
|
@@ -174,7 +212,6 @@ export default defineComponent({
|
|
|
</CellGroup>
|
|
|
|
|
|
{checked.value ? (
|
|
|
- <>
|
|
|
<CellGroup class={['mb12', styles.cellGroup]} border={false}>
|
|
|
<Cell
|
|
|
center
|
|
@@ -192,7 +229,11 @@ export default defineComponent({
|
|
|
}}
|
|
|
/>
|
|
|
</CellGroup>
|
|
|
- <CellGroup class={['mb12', styles.cellGroup]} border={false}>
|
|
|
+ ) : (
|
|
|
+ ''
|
|
|
+ )}</> : ''}
|
|
|
+
|
|
|
+ {checked.value || isDiscountApply.value ? <CellGroup class={['mb12', styles.cellGroup]} border={false}>
|
|
|
<Cell
|
|
|
center
|
|
|
v-slots={{
|
|
@@ -206,11 +247,7 @@ export default defineComponent({
|
|
|
)
|
|
|
}}
|
|
|
/>
|
|
|
- </CellGroup>
|
|
|
- </>
|
|
|
- ) : (
|
|
|
- ''
|
|
|
- )}
|
|
|
+ </CellGroup> : ''}
|
|
|
</div>
|
|
|
) : (
|
|
|
''
|