<template>
	<view :style="'background-color: '+theme.bg+';color: '+theme.text" style="height: 100vh;">
		<myNav :title="i18n.appeal.title"></myNav>
		<!-- 身体 -->
		<view class="width-750 padding-w-30 padding-t-32 padding-b-40">
			<textarea class="textbox" v-model="content" :placeholder="i18n.appeal.tos1"
				maxlength="-1" :style="'background-color: '+theme.fu_bg+';color: '+theme.text"/>
			<view class="grid col-3">
				<view v-for="(item,index) in images" class="text-center margin-top">
					<view style="width: 220rpx;height: 220rpx;position: relative;">
						<image :src="item" style="width: 220rpx;height: 220rpx;border-radius: 10rpx;"></image>
						<view @click="del(index)" class="flex align-center justify-center bg-red round"
							style="position: absolute;right: 5rpx;top: 5rpx;width: 30rpx;height: 30rpx;">
							<view class="cuIcon-close"></view>
						</view>
					</view>
				</view>
				<view v-if="images.length<6" class="text-center margin-top">
					<view @click="choose" class="flex align-center justify-center"
					:style="'background-color: '+theme.fu_bg+';color: '+theme.fu_text"
						style="width: 220rpx;height: 220rpx;border-radius: 10rpx;">
						<view class="font-70 cuIcon-camera"></view>
					</view>
				</view>
			</view>

			<view @click="getaa"
				class="width-600 height-96 radiu-10 bj-0165EE line-height-96 text-center margin-0-auto margin-t-200">
				<text class="font-32 color-white">{{i18n.appeal.text1}}</text>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				content: '',
				images: [],
				upimages: [],
				flag: true,
				id: '',
				theme: '',
			}
		},
		computed: {
			i18n() {
				return this.$t('message');
			}
		},
		onLoad(e) {
			this.id = e.id
		},
		onShow() {
			if (uni.getStorageSync("theme") == "dark") {
				this.theme = this.$store.state.darkTheme
			} else {
				this.theme = this.$store.state.lightTheme
			}
		},
		methods: {
			// 申诉
			getaa() {
				if (this.content == '') return this.tos(this.i18n.appeal.tos1)
				if (this.upimages.length == 0) return this.tos(this.i18n.appeal.tos2)
				if (!this.flag) {
					return
				} else {
					uni.showLoading({
						title: '',
						mask: true
					})
					this.flag = false
					let obj = {
						id: this.id,
						content: this.content,
						annex_image: this.upimages.join(',')
					}
					this.post('/marketotc/shenshu', obj).then(res => {
						console.log('申诉返回', res)
						uni.hideLoading()
						this.flag = true
						if (res.code == 1) {
							this.content = ''
							this.images = ''
							this.upimages = ''
							this.tos(res.msg)
							setTimeout(() => {
								uni.redirectTo({
									url: '/pages/index/orderDetails?id=' + this.id
								})
							}, 500)
						}
					})
				}
			},
			del(e) {
				this.images.splice(e, 1)
				this.upimages.splice(e, 1)
				console.log(this.images, this.upimages)
			},
			choose() {
				var self = this
				uni.chooseImage({
					count: 6 - self.images.length,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						tempFilePaths.forEach((item, index) => {
							console.log(item)
							uni.uploadFile({
								url: this.upload + '/publics/image_upload',
								filePath: item,
								name: 'file',
								success: (res) => {
									let data = JSON.parse(res.data)
									uni.hideLoading()
									if (data.code == 1) {
										console.log(data, index)
										self.images = self.images.concat(data.data
											.iamge_url)
										self.upimages = self.upimages.concat(data.data.url)
									}
								}
							})
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.textbox {
		width: 686rpx;
		height: 367rpx;
		// background: #F6F8FB;
		border-radius: 20rpx;
		padding: 24rpx;
		font-size: 28rpx;
		// color: #8B99A2;
	}
</style>
