<template>
  <view class="">
    <view v-if="state == -1" class="body-box">
      <div class="bg2"></div>
      <Navigater :title="t('rongzi.title')" style="background-color: transparent" :style="{ color: '#fff' }" :arrow-style="{ color: '#fff' }" />
      <scroll-view scroll-y :style="{ height: `calc(${store.pageHeight} - 3.125rem)`, position: 'relative' }">
        <div class="bg"></div>
        <view class="money">
          <view class="money-bg">
            <view class="tip-box">
              <view class="tip">{{ t('rongzi.tip38') }}</view>
              <view class="value"
                >{{ t('rongzi.tip39') }}<span>{{ t('rongzi.tip40') }}</span></view
              >
            </view>
          </view>
          <view class="card">
            <view class="tab-flex">
              <view class="tab-li">
                <view class="icon-box">
                  <div class="image_wrap">
                    <image src="/static/image/rongzi/icon1.png" class="icon"></image>
                  </div>
                  <view class="desc">{{ t('rongzi.tip1') }}</view>
                </view>
                <view class="main">{{ t('rongzi.tip2') }}</view>
              </view>
              <view class="tab-li">
                <view class="icon-box">
                  <div class="image_wrap">
                    <image src="/static/image/rongzi/icon2.png" class="icon"></image>
                  </div>
                  <view class="desc">{{ t('rongzi.tip3') }}</view>
                </view>
                <view class="main">{{ t('rongzi.tip4') }}</view>
              </view>
              <view class="tab-li">
                <view class="icon-box">
                  <div class="image_wrap">
                    <image src="/static/image/rongzi/icon3.png" class="icon"></image>
                  </div>
                  <view class="desc">{{ t('rongzi.tip5') }}</view>
                </view>
                <view class="main">{{ t('rongzi.tip6') }}</view>
              </view>
            </view>
            <view class="sq-txt">{{ t('rongzi.tip7') }}</view>
            <view class="color-gary">
              <view>{{ t('rongzi.tip8') }}</view>
              <view>{{ t('rongzi.tip9') }}</view>
              <view>{{ t('rongzi.tip10') }}</view>
            </view>

            <view class="info-box">
              <view>{{ t('rongzi.tip11') }}</view>
              <view class="list">
                <view style="width: auto">￥</view>
                <input v-model="params.money" style="font-size: 1.3125rem" type="number" :placeholder="t('rongzi.tip12')" />
              </view>
              <view class="xian"></view>
            </view>

            <view class="info-box">
              <view class="fs-16 list">{{ t('rongzi.tip13') }}</view>
              <view class="xian"></view>
              <view class="list">
                <view class="list-title">{{ t('rongzi.tip15') }}</view>
                <view>
                  <input v-model="params.name" :placeholder="t('rongzi.tip14')" class="info-input" />
                </view>
              </view>
              <view class="xian"></view>
              <view class="list">
                <view class="list-title">{{ t('rongzi.tip16') }}</view>
                <view>
                  <input v-model="params.card" :placeholder="t('rongzi.tip17')" class="info-input" />
                </view>
              </view>
              <view class="xian"></view>
              <view class="list">
                <view class="list-title">{{ t('rongzi.tip18') }}</view>
                <view>
                  <input v-model="params.address" :placeholder="t('rongzi.tip19')" class="info-input" />
                </view>
              </view>
              <view class="xian"></view>
              <view class="list">
                <view class="list-title">{{ t('rongzi.tip20') }}</view>
                <view>
                  <input v-model="params.phone" :placeholder="t('rongzi.tip21')" class="info-input" />
                </view>
              </view>
              <view class="xian"></view>
              <view class="list">
                <view class="list-title">{{ t('rongzi.tip22') }}</view>
                <view>
                  <input v-model="params.mail" :placeholder="t('rongzi.tip23')" class="info-input" />
                </view>
              </view>
            </view>
            <view class="sumbit" @click="saveSumbit()">{{ t('rongzi.tip24') }}</view>
          </view>
        </view>
      </scroll-view>
    </view>
    <view v-else class="state-container">
      <image v-if="state === 0" class="state-image" src="/static/image/rongzi/state11.png" mode="widthFix" />
      <image v-if="state === 1" class="state-image1" src="/static/image/rongzi/state22.png" mode="widthFix" />
      <image v-if="state === 2" class="state-image2" src="/static/image/rongzi/state33.png" mode="widthFix" />
      <view v-if="state === 0" class="tip1" style="color: #222">{{ tip1 }}</view>
      <view v-if="state === 1" class="tip1" style="color: #4e55af">{{ tip1 }}</view>
      <view v-if="state === 2" class="tip1" style="color: #ee2560">{{ tip1 }}</view>
      <view class="tip2">{{ tip2 }}</view>
      <view class="but-box">
        <view class="first" @click="goWeb()">{{ t('rongzi.tip36') }}</view>
        <view v-if="state == 0" class="last" @click="switchTab('/pages/index/index')">{{ t('rongzi.tip37') }}</view>
        <view v-else-if="state == 1" class="last" @click="state = -1">{{ t('rongzi.tip25') }}</view>
        <view v-else-if="state == 2" class="last" @click="state = -1">{{ t('rongzi.tip26') }}</view>
      </view>
    </view>
  </view>
