<template>
  <div class="h-[80px] w-full bg-[#fff] flex items-center justify-between px-[12%]">
    <!-- 头部title -->
    <div class="flex items-center">
      <img src="~/public/favicon.ico" class="w-[50px] h-[50px] mr-[10px]" alt="">
      <div class="flex flex-col">
        <span class="text-[#333333] text-[18px] font-medium">惠融易客</span>
        <span class="text-[15px] font-light">
          huirong crm
        </span>
      </div>
    </div>
    <!-- 右边 -->
    <ul class='flex items-center'>
      <li v-for="i in headerTitle" :key="i.go" class="px-[16px] text-[#999999] font-medium">
        {{ i.title }}
      </li>
      <li class="px-[16px] text-[#999999] font-medium">
        <n-button type="info" class="bg-[#165DFF]">
          登录/注册
        </n-button>
      </li>
    </ul>

  </div>
  <!-- 图片 -->
  <div class="relative">
    <img src="~/public/image/img_home.png" class="w-full" alt="">
    <div class="flex flex-col absolute left-[12%] top-[30%] text-[#fff]">
      <div class="text-[40px] font-black flex">
        <h1 class="pr-[15px]">惠融易客</h1>
        <div>
          数字金融服务商
        </div>
      </div>
      <span class="mt-[10px] mb-[35px]">提交申请，立即开启企业数字化升级/提供专家1V1服务，提供企业定制化数字解决方案</span>
      <n-button type="info" class="bg-[#165DFF] w-[180px] h-[50px] text-[18px]" @click="btn">
        立即申请试用
      </n-button>
    </div>
  </div>
  <!-- 传统问题 traditional-->
  <div class="flex flex-col items-center justify-center pt-[70px] pb-[70px]">
    <h2 class="text-[20px] font-medium">传统方式管理难点</h2>
    <span class="text-[#999999] px-[12px] pt-[15px] pb-[40px] text-[12px]">传统方式管理过程中有哪些问题？</span>
    <ul class="flex items-center justify-center pb-[50px]">
      <li class="w-[25%]">
        <img src="../public/image/p_img_home_qs_0_0.png" alt="">
      </li>
      <li class="w-[25%]">
        <img src="../public/image/p_img_home_qs_0_1.png" alt="">
      </li>
      <li class="w-[25%]">
        <img src="../public/image/p_img_home_qs_0_2.png" alt="">
      </li>
    </ul>
  </div>
  <div class="w-full">
    <img src="~/public/image/advantage.png" class="w-full" alt="">
  </div>
  <!-- 精准获客 -->
  <div class="flex flex-col items-center justify-center pt-[70px] pb-[70px] px-[10%]">
    <h2 class="text-[20px] font-medium">精准获客</h2>
    <span class="text-[#999999] px-[12px] pt-[15px] pb-[40px] text-[12px]">多渠道投放对接，帮助企业精准推广产品矩阵</span>
    <ul class="flex items-center flex-wrap justify-center pb-[50px] ">
      <li class="w-[20%] mx-[10px] my-[10px]">
        <img src="../public/image/img_home_ad_0.png" alt="">
      </li>
      <li class="w-[20%] mx-[10px] my-[10px]">
        <img src="../public/image/img_home_ad_1.png" alt="">
      </li>
      <li class="w-[20%] mx-[10px] my-[10px]">
        <img src="../public/image/img_home_ad_2.png" alt="">
      </li>
      <li class="w-[20%] mx-[10px] my-[10px]">
        <img src="../public/image/img_home_ad_3.png" alt="">
      </li>
      <li class="w-[20%] mx-[10px] my-[10px]">
        <img src="../public/image/img_home_ad_4.png" alt="">
      </li>
      <li class="w-[20%] mx-[10px] my-[10px]">
        <img src="../public/image/img_home_ad_5.png" alt="">
      </li>
      <li class="w-[20%] mx-[10px] my-[10px]">
        <img src="../public/image/img_home_ad_6.png" alt="">
      </li>
      <li class="w-[20%] mx-[10px] my-[10px]">
        <img src="../public/image/img_home_ad_7.png" alt="">
      </li>
    </ul>

  </div>
  <!-- 免费试用 trial-->
  <div class="w-full h-full trial">
    <div class="flex flex-col items-center text-[#161616] py-[100px]">
      <h2 class="font-medium text-[20px]" @click="btn">免费试用</h2>
      <div class="mt-[12px] mb-[18px] text-[12px] text-[#999999]">
        立即免费试用惠融易客CRM 提升企业业绩
      </div>
      <div class="mb-[25px] flex items-center font-medium text-[18px]">
        <span>已有</span>
        <ul class="flex justify-center items-center mx-[5px] my-[20px] bg-[#f7f8fa]">
          <li v-for="item in freeList" class=" py-[5px] px-[10px] bg-[#fff] mx-[5px] text-[18px]">
            {{ item }}
          </li>
        </ul>
        <span>
          人加入
        </span>
      </div>
      <n-button type="info" class="bg-[#165DFF] w-[250px] h-[40px] text-[14px]">
        立即申请试用
      </n-button>
    </div>
  </div>
  <!-- 咨询信息 message-->
  <div class="flex flex-col items-center justify-center pt-[70px] pb-[70px] mx-[50px]" v-if="homeList[0]">
    <h2 class="text-[20px] font-medium">资讯信息</h2>
    <span class="text-[#999999] px-[12px] pt-[15px] pb-[40px] text-[12px]">点击了解惠融易客的更多信息</span>
    <div class="flex flex-row items-center w-[70%]">
      <div @click="go(-1)">
        <img src="~/public/image/left.png" class="w-[50px] h-[40px]" alt="">
      </div>
      <div class="mx-[5%] flex flex-col items-center w-[100%]">
        <div class="flex justify-center w-[100%] pb-[20px]">
          <n-carousel class="w-[400px]" autoplay :currentIndex="currentIndex">
            <img v-for="item in homeList" class="carousel-img" :src="item.images">
          </n-carousel>
          <div class="flex flex-col justify-between ml-[50px] font-medium text-[18px] w-[500px]">
            <h1>{{ homeList[currentIndex].title }}</h1>
            <div class="flex justify-between h-[30px]">
              <span class="text-[14px] ">
                {{ homeList[currentIndex].summary }}
              </span>
              <n-button type="info" class="bg-[#165DFF]" @click="btnContent(currentIndex)">
                查看详情
              </n-button>
            </div>
          </div>
        </div>
        <ul class="custom-dots">
          <li v-for="(i, index) in homeList" :key="index" :class="{ ['is-active']: currentIndex === index }"
            @click="customFn(index)">
          </li>
        </ul>
      </div>
      <div @click="go(+1)">
        <img src="~/public/image/right.png" class="w-[50px] h-[40px]" alt="">
      </div>
    </div>

  </div>
  <div class="w-full bg-[#1f1d2a] px-[50px] pt-[20px] pb-[10px]" id="contact">
    <div class="w-[60%] m-auto">
      <div class="flex justify-between">
        <!-- 左侧 -->
        <div class="flex">
          <!-- 左边 -->
          <div class="flex  flex-col text-[#999999] mr-[30px]">
            <h3 class="text-[16px] font-medium text-[#fff]">
              联系方式
            </h3>
            <span class="text-[12px] my-[16px]">
              客服： kefu@meloinfo.com
            </span>
            <span class="text-[12px]">
              商务： 17723267692（微信同号）
            </span>
          </div>
          <!-- 地址 -->
          <div class="text-[#999999]">
            <h3 class="text-[16px] font-medium mb-[16px] text-[#fff]">
              公司地址
            </h3>
            <span class="text-[12px]">
              重庆市两江新区大竹林街道清枫北路10号3幢双子座A座1406
            </span>
          </div>
        </div>
        <!-- 二维码 -->
        <div class="flex items-center justify-center">
          <div class="flex flex-col items-center justify-center" v-if="bottomCode.wxQrUrl">
            <!-- <div class="flex flex-col items-center justify-center"> -->
            <span class="text-[#fff] text-[12px]" style="font-size: 11px; margin-bottom: 5px;">
              关注公众号
            </span>
            <img :src="bottomCode.wxQrUrl" style="width:100px;height:100px" alt="">
            <!-- <img src="~/public/image/tryOut.png" style="width:100px;height:100px" alt=""> -->
          </div>
          <div class="flex flex-col items-center justify-center" v-if="bottomCode.iosQrUrl" style="margin: 0 30px">
            <!-- <div class="flex flex-col items-center justify-center" style="margin: 0 30px"> -->
            <span class="text-[#fff] text-[12px]" style="font-size: 11px; margin-bottom: 5px;">
              iosAPP下载
            </span>
            <img :src="bottomCode.iosQrUrl" style="width:100px;height:100px" alt="">
            <!-- <img src="~/public/image/tryOut.png" style="width:100px;height:100px" alt=""> -->

          </div>
          <div class="flex flex-col items-center justify-center" v-if="bottomCode.androidQrUrl">
            <!-- <div class="flex flex-col items-center justify-center"> -->
            <span class="text-[#fff] text-[12px]" style="font-size: 11px; margin-bottom: 5px;">
              安卓APP下载
            </span>
            <img :src="bottomCode.androidQrUrl" style="width:100px;height:100px" alt="">
            <!-- <img src="~/public/image/tryOut.png" style="width:100px;height:100px" alt=""> -->
          </div>
        </div>
      </div>
      <!-- 备案号 -->
      <div class="flex items-center justify-center text-[#585667] text-[10px] my-[30px]">
        <span>重庆惠融数字科技有限公司版权所有</span>
        <span>
          渝ICP备2023000211号-4
        </span>
      </div>
    </div>
  </div>
  <n-modal v-model:show="showModal">
    <n-card style="width: 800px" title="申请试用" :bordered="false" size="huge" role="dialog" aria-modal="true">
      <div class="text-[#999999] text-[12px] pt-[15px] pb-[30px]">
        为了我们能更好的服务您，请您填写以下信息，如遇到问题，请您拨打免费服务热线
      </div>
      <n-form ref="formRef" :model="customer" :rules="rules">
        <n-form-item path="companyName" label="公司名称">
          <n-input v-model:value="customer.companyName" @keydown.enter.prevent class="h-[55px] leading-[55px]"
            placeholder="请输入公司名称" />
        </n-form-item>
        <n-form-item path="city" label="所在城市">
          <n-input v-model:value="customer.city" class="h-[55px] leading-[55px]" placeholder="请选择所在城市" />
          <!-- <n-cascader v-model:value="customer.city" placeholder="请选择所在城市" class="h-[55px] leading-[55px]"
            :options="provice" check-strategy="child" :show-path="true" value-field="name" label-field="name" @update:value="handleUpdateValue"
            /> -->
        </n-form-item>
        <n-form-item path="customName" label="姓名">
          <n-input v-model:value="customer.customName" class="h-[55px] leading-[55px]" placeholder="请输入姓名" />
        </n-form-item>
        <n-form-item path="phone" label="联系方式">
          <n-input v-model:value="customer.phone" class="h-[55px] leading-[55px]" placeholder="请输入联系方式" />
        </n-form-item>
        <n-form-item path="verifyCode" label="验证码" class="">
          <n-input v-model:value="customer.verifyCode" class="h-[55px] leading-[55px]" placeholder="请输入验证码" />
          <n-button type="info" class="w-[100px] h-[50px] text-[#fff] bg-[#1f4df5] ml-[10px]" :disabled="countdown != 0"
            @click="verifyCodeFn">
            {{ countdown == 0 ? '获取验证码' : countdown }}
          </n-button>
        </n-form-item>
        <div class="flex justify-center">
          <n-button type="info" class="w-[300px] h-[50px] text-[#fff] bg-[#1f4df5]" @click="handleValidateButtonClick">
            立即提交
          </n-button>
        </div>
      </n-form>
    </n-card>
  </n-modal>
