<template>
	<view class='center'>
		<view style="background: linear-gradient( 180deg, #1FCA7C 0%, #F2F2F2 100%);">
			<u-navbar :autoBack="true" title="报修详情" placeholder="true" bgColor="transparent" leftIconColor="#FFF"
				:title-style="{color: '#FFF'}">
			</u-navbar>
			<view class="h-300 flex flex-row-between v-center  ml-60 mr-35">
				<view class="flex-column" style="color: #1BB871;">
					<text class="fs-52">今日报修</text>
					<text class="fs-30">报修详情我知道</text>
				</view>
				<image class="h-225 w-225" src="/pagesMain/static/icon_bxxq.png"></image>
			</view>
		</view>

		<view class="overflow-y"
			style="background: white;border-top-left-radius: 20rpx;border-top-right-radius: 20rpx;margin-top: -20rpx;">
			<scroll-view scroll-y style="height: 100%;">
				<view class="mar-20">
					<view class="flex-column-center fs-24">
						<image class="w-40 h-40 mr-10" src="/static/icon_gd.png"></image>
						<text style="flex: 1;text-align: left;"
							class="fs-32 fw-700">{{data.type==1?'居家报修':'公区报事'}}</text>
						<text
							:style="{ color: data.state==1?'#FF682D':data.state==2?'#EEA616':data.state==3?'#1FCA7C':'#23BBEE'}">
							{{data.state==1?'待处理':data.state==2?'待支付':data.state==3?'已完成':data.state==4?'已取消':''}}
						</text>
					</view>
					<view class="flex-column br-12 fs-28 mt-30" style="background: #EBF5F0;">
						<view class="flex pad-30">
							<text class="fw-700 w-200" style="text-align: left;">业主姓名：</text>
							<text>{{$wskj.isNullStr(data.proprietorName)}}</text>
						</view>
						<view class="flex pad-30">
							<text class="fw-700 w-200" style="text-align: left;">业主房间号</text>
							<text>{{data.room}}</text>
						</view>
						<view class="flex pad-30">
							<text class="fw-700 w-200" style="text-align: left;">业主手机号</text>
							<text>{{data.proprietorPhone}}</text>
						</view>
					</view>
					<view class="flex-column-center fs-32 fw-700 mt-30">
						<image class="w-10 h-40 mr-15" style="background-color: #1FCA7C;"></image>
						<text>报修信息</text>
					</view>
					<view class="flex-column br-12 fs-28 mtb-30 pad-30" style="background: #EBF5F0;">
						<text style="text-align: left;">{{data.repairsDescription}}</text>
					</view>
					<scroll-view scroll-x="true" scroll-with-animation="true">
						<view class="flex">
							<view class="w-140 h-140 mr-15"
								v-for="(itemImg, index2) in $wskj.splitList(data.repairsImg)" :key="index2">
								<image class="w-140 h-140" :src="itemImg"></image>
							</view>
						</view>
					</scroll-view>
					<view class="flex mt-20 h-40 lh-40">
						<text class="fw-700 fs-28">报修时间:</text>
						<text class="fs-24 ml-10">{{data.repairsTime}}</text>
						<text class="fs-24 ml-10" style="flex: 1;"></text>
						<!-- <text @click="onCz('关闭报修')" v-if="data.state==1" class="fs-24 mr-10" style="color: #23BBEE;">
							关闭报修</text> -->
					</view>
					<view v-if="data.state==2||data.state==3" class="flex-column br-12 fs-28 mt-30"
						style="background: #EBF5F0;">
						<view class="flex pad-30">
							<text class="fw-700 w-200" style="text-align: left;">负责人：</text>
							<text>{{data.accountName}}</text>
						</view>
						<view class="flex pad-30">
							<text class="fw-700 w-200" style="text-align: left;">手机号：</text>
							<text>{{data.accountMobile}}</text>
						</view>
						<view class="flex pad-30" v-if="data.state==3">
							<text class="fw-700 w-200" style="text-align: left;">完成时间：</text>
							<text>{{data.completeTime}}</text>
						</view>
					</view>
					<view v-if="data.state==4" class="flex pad-30 br-12 mt-30" style="background: #EBF5F0;">
						<text class="fw-700 w-200" style="text-align: left;">关闭时间：</text>
						<text>{{data.closeTime}}</text>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="h-140 pt-20">
			<view class="full-btn" v-if="data.state==2" style="color:#EEA616;" @click="onCz('去支付')">
				去支付
			</view>
			<view @click="onCz('关闭报修')" class="full-btn" style="color: #FF682D;" v-if="data.state==1">
				取消报修
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 0,
				reason: '',
				submitShow: false,
				images: '',
				id: '',
				data: {},
			};
		},
		onLoad(e) {
			this.id = e.id
			this.getData()
		},
		methods: {
			getData() {
				const params = {
					url: '/api/repairs/' + this.id,
					method: 'GET',
				}
				this.$request(params).then(res => {
					this.data = res.data
				})
			},
			gb() {
				const params = {
					url: '/api/repairs/cancel/' + this.id,
					method: 'PUT',
				}
				this.$request(params).then(res => {
					this.getData()
				})
			},
			onCz(e) {
				if (e == "关闭报修") {
					this.$wskj.showModal('提示', '确定关闭报修？', true, (confirmed) => {
						if (confirmed) {
							this.gb();
						}
					});
					return
				}
				if (e == "去支付") {
					this.pay()
					return
				}
			},
			pay() {
				const params = {
					url: '/api/payRecord/pay',
					loadingTip: '',
					data: {
						orderId: this.id,
						amount: this.data.money,
						payBizCode: "MAINTAIN", //PRESTORE（预存）MAINTAIN（维修）
					}
				}
				this.$request(params).then(res => {
					uni.requestPayment({
						provider: 'wxpay',
						appid: res.data.data.appId, // 微信开放平台 - 应用 - AppId，注意和微信小程序、公众号 AppId 可能不一致
						nonceStr: res.data.data.nonceStr, // 随机字符串
						package: res.data.data.package, // 固定值
						timeStamp: res.data.data.timeStamp, // 时间戳（单位：秒）
						paySign: res.data.data.paySign, // 签名，这里用的 MD5/RSA 签名
						signType: 'MD5',
						success: (res) => {
							this.getData()
						},
						fail: (err) => {
							console.log(err);
						}
					});
				})
			},

		},
	};
</script>

<style scoped>
	.center {
		height: 100vh;
		display: flex;
		flex-direction: column;
		background: white;
	}
</style>