</template>

<script lang="ts" setup>
import { onShow } from '@dcloudio/uni-app'
import { useI18n } from 'vue-i18n'
import { getRongziApi, rongziApi } from '@/api/index/index'
import { switchTab } from '@/common/common'
import { ref, computed } from 'vue'
import { getCzhiurlApi } from '@/api/user'
// import bg from '@/static/image/rongzi/bg.png'
// import bg2 from '@/static/image/rongzi/bg2.png'
// import logo from '@/static/image/rongzi/logo.png'
import { useCounterStore } from '@/store/store'
import { closeToast, showToast } from 'vant'
const store = useCounterStore()
const { t } = useI18n()
// 页面基础配置
onShow(() => {
  getRongziList()
  getCzhiurlFn()
})

const kefu_url = ref('')

const getCzhiurlFn = async () => {
  const res = await getCzhiurlApi()
  if (res.code === 1) {
    kefu_url.value = res.data.kefu_url
  }
}

const goWeb = () => {
  window.open(kefu_url.value)
}

// 獲取融资详情
const rongziInfo = ref({})
const getRongziList = async () => {
  const res = await getRongziApi()
  rongziInfo.value = res.data.data
  console.log(res.data)
  if (res.data?.state === 0) {
    state.value = 0
  } else if (res.data?.state === 1) {
    state.value = 1
  } else if (res.data?.state === 2) {
    state.value = 2
  } else {
    state.value = -1
  }
}

const state = ref(-1)
const tip1 = computed(() => {
  const text = [t('rongzi.tip27'), t('rongzi.tip28'), t('rongzi.tip29')]
  return text[state.value]
})
const tip2 = computed(() => {
  const text2 = [t('rongzi.tip30'), t('rongzi.tip31'), t('rongzi.tip32')]
  return text2[state.value]
})

const params = ref({
  money: null,
  name: null,
  card: null,
  address: null,
  phone: null,
  mail: null,
  income: null,
  credit: null,
  qualifications: null
})

let ist = true

const saveSumbit = async () => {
  if (!ist) return
  ist = false
  if (params.value.money < 500000) {
    ist = true
    return showToast({
      icon: 'none',
      message: t('rongzi.tip33')
    })
  }
  if (params.value.money > 3000000) {
    ist = true
    return showToast({
      message: t('rongzi.tip34')
    })
  }
  if (validInfo() === true) {
    const res = await rongziApi(params.value)
    ist = true
    params.value = {
      money: null,
      name: null,
      card: null,
      address: null,
      phone: null,
      mail: null,
      income: null,
      credit: null,
      qualifications: null
    }
    if (res.code === 1) {
      state.value = 0
    }
    closeToast()
  }
}

const validInfo = () => {
  if (params.value.name && params.value.card && params.value.address && params.value.phone && params.value.mail) {
    return true
  } else {
    showToast({
      message: t('rongzi.tip35')
    })
    return false
  }
}
</script>
<style scoped lang="scss">
.bg {
  height: calc(var(--vh) * 100);
  background: url('@/static/image/rongzi/bg2.png');
  background-color: #000;
  // opacity: 0.4;
  background-size: 100% 100%;
  width: 100%;
  top: 0;
  position: fixed;
  z-index: -1;
}
.bg2 {
  height: calc(var(--vh) * 100);
  background: url('@/static/image/rongzi/bg2.png');
  background-color: #000;
  // opacity: 0.4;
  background-size: 100% auto;
  width: 100%;
  top: 0;
  height: 3.125rem;
  position: fixed;
  z-index: -1;
  // display: none;
}
.uni-app--maxwidth {
  overflow-x: hidden;
}

.header {
  position: fixed;
  background: #ffffff;
  width: 100%;
  display: flex;
  height: 3.125rem;
  padding: 0.625rem;
  z-index: 9;
  display: flex;
  justify-content: space-between;

  .back {
    width: 0.5rem;
    height: 1rem;
  }

  .title {
    margin-right: 2.5rem;
    color: #000;
  }
}

