<template>
  <view class="page__view">
    
		<!-- 导航栏 -->
		<navbar :title="details.title" leftClick @leftClick="$utils.navigateBack" bgColor="#4883F9" color="#FFFFFF" />

    <!-- 轮播图 -->
    <view class="swiper">
      <uv-swiper :list="bannerList" keyName="image" :autoplay="bannerList.length > 1" :indicator="bannerList.length > 1" indicatorMode="dot" indicatorActiveColor="#4883F9" indicatorInactiveColor="#FFFFFF" height="424rpx"></uv-swiper>
    </view>

    <!-- 发表全流程辅导 -->
    <view class="section">
      <view class="section-header">发表全流程辅导</view>
      <view class="section-content paragraph process">
        <view class="paragraph">
          <uv-parse :content="details.process"></uv-parse>
        </view>
      </view>
    </view>

    <!-- 可发表方向 -->
    <view class="section">
      <view class="section-header">
        <view class="section-header-line"></view>
        <view>可发表方向</view>
      </view>
      <view class="section-content direction">
        <view class="table">
          <view class="table-row" v-for="row in details.educationTargetList" :key="row.id">
            <view class="table-cell">{{ row.title }}</view>
            <view class="table-cell">{{ row.description }}</view>
          </view>
        </view>
      </view>
    </view>
    
    <!-- 师资介绍 -->
    <view class="section">
      <view class="section-header">
        <view class="section-header-line"></view>
        <view>师资介绍</view>
      </view>
      <view class="section-content teachers">
        <view class="card" v-for="item in details.educationTeacherList" :key="item.id">
          <view class="info">
            <view class="title">
              <view class="name">{{ item.title }}</view>
              <view class="label">
                <view class="label-text">{{ item.career }}</view>
                <view class="label-line"></view>
              </view>
            </view>
            <view class="tag">
              <image class="tag-icon" src="@/static/image/icon-degree.png" mode="widthFix"></image>
              <vie>{{ item.qualification }}</vie>
            </view>
            <view class="desc">
              <view>专业经历：</view>
              <view>{{ item.experience }}</view>
            </view>
          </view>
          <view class="pic">
            <image class="img" :src="item.image" mode="aspectFill"></image>
          </view>
        </view>
      </view>
    </view>

    <!-- 课程安排 -->
    <view class="section">
      <view class="section-header">
        <view class="section-header-line"></view>
        <view>课程安排</view>
      </view>
      <view class="section-content">
        <view class="table">
          <view class="table-row" v-for="row in details.educationCourseList" :key="row.id">
            <view class="table-cell">{{ row.title }}</view>
            <view class="table-cell">{{ row.description }}</view>
          </view>
        </view>
      </view>
    </view>

    <!-- 适用人群 -->
    <view class="section">
      <view class="section-header">
        <view class="section-header-line"></view>
        <view>适用人群</view>
      </view>
      <view class="section-content target-audience">
        <view class="paragraph">
          <uv-parse :content="details.suit"></uv-parse>
        </view>
      </view>
    </view>

    <!-- 期刊推荐 -->
    <view class="section">
      <view class="section-header">
        <view class="section-header-line"></view>
        <view>期刊推荐</view>
      </view>
      <view class="section-content journal">
        <view class="box" v-for="item in details.educationPeriodicalList" :key="item.id">
          <view class="card">
            <view class="top">
              <view class="pic">
                <image class="img" :src="item.image" mode="aspectFill"></image>
              </view>
              <view class="info">
                <view class="name">{{ item.title }}</view>
                <view class="desc">{{ item.shortTitle }}</view>
              </view>
            </view>
            <view class="main">
              {{ item.description }}
            </view>
          </view>
        </view>
      </view>
    </view>

    <!-- 附加材料 -->
    <view class="section">
      <view class="section-header">
        <view class="section-header-line"></view>
        <view>附加材料</view>
      </view>
      <view class="section-content attachment">
        <view class="flex file" v-for="item in details.educationDocumentList" :key="item.id">
          <view class="file-info">
            <template v-if="item.type == 'pdf'">
              <image class="file-icon" src="@/static/image/icon-pdf.png" mode="widthFix"></image>
            </template>
            <template v-else>
              <image class="file-icon" src="@/static/image/icon-word.png" mode="widthFix"></image>
            </template>
            <view class="file-detail">
              <view class="title">{{ item.title }}</view>
              <view class="desc">{{ `${getFileType(item.document)} ${item.size || '-'}MB` }}</view>
            </view>
          </view>
          <button class="btn" @click="downloadFile(item.document)">下载</button>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        details: {},
      }
    },
    onLoad({ thesisId }) {
      this.getData(thesisId)
    },
    computed: {
      bannerList() {
        const { image } = this.details || {}
        return (image || '').split(',').map(url => ({ image: url }))
      }
    },
    methods: {
      async getData(thesisId) {

        try {
          this.details = await this.$fetch('queryThesisById', { thesisId })
        } catch (err) {

        }

      },
      getFileType(fileName) {
        const pdfReg = /(.pdf)$/g
        // const officeReg = /(doc|docx|ppt|pptx|xls|xlsx)$/g

        return pdfReg.test(fileName) ? 'pdf' : ''
      },
      downloadFile(url) {
        console.log('downloadFile', url)
        uni.downloadFile({
          url, // 文件地址
          success: (downloadRes) => {
            console.log('downloadRes', downloadRes)
            if (downloadRes.statusCode === 200) {
              uni.openDocument({
                showMenu: true,
                filePath: downloadRes.tempFilePath,
                success: () => console.log('打开成功')
              });
            } else {
              uni.showToast({ title: '下载失败', icon: 'none' });
            }
          },
          fail: (err) => {
            uni.showToast({ title: '网络异常', icon: 'none' });
          }
        });
      },
    },
  }
