<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="sendUrgentMsgModal" @click="hideModal">
					<text class="cuIcon-close text-red"></text>
				</view>
			</view>
			<view class="padding padding-lr-xl bg-white text-left">
				<view>
					<text>TO：</text>
					<button class="cu-btn" :class="toWho === 0 ? 'bg-main-color' : ''" @click="changeToWho(0)">商家</button>
					<button class="cu-btn margin-left-sm" :class="toWho === 1 ? 'bg-main-color' : ''" @click="changeToWho(1)">平台</button>
				</view>
				<view class="margin-top-sm">
					<textarea style="width: 100%;" class="solid radius text-left padding-sm" v-model="detailDesc" maxlength="-1"
						placeholder="请输入需报商家或平台的情况，申请厂家配件请以“申请配件”开头"></textarea>
				</view>
				<view class="margin-top-sm">
					<view class="margin-bottom-sm">上传照片</view>
					<view class="grid col-4 grid-square flex-sub">
						<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="chooseImgList" v-if="imgList.length<9">
							<text class='cuIcon-cameraadd'></text>
						</view>
					</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="sendUrgentMsgModal"
					@tap="hideModal" @click="sendUrgentMsg">发送急报</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		nama: 'new-serv-price',
		emits: ['hideModal'],
		props: {
			show: {
				type: Boolean,
				default: false
			},
			data: {
				type: Object,
				default: {}
			}
		},
		data() {
			return {
				toWho: 0,
				detailDesc: '',
				imgList: []
			}
		},
		methods: {
			hideModal(e) {
				this.$emit('hideModal', e);
			},
			sendUrgentMsg(e) {
				uni.showToast({
					icon: 'none',
					title: '功能开发中'
				})
			},
			changeToWho(toWho) {
				this.toWho = toWho;
			},
			chooseImgList(e) {
				uni.chooseImage({
					count: 9, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						if (this.imgList.length != 0) {
							this.imgList = this.imgList.concat(res.tempFilePaths)
						} else {
							this.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)
						}
					}
				})
			}
		}
	}
</script>

<style>
</style>
