<template>
	<view class="plr20 pay pos">
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		onLoad(options) {

		},
		methods: {
			goback(){
				uni.reLaunch({
					url:"/pages/index/index"
				})
			},
			getcardid() {
				this.api.cardinfo({
					id: this.xiaid
				}).then((res) => {
					console.log(res)
					if (res.data.code == 200) {
						this.form.cate_id = res.data.data.category_id
						this.getcodes()
					} else {
						this.istrue = true
						uni.showToast({
							icon: "none",
							title: res.data.message
						})
					}
				})
			},
			getcodes(aa) {
				this.codeimg = this.api.imgUrl + "front/order/captcha?tt=" + new Date().getTime()
				if (!aa) {
					this.getcardtype()
				}
			},
			getcardtype() {
				uni.showLoading({
					title: "加载中..."
				})
				this.api.cardzhong().then((res) => {
					console.log(res)
					if (res.data.code == 200) {
						this.columns = res.data.data
						if (this.xiaid == "") {
							this.form.cate_id = this.columns[this.chsoeindex].id
						} else {
							this.columns.forEach((item, index) => {
								if (item.id == this.form.cate_id) {
									this.chsoeindex = index
								}
							})
						}
						this.getcardzhong()
					} else {
						this.istrue = true
						uni.showToast({
							icon: "none",
							title: res.data.message
						})
					}
				})
			},
			getcardzhong() {
				this.api.cardtypes({
					page: 1,
					pageSize: 1000,
					category_id: this.form.cate_id
				}).then((res) => {
					console.log(res)
					if (res.data.code == 200) {
						this.columns2 = res.data.data.data
						if (this.columns2.length != 0) {
							this.form.product_id = this.columns2[this.chsoeindex2].id
						}
						if (this.xiaid != "") {
							this.form.cate_id = this.columns[this.chsoeindex].id
							this.columns2.forEach((item, index) => {
								if (item.id == this.xiaid) {
									this.chsoeindex2 = index
								}
							})
						}
						uni.hideLoading()
						this.istrue = true
					} else {
						this.istrue = true
						uni.showToast({
							icon: "none",
							title: res.data.message
						})
					}
				})
			},
			submit() {
				uni.showLoading({
					title: "提交中..."
				})
				this.api.creatorder(this.form).then((res) => {
					console.log(res)
					if (res.data.code == 200) {
						uni.hideLoading()
						// uni.showToast({
						// 	title: "提交成功",
						// 	icon: "none",
						// 	duration: 1200
						// })
						this.card_num = res.data.data.card_num
						this.discount = res.data.data.discount
						this.totalAmount = res.data.data.totalAmount
						this.name = res.data.data.product.name
						this.createorder()
						// let that = this
						// setTimeout(function() {
						// 	that.showpop = true
						// }, 1200);
					} else {
						uni.showToast({
							icon: "none",
							title: res.data.message
						})
					}
				})
			},
		}
	}
</script>

<style>
	page {
		background: #FAFAFA !important;
	}
</style>