<template>
	<view class="container">
		<view class="address-form">
			<u-cell-group :border="false">
				<u-cell-item title="评分" title-width="120" :arrow="false" :value-style="{textAlign: 'left'}">
					<u-rate v-model="formData.score" active-color="#FFAE21"></u-rate>
				</u-cell-item>
				<u-field type="textarea" placeholder="请对商品进行评价" v-model="formData.evaluateContent" label-width="0"></u-field>
			</u-cell-group>
			<u-upload :action="uploadUrl" max-count="3" :form-data="uploadData" @on-success="uploadSuccess" @on-error="uploadError" @on-remove="uploadRemove"></u-upload>
		</view>
		<view class="form-handle">
			<u-button type="success" shape="circle" :ripple="true" @click="submitData" class="handle-custom">提交</u-button>
		</view>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
</template>

<script>
	const NET = require('@/utils/request')
	const API = require('@/config/api')
	export default {
		data() {
			return {
				formData: {
					orderId: '',
					tenantCode: '',
					productIds: '',
					score: 5,
					evaluateContent: '',
				},
				uploadData: {
					folderId: 0,
				},
				uploadUrl: '',
				fileList: []
			}
		},
		onLoad(options) {
			this.uploadUrl = API.uploadFile
			this.formData.orderId = options.orderId
			this.formData.tenantCode = options.tenantCode
			this.formData.productIds = options.productIds
		},
		methods: {
			//  文件上传成功回调
			uploadSuccess(res, index, lists, name) {
				this.fileList.push(res.data.url)
				this.$refs.uTips.show({
					title: '文件上传成功',
					type: 'success',
				})
				return true
			},
			//  文件上传失败回调
			uploadError(res, index, lists, name) {
				this.$refs.uTips.show({
					title: '文件上传失败',
					type: 'warning',
				})
			},
			//  移除文件回调
			uploadRemove(index, lists, name) {
				this.fileList.splice(index, 1)
			},
			//  提交数据
			submitData() {
				NET.request(API.evaluateOrder, {
						...this.formData,
						mid: uni.getStorageSync("userData").userId,
						nickname: uni.getStorageSync("userData").userName,
						evaluateImgs: this.fileList.map((site, index) => {
							return {
								imgUrl: site,
								sortOrder: index + 1,
							}
						})
					},
					'POST').then(res => {
					this.$refs.uTips.show({
						title: '评价成功',
						type: 'success',
					})
					setTimeout(()=>{
						// uni.reLaunch({
						// 	url: '/pagesMain/orderList?type=5'
						// });
						uni.navigateTo({
							url: '/pagesMain/orderList?type=5'
						});
					},1000)
				}).catch(error => {
					this.modalShow = false
					this.$refs.uTips.show({
						title: error.data.msg,
						type: 'warning',
					})
				})
			},
		},
	}
</script>

<style lang="less" scoped>
	page {
		width: 100%;
		height: 100%;
	}

	.container {
		width: 100%;
		height: 100%;
		float: left;
		box-sizing: border-box;
		background-color: #FFFFFF;
		padding-bottom: 70px;
		overflow-y: auto;

		.address-form {
			width: 100%;
			float: left;
			box-sizing: border-box;
			padding: 0 15px;
			background-color: #ffffff;

			/deep/.u-field {
				padding-left: 0px;
				padding-right: 0px;
			}

			/deep/.u-cell {
				padding-left: 0px;
				padding-right: 0px;
			}
		}

		.address-form-top {
			/deep/.u-cell_title {
				color: #999999;
			}

			/deep/.u-label-text {
				color: #999999;
			}
		}

		.address-form-bottom {
			margin-top: 10px;

			/deep/.u-cell_title {
				color: #333333;
			}

			/deep/.u-label-text {
				color: #333333;
			}
		}

		.form-handle {
			width: calc(100% - 30px);
			height: 40px;
			position: fixed;
			bottom: 20px;
			left: 15px;

			.handle-custom {
				background-color: #51A539;

				/deep/button {
					background-color: #56a83a;
				}

				/deep/.u-btn--success--disabled {
					background-color: #74bd60 !important;
				}
			}
		}
	}
</style>
