<template>
  <!-- 使用方式 -->
  <div class="usage-mode" v-if="true">
    <div class="tltle">
      <DetalsTitle
        :title="dataFrom.title"
        :type="dataFrom.englishTitle"
      ></DetalsTitle>
    </div>
    <div style="width: 100%; display: flex; justify-content: center">
      <div class="content" v-for="item in dataFrom.content" :key="item.title">
        <div class="content-left">
          <div class="left">
            <a-tooltip>
              <template #title>
                {{ approveStatus === '通过' ? item.linkValue : '请申请后查看' }}
              </template>
              <p @click="ServiceAddressFunction(item.linkValue)">
                <span>服务地址：</span>
                <span :class="{ 'blur-word': approveStatus !== '通过' }">
                  {{ item.linkValue }}
                </span>
              </p>
            </a-tooltip>
            <a-tooltip>
              <template #title>
                {{
                  approveStatus === '通过' ? item.csslinkValue : '请申请后查看'
                }}
              </template>

              <p @click="ServiceAddressFunction(item.csslinkValue)">
                <span>样式服务地址：</span>
                <span :class="{ 'blur-word': approveStatus !== '通过' }">
                  {{ item.csslinkValue }}
                </span>
              </p>
            </a-tooltip>
          </div>
          <div class="right" v-show="approveStatus === '通过'">
            <div @click="technical()">技术文档</div>
            <div @click="technicalNew()">新手指引</div>
          </div>
        </div>
        <div class="content-right">
          <div class="content-right-left">
            <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>
                    {{
                      approveStatus === '通过' || role
                        ? item.people.value
                        : '请申请后查看'
                    }}
                  </template>
                  <span
                    :class="{ 'blur-word': approveStatus !== '通过' && !role }"
                  >
                    {{ item.people.value }}
                  </span>
                </a-tooltip>
              </p>
              <p>
                <span>{{ item.phone.name }}</span>
                <a-tooltip>
                  <template #title>
                    {{
                      approveStatus === '通过' || role
                        ? item.phone.value
                        : '请申请后查看'
                    }}
                  </template>
                  <span
                    :class="{ 'blur-word': approveStatus !== '通过' && !role }"
                  >
                    {{ item.phone.value }}
                  </span>
                </a-tooltip>
              </p>
            </div>
          </div>
          <div class="content-right-right">
            <div class="content-right-title">{{ item.contact2 }}</div>
            <div class="content-right-content">
              <p>
                <span>{{ item.facilitator2.name }}</span>
                <a-tooltip>
                  <template #title>{{ item.facilitator2.value }}</template>
                  <span>{{ item.facilitator2.value }}</span>
                </a-tooltip>
              </p>
              <p>
                <span>{{ item.people2.name }}</span>
                <a-tooltip>
                  <template #title>{{ item.people2.value }}</template>
                  <span>{{ item.people2.value }}</span>
                </a-tooltip>
              </p>
              <p>
                <span>{{ item.phone2.name }}</span>
                <a-tooltip>
                  <template #title>{{ item.phone2.value }}</template>
                  <span>{{ item.phone2.value }}</span>
                </a-tooltip>
              </p>
            </div>
          </div>
        </div>
      </div>
      <!-- <div v-show="approveStatus !== '通过'" class="contentOther">
        <img src="~@/assets/detailsAll/uesBefore.png" />
        <div class="contentOtherRight">
          <p>请在申请能力后返回查看使用方式</p>
          <div @click="toView()">进入能力申请</div>
        </div>
      </div> -->
    </div>
  </div>
</template>