</script>

<style scoped lang="scss">

  .page__view {
    padding-bottom: 62rpx;
    background: #FFFFFF;
  }

  .swiper {
    margin: 20rpx 18rpx 32rpx 18rpx;
    border-radius: 25rpx;
    overflow: hidden;
    
    /deep/ .uv-swiper-indicator__wrapper__dot {
      width: 15rpx;
      height: 15rpx;
    }

    /deep/ .uv-swiper-indicator__wrapper__dot--active {
      width: 15rpx;
    }
  }

  .section {
    width: 100%;
    padding: 0 18rpx;
    box-sizing: border-box;

    & + & {
      margin-top: 40rpx;
    }

    &-header {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      column-gap: 15rpx;
      padding-left: 18rpx;
      font-size: 32rpx;
      font-weight: 700;
      color: #000000;

      &-line {
        width: 11rpx;
        height: 45rpx;
        border-radius: 6rpx;
        background-image: linear-gradient(#FFFFFF, #4883F9);
      }
    }

    &-content {
      margin-top: 37rpx;

      .paragraph {
        width: 100%;
        padding: 22rpx;
        box-sizing: border-box;
        white-space: pre-line;
        font-size: 28rpx;
        color: #000000;
        background: #F8F8F8;
        border-radius: 15rpx;
      }

      .table {
        width: 100%;
        border-radius: 15rpx;
        overflow: hidden;

        &-row {
          display: grid;
          grid-template-columns: 218rpx auto;
          background: #EEEEEE;

          &:nth-child(2n) {
            background: #DEDEDE;
          }
        }

        &-cell {
          display: inline-flex;
          flex-direction: column;
          align-items: flex-start;
          justify-content: center;
          padding: 17rpx;
          box-sizing: border-box;
          font-family: PingFang SC;
          font-weight: 400;
          font-size: 28rpx;
          color: #080808;

          &:first-child {
            border-right: 1rpx solid #E5E5E5;
          }
        }

      }

      &.process {
        margin-top: 24rpx;

        .difficulty {
          justify-content: flex-start;
        }
      }

      &.teachers {

        .card {
          display: flex;
          align-items: center;
          column-gap: 12rpx;
          background: #ffffff;
          border-radius: 15rpx;
          box-shadow: 0rpx 3rpx 6rpx 0rpx rgba(0,0,0,0.16); 

          .info {
            flex: 1;
            padding: 19rpx 0 28rpx 17rpx;

            .title {
              display: flex;
              align-items: center;
              padding-left: 11rpx;
              color: #000000;

              .name {
                font-size: 32rpx;
                font-weight: 700;
              }

              .label {
                margin-left: 12rpx;
                position: relative;
                height: 30rpx;

                &-line {
                  margin: 24rpx 0 0 25rpx;
                  width: 195rpx;
                  height: 4rpx;
                  background-image: linear-gradient(#4883F9, #FFFFFF);
                  border-radius: 2rpx;
                }

                &-text {
                  position: absolute;
                  top: 0;
                  left: 0;
                  font-size: 22rpx;
                  font-weight: 400;
                }
              }
            }

            .tag {
              margin: 5rpx 0 18rpx 0;
              display: inline-flex;
              align-items: center;
              padding: 5rpx 43rpx 5rpx 16rpx;
              column-gap: 16rpx;
              font-size: 28rpx;
              color: #FFFFFF;
              background: rgba(72,131,249,0.58);
              border-radius: 30rpx 0rpx 30rpx 0rpx;

              &-icon {
                width: 38rpx;
                height: auto;
              }
            }

            .desc {
              padding: 12rpx 15rpx;
              font-size: 28rpx;
              font-weight: 500;
              color: #000000;
              background: #f8f8f8;
              border-radius: 16rpx;
            }
          }

          .pic {
            margin: 48rpx 9rpx 48rpx 0;
            width: 253rpx;
            height: 345rpx;
            border-radius: 127rpx;
            overflow: hidden;

            .img {
              width: 100%;
              height: 100%;
            }
          }
          
          &:nth-child(2n) {
            flex-direction: row-reverse;

            .info {
              padding: 19rpx 17rpx 28rpx 0;
            }

            .pic {
              margin: 48rpx 0 48rpx 9rpx;
            }
          }
        }

        .card + .card {
          margin-top: 24rpx;
        }
      }
      
      &.journal {
        
        .box {
          padding-top: 73rpx;

          .card {
            padding: 29rpx 12rpx 19rpx 12rpx;
            background: #f6f6f6;
            border-radius: 15rpx;
            box-shadow: 0rpx 3rpx 6rpx 0rpx rgba(0,0,0,0.16); 

            .top {
              position: relative;

              .pic {
                position: absolute;
                left: 42rpx;
                bottom: 0;
                width: 213rpx;
                height: 285rpx;

                .img {
                  width: 100%;
                  height: 100%;
                }
              }

              .info {
                height: 181rpx;
                padding: 0 14rpx 0 266rpx;

                .name {
                  padding-left: 6rpx;
                  font-size: 32rpx;
                  font-weight: 700;
                  color: #000000;
                }

                .desc {
                  margin-top: 24rpx;
                  font-size: 28rpx;
                  font-weight: 700;
                  color: #707070;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  display:-webkit-box; //作为弹性伸缩盒子模型显示。
                  -webkit-box-orient:vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
                  -webkit-line-clamp:3; //显示的行
                }
              }
              
            }

            .main {
              margin-top: 18rpx;
              padding: 14rpx;
              font-size: 28rpx;
              color: #000000;
              background: #ebebeb;
              border-radius: 30rpx 0rpx 30rpx 0rpx;
            }

          }
          
          &:nth-child(2n) {

            .card {

              .top {
                .info {
                  padding: 0 258rpx 0 14rpx;
                }

                .pic {
                  left: unset;
                  right: 29rpx;
                }
              }

            }
          }
        }

        .box + .box {
          margin-top: 28rpx;
        }
      }

      &.attachment {

        .file {
          justify-content: space-between;
          padding: 32rpx 15rpx 32rpx 26rpx;
          background: #f8f8f8;
          border-radius: 15rpx;

          &-info {
            display: flex;
            align-items: flex-end;
          }

          &-icon {
            width: 64rpx;
            height: auto;
          }

          &-detail {
            margin-left: 14rpx;

            .title {
              font-size: 30rpx;
              color: #000000;
            }

            .desc {
              font-size: 28rpx;
              color: #999999;
            }

          }

          .btn {
            padding: 7rpx 30rpx;
            font-size: 28rpx;
            color: #FFFFFF;
            background: #4883f9;
            border-radius: 27rpx;
          }
        }

        .file + .file {
          margin-top: 21rpx;
        }

      }

    }
  }

</style>