<template>
	<view>
		<!-- tabs栏 -->
		<view class="backcorfff width100">
			<QSTabs ref="tabs" :tabs="tabs" animationMode="line2" :current="current" @change="change"
				activeColor="#089bf5" lineColor="#089bf5" minWidth="220">
			</QSTabs>
		</view>

		<!-- 商户信息 -->
		<view class="mart15 width100 backcorfff" v-if="current == 0">
			<view class="notes">
				<view class="fcor666 width25">账号</view>
				<view class="font14 fcor333 text2 width75 fotrt" v-if="merDesInfo&&merDesInfo.account">{{merDesInfo.account.loginName}}</view>
			</view>
			<view class="notes">
				<view class="fcor666 width25">商户ID</view>
				<view class="font14 fcor333 text2 width75 fotrt">{{merDesInfo.merNo}}</view>
			</view>
			<view class="notes">
				<view class="fcor666 width25">商户名称</view>
				<view class="font14 fcor333 text2 width75 fotrt">{{merDesInfo.merName}}</view>
			</view>

			<view class="notes" v-if="merDesInfo&&merDesInfo.account">
				<view class="fcor666 width25">商户状态</view>
				<view class="font14 fcor333 text2 width75 fotrt" v-if="merDesInfo.account.status == 1">正常</view>
				<view class="font14 fcor333 text2 width75 fotrt" v-if="merDesInfo.account.status == 4">违规</view>
			</view>
			<view class="notes">
				<view class="fcor666 width25">联系人</view>
				<view class="font14 fcor333 text2 width75 fotrt" v-if="merDesInfo&&merDesInfo.account">{{merDesInfo.account.userName}}</view>
			</view>
			<view class="notes">
				<view class="fcor666 width25">手机号</view>
				<view class="font14 fcor333 text2 width75 fotrt">{{merDesInfo.regPhone}}</view>
			</view>
			<!-- <view class="notes">
				<view class="fcor666 width25">身份证号</view>
				<view class="font14 fcor333 text2 width75 fotrt">-</view>
			</view> -->
			<view class="notes">
				<view class="fcor666 width25">银行卡号</view>
				<view class="font14 fcor333 text2 width75 fotrt" v-if="merDesInfo.merSettleAcct">{{merDesInfo.merSettleAcct.bankCardNo}}</view>
			</view>
			<view class="notes">
				<view class="fcor666 width25">所属银行</view>
				<view class="font14 fcor333 text2 width75 fotrt" v-if="merDesInfo.merSettleAcct">{{merDesInfo.merSettleAcct.bankName}}</view>
			</view>

		</view>
		<!-- 门店信息 -->
		<view class="mart15 width100" v-if="current == 1">
			<view class="width94 backcorfff border-r mart15" v-for="(item,index) in storeList" :key="index"
				@click="jumpstoredes(item.id)">
				<view class="notes" style="border-bottom: 0px;">
					<image src="../../../static/img/store/store7.png" mode="widthFix" class="iconw40 height40p"></image>
					<view class="width65 margle">
						<view class="font14 fcor333">{{item.name}}</view>
						<view class="font12 fcor999">{{item.updateTime | timeFormat('yyyy-mm-dd')}}
							{{item.updateTime | timeFormat('hh:mm')}}
						</view>
					</view>
					<view class="storestus" v-if="item.status == 2">
						正常
					</view>
					<view class="otstatucs" v-if="item.status == 1">
						编辑中
					</view>
					<view class="otstatucs" v-if="item.status == 3">
						审核中
					</view>
					<view class="otstatucs" v-if="item.status == 4">
						审核失败
					</view>
					<view class="otstatucs" v-if="item.status == 5">
						停用
					</view>
				</view>
				<view class="conts" style="border-bottom: 0px;">
					<image src="../../../static/img/store/store8.png" mode="widthFix" class="iconw"></image>
					<view class="margle10 font14 fcor999">{{item.account.telephone}}</view>
				</view>
				<view class="conts" style="border-bottom: 0px;">
					<image src="../../../static/img/store/store9.png" mode="widthFix" class="iconw"></image>
					<view class="margle10 font14 fcor999">{{item.telephone}}</view>
				</view>
				<view class="conts" style="border-bottom: 0px;">
					<image src="../../../static/img/store/store10.png" mode="widthFix" class="iconw"></image>
					<view class="margle10 font14 fcor999 width90p">{{item.storeRegion.address}}</view>
				</view>
				<view class="height45 width100">
					<button class="btns mart10 margle10" @click.stop="jumpBindScan(item.id,1)">绑定二维码</button>
					<button class="btns mart10 margle10" @click.stop="jumpBindScan(item.id,2)">二维码列表</button>
					<button class="btns mart10 margle10" @click.stop="jumpService(item.id)">绑定设备</button>
					<button class="btns mart10 margle10" @click.stop="jumpGroupService(item.id)">团购配置</button>
					<!-- <button class="btns mart10 marRight10" @click.stop="jumpService(item.id,2)">设备列表</button> -->
				</view>
				<view class="lin10"></view>
			</view>
		</view>
		<!-- 渠道列表 -->
		<view class="mart15 width100" v-if="current == 2">
			<!-- v-for="(item,indexplt) in merPlatformList" :key="indexplt" -->
			<view class="width94 backcorfff border-r mart15 paddbotm10" v-for="(item,indexplt) in merPlatformList"
				:key="indexplt" @click="jumpDetailsparts(item.merId,item.platformType)">
				<view class="notes" style="border-bottom: 0px;">
					<view class="width70 margle">
						<view class="font16 fcor333" v-if="item.platformType == 1">渠道名称: 拉卡拉</view>
						<view class="font16 fcor333" v-if="item.platformType == 5">渠道名称: 随行付</view>
						<view class="font14 fcor999 mart5" v-if="item.cupNo">商户号: {{item.cupNo}}</view>
						<view class="font14 fcoreb5 mart5" v-if="item.suggestionReject">审核驳回原因:
							{{item.suggestionReject}}
						</view>
					</view>
					<view class="otstatucs" v-if="item.status == 0">
						不可用
					</view>
					<view class="storestus" v-if="item.status == 1">
						可用
					</view>
					<view class="otstatucs" v-if="item.status == 2">
						审核中
					</view>
					<view class="otstatucs" v-if="item.status == 3">
						审核驳回
					</view>
				</view>
				<view class="btnschange width90 border-r" v-if="item.platformType == 1 && !item.currentPlatform"
					@click.stop="switchPlatform(item.merId,item.platformType)">切换拉卡拉</view>
				<view class="btnschange width90 border-r" v-if="item.platformType == 5 && !item.currentPlatform"
					@click.stop="switchPlatform(item.merId,item.platformType)">切换随行付</view>
			</view>
		</view>
		<view class="width94 alijus" v-if="current == 0">
			<view class="subbtn" @tap="updateFigMerBasis()">修改结算</view>
			<view class="subbtn" @tap="updatemodifyRate()">修改费率</view>
		</view>
	</view>