<script setup>
  import DetalsTitle from '@/views/detailsAll/components/DetalsTitle'
  import { message } from 'ant-design-vue'
  import { pinyin } from 'pinyin-pro'
  import { ref, defineProps, watch } from 'vue'
  import { useRouter } from 'vue-router'
  import { useStore } from 'vuex'
  const router = useRouter()
  const store = useStore()
  const role = ref(false)
  store.getters['user/roleList'].map((val) => {
    if (val === '运维管理员') {
      role.value = true
    }
  })
  const approveStatus = ref('通过')
  const whoShow1 = ref(whoShow)
  let dataFrom = ref({
    link: '',
    title: '使用方式',
    englishTitle: 'USAGE',
    content: [
      {
        title: '组件地址',
        link: {
          name: '接口地址：',
        },
        linkValue: '',
        csslinkValue: '',
        contact: '归属部门',
        facilitator: { name: '归属部门：', value: '' },
        people: { name: '部门联系人：', value: '' },
        phone: {
          name: '联系人电话：',
          value: '',
        },
        contact2: '服务商',
        facilitator2: { name: '服务商：', value: '' },
        people2: { name: '服务商联系人：', value: '' },
        phone2: {
          name: '联系人电话：',
          value: '',
        },
      },
    ],
  })
  //数据初始化
  const props = defineProps({
    dataList: { type: Object, default: null },
  })
  const flag = ref(true)
  //立即申请
  function toView() {
    // window.open(newpage.href, '_blank')
    console.log('一键申请===================>', props.dataList)
    localStorage.setItem(
      'applyList',
      JSON.stringify([
        {
          arr: [
            {
              delFlag: props.dataList.delFlag,
              description: props.dataList.description,
              resourceId: props.dataList.id,
              resourceName: props.dataList.name,
              time: props.dataList.createDate,
              type: props.dataList.type,
              componentType: '智能算法',
            },
          ],
          deptId: props.dataList.deptId,
          deptName: props.dataList.deptName,
        },
      ])
    )
    router.push({
      path: '/apply',
    })
  }
  if (props.dataList.infoList) {
    let obj = true
    if (!obj) {
      flag.value = false
    } else {
      // eslint-disable-next-line vue/no-setup-props-destructure
      dataFrom.value.content[0].link.value = props.dataList.apiUrl || '--'
      dataFrom.value.content[0].facilitator.value =
        props.dataList.deptName || '--'
      dataFrom.value.content[0].people.value =
        props.dataList.deptContacts || '--'
      dataFrom.value.content[0].phone.value = props.dataList.deptPhone || '--'
      console.log('dataList', props.dataList)
      props.dataList.infoList.map((item) => {
        if (item.attrType === '服务地址') {
          dataFrom.value.content[0].linkValue = item.attrValue || '--'
        } else if (item.attrType === '服务商') {
          dataFrom.value.content[0].facilitator2.value = item.attrValue || '--'
        } else if (item.attrType === '服务商联系人') {
          dataFrom.value.content[0].people2.value = item.attrValue || '--'
        } else if (item.attrType === '服务商联系电话') {
          dataFrom.value.content[0].phone2.value = item.attrValue || '--'
        } else if (item.attrType === '样式服务地址') {
          dataFrom.value.content[0].csslinkValue = item.attrValue || '--'
        }
      })
    }
  }
  watch(
    () => props.dataList,
    (val) => {
      if (val) {
        let obj = true
        if (!obj) {
          flag.value = false
        } else {
          approveStatus.value = val.approveStatus
          dataFrom.value.content[0].link.value = val.apiUrl || '--'
          dataFrom.value.content[0].facilitator.value = val.deptName || '--'
          dataFrom.value.content[0].people.value = val.deptContacts || '--'
          dataFrom.value.content[0].phone.value = val.deptPhone || '--'
          console.log('dataList', val)
          val.infoList.map((item) => {
            if (item.attrType === '服务地址') {
              dataFrom.value.content[0].linkValue = item.attrValue || '--'
            } else if (item.attrType === '服务商') {
              dataFrom.value.content[0].facilitator2.value =
                item.attrValue || '--'
            } else if (item.attrType === '服务商联系人') {
              dataFrom.value.content[0].people2.value = item.attrValue || '--'
            } else if (item.attrType === '服务商联系电话') {
              dataFrom.value.content[0].phone2.value = item.attrValue || '--'
            } else if (item.attrType === '样式服务地址') {
              dataFrom.value.content[0].csslinkValue = item.attrValue || '--'
            }
          })
        }
      }
    }
  )
  //服务地址和样式服务地址跳转方法
  function ServiceAddressFunction(link) {
    if (link && approveStatus.value === '通过') {
      window.open(link)
    }
  }
  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)
    let obj = props.dataList.infoList.filter(
      (item) => item.attrType === '技术文档'
    )[0]
    if (obj) {
      window.open(window.SITE_CONFIG.frontUrl + obj.attrValue)
    } else {
      message.config({
        top: '100px', // 距离顶部的位置
      })
      message.error('暂未开放技术文档')
    }
  }
  function technicalNew() {
    // 拼接路径
    // 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')
    let obj = props.dataList.infoList.filter(
      (item) => item.attrType === '使用手册'
    )[0]
    if (obj) {
      window.open(
        window.SITE_CONFIG.previewUrl +
          'hisense_office/onlinePreview?url=' +
          btoa(encodeURI(obj.attrValue))
      )
    } else {
      message.config({
        top: '100px', // 距离顶部的位置
      })
      message.error('暂未开放新手指引')
    }
  }
