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

  https://www.mall4j.com/

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

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

<template>
  <view class="Mall4j prod-application">
    <uni-forms>
      <uni-forms-item
        name="creditCode"
        class="setting-info-item"
      >
        <view class="title">
          <text class="txt">
            {{ $t('chuLiRen') }}
          </text>
        </view>
        <view class="input-box">
          {{ dataForm.handler }}
        </view>
      </uni-forms-item>
      <uni-forms-item
        name="firmName"
        class="setting-info-item"
      >
        <view class="title">
          <text class="txt">
            {{ $t('chuLiZhuangTai') }}
          </text>
        </view>
        <view class="input-box">
          {{ statusList[dataForm.status] }}
        </view>
      </uni-forms-item>
      <uni-forms-item
        name="residence"
        class="setting-info-item"
      >
        <view class="title">
          <text class="txt">
            {{ $t('xiaXianYuanYin') }}
          </text>
        </view>
        <view class="input-box reason">
          {{ dataForm.offlineReason }}
        </view>
      </uni-forms-item>
      <uni-forms-item
        name="representative"
        class="setting-info-item"
      >
        <view class="title">
          <text class="txt">
            {{ $t('xiaXianShiJian') }}
          </text>
        </view>
        <view class="input-box">
          {{ dataForm.createTime }}
        </view>
      </uni-forms-item>
      <uni-forms-item
        v-if="dataForm.status === 1 || dataForm.status === 4"
        name="capital"
        class="setting-info-item capital"
      >
        <view class="title">
          <text class="star">
            *
          </text>
          <text class="txt">
            {{ $t('shenQingLiYou') }}
          </text>
        </view>
        <view class="application-input-box application-input-res">
          <textarea
            v-model="reapplyReason"
            style="height: 100%"
          />
        </view>
      </uni-forms-item>
      <uni-forms-item
        v-if="hasHis"
        name="capital"
        class="setting-info-item capital"
      >
        <view class="title">
          <text class="txt">
            {{ $t('shenQingLiShi') }}
          </text>
        </view>
        <view
          v-for="item in dataForm.offlineHandleEventItemList"
          :key="item.eventItemId"
          class="input-box-his"
        >
          <view v-if="item.createTime">
            {{ $t('shenQingShiJian') }}{{ item.createTime }}
          </view>
          <view
            v-if="item.reapplyReason"
            class="reason"
          >
            {{ $t('shenQingLiYou-0') }}{{ item.reapplyReason }}
          </view>
          <view v-if="item.auditTime">
            {{ $t('shenHeShiJian') }}{{ item.auditTime }}
          </view>
          <view
            v-if="item.refuseReason"
            class="reason"
          >
            {{ $t('juJueYuanYin-0') }}{{ item.refuseReason }}
          </view>
        </view>
      </uni-forms-item>

      <view class="footer">
        <button
          v-if="dataForm.status === 1 || dataForm.status === 4"
          type="default"
          hover-class="none"
          @tap="dataFormSubmit(dataForm.status !== 1 && dataForm.status !== 4)"
        >
          {{ $t('tiJiaoShenQing') }}
        </button>
      </view>
    </uni-forms>
  </view>
</template>

<script setup>
// <!-- 1平台进行下线 2 重新申请，等待审核 3.审核通过 4 审核未通过 -->
const statusList = reactive({
  1: $t('weiGuiXiaJia'),
  2: $t('dengDaiShenHe'),
  3: $t('yiTongGuo'),
  4: $t('shenHeBuTongGuo')
})

let prodId = ''
onLoad((options) => {
  prodId = options.prodId
  getOrderInfoById()
})

/**
 * 获取详情
 */
const dataForm = ref({})
const hasHis = ref(true)
const getOrderInfoById = () => {
  const params = {
    url: `/prod/prod/getOfflineHandleEventByProdId/${prodId}`,
    method: 'GET'
  }
  http.request(params).then(({ data }) => {
    if (!data) {
      uni.reLaunch({
        url: '/package-prod/pages/prod-management/prod-management'
      })
      return
    }
    hasHis.value = data?.offlineHandleEventItemList?.filter(x => x.createTime).length > 0
    dataForm.value = data
    uni.setNavigationBarTitle({
      title: (data.status === 1 || data.status === 4 ? $t('shenQingShangJia') : $t('shenHeLiShi'))
    })
  })
}
/**
 * 提交
 */
const reapplyReason = ref('')
const dataFormSubmit = (status) => {
  const reg = /^\s+$/g
  if (status) {
    return
  }
  if (!reapplyReason.value || !reapplyReason.value.trim()) {
    uni.showToast({
      title: $t('shenQingLiYouBuNengWeiKong'),
      mask: true,
      icon: 'none',
      duration: 1200
    })
    return
  }
  if (reg.test(reapplyReason.value)) {
    uni.showToast({
      title: $t('neiRongBuNengQuanWeiKongGe'),
      mask: true,
      icon: 'none',
      duration: 1200
    })
    return
  }
  uni.showModal({
    title: $t('tiShi'),
    content: $t('queDingTiJiaoShenQingMa'),
    cancelText: $t('quXiao-0'),
    confirmText: $t('queDing'),
    success (res) {
      if (res.confirm) {
        const params = {
          url: '/prod/prod/auditApply',
          method: 'post',
          data: {
            eventId: dataForm.value.eventId,
            handleId: prodId,
            reapplyReason: reapplyReason.value
          }
        }
        http.request(params).then(() => {
          uni.showToast({
            title: $t('caoZuoChengGong-0'),
            mask: true,
            icon: 'none',
            duration: 1200
          })
          setTimeout(() => {
            uni.navigateBack(1)
          }, 1200)
        })
      }
    }
  })
}

</script>

<style lang="scss" scoped>
@use './prod-application.scss';
</style>