</template>

<script>
	import QSTabs from '../../../components/QS-tabs/QS-tabs.vue';
	import {
		getMerDetail,
		getStoreListByMer,
		getMerPlatformList,
		switchPlatform
	} from '../../../Utils/Api.js';
	export default {
		components: {
			QSTabs
		},
		data() {
			return {
				tabs: ["商户信息", "门店信息", "渠道列表"],
				current: 0, // tabs默认值
				storeList: [], // 门店数据
				merid: '', // 商户id
				merDesInfo: '', // 门店信息
				merPlatformList: '' //渠道列表

			}
		},
		onLoad(options) {
			this.merid = options.id;
			this.getMerDetail(this.merid);
		},
		onShow() {
			this.getMerPlatformList();
		},
		methods: {
			//筛选
			change(index) {
				this.$refs.tabs.setFinishCurrent(index);
				this.current = index;
				if (index == 1) {
					this.getStoreListByMer();
				}
				if (index == 2) {
					this.getMerPlatformList();
				}
			},
			//查询商户信息
			getMerDetail(item) {
				uni.showLoading({
					title: '加载中...'
				})
				let datas = {
					merId: item
				}
				getMerDetail(datas).then(res => {
					uni.hideLoading();
					if (res.return_code == '000000' && res.return_data) {
						this.merDesInfo = res.return_data;
					} else {
						uni.showToast({
							title: res.return_msg,
							duration: 2000,
							icon: 'none'
						})
					}
				})
			},
			//查询门店列表
			getStoreListByMer() {
				uni.showLoading({
					title: '加载中...'
				})
				let datas = {
					merId: this.merid,
					pageNum: 1,
					pageSize: 10
				}
				getStoreListByMer(datas).then(res => {
					uni.hideLoading();
					if (res.return_code == '000000' && res.return_data.list) {
						this.storeList = res.return_data.list;
					} else {
						uni.showToast({
							title: res.return_msg,
							duration: 2000,
							icon: 'none'
						})
					}
				})
			},
			//查询渠道列表
			getMerPlatformList() {
				uni.showLoading({
					title: '加载中...'
				})
				let datas = {
					merId: this.merid
				}
				getMerPlatformList(datas).then(res => {
					uni.hideLoading();
					if (res.return_code == '000000' && res.return_data) {
						this.merPlatformList = res.return_data;
					} else {
						uni.showToast({
							title: res.return_msg,
							duration: 2000,
							icon: 'none'
						})
					}
				})
			},
			//跳转门店详情
			jumpstoredes(item) {
				uni.navigateTo({
					url: '../store-details/store-details?id=' + item
				})
			},
			//跳转设备管理
			jumpService(item) {
				uni.navigateTo({
					url: '/pages/index/mineService/mineService?id=6' + '&storeid=' + item
				})
			},
			//跳转团购配置
			jumpGroupService(id){
				uni.navigateTo({
					url:"/subpackages/groupBuyingConfiguration/groupBuyingConfiguration?storeId="+id
				})
			},
			//更换结算信息
			updateFigMerBasis() {
				uni.navigateTo({
					url: '/pages/index/updateSettlement/updateSettlement?id=' + this.merid
				})
			},
			//修改费率
			updatemodifyRate() {
				uni.navigateTo({
					url: '/pages/index/modifyRate/modifyRate?id=' + this.merid
				})
			},
			//跳转绑定二维码
			jumpBindScan(item, items) {
				uni.navigateTo({
					url: '../bindScan/bindScan?storeid=' + item + '&type=' + items
				})
			},
			//跳转进件
			jumpDetailsparts(item, item1) {
				uni.navigateTo({
					url: '../merchant-incoming-parts/merchant-incoming-parts?id=' + item + '&merPlatformType=' +
						item1
				})
			},
			//切换渠道
			switchPlatform(item, item1) {
				uni.showModal({
					title: '切换渠道',
					content: '是否确认切换当前渠道',
					success: (res) => {
						if (res.confirm) {
							uni.showLoading({
								title: '处理中...'
							})
							let data = {
								"merId": item,
								"platformType": item1
							}
							switchPlatform(data).then(res => {
								uni.hideLoading();
								if (res.return_code == '000000') {
									this.getMerPlatformList();
								}
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f6f6f6;
	}

	.notes {
		width: calc(100% - 40rpx);
		display: flex;
		align-items: flex-start;
		padding: 30rpx 0 30rpx 20rpx;
		border-bottom: 1px solid #f6f6f6;
	}

	.storestus {
		padding: 1px 5px;
		color: #91bb88;
		font-size: 14px;
		background-color: #e8fbe6;
	}

	.otstatucs {
		background-color: #fbeee4;
		color: #db8c73;
		font-size: 14px;
		padding: 1px 5px;
	}

	.conts {
		width: calc(100% - 60rpx);
		display: flex;
		align-items: center;
		padding: 0 30rpx 10rpx 30rpx;
	}

	.btns {
		width: 21%;
		float: left;
		height: 35px;
		line-height: 35px;
		background-color: #0083f5;
		color: #FFFFFF;
		font-weight: bold;
		font-size: 12px;
		padding: 0px;
	}

	.subbtn {
		color: #FFFFFF;
		background-color: #0083f5;
		width: 40%;
		margin-left: 5%;
		margin-top: 80rpx;
		margin-bottom: 50rpx;
		height: 90rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 10rpx;
		font-size: 30rpx;
	}

	.lin10 {
		height: 10px;
	}

	.btnschange {
		background-color: #0083f5;
		font-size: 14px;
		width: 90px;
		text-align: center;
		padding-top: 5px;
		padding-bottom: 5px;
		color: #FFFFFF;
	}
</style>