<template>
	<view class='app'>
		<view class="rate">
			<view class="images">
				<view class="itemimgs" v-for="(item,index) in file">
					<image class="delimg" src="/pagesB/static/gb2.png" mode="" style="color: red;" @tap='delimg(item)'>
					</image>
					<image class="itemimg" :src="item" mode=""></image>
				</view>
				<view class="shot item" @tap='updataImage'>
					<image src="/pagesB/static/paishe.png" mode=""></image>
					<view class="title">
						拍摄
					</view>
				</view>
				<!-- <view class="videotape item">
					<image src="../../static/video.png" mode=""></image>
					<view class="title">
						录像
					</view>
				</view> -->
			</view>
		</view>
		<view class="score">
			<view class="title">
				综合评分
			</view>
			<u-rate :count="count" v-model="countvalue" size='46'></u-rate>
			<view class="text">
				<u-input v-model="text" type="textarea" :clearable='false' />
			</view>
		</view>
		<view class="updata" @tap='updata'>
			提交评价
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import baseurl from '@/api/baseurl.js'
	import {
		insertGoodsEvaluate,
		uploadEvaluatePictureUrl
	} from '@/api/pagesB/goodsorderRate/index.js'
	export default {
		data() {
			return {
				orderlist: {},
				count: 5,
				countvalue: 0,
				text: '',
				baseurl: null,
				file: [],
				imgs: [],
				patientId: null,
				openid: null,
				timer: null,
				delta: null,
			};
		},
		methods: {
			delimg(item) {
				this.file = this.file.filter(e => e != item)
			},
			updata() {
				let that = this
				if (this.file.length > 0) {
					this.file.forEach(e => {
						uni.uploadFile({
							url: baseurl + '/nurseApp/orderEvaluate/uploadEvaluatePictureUrl',
							filePath: e,
							name: 'file',
							formData: {
								'orderNo': that.orderlist.goOrderNo
							},
							timeout: 5000,
							success(res) {
								var img = {
									evaluatePictureUrl: JSON.parse(res.data).imgUrl
								}
								that.imgs.push(img)
								if (that.imgs.length == that.file.length) {
									that.info();
								}
							}
						})
					})
				} else {
					that.info();
				}
			},
			info() {
				var that = this
				var obj = {
					"patientId": that.patientId,
					"openid": that.openid,
					"orderNo": that.orderlist.goOrderNo,
					"evaluateChannel": "WE_CHAT_APPLET",
					"evaluateContent": that.text,
					"compositeScore": that.countvalue,
					"orderEvaluatePictureInfoList": that.imgs
				}
				insertGoodsEvaluate(obj).then(res => {
					if (res.code == 200) {
						uni.setStorageSync("Refresh", 'Refresh')
						that.$refs.uToast.show({
							title: '评价成功',
							type: 'success',
							duration: '1500'
						})
						if (that.timer) {
							clearTimeout(that.timer)
						}
						that.timer = setTimeout(e => {
							that.imgs = []
							if (that.delta == 2) {
								uni.navigateBack({
									delta: 2
								})
							} else if (that.delta == 1) {
								uni.navigateBack({
									delta: 1
								})
							}
						}, 1500)
					} else {
						that.imgs = []
					}
				})
			},
			updataImage() {
				var that = this;
				uni.chooseImage({
					count: 9,
					success(res) {
						res.tempFilePaths.forEach(e => {
							that.file.push(e)
						})
					}
				})
			},
		},
		onLoad(options) {
			console.log(options,'4')
			this.orderlist = JSON.parse(options.item)
			console.log(this.orderlist,'47')
			this.delta = options.delta
		},
		onShow() {
			this.baseurl = baseurl
			var that = this
			const value = uni.getStorageSync('openid');
			if (value) {
				that.openid = value
			} else {}
			const value2 = uni.getStorageSync('patientId');
			if (value2) {
				that.patientId = value2
			} else {}
		},
	}
</script>

<style lang="scss">
	@import './goodsorderRate.scss';
</style>
