<template>
	<view class="box">
		<view class="content">


			<view class="leftTitle2" style="padding: 24rpx 0; border-bottom: 1rpx solid #EEEEEE;">原服务门店信息</view>

			<view class="shopBg">
				<view class="leftTitle2">{{oldStoreName}}</view>
				<view class="addrressBg">
					<image src="../../static/img/icon_coordinate.png" mode="" style="width: 22rpx; height: 30rpx;">
					</image>
					<view style="color: #999999; font-size: 24rpx; margin-left: 20rpx;">{{oldStoreAddress}}</view>
				</view>
			</view>
		</view>

		<view class="content">
			<view class="viewBg">
				<image src="../../static/img/icon_xinghao.png" mode="" style="width: 14rpx; height: 14rpx;"></image>
				<view class="leftTitle">更换门店</view>
				<view class="blackColor width70" :class="{grayColor: store==''}" @click="storeChange">
					{{store == ''? '请选择':store}}
				</view>

				<image src="../../static/img/rightArrow.png" mode="" style="width: 13rpx; height: 23rpx;"></image>


			</view>

		</view>


		<view class="content">
			<view class="viewBg" style="border-bottom: 1rpx solid #EEEEEE;">
				<image src="../../static/img/icon_xinghao.png" mode="" style="width: 14rpx; height: 14rpx;"></image>
				<view class="leftTitle">更换原因</view>
				<picker class="width70" mode="selector" :range="reasonNameArray" @change="reasonChange">
					<view class="blackColor" :class="{grayColor: reason==''}">
						{{reason == '' ? '请选择' : reason}}

					</view>
				</picker>

				<image src="../../static/img/rightArrow.png" mode="" style="width: 13rpx; height: 23rpx;"></image>


			</view>

			<view class="viewBg">

				<view class="leftTitle">补充描述</view>

				<textarea placeholder-style="color:#999999" placeholder="选填,请输入补充描述" v-model="exeContent"
					class="textareaCont" maxlength="-1" auto-height="true" @confirm="feedDone" />

			</view>
		</view>

		<view class="bottom">
			<view class="shoreDz" @click="submit">提交</view>
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				sheetId: '',
				oldShopID:'',
				oldStoreName: '',
				oldStoreAddress: '',
				store: '',
				storeId: '',
				reasonArray: [],
				reasonNameArray: [],
				reasonId: '',
				reason: "",
				exeContent: '',
				edit: '', //修改申请
				editId: '',
				brand:'',
			}
		},
		onLoad(opt) {
			this.sheetId = opt.sheetId;
			this.oldShopID = opt.oldShopID;
			this.oldStoreName = opt.oldStoreName;
			this.oldStoreAddress = opt.oldStoreAddress;
			this.getChangeData();
			console.log(this.sheetId);
			this.brand = opt.brand;
			
			//修改申请
			this.edit = opt.edit;
			this.editId = opt.editId;
			this.oldShopID = opt.oldShopID;
			this.oldStoreName = opt.oldStoreName;
			this.oldStoreAddress = opt.oldStoreAddress;
			this.store = opt.store;
			this.storeId = opt.storeId;
			this.reasonId = opt.reasonId;
			this.reason = opt.reason;
			this.exeContent = opt.exeContent;
			if (opt.exeContent == null || opt.exeContent == 'null') {
				this.exeContent = ''
			}
		},
		onShow() {
			let storeMes = uni.getStorageSync('changeStore')
			if (storeMes) {
				this.storeId = storeMes.shopId
				this.store = storeMes.shopName
			}
			
		},
		methods: {
			submit() {
				console.log(this.reason, this.reasonId);
				if (!this.store) {
					uni.showToast({
						title: '请选择更换门店',
						icon: 'none',
						duration: 2000,
					});
					return;
				}
				if (!this.reasonId) {
					uni.showToast({
						title: '请选择更换原因',
						icon: 'none',
						duration: 2000,
					});
					return;
				}

				if (this.edit == 'true') {
					console.log('修改申请');
					this.editUrl();
				} else {
					this.addUrl();
				}

			},
			addUrl() {
				uni.showLoading({
					title: '保存中'
				})

				this.$http('worldKeepCar/orderChangeShop/applyChangeShop',
					{
						sheetId: this.sheetId,
						applyReasonId: this.reasonId,
						applyReason: this.reason,

						reasonComment: this.exeContent,
						newShopId: this.storeId,
						newShopName: this.store,

					}, 'POST').then(res => {
					uni.hideLoading();
					if (res.code == 0) {
						
						uni.removeStorageSync('changeStore')
						
						uni.showModal({
						    title: '更换门店申请成功,请等待平台处理',
						    content: '您可以在【我的-更换门店申请记录】里查看申请的处理进度哦',
							showCancel:false,
							confirmText:'知道了',
						    success: function (res) {
						        if (res.confirm) {
						           uni.navigateBack({
						           	
						           })
						        } 
						    }
						});
						
					}



				})
			},
			editUrl() {
				uni.showLoading({
					title: '保存中'
				})
				this.$http('worldKeepCar/orderChangeShop/editApply',
					{

						applyReasonId: this.reasonId,
						applyReason: this.reason,

						reasonComment: this.exeContent,
						newShopId: this.storeId,
						newShopName: this.store,
						id: this.editId,

					}, 'POST').then(res => {
					uni.hideLoading();
					if (res.code == 0) {
						uni.removeStorageSync('changeStore')
						
						uni.showModal({
						    title: '更换门店申请成功,请等待平台处理',
						    content: '您可以在【我的-更换门店申请记录】里查看申请的处理进度哦',
							showCancel:false,
							confirmText:'知道了',
						    success: function (res) {
						        if (res.confirm) {
						           uni.navigateBack({
						           	
						           })
						        } 
						    }
						});
					}



				})
			},
			getChangeData() {
				uni.showLoading({
					title: '加载中'
				})
				let url = 'worldKeepCar/orderChangeShop/refuseReasonList',
					params = {
						type: 1,

					}
				this.$http(url, params, 'GET').then(res => {

					uni.hideLoading();

					this.reasonArray = res.data

					this.reasonArray.forEach((item, index) => {
						this.reasonNameArray.push(item.contents)
					});

					console.log(this.reasonNameArray);


				})
			},
			feedDone(e) {
				this.exeContent = e.target.value

			},
			storeChange(e) {
				uni.navigateTo({

					url: '../module/orderShop?fromChangeStore=true'+'&oldShopID='+this.oldShopID+'&brand='+this.brand
				})
			},
			reasonChange(e) {

				this.reasonId = this.reasonArray[e.target.value].id
				this.reason = this.reasonArray[e.target.value].contents
			}
		}
	}
