Showing
1 changed file
with
64 additions
and
57 deletions
| ... | @@ -55,7 +55,7 @@ import Cookies from 'js-cookie' | ... | @@ -55,7 +55,7 @@ import Cookies from 'js-cookie' |
| 55 | import icon_avatar from '@images/que-touxiang@2x.png' | 55 | import icon_avatar from '@images/que-touxiang@2x.png' |
| 56 | 56 | ||
| 57 | import MyButton from '@/components/MyButton/index.vue' | 57 | import MyButton from '@/components/MyButton/index.vue' |
| 58 | -import { ref, reactive, onMounted } from 'vue' | 58 | +import { ref, reactive, onMounted, watch, nextTick } from 'vue' |
| 59 | import { useRoute, useRouter } from 'vue-router' | 59 | import { useRoute, useRouter } from 'vue-router' |
| 60 | import axios from '@/utils/axios'; | 60 | import axios from '@/utils/axios'; |
| 61 | import $ from 'jquery' | 61 | import $ from 'jquery' |
| ... | @@ -63,6 +63,69 @@ import { Toast } from 'vant'; | ... | @@ -63,6 +63,69 @@ import { Toast } from 'vant'; |
| 63 | const $route = useRoute(); | 63 | const $route = useRoute(); |
| 64 | const $router = useRouter(); | 64 | const $router = useRouter(); |
| 65 | 65 | ||
| 66 | +const props = defineProps({ | ||
| 67 | + item: Object, | ||
| 68 | + showPopup: Boolean | ||
| 69 | +}) | ||
| 70 | + | ||
| 71 | +const emit = defineEmits(['on-close']); | ||
| 72 | + | ||
| 73 | +let donate_number = ref(1) | ||
| 74 | +const donateBook = () => { | ||
| 75 | + // 爱心捐书接口 | ||
| 76 | + axios.post('/srv/?a=add_donate', { | ||
| 77 | + book_id: props.item.book_id, | ||
| 78 | + qty: donate_number.value, | ||
| 79 | + donate_name: props.item.perf_name, | ||
| 80 | + }) | ||
| 81 | + .then(res => { | ||
| 82 | + if (res.data.code === 1) { | ||
| 83 | + console.warn(res.data.data); | ||
| 84 | + closeBtn(); | ||
| 85 | + | ||
| 86 | + // 交易成功跳转回调页面 | ||
| 87 | + // TEMP: 临时传参 donate_id | ||
| 88 | + $router.push({ | ||
| 89 | + path: '/client/wechatpayCallback', | ||
| 90 | + query: { | ||
| 91 | + donate_id: res.data.data.id | ||
| 92 | + } | ||
| 93 | + }) | ||
| 94 | + } else { | ||
| 95 | + console.warn(res); | ||
| 96 | + if (!res.data.show) return false; | ||
| 97 | + Toast({ | ||
| 98 | + icon: 'close', | ||
| 99 | + message: res.data.msg | ||
| 100 | + }); | ||
| 101 | + } | ||
| 102 | + }) | ||
| 103 | + .catch(err => { | ||
| 104 | + console.error(err); | ||
| 105 | + }) | ||
| 106 | +} | ||
| 107 | + | ||
| 108 | +const show = ref(false); | ||
| 109 | +let popupHeight = ref('60%'); | ||
| 110 | + | ||
| 111 | +watch(() => props.showPopup, (v) => { | ||
| 112 | + show.value = v | ||
| 113 | + // DOM调整后,把弹出框高度设定到适合高度,配合不同分辨率效果 | ||
| 114 | + nextTick(() => { | ||
| 115 | + let height = $('.donate-wrapper').height(); | ||
| 116 | + popupHeight.value = height + 10 + 'px'; | ||
| 117 | + }) | ||
| 118 | +}) | ||
| 119 | + | ||
| 120 | +const closeBtn = () => { | ||
| 121 | + emit('on-close', false) | ||
| 122 | + show.value = false; | ||
| 123 | +} | ||
| 124 | + | ||
| 125 | +const cancelDonate = () => { | ||
| 126 | + closeBtn(); | ||
| 127 | +} | ||
| 128 | + | ||
| 66 | // TODO: 微信支付 | 129 | // TODO: 微信支付 |
| 67 | 130 | ||
| 68 | onMounted(() => { | 131 | onMounted(() => { |
| ... | @@ -74,70 +137,14 @@ onMounted(() => { | ... | @@ -74,70 +137,14 @@ onMounted(() => { |
| 74 | import mixin from 'common/mixin'; | 137 | import mixin from 'common/mixin'; |
| 75 | 138 | ||
| 76 | export default { | 139 | export default { |
| 77 | - props: ['showPopup', 'item'], | ||
| 78 | mixins: [mixin.init], | 140 | mixins: [mixin.init], |
| 79 | data() { | 141 | data() { |
| 80 | return { | 142 | return { |
| 81 | - popupHeight: '60%', | ||
| 82 | - show: false, | ||
| 83 | - donate_number: 1, | ||
| 84 | } | 143 | } |
| 85 | }, | 144 | }, |
| 86 | mounted() { | 145 | mounted() { |
| 87 | }, | 146 | }, |
| 88 | - watch: { | ||
| 89 | - showPopup(value, pre) { | ||
| 90 | - if (value) { | ||
| 91 | - this.show = value; | ||
| 92 | - // DOM调整后,把弹出框高度设定到适合高度,配合不同分辨率效果 | ||
| 93 | - this.$nextTick(() => { | ||
| 94 | - let height = $('.donate-wrapper').height(); | ||
| 95 | - this.popupHeight = height + 10 + 'px'; | ||
| 96 | - }) | ||
| 97 | - } | ||
| 98 | - } | ||
| 99 | - }, | ||
| 100 | methods: { | 147 | methods: { |
| 101 | - closeBtn() { | ||
| 102 | - this.$emit('on-close', false) | ||
| 103 | - this.show = false; | ||
| 104 | - }, | ||
| 105 | - cancelDonate() { | ||
| 106 | - this.closeBtn(); | ||
| 107 | - }, | ||
| 108 | - donateBook() { | ||
| 109 | - // 爱心捐书接口 | ||
| 110 | - axios.post('/srv/?a=add_donate', { | ||
| 111 | - book_id: this.item.book_id, | ||
| 112 | - qty: this.donate_number, | ||
| 113 | - donate_name: this.item.perf_name, | ||
| 114 | - }) | ||
| 115 | - .then(res => { | ||
| 116 | - if (res.data.code === 1) { | ||
| 117 | - console.warn(res.data.data); | ||
| 118 | - this.closeBtn(); | ||
| 119 | - | ||
| 120 | - // 交易成功跳转回调页面 | ||
| 121 | - // TEMP: 临时传参 donate_id | ||
| 122 | - this.$router.push({ | ||
| 123 | - path: '/client/wechatpayCallback', | ||
| 124 | - query: { | ||
| 125 | - donate_id: res.data.data.id | ||
| 126 | - } | ||
| 127 | - }) | ||
| 128 | - } else { | ||
| 129 | - console.warn(res); | ||
| 130 | - if (!res.data.show) return false; | ||
| 131 | - Toast({ | ||
| 132 | - icon: 'close', | ||
| 133 | - message: res.data.msg | ||
| 134 | - }); | ||
| 135 | - } | ||
| 136 | - }) | ||
| 137 | - .catch(err => { | ||
| 138 | - console.error(err); | ||
| 139 | - }) | ||
| 140 | - }, | ||
| 141 | } | 148 | } |
| 142 | } | 149 | } |
| 143 | </script> | 150 | </script> | ... | ... |
-
Please register or login to post a comment