<template>
  <!-- 使用方式 -->
  <div class="usage-mode" v-if="flag">
    <div class="tltle">
      <DetalsTitle
        :title="dataFrom.title"
        :type="dataFrom.englishTitle"
      ></DetalsTitle>
    </div>
    <div class="content" v-for="item in dataFrom.content" :key="item.title">
      <div class="content-left">
        <div class="left">
          <div class="content-left-title">
            <span>{{ item.title }}</span>
            <span>{{ item.titleSon }}</span>
          </div>
          <div class="content-left-content">
            <p>
              <span>{{ item.link.name }}</span>
              <span>{{ item.link.value }}</span>
            </p>
            <p>
              <span>{{ item.postMethod.name }}</span>
              <span>{{ item.postMethod.value }}</span>
            </p>
          </div>
        </div>
        <div class="right">
          <div @click="technical()">技术文档</div>
          <div>新手指引</div>
        </div>
      </div>
      <div class="content-right">
        <div class="content-right-title">{{ item.contact }}</div>
        <div class="content-right-content">
          <p>
            <span>{{ item.facilitator.name }}</span>
            <a-tooltip>
              <template #title>{{ item.facilitator.value }}</template>
              <span>{{ item.facilitator.value }}</span>
            </a-tooltip>
          </p>
          <p>
            <span>{{ item.people.name }}</span>
            <a-tooltip>
              <template #title>{{ item.people.value }}</template>
              <span>{{ item.people.value }}</span>
            </a-tooltip>
          </p>
          <p>
            <span>{{ item.phone.name }}</span>
            <a-tooltip>
              <template #title>{{ item.phone.value }}</template>
              <span>{{ item.phone.value }}</span>
            </a-tooltip>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
  import DetalsTitle from '@/views/detailsAll/components/DetalsTitle'
  import { pinyin } from 'pinyin-pro'
  import { ref, defineProps, watch } from 'vue'
  let dataFrom = ref({
    title: '使用方式',
    englishTitle: 'USAGE',
    content: [
      {
        title: '技术对接',
        titleSon: '调用接口',
        link: {
          name: '接口地址：',
          value: 'http://localhost:9999/#/details?id=1532278256619307010',
        },
        postMethod: {
          name: '请求方式：',
          value: 'POST',
        },
        contact: '联系厂商：',
        facilitator: { name: '服务商：', value: '科大讯飞' },
        people: { name: '联系人：', value: '李四' },
        phone: {
          name: '联系电话：',
          value: '12345678901',
        },
      },
    ],
    link: '',
  })
  //数据初始化
  const props = defineProps({
    dataList: { type: Object, default: null },
  })
  const flag = ref(true)
  if (props.dataList.infoList) {
    let obj = props.dataList.infoList.filter(
      (item) => item.attrType === '技术文档'
    )[0]
    if (!obj) {
      flag.value = false
    } else {
      // eslint-disable-next-line vue/no-setup-props-destructure
      dataFrom.value.content[0].link.value = props.dataList.apiUrl
      // eslint-disable-next-line vue/no-setup-props-destructure
      dataFrom.value.content[0].postMethod.value = props.dataList.apiMethodType
      console.log('dataList', props.dataList)
      props.dataList.infoList.map((item) => {
        if (item.attrType === '使用方式') {
          dataFrom.value.content[0].titleSon = item.attrValue
        } else if (item.attrType === '服务商') {
          dataFrom.value.content[0].facilitator.value = item.attrValue || '--'
        } else if (item.attrType === '服务商联系人') {
          dataFrom.value.content[0].people.value = item.attrValue || '--'
        } else if (item.attrType === '服务商联系电话') {
          dataFrom.value.content[0].phone.value = item.attrValue || '--'
        } else if (item.attrType === '技术文档') {
          dataFrom.value.link = item.attrValue || '--'
        }
      })
    }
  }
  watch(
    () => props.dataList,
    (val) => {
      if (val) {
        let obj = val.infoList.filter((item) => item.attrType === '技术文档')[0]
        if (!obj) {
          flag.value = false
        } else {
          dataFrom.value.content[0].link.value = val.apiUrl
          dataFrom.value.content[0].postMethod.value = val.apiMethodType
          console.log('dataList', val)
          val.infoList.map((item) => {
            if (item.attrType === '使用方式') {
              dataFrom.value.content[0].titleSon = item.attrValue
            } else if (item.attrType === '服务商') {
              dataFrom.value.content[0].facilitator.value =
                item.attrValue || '--'
            } else if (item.attrType === '服务商联系人') {
              dataFrom.value.content[0].people.value = item.attrValue || '--'
            } else if (item.attrType === '服务商联系电话') {
              dataFrom.value.content[0].phone.value = item.attrValue || '--'
            } else if (item.attrType === '技术文档') {
              dataFrom.value.link = item.attrValue || '--'
            }
          })
        }
      }
    }
  )
  function technical() {

    // 拼接路径
    const type = pinyin(props.dataList.type, {
      pattern: 'initial',
    }).replace(/\s*/g, '')
    // 打开文档
    const id = props.dataList.id
    window.open(window.SITE_CONFIG.frontUrl + type + '/' + id + '.md', '_blank')
    // console.log('dataFrom.value.link', dataFrom.value.link)
    // window.open(
    //   window.SITE_CONFIG.previewUrl +
    //     'hisense_office/onlinePreview?url=' +
    //     btoa(encodeURI(dataFrom.value.link))
    // )
  }