</script>

<style scoped>
	.box {
		min-height: 100vh;
		background: #F4F5F7;
		padding-top: 20rpx;
	}

	.content {
		background-color: #FFFFFF;
		border-radius: 10rpx;
		margin: 20rpx 24rpx;
		padding: 0 20rpx;
	}

	.shopBg {
		padding: 30rpx 0;
	}

	.addrressBg {
		padding-top: 12rpx;
		display: flex;
		align-items: center;
	}

	.viewBg {
		display: flex;
		align-items: center;
		padding: 30rpx 0;
	}

	.width70 {
		width: 70%;
	}

	.leftTitle2 {
		color: #333333;
		font-size: 28rpx;

	}

	.leftTitle {
		color: #333333;
		font-size: 28rpx;
		width: 130rpx;
		margin-right: 50rpx;
	}

	.blackColor {
		color: #333333;
		font-size: 28rpx;
	}

	.grayColor {
		color: #999999;
		font-size: 28rpx;
	}

	.textareaCont {

		width: 70%;
		font-size: 28rpx;
		color: #333333;

	}

	.bottom {
		width: 750rpx;
		height: 120rpx;
		background: #FFFFFF;
		box-shadow: 0px -4px 8px 0px rgba(153, 153, 153, 0.08);
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		justify-content: space-around;
	}

	.shoreDz {
		width: 702rpx;
		height: 74rpx;

		background: linear-gradient(135deg, #FD5300 0%, #FF270A 100%);
		border-radius: 37rpx;
		text-align: center;
		line-height: 74rpx;
		color: #FFFFFF;
		font-size: 30rpx;
		margin-top: 24rpx;
	}
</style>