<template>
	<view>
		<!-- 预约列表 -->
		<view class="appointList">
			<template>
				<u-cell v-for="item in isLinkList1" :key="item.id" :border="false" :icon="item.icon" :title="item.title"
					isLink :url="item.url" />
			</template>
		</view>

		<view class="other-out-box">
			<u-cell v-for="item in isLinkList2" :key="item.id" :border="false" :icon="item.icon" :title="item.title"
				:isLink="item.isLink" :url="item.url" @click="handleCellClick(item)" />
		</view>

		<u-modal :show="showSwitchDialog" :showCancelButton="true" :title="title" :content="content"
			@confirm="confirmSwitch" @cancel="cancelSwitch  "></u-modal>
	</view>
</template>

<script>
	import {
		getMerchantAuthData
	} from '@/api/merchant/merchantAuth';
	export default {

		data() {
			return {
				isLinkList1: [{
						id: '0',
						icon: 'list-dot',
						title: '预约列表',
						url: '/PageMine/goodsReserve',
					}
					// ,
					// {
					//   id: '1',
					//   icon: 'list',
					//   title: '询价列表',
					//   url: '/pages/client/clientUser/inquiryList',
					// },
				],
				isLinkList2: [{
						id: '0',
						icon: 'home-fill',
						title: '我的店铺',
						url: '',
						isLink: true,
					},
					{
						id: '1',
						icon: 'plus-people-fill',
						title: '我的团队',
						url: '/PageMine/myTeam',
						isLink: true,
					},
					{
						id: '2',
						icon: 'server-man',
						title: '客服中心',
						url: '/PageMine/serviceCenter/index',
						isLink: true,
					},
					{
						id: '3',
						icon: 'share-square',
						title: '意见反馈',
						url: '/PageMine/feedback?channelType=0',
						isLink: true,
					},
					{
						id: '4',
						icon: 'thumb-up',
						title: '关于我们',
						url: '/PageMine/aboutUs',
						isLink: true,
					},
				],

				showSwitchDialog: false,
				title: '提醒',
				content: '您确定要从用户端切换到商家端吗?',
			};
		},

		methods: {
			handleCellClick(item) {
				console.log('item', item);
				if (item.id == 0) {
					this.showSwitchDialog = true;
				} else {
					// console.log('点击了非链接项');
				}
			},
			//点击取消时
			cancelSwitch() {
				this.showSwitchDialog = false
				this.title = "提醒"
				this.content = "您确定要从用户端切换到商家端吗?"
			},
			// 点击确认时
			confirmSwitch() {
				if (this.title == "提醒") {
					this.getMerchantAuth()

				} else if (this.title == "警告！") {
					//进入审核未通过详情
					uni.navigateTo({
						url: 'pageMerchant/mineModule/openStoreAppealDetail'
					});
					this.cancelSwitch()
				} else {
					// 进入开店流程页面
					uni.navigateTo({
						url: '/pageMerchant/mineModule/certification/index'
					});
					this.cancelSwitch()

				}

			},

			/*===========================================================*/
			// 获取商家信息
			async getMerchantAuth() {
				 let res = await getMerchantAuthData();
				if (res.code === 'OK' && res.data) {
					console.log(res, "获取商家信息")
					this.$store.dispatch('SwitchIdentity', 'MERCHANT')
					// 将数据存储到vuex中
					this.merchantInfo = Object.assign({}, {
						...res.data,
						mobileNumber: res.data.mobileNumber,
					});
					this.$store.commit('SET_MERCHANTINFO', res.data);
					if (res.data.reviewStatus == 2) {
						//跳转认证中页面
						uni.navigateTo({
							// url: '/pageMerchant/mineModule/certification/openStoreAppealDetail'
							url: 'pageMerchant/mineModule/openStoreAppealDetail'
						});
						this.cancelSwitch();
					} else if (res.data.reviewStatus == 1) {
				 
						uni.navigateTo({
							url: '/pageMerchant/index',
						});
						this.cancelSwitch();
					} else {
						this.title = "警告！"
						this.content = `认证未通过, ${res.data.message?'审核意见：' +res.data.message : "" }. 点击确认进入查看信息`
					}
				} else {
					this.title = "温馨提示！"
					this.content = "您还没有自己的店铺，如果您确定要开店，请点击确定进入开店流程"
				}
			},

		},
	};
</script>

<style lang="scss" scoped>
	.appointList {
		margin: 20rpx;
		padding: 20rpx 10rpx;
		border-radius: 10rpx;
		background-color: #fff;
	}

	.other-out-box {
		margin: 20rpx;
		padding: 20rpx 10rpx;
		border-radius: 10rpx;
		margin-top: 0;
		box-sizing: border-box;
		background-color: $uni-bg-color;
	}
</style>