</script>

<style lang="less" scoped>
  .usage-mode {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 80px 0;
    .content {
      margin-top: 30px;
      display: flex;
      .content-left {
        height: 150px;
        width: 620px;
        background: linear-gradient(to right, #7184fc, #94a3fc);
        border-radius: 10px;
        margin-right: 60px;
        box-shadow: 0px 5px 15px rgba(82, 106, 255, 0.4);
        display: flex;
        align-items: center;
        padding: 0 35px;
        .left {
          .content-left-title {
            font-size: 26px;
            line-height: 26px;
            color: #212956;
            margin-bottom: 20px;
            span:first-child {
              margin-right: 10px;
            }
          }
          .content-left-content {
            width: 420px;
            font-size: 20px;
            color: rgba(33, 41, 86, 0.8);
            line-height: 20px;
            p {
              display: -webkit-box;
              overflow: hidden;
              -webkit-line-clamp: 1;
              -webkit-box-orient: vertical;
              margin-bottom: 10px;
            }
          }
        }
        .right {
          div {
            height: 40px;
            width: 130px;
            background: #ffffff;
            border-radius: 20px;
            color: #526aff;
            font-size: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
          }
          div:first-child {
            margin-bottom: 20px;
          }
        }
      }
      .content-right {
        height: 150px;
        width: 620px;
        background: linear-gradient(
          to right,
          rgba(113, 132, 252, 0.4),
          rgba(148, 163, 252, 0.4)
        );
        border-radius: 10px;
        box-shadow: 0px 5px 15px rgba(82, 106, 255, 0.4);
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 0 30px;
        .content-right-title {
          font-size: 26px;
          line-height: 26px;
          color: #212956;
          margin-bottom: 25px;
        }
        .content-right-content {
          display: flex;
          font-size: 18px;
          color: rgba(33, 41, 86, 0.8);
          line-height: 20px;
          overflow: hidden;
          -webkit-line-clamp: 1;
          -webkit-box-orient: vertical;
          margin-bottom: 10px;
          p {
            // width: 160px;
            height: 20px;
            display: -webkit-box;
            // overflow: hidden;
            white-space: nowrap;
            -webkit-line-clamp: 1;
            -webkit-box-orient: vertical;
            margin-right: 15px;
            span {
              cursor: pointer;
            }
          }
        }
      }
    }
  }
</style>
