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

  https://www.mall4j.com/

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

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

<template>
  <view
    class="Mall4j page-store-settings-apply-online"
    :style="{height:windowHeight+'px'}"
  >
    <view>
      <view class="setting-info-item">
        <view class="title">
          {{ $t('chuLiRen') }}
        </view>
        <view class="input-box">
          <uni-easyinput
            v-model="infoData.handler"
            type="text"
            disabled
            :clearable="false"
            :placeholder="admin"
          />
        </view>
      </view>
      <view class="setting-info-item">
        <view class="title">
          {{ $t('xiaXianYuanYin') }}
        </view>
        <view class="input-box">
          <uni-easyinput
            v-model="infoData.offlineReason"
            type="text"
            disabled
            :clearable="false"
            :placeholder="admin"
          />
        </view>
      </view>
      <view class="setting-info-item">
        <view class="title">
          {{ $t('xiaXianShiJian') }}
        </view>
        <view class="input-box">
          <uni-easyinput
            v-model="infoData.updateTime"
            type="text"
            disabled
            :clearable="false"
            :placeholder="admin"
          />
        </view>
      </view>
      <view class="setting-info-item">
        <view class="title">
          <text class="star">
            *
          </text>
          <text>{{ $t('shenQingLiYou') }}</text>
        </view>
        <view class="textarea-box">
          <textarea
            v-model="reapplyReason"
            :placeholder="$t('qingShuRuShenQingLiYou')"
            maxlength="200"
            @blur="checkInput()"
          />
        </view>
        <view
          v-show="reapplyReasonRules"
          class="tic"
        >
          {{ $t('qingShuRuShenQingLiYou-0') }}
        </view>
      </view>
      <view
        v-if="infoData.offlineHandleEventItemList&&infoData.offlineHandleEventItemList.length"
        class="setting-info-item"
      >
        <view class="title">
          {{ $t('shenQingLiShi') }}
        </view>
        <view
          v-for="(value,item) in infoData.offlineHandleEventItemList"
          :key="item"
          class="textarea-box applyLog-box "
        >
          <view>
            <text>{{ $t('shenQingShiJian') }}</text>
            <text>{{ value.reapplyTime }}</text>
          </view>
          <view>
            <text>{{ $t('shenQingLiYou-0') }}</text>
            <text>{{ value.reapplyReason }}</text>
          </view>
          <view>
            <text>{{ $t('shenHeJieGuo') }}</text>
            <text>{{ value.refuseReason }}</text>
          </view>
        </view>
        <!-- <view v-if="!infoData.offlineHandleEventItemList" class="textarea-box not-applyLog-box">暂无申请记录</view> -->
      </view>
    </view>
    <button
      type="primary"
      class="submit button"
      @tap="auditApply"
    >
      {{ $t('tiJiaoShenQing') }}
    </button>
    <!-- <button v-if=" infoData.status===1" type="primary" class="submit" @tap="auditApply">提交申请</button> -->
  </view>
</template>

<script setup>
import { reactive } from 'vue'

const Data = reactive({
  infoData: {
  },
  reapplyReason: '',
  reapplyReasonRules: false,
  // 设备显示高度
  windowHeight: 0
})

const { infoData, reapplyReason, reapplyReasonRules, windowHeight } = toRefs(Data)

onLoad(() => {
  uni.getSystemInfo({
    success: (res) => {
      Data.windowHeight = res.windowHeight
    }
  })
})

onShow(() => {
  uni.setNavigationBarTitle({
    title: $t('shenQingShangXian')
  })
})

onReady(() => {
  getOfflineHandleEvent()
})

// 获取店铺下线信息
const getOfflineHandleEvent = () => {
  http.request({
    url: '/shop/shopDetail/getOfflineHandleEvent',
    method: 'GET'
  }).then(({ data }) => {
    if (data.offlineHandleEventItemList) {
      data.offlineHandleEventItemList = data.offlineHandleEventItemList.filter((element) => {
        return element.reapplyTime || element.reapplyReason || element.refuseReason
      })
    }
    Data.infoData = data
  })
}

// 提交审核
const auditApply = () => {
  if (Data.infoData.status === 2) {
    return uni.showToast({
      title: $t('shenHeZhong'),
      icon: 'error'
    })
  }
  Data.reapplyReasonRules = !Data.reapplyReason.trim()
  if (Data.reapplyReasonRules) return
  http.request({
    data: {
      eventId: Data.infoData.eventId,
      reapplyReason: Data.reapplyReason
    },
    url: '/shop/shopDetail/auditApply'
  }).then(() => {
    uni.showToast({
      title: $t('tiJiaoChengGong'),
      icon: 'success',
      mask: true,
      success: () => {
        setTimeout(() => {
          uni.switchTab({ url: '/pages/store-settings/store-settings' })
        }, 1500)
      }
    })
  })
}

const checkInput = () => {
  Data.reapplyReasonRules = !Data.reapplyReason.trim()
}
</script>

<style lang="scss" scoped>
@use "store-settings-apply-online";
</style>