</script>

<style lang="less" scoped>
  .usage-mode {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.8rem 0;
    .blur-word {
      filter: blur(4px);
    }
    .content {
      margin-top: 0.3rem;
      display: flex;

      .content-left {
        height: 1.8rem;
        width: 6.2rem;
        background: url('~@/assets/detailsAll/business/business_usage_mode_bg.png')
          no-repeat;
        background-position: center;
        background-size: 100% 100%;
        border-radius: 0.1rem;
        margin-right: 0.6rem;
        box-shadow: 0rem 0.05rem 0.15rem rgba(82, 106, 255, 0.4);
        display: flex;
        align-items: center;
        padding: 0 0.35rem;

        .left {
          .content-left-title {
            font-size: 0.26rem;
            line-height: 0.26rem;
            color: #212956;
            margin-bottom: 0.2rem;

            span:first-child {
              margin-right: 0.1rem;
            }
          }
          p {
            display: block;
            color: rgba(33, 41, 86, 0.8);
            width: 4.2rem;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            font-size: 20px;
            color: #212956;
            line-height: 26px;
            margin-top: 0.3rem;
            cursor: pointer;
          }
          p:first-child {
            margin-top: 0.2rem;
          }
        }

        .right {
          div {
            height: 0.4rem;
            width: 1.3rem;
            background: #ffffff;
            border-radius: 0.2rem;
            color: #526aff;
            font-size: 0.2rem;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
          }

          div:first-child {
            margin-bottom: 0.2rem;
          }
        }
      }

      .content-right {
        height: 1.8rem;
        width: 6.2rem;
        background: url('~@/assets/detailsAll/business/business_usage_mode_bg.png')
          no-repeat;
        background-position: center;
        background-size: 100% 100%;
        border-radius: 0.1rem;
        box-shadow: 0rem 0.05rem 0.15rem rgba(82, 106, 255, 0.4);
        display: flex;
        justify-content: space-around;
        align-items: center;
        padding: 0 0.3rem;

        .content-right-left {
          // border-right: 0.01rem solid #b0b9f1;
          padding-right: 0.1rem;
          margin-right: 0.1rem;
        }

        .content-right-title {
          font-size: 0.26rem;
          line-height: 0.26rem;
          color: #212956;
          margin-bottom: 0.15rem;
        }

        .content-right-content {
          display: flex;
          font-size: 0.16rem;
          color: rgba(33, 41, 86, 0.8);
          line-height: 0.2rem;
          overflow: hidden;
          -webkit-line-clamp: 1;
          -webkit-box-orient: vertical;
          flex-direction: column;
          word-break: break-all;

          p {
            width: 2.6rem;
            // height: 0.2rem;
            margin-right: 0.15rem;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 1;
            -webkit-box-orient: vertical;
            word-break: break-all;

            span {
              cursor: pointer;
              font-size: 20px;
              color: #212956;
              opacity: 0.8;
            }
          }
        }
      }
    }
    .contentOther {
      width: 80%;
      height: 4rem;
      border: 1px dashed #7b98fd;
      margin-top: 0.3rem;
      display: flex;
      justify-content: center;
      align-items: center;
      img {
        margin-right: 2rem;
      }
      .contentOtherRight {
        p {
          font-weight: bold;
          font-size: 0.2rem;
        }
        div {
          width: 1.3rem;
          height: 0.4rem;
          line-height: 0.4rem;
          background: #0885ff;
          color: #ffffff;
          border-radius: 0.05rem;
          font-size: 0.18rem;
          text-align: center;
          cursor: pointer;
          transition: all 0.3s;
        }
        div:hover {
          background: #359bff;
        }
      }
    }
  }
</style>
