<template>
	<view class="cu-modal" :class="show?'show':''">
		<view class="cu-dialog">
			<view class="cu-bar bg-white justify-end solid-bottom">
				<view class="content">未能排单</view>
				<view class="action" data-modal="showArrangeFailTimeModal" @click="hideModal">
					<text class="cuIcon-close text-red"></text>
				</view>
			</view>
			<view class="bg-white padding text-left">
				<view class="padding-tb-sm">2次以上未接通，上传拨打或短信截图备案，一是避免客户投诉无人联系，二是销售或平台方见图无需陆续找来</view>
				<!-- <view class="padding-top-sm">
					<view class="flex justify-start">
						<view class="margin-right">原因选择：</view>
						<radio-group @change="changeReasonRadio">
							<label class="radio margin-right-sm">
								<radio style="transform:scale(0.7)" class="main-color" value="customer"
									:checked="true" />
								<text>客户原因</text>
							</label>
							<label class="radio">
								<radio style="transform:scale(0.7)" class="main-color" value="master" />
								<text>师傅原因</text>
							</label>
						</radio-group>
					</view>
					<view class="margin-top">
						<textarea style="width: 100%; height: 300rpx;" class="solid padding-sm" maxlength="-1" @input="inputSpecificReason"
							placeholder="具体情况(选填)"></textarea>
					</view>
				</view> -->
				<view>
					<view class="padding-tb-sm">上传拨打或短信截图</view>
					<view class="grid col-3 grid-square">
						<view class="bg-img" v-for="(item,index) in imgList" :key="index"
							@tap="viewImage($event, imgList)" :data-url="item">
							<image :src="item" mode="aspectFill"></image>
							<view class="cu-tag bg-red" @tap.stop="delImg($event, imgList)" :data-index="index">
								<text class='cuIcon-close'></text>
							</view>
						</view>
						<view class="solids" @tap="chooseImage" v-if="imgList.length < 1">
							<text class='cuIcon-cameraadd'></text>
						</view>
					</view>
					<!-- <view class="text-center">（选填）</view> -->
				</view>
			</view>
			<view class="cu-bar bg-white solid-top">
				<view class="action margin-0 flex-sub text-main-color solid-left" data-modal="showArrangeFailTimeModal"
					@click="submitFailReason">确认无法排单</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'timeArrangeFail',
		props: {
			show: {
				type: Boolean,
				default: false
			},
			data: {
				type: Object,
				default: {}
			}
		},
		data() {
			return {
				imgList: [],
				problemPerson: '',
				specificReason: ''
			}
		},
		methods: {
			hideModal(e) {
				uni.$emit(this.$globalFun.HIDE_MODAL, e);
			},
			chooseImage(e) {
				uni.chooseMedia({
					count: 1, //默认9
					mediaType: ['image'],
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						let tempFilePaths = [];
						res.tempFiles.forEach((fileObj) => {
							tempFilePaths.push(fileObj.tempFilePath)
						})
						if (this.imgList.length != 0) {
							this.imgList = this.imgList.concat(tempFilePaths)
						} else {
							this.imgList = 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)
						}
					}
				})
			},
			changeReasonRadio(e) {
				this.problemPerson = e.detail.value;
			},
			inputSpecificReason(e) {
				this.specificReason = e.detail.value;
			},
			submitFailReason(e) {
				let reasonObj = {
					imgList: this.imgList,
					problemPerson: this.problemPerson,
					specificReason: this.specificReason
				}
				uni.$emit(this.$globalFun.SUBMIT_FAIL_REASON, e, reasonObj)
			}
		}
	}
</script>

<style scoped>
	.grid.col-3.grid-square>view {
		padding-bottom: calc((100% - 40rpx)/3);
		height: 0;
		width: calc((100% - 40rpx)/3);
	}
</style>
