<template>
	<view class="v-order-cancel">
		<view class="v-card container-fluid">
			<view class="v-order-title">取消原因<text class="text">*</text></view>
			<view class="v-order-tip">请告知取消原因，我们将努力改善服务</view>
			<view class="v-order-cancel-list">

				<radio-group @change="radioChange">
					<label class="list_item row" v-for="(item, index) in cancelList" :key="item.value">
						<view class="label col">{{item.label}}</view>
						<view>
							<radio color="#0983ff" :value="item.value" :checked="item.value === current" />
						</view>
					</label>
				</radio-group>
			</view>
		</view>
		<view class="v-cancel-bottom">
			<view class="btn" @click="submit">确认取消订单</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cancelList: [],
				current: "1",
				orderId: undefined
			}
		},
		onLoad(options) {
			this.orderId = options.id
			this.getInitPage()
		},

		methods: {
			getInitPage(id) {
				this.$Request.get(this.$config.getDictDataList, null, null, null, false, true).then((res) => {
					this.cancelList = res.data
				}).catch(() => {

				});
			},
			radioChange: function(evt) {
				for (let i = 0; i < this.cancelList.length; i++) {
					if (this.cancelList[i].value === evt.detail.value) {
						this.current = evt.detail.value;
						break;
					}
				}
			},
			submit() {
				const userInfo = uni.getStorageSync("userInfo");
				let parame = {
					id: this.orderId,
					openid: userInfo.openid,
					cancelType: this.current,
				}
			
				this.$Request.get(this.$config.userCancelUpdateOrder, parame, null, null, false, null).then((res) => {
					if (res.code == "0") {
						uni.showToast({
							title: '订单取消成功',
							icon: 'none'
						});
						setTimeout(() => {
							uni.navigateBack({
								delta: 2
							});
						}, 1000)
					} else {
						uni.showToast({
							title: '订单取消失败，请稍后重试',
							icon: 'none'
						});
					}

				}).catch(() => {

				});
			}
		}
	}
</script>

<style lang="scss">
	.v-order-title {
		font-size: 32rpx;

		.text {
			color: #E02222;
			margin-left: 8rpx;
		}

		margin-bottom: 24rpx;
		font-weight: bold;
	}

	.v-order-tip {
		font-size: 24rpx;
		color: #999999;
	}

	.v-order-cancel-list {
		padding: 2rpx 30rpx;
		margin-top: 20rpx;
		border-radius: 10rpx;
		background: linear-gradient(to bottom, rgba(9, 131, 255, .05), transparent);

		.list_item {
			margin: 30rpx 0;

			.label {
				font-size: 28rpx;
			}
		}
	}

	.v-cancel-bottom {
		position: fixed;
		bottom: 30rpx;
		left: 0;
		width: 100%;
		padding: 24rpx 32rpx;
		box-sizing: border-box;

		.btn {
			font-size: 30rpx;
			height: 88rpx;
			line-height: 88rpx;
			border-radius: 88rpx;
			color: #fff;
			text-align: center;
			background: linear-gradient(to right, #0983FF, #57ABFF);
		}
	}
</style>