<template>
	<view>
		<!-- 顶部操作条 -->
		<cu-custom :bgColor="'bg-main-color'" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">申请退单</block>
		</cu-custom>
		<view class="padding flex justify-start margin-top-sm bg-white">
			<view class="cu-avatar xxl-view" :style="'background-image:url(' + good.picUrl + ');'"></view>
			<view class="flex flex-column-between margin-left-sm">
				<view class="text-black text-lg">{{good.servTitle}}</view>
				<view>
					<view v-for="(item, index) in good.orderTag" class='cu-tag radius margin-right-sm'>
						{{item}}</view>
				</view>
			</view>
		</view>
		<view class="margin-top-sm padding flex justify-between bg-white">
			<view>申请原因</view>
			<picker @change="reasonChange" :range="cancelReasonList" :range-key="'reasonName'">
				<view class="picker">
					{{formData.reasonObj.reasonId ? formData.reasonObj.reasonName : '请选择' }}
					<text class="text-gray text-lg margin-left-xs"><text class="cuIcon-right"></text></text>
				</view>
			</picker>
		</view>
		<view class="margin-top-sm padding bg-white">
			<view class="margin-bottom-sm">具体原因</view>
			<textarea style="width: 100%;" class="solid radius text-left padding-sm" v-model="formData.detailDesc" maxlength="-1" 
				placeholder="接单半小时内退单你无责，无故退单、无理由退单引起客诉将由您承担责任；请如实填写退单原因！平台方将实时监管本次订单。"></textarea>
		</view>
		<view class="margin-top-sm padding bg-white">
			<view class="margin-bottom-sm">上传凭证（选填）</view>
			<view class="grid col-4 grid-square flex-sub">
				<view class="bg-img" v-for="(item,index) in formData.imgList" :key="index" @tap="viewImage($event, formData.imgList)"
					:data-url="item">
					<image :src="item" mode="aspectFill"></image>
					<view class="cu-tag bg-red" @tap.stop="delImg($event, formData.imgList)" :data-index="index">
						<text class='cuIcon-close'></text>
					</view>
				</view>
				<view class="solids" @tap="chooseImgList" v-if="formData.imgList.length<9">
					<text class='cuIcon-cameraadd'></text>
				</view>
			</view>
		</view>
		<view class="cu-bar tabbar fixed-bottom-bar bg-back">
			<button class="bg-main-color cu-btn lg shadow-warp long-btn margin-lr" @click="nextStep">提交退单</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				good: {},
				formData: {
					imgList: [],
					reasonObj: {}
				},
				cancelReasonList: [{
					reasonId: 1,
					reasonName: '申请退单原因分类1'
				}, {
					reasonId: 2,
					reasonName: '申请退单原因分类2'
				}]
			}
		},
		onLoad(options) {
			if (options && options.params) {
				this.good = JSON.parse(decodeURIComponent(options.params)).orderInfo;
			}
		},
		methods: {
			chooseImgList(e) {
				uni.chooseImage({
					count: 9, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						if (this.formData.imgList.length != 0) {
							this.formData.imgList = this.formData.imgList.concat(res.tempFilePaths)
						} else {
							this.formData.imgList = res.tempFilePaths
						}
					}
				});
			},
			viewImage(e, imgList) {
				uni.previewImage({
					urls: imgList,
					current: e.currentTarget.dataset.url
				});
			},
			delImg(e, imgList) {
				uni.showModal({
					title: '',
					content: '确定要删除这张图片吗？',
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							imgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
			reasonChange(e) {
				this.formData.reasonObj = this.cancelReasonList[e.detail.value]
			}
		},
	}
</script>

<style scoped>
	.xxl-view {
		min-width: 100rpx;
		min-height: 100rpx;
	}
</style>
