<template>
  <el-col>
    <div class="loading" v-if="load">
      <i class="el-icon-loading"></i>
      <span>授权中...</span>
    </div>
    <template v-else>
      <el-result icon="success" title="授权成功" :subTitle="value.platformType + ' - ' + value.refUserNick" v-if="autoState">
        <template slot="extra">
          <!-- <div class="time">刷新授权过期:{{ value.expiresTime }}</div>
          <div class="time">授权过期时间:{{ value.reExpiresTime }}</div> -->
          <el-button type="primary" size="medium" @click="back">返回</el-button>
        </template>
      </el-result>
      <el-result v-else icon="warning" :title="title" :subTitle="errMsg">
        <template slot="extra">
          <el-button type="primary" size="medium" @click="back">返回</el-button>
        </template>
      </el-result>
    </template>
  </el-col>
</template>

<script lang="ts">
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
import { shopAdd } from '@/api/shop'
import {getQueryObject} from '@/benyun/utils'
@Component({components:{}})
export default class ShopAuto extends Vue {
  value:any={}
  load=true
  autoState=false
  title='提示'
  errMsg=''
  mounted(){
    this.$nextTick(()=>{
      let parames=getQueryObject();
      this.value = parames;
      if(parames.id){
        shopAdd({
          tenantId:(this as any).$store.getters.userInfo.tenantId,
          shopId:parames.id,
          platformType:parames.platformType,
          userNick:parames.refUserNick,
          userId:parames.refUserId,
          expireDate:parames.expiresTime,
          refreshExpiresTime:parames.reExpiresTime
        }).then(()=>{
          this.autoState = true
          this.load = false
          this.$message({
            message:'店铺授权成功！',
            type:'success'
          })
        }).catch((res:any)=>{
          this.title = '提示'
          if(res.message){
            this.errMsg = res.message
          }else{
            this.errMsg = '操作失败！'
          }
          
          this.load = false
        })
      }else{
        this.load = false
        this.title = decodeURIComponent(parames.msg);
        this.errMsg = decodeURIComponent(parames.subMsg);
        this.errMsg = this.errMsg ? this.errMsg.replaceAll('+',''): this.errMsg;
      }
    })
  }

  back(){
    this.$router.push({path:`/oms/shop`})
    // let url = window.location.protocol + window.location.host + '/oms/shop'
    // window.location.href = url
  }
}
</script>

<style lang="scss" scoped>
.time{
  font-size: 14px;
  padding-bottom: 4px;
}
.loading{
  text-align: center;
  padding-top: 32px;
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
  i{
    font-size: 36px;
  }
  span{
    // color: dodgerblue;
    padding-left: 8px;
    font-size: 14px;
    padding-top: 8px;
  }
}
</style>