<!--
  Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.

  https://www.mall4j.com/

  未经允许，不可做商业用途！

  版权所有，侵权必究！
-->

<template>
  <!-- 店铺设置 -->
  <view class="Mall4j page-store-settings shop-setting-module">
    <view class="header">
      <view class="shop-basic-con">
        <view class="shop-logo">
          <img-show
            :class-list="['shop-logo']"
            :src="userInfo.shopLogo"
            :def-img-inx="2"
          />
        </view>
        <view class="con">
          <view class="shop-name">
            {{ userInfo.shopName?userInfo.shopName:userInfo.userName }}
          </view>
          <!-- <view class="shop-desc">(营业中，账号已启用，店铺已审核)</view> -->
          <view class="shop-desc">
            （
            <text v-if="userInfo.shopStatus===-1">
              {{ $t('weiKaiTong') }}
            </text>
            <text v-if="userInfo.shopStatus===0">
              {{ $t('tingYeZhong') }}
            </text>
            <text v-if="userInfo.shopStatus===1">
              {{ $t('yingYeZhong') }}
            </text>
            <text v-if="userInfo.shopStatus===2">
              {{ $t('weiGuiXiaXian') }}
            </text>
            <text v-if="userInfo.shopStatus===3">
              {{ $t('shangXianDaiShenHe') }}
            </text>
            <text v-if="userInfo.shopStatus===4">
              {{ $t('kaiDianShenQingZhong') }}
            </text>
            <text v-if="userInfo.shopStatus===5">
              {{ $t('kaiDianDaiShenHe') }}
            </text>

            <text v-if="userInfo.accountStatus===1">
              {{ $t('zhangHaoYiQiYong') }}
            </text>
            <text v-if="userInfo.accountStatus===0">
              {{ $t('zhangHaoYiJinYong') }}
            </text>
            <text v-if="userInfo.accountStatus===-1">
              {{ $t('zhangHaoYiShanChu') }}
            </text>

            <text v-if="auditingInfoStatus===0">
              {{ $t('dianPuWeiShenHe') }}
            </text>
            <text v-if="auditingInfoStatus===1">
              {{ $t('dianPuYiShenHe') }}
            </text>
            <text v-if="auditingInfoStatus===-1">
              {{ $t('dianPuShenHeWeiTongGuo') }}
            </text>
            <text v-if="auditingInfoStatus===-2">
              {{ $t('dianPuWeiTiJiaoShenHe') }}
            </text>
            )
          </view>
        </view>
      </view>
    </view>
    <!-- 菜单 -->
    <view class="setting-menu">
      <block
        v-for="item in menuList"
        :key="item.id"
      >
        <view
          v-if="item.authorities===true || util.isAuthorities(item.authorities)"
          class="menu-item"
          @tap="toSettingsPage(item.url)"
        >
          <view class="menu-name">
            {{ item.name }}
          </view>
          <view class="menu-operation">
            <view v-if="item.id===6" />
            <uni-icons
              class="ml-auto"
              type="arrowright"
              color="#999999"
            />
          </view>
        </view>
      </block>
    </view>
    <!-- 退出登录 -->
    <view
      v-if="userInfo.shopStatus===2 && paySettlementType!==1"
      class="logout-btn  apply-online"
      @tap="toSettingsPage('/package-settings/pages/store-settings-apply-online/store-settings-apply-online')"
    >
      {{ $t('shenQingShangXian') }}
    </view>
    <view
      class="logout-btn"
      @tap="logout"
    >
      {{ $t('tuiChuDengLu') }}
    </view>
    <!-- 切换语言 -->
    <switch-lang
      v-if="showSwitchLang"
      ref="switchLangRef"
    />
  </view>
</template>

<script setup>
import util from '@/utils/util'
import { WKSDK } from 'wukongimjssdk'
const paySettlementType = uni.getStorageSync('bbcPaySettlementType')

const userInfo = ref('')
const menuList = [
  {
    name: $t('jiBenXinXi'),
    id: 1,
    url: '/package-settings/pages/store-settings-basic/store-settings-basic',
    authorities: 'shop:shopDetail:view'
  },
  {
    name: $t('gongShangXinXi'),
    id: 2,
    url: '/package-settings/pages/store-settings-business/store-settings-business',
    authorities: 'shop:shopCompany:view'
  },
  {
    name: $t('qianYueXinXi'),
    id: 3,
    url: '/package-settings/pages/store-settings-contract/store-settings-contract',
    authorities: 'shop:shopContract:view'
  },
  {
    name: $t('caiWuXinXi'),
    id: 4,
    url: '/package-settings/pages/store-settings-financial/store-settings-financial',
    authorities: 'shop:shopFinancial:view'
  },
  {
    name: $t('xiuGaiMiMa'),
    id: 5,
    url: '/package-settings/pages/find-pwd/find-pwd?edit=1',
    authorities: true
  },
  {
    name: $t('qieHuanYuYan'),
    id: 6,
    url: 'switch-language',
    authorities: true
  }
]

onShow(() => {
  getUserInfo()
  getAuditingInfo()
  uni.setNavigationBarTitle({
    title: $t('dianPuSheZhi')
  })
  util.transTabbar()
})

onHide(() => {
  showSwitchLang.value = false
})

const showSwitchLang = ref(false)
const switchLangRef = ref()
/**
   * 跳转
   */
const toSettingsPage = (url) => {
  if (url === '/package-settings/pages/store-settings-financial/store-settings-financial' && paySettlementType === 1 && (userInfo.value.companyInfoProcessStatus === 0 || userInfo.value.companyInfoProcessStatus === 3)) {
    uni.navigateTo({
      url: '/package-settings/pages/allinpay-store-account/allinpay-store-account'
    })
    return
  }
  if (url === 'switch-language') {
    showSwitchLang.value = true
    nextTick(() => {
      switchLangRef.value.onShowLangs()
    })
    return
  }
  uni.navigateTo({
    url
  })
}
/**
   * 退出登录
   */
const logout = async () => {
  await WKSDK.shared().disconnect()
  uni.showLoading()
  const params = {
    url: '/logOut',
    method: 'POST'
  }
  http.request(params).then(() => {
    uni.hideLoading()
    uni.removeStorageSync('bbcToken_us')
    uni.removeStorageSync('bbcLoginResult')
    uni.removeStorageSync('bbcAuthorities')
    uni.redirectTo({
      url: '/pages/login/login'
    })
  })
}
/**
 * 获取用户信息
 */
const getUserInfo = () => {
  http.request({
    url: '/shop/shopDetail/info',
    method: 'GET'

  }).then(({ data }) => {
    userInfo.value = data
  })
}
/**
 * 获取审核状态
 */
const auditingInfoStatus = ref(null)
const getAuditingInfo = () => {
  http.request({
    url: '/shop/shopDetail/getAuditingInfo',
    method: 'GET'
  }).then(({ data: { status } }) => {
    auditingInfoStatus.value = status
  })
}

</script>

<style lang="scss" scoped>
@use './store-settings.scss';
</style>