</template>
<script lang="ts" setup>
import { reactive, ref } from 'vue'
import { postListData, downInfo, sendSms, postCustomer } from '~/server/api/index'
import {provice} from '~/utils/city'
import {
  FormRules,
  useMessage,
  FormInst,
} from 'naive-ui'
console.log('provice',provice)
const headerTitle = reactive([
  {
    title: '首页',
    go: 'home'
  },
  {
    title: '解决方案',
    go: 'solution'
  },
  {
    title: '联系我们',
    go: 'contact'
  },
  {
    title: '申请试用',
    go: 'probation'
  }
]
)
const freeList = reactive(['3', '0', '7', '0', '1', '3', '7', '4'])
const message = useMessage()
const num = reactive([{
  img: '~/public/image/p_img_home_qs_0_0.png'
},
{
  img: '~/public/image/p_img_home_qs_0_1.png'

},
{
  img: '~/public/image/p_img_home_qs_0_2.png'

}
])
console.log('import.meta.url', import.meta.url)
const getImg = (name: number) => {
  return new URL(`/public/image/p_img_home_qs_0_${name}.png`, import.meta.url).href;
}
const currentIndex = ref(1)
const customFn = (i: number) => {
  console.log('i', i)
  currentIndex.value = i
}
const go = (i: number) => {
  currentIndex.value = currentIndex.value + i
  if (currentIndex.value > homeList.value.length - 1) {
    currentIndex.value = 0
    return
  }
  if (currentIndex.value < 0) {
    currentIndex.value = homeList.value.length - 1
    return
  }
}
const btnContent = (i: number) => {
  // 跳转
  console.log('跳转',i)

}
let homeList: any = ref([])
const postListDataFn = async () => {
  let list = await postListData({
    "categoryId": 1
  })
  console.log('postListDataFn', list)
  list.data.data ? homeList.value = list.data.data.list : ''
}
let bottomCode: any = ref([])
postListDataFn()
const downInfoFn = async () => {
  const list = await downInfo()
  console.log('list', list)
  bottomCode.value = list.data.data
}
downInfoFn()
// 框显示隐藏
let showModal = ref<boolean>(false)
const rules: FormRules = {
  companyName: [
    {
      required: true,
      trigger: ['blur', 'input'],
      message: '请输入公司名称'
    }
  ],
  customName: [
    {
      required: true,
      trigger: ['blur', 'input'],
      message: '请输入姓名'
    }
  ],
  city: [
    {
      required: true,
      trigger: ['blur', 'input'],
      message: '请选择所在城市'
    }
  ],
  phone: [
    {
      required: true,
      trigger: ['blur', 'input'],
      message: '请输入手机号'
    }
  ],
  verifyCode: [
    {
      required: true,
      trigger: ['blur', 'input'],
      message: '请输入验证码'
    }
  ],
}
interface customerType {
  sceneType?: string;
  companyName?: null | string;
  customName?: null | string;
  city?: null | string;
  phone?: null | string;
  verifyCode?: null | string;
  channel?: number;

}
let countdown = ref(0)
const customer = ref<customerType>({
  sceneType: "loanofficial", // 场景
  companyName: null,// 公司名称
  customName: null, // 姓名
  city: null, // 所在城市
  phone: null, // 手机号
  verifyCode: null, //验证码
  channel: 16, //pc官网16 手机端17
})
const verifyCodeFn = async () => {
  if (customer.value.phone) {
    if (new RegExp('^1[0-9]{10}$').test(customer.value.phone)) {
      let z = await sendSms({
        sceneType: "loanofficial",
        userMobile: customer.value.phone
      })
      if (z.data.code == 0) {
        message.success('发送成功')
        countdown.value = 60
        // this.countDown()
        countDown()
        // console.log('进来了', this.countdown)
      } else {
        message.error('发送失败')
      }
    } else {
      message.error('请输入正确手机号')
    }
  } else {
    // 唤起提示
    message.error('请输入手机号')

  }
}
// 倒计时
const countDown = () => {
  // 设置倒计时
  const intervalBtn = setInterval(() => {
    if (countdown.value == 1) {
      // 清除定时器
      clearInterval(intervalBtn)
      // 重置倒计时状态
      countdown.value = 0
    };
    // 倒计时
    countdown.value--
  }, 1000)
}
const formRef = ref<FormInst | null>(null)
const handleValidateButtonClick = (e: MouseEvent) => {
  e.preventDefault()
  formRef.value?.validate(async (errors) => {
    if (!errors) {
      message.success('验证成功')
      console.log('customer.value', customer.value)
      let z = await postCustomer(customer.value)
      console.log('zzz', z)
      if (z.data.msg == '成功') {
        // 关闭页面
        fouse()
      }
    } else {
      console.log(errors)
      message.error('验证失败')
    }
  })
}
const fouse = () => {
  showModal.value = false
}
const btn = () => {
  showModal.value = true
}

const handleUpdateValue =(value: string)=> {
        console.log(value,'进来了')
      }
</script>
<style scoped lang="scss">
p {
  color: var(--link-color)
}

.trial {
  background: url(~/public/image/try_out.png) no-repeat;
  background-size: cover;

}

.n-carousel {
  width: 400px !important;
}

.carousel-img {
  width: 400px;
  height: 200px;
  // object-fit: cover;
}

.custom-dots {
  display: flex;
  margin: 0;
  padding: 0;
}

.custom-dots li {
  display: inline-block;
  width: 30px;
  height: 4px;
  margin: 0 3px;
  border-radius: 4px;
  background: #888888;
  transition: width 0.3s, background-color 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.custom-dots li.is-active {
  width: 50px;
  background: #0047FF;
}

// 框
::v-deep(.n-card-header__main) {
  flex: inherit !important;
  margin: 0 auto !important;
}

::v-deep(.n-card-header) {
  padding: 0;
  padding-top: 50px;
}

::v-deep(.n-card__content) {
  flex: inherit;
  margin: 0 auto;
}

::v-deep(.n-form-item-label) {
  display: none !important;
}
</style>