<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="本次原因请如实填写。无故退单，无理由退单引起客诉的你有责，订单大多数由推荐/分销人员带单产生，注意不要产生私自成交，撬单等行为，造成订单销售人员的佣金损失，不利于长远合作。被带单销售人员发现恶意违规破坏合作的，将追责3000元／单。"></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: '客户的时间我无法配合'
				}, {
					reasonId: 2,
					reasonName: '客户多次爽约'
				}, {
					reasonId: 3,
					reasonName: '客户不能确定时间'
				}, {
					reasonId: 4,
					reasonName: '客户多天未能联系上'
				}, {
					reasonId: 5,
					reasonName: '客户说无此服务'
				}, {
					reasonId: 6,
					reasonName: '客户要求已超出服务范围'
				}, {
					reasonId: 7,
					reasonName: '环境问题无法施工'
				}, {
					reasonId: 8,
					reasonName: '技能原因无法完成'
				}, {
					reasonId: 9,
					reasonName: '分岐未能谈妥'
				}, {
					reasonId: 10,
					reasonName: '不愿支付费用'
				}]
			}
		},
		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>