.money-bg {
  position: relative;
  width: 17.63rem;
  height: 17.63rem;
  margin: 0 auto;
  background: url('@/static/image/rongzi/logo2.png');
  background-size: 100% 100%;
  .tip-box {
    overflow: hidden;
    .tip {
      color: $color-black;

      text-align: center;
      font-family: 'PingFang SC';
      font-size: 1.13rem;
      font-style: normal;
      font-weight: 600;
      line-height: normal;
      margin-top: 4.38rem;
      // text-shadow: 0rem 0rem 0.23rem #4e55af;
    }

    .value {
      color: $color-black;
      text-align: center;
      font-family: 'PingFang SC';
      font-size: 2.375rem;
      font-style: normal;
      font-weight: 600;
      line-height: normal;
      margin-top: 1.88rem;
      // text-shadow: 0rem 0rem 0.23rem #4e55af;

      span {
        color: $color-black;
        font-family: 'PingFang SC';
        font-size: 1.125rem;
        font-style: normal;
        font-weight: 600;
        line-height: normal;
      }
    }
  }
}

.top-bg {
  width: 100%;
  height: 18.75rem;
}

.tab-flex {
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.card {
  padding: 2.38rem 0.94rem 2rem;
}

.tab-li {
  text-align: center;
  width: 33%;

  .icon-box {
    border-radius: 1.25rem;
    padding-top: 0.75rem;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
  }
  .image_wrap {
    width: 3.56rem;
    height: 3.56rem;
    background: $color-primary;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .icon {
    width: 1.81rem;
    height: 1.81rem;
  }

  .desc {
    color: $color-black;
    margin-top: 0.625rem;
    font-size: 0.75rem;
    width: 100%;
  }

  .main {
    color: $color-gray;
    margin-top: 0.3125rem;
    font-size: 0.75rem;
  }
}

.sq-txt {
  margin: 0.625rem;
  color: $color-black;

  font-size: 1.125rem;
}

.color-gary {
  font-size: 0.75rem;
  margin: 0.3125rem 0.625rem;
  uni-view {
    color: $color-gray;
  }
}

.info-box {
  margin: 1.25rem 0.625rem;
  border-radius: 0.625rem;
  padding: 0.625rem;
}

.xian {
  border-bottom: 0.0625rem solid #36394225;
}

.list {
  line-height: 2.5rem;
  display: flex;
  align-items: center;
  margin: 0.31rem 0;
  width: 100%;
  ::v-deep .uni-input-input {
    font-size: 0.875rem;
  }
  ::v-deep .uni-input-placeholder {
    font-size: 0.875rem;
  }
}
.list .list-title {
  width: 6.4375rem;
  line-height: 1.375rem;
  color: $color-gray;
}

.list > view {
  font-size: 0.875rem;
}

.c-79 {
  color: #797c84;
}

.mt-10 {
  margin-top: 0.625rem;
}

input {
  font-size: 1.125rem;
  width: 100%;
  height: 1.875rem;
  line-height: 0.9375rem;
  color: #988b7d;
  border: 0.05rem solid #aeaeae;
  border-radius: 0.38rem;
  padding: 0 0.51rem;
}

input::placeholder {
  color: #251c16;
}

.file-box {
  width: 6.25rem;
  height: 6.25rem;
  margin-top: 0.9375rem;
  margin-bottom: 0.9375rem;
  border-radius: 0.625rem;
}

.sumbit {
  background: $color-primary;
  color: #fff;
  font-weight: 500;
  margin: 0.625rem;
  border-radius: 0.5rem;

  line-height: 3.125rem;
  text-align: center;
}

.upload-Image {
  display: flex;
  align-items: center;
}

.ml-10 {
  margin-left: 0.625rem;
}

.state-container {
  overflow: hidden;
  text-align: center;
  overflow: hidden;
  padding-top: 6.25rem;

  .state-image {
    width: 19.75rem;
    margin: 0 auto -6.5625rem auto;
    display: block;
  }

  .state-image1 {
    width: 19.75rem;
    margin: 0 auto -6.5625rem auto;
    display: block;
  }

  .state-image2 {
    width: 11.56rem;
    margin: 2.8125rem auto 0.5625rem auto;
    display: block;
  }

  .tip1 {
    font-size: 1rem;
    font-weight: 600;
    color: #000;
  }

  .tip2 {
    font-size: 0.8rem;
    font-weight: 400;
    color: #a6a6a6;
    padding: 0.5rem 0 2.25rem 0;
    margin: 0 1rem;
  }

  .but-box {
    display: flex;
    justify-content: space-around;
    margin: 0 1.25rem;
    gap: 0.94rem;
    view {
      flex: 1;
      height: 2.9375rem;
      line-height: 2.9375rem;
      border-radius: 0.625rem;
    }

    .first {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      background: $color-primary;
      color: #fff;
      font-weight: 500;
      border-radius: 0.5rem;
      margin-bottom: 15px;
    }

    .last {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      border: 0.05rem solid $color-primary;
      border-radius: 0.5rem;
      color: $color-primary;
    }
  }
}
</style>
