<template>
  <view :class="['page__view', hasPoster ? 'with-bottom' : '']">
    
		<!-- 导航栏 -->
		<navbar :title="details.title" leftClick @leftClick="$utils.navigateBack" />

    <view class="cover-image" :style="{ height: coverImageHeight }">
      <image class="img" :src="details.image" mode="scaleToFill" ></image>
      <view class="shadow" :style="{ height: coverImageShadowHeight }"></view>
    </view>
    <view class="page-title">
      <view v-if="details.process || (details.educationProcessList && details.educationProcessList.length)">{{ details.processTitle || '发表全流程辅导' }}</view>
      <view v-else>{{ details.title }}</view>
      <view class="page-title-line"></view>
    </view>

    <!-- 发表全流程辅导 -->
    <view class="process" v-if="details.process || (details.educationProcessList && details.educationProcessList.length)">
      <view class="flex process-custom" v-if="difficulty">
        <view class="process-custom-title">难度</view>
        <view class="flex star">
          <uv-icon v-for="(item, index) in new Array(difficulty).fill(1)" :key="index" name="star-fill" color="#FFFFFF" size="20rpx"></uv-icon>
        </view>
      </view>
      <view class="process-item" v-for="item in details.educationProcessList" :key="item.id">
        <view class="process-item-title">{{ item.title }}</view>
        <view class="process-item-content">{{ item.content }}</view>
      </view>
    </view>

    <!-- 可发表方向 -->
    <view class="section" v-if="details.educationTargetList && details.educationTargetList.length">
      <view class="section-header">
        <view class="section-header-line"></view>
        <view>{{ details.targetTitle || '可发表方向' }}</view>
      </view>
      <view class="section-content direction">
        <uv-read-more show-height="300rpx" :toggle="true" textIndent="0" :shadowStyle="{ backgroundImage: 'linear-gradient(-180deg, rgba(255, 255, 255, 0) 0%, #fff 80%)', paddingTop: '100rpx', marginTop: '-100rpx' }">
          <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>
        </uv-read-more>
      </view>
    </view>
    
    <!-- 师资介绍 -->
    <view class="section" v-if="details.educationTeacherList && details.educationTeacherList.length">
      <view class="section-header">
        <view class="section-header-line"></view>
        <view>{{ details.teacherTitle || '师资介绍' }}</view>
      </view>
      <view class="section-content teachers">
        <view class="card" v-for="item in details.educationTeacherList" :key="item.id">
          <view class="info">
            <view class="pic">
              <image class="img" :src="item.image" mode="aspectFill" ></image>
            </view>
            <view class="flex flex-column title">
              <view class="name">{{ item.title }}</view>
              <view class="label" v-if="item.career">{{ item.career }}</view>
            </view>
            <view class="flex tag">
              <image class="tag-icon" src="@/static/image/icon-degree.png" mode="widthFix"></image>
              <view>{{ item.qualification }}</view>
            </view>
            <view class="desc desc-top">
              <view class="desc-title">专业经历</view>
            </view>
            <view class="desc desc-bottom">{{ item.experience }}</view>
          </view>
        </view>
      </view>
    </view>

    <!-- 课程安排 -->
    <view class="section" v-if="details.educationCourseList && details.educationCourseList.length">
      <view class="section-header">
        <view class="section-header-line"></view>
        <view>{{ details.courseTitle || '课程安排' }}</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" v-if="details.suit">
      <view class="section-header">
        <view class="section-header-line"></view>
        <view>{{ details.suitTitle || '适用人群' }}</view>
      </view>
      <view class="section-content target-audience">
        <view class="paragraph">
          <uv-parse :content="details.suit"></uv-parse>
        </view>
      </view>
    </view>

    <!-- 期刊推荐 -->
    <view class="section" v-if="details.educationPeriodicalList && details.educationPeriodicalList.length">
      <view class="section-header">
        <view class="section-header-line"></view>
        <view>{{ details.periodicalTitle || '期刊推荐' }}</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" v-if="details.educationDocumentList && details.educationDocumentList.length">
      <view class="section-header">
        <view class="section-header-line"></view>
        <view>{{ details.documentTitle || '附加材料' }}</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 class="flex bottom" v-if="hasPoster">
      <view class="flex btns">
        <button class="btn" @click="jumpToPoster">保存海报</button>
        <button class="btn btn-share" open-type="share">分享文章</button>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        details: {},
        coverImageHeight: '566rpx',
        coverImageShadowHeight: '113rpx'
      }
    },
    onLoad({ thesisId }) {
      
      const windowWidth = uni.getSystemInfoSync().windowWidth
      const coverImageHeight = (windowWidth) * 566 / 714
      const coverImageShadowHeight = (windowWidth) * 113 / 714
      this.coverImageHeight = `${coverImageHeight}px`
      this.coverImageShadowHeight = `${coverImageShadowHeight}px`
      
      this.getData(thesisId)
      // this.getData('1949729528544800770')
    },
    onShareAppMessage(res) {
      return {
        title: this.posterData.paperDesc,
        imageUrl: this.posterData.paperImage,
        path: this.posterData.path,
      }
    },
    computed: {
      difficulty() {
        const num = parseInt(this.details?.process)

        return isNaN(num) ? 0 : num
      },
      posterData() {
        const { id, title, image, paperDesc, paperImage } = this.details || {}

        return {
          paperDesc: paperDesc || title,
          paperImage: paperImage || image || '',
          path: `pages_order/thesis/index?thesisId=${id}`
        }
      },
      hasPoster() {
        const { paperImage } = this.details || {}

        return !!paperImage
      }
    },
    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) => {
            console.log('downloadFile fail', err)
            uni.showToast({ title: '网络异常', icon: 'none' });
          }
        });
      },
      jumpToPoster() {
        uni.setStorageSync('posterData', this.posterData)

        uni.navigateTo({
					url: `/pages_order/thesis/poster`
				})
      },
    },
  }
</script>

<style scoped lang="scss">

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

    &.with-bottom {
		  padding-bottom: calc(62rpx + 110rpx + env(safe-area-inset-bottom));
    }
  }

  .cover-image {
    position: relative;
    width: 100%;
    background: #FFFFFF;
    
    .img {
      width: 100%;
      height: 100%;
    }

    .shadow {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: linear-gradient(transparent, #FFFFFF);
    }
  }

  .page-title {
    padding: 0 26rpx;
    font-size: 60rpx;
    font-weight: 700;
    color: $uni-color;
    
    &-line {
      margin: 12rpx 0 24rpx 0;
      width: 120rpx;
      height: 8rpx;
      background: $uni-color;
    }
  }

  .process {
    position: relative;
    width: 100%;
    padding: 0 26rpx;
    box-sizing: border-box;

    &-custom {
      display: inline-flex;
      column-gap: 8rpx;
      padding: 4rpx 16rpx;
      background: #9787C2;
      border-top-right-radius: 18rpx;
      border-bottom-right-radius: 18rpx;

      &-title {
        font-size: 24rpx;
        font-weight: 600;
        line-height: 1.2;
        color: #FFFFFF;
      }

      .star {
        column-gap: 10rpx;
      }
    }

    &-item {
      margin-top: 22rpx;
      font-size: 0;

      &-title {
        display: inline-block;
        padding: 4rpx 36rpx 4rpx 20rpx;
        box-sizing: border-box;
        font-size: 30rpx;
        font-weight: 600;
        line-height: 1.2;
        color: #FFFFFF;
        background: #9787C2;
        border-top-right-radius: 21rpx;
        border-bottom-right-radius: 21rpx;
      }

      &-content {
        padding: 28rpx 34rpx;
        box-sizing: border-box;
        font-size: 24rpx;
        line-height: 1.6;
        white-space: pre-wrap;
        color: #595757;
        background: #EDEAFF;
        border-radius: 15rpx;
        border-top-left-radius: 0;
      }

    }
  }

  .section {
    margin-top: 40rpx;
    width: 100%;
    padding: 0 26rpx;
    box-sizing: border-box;

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

    &-header {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      column-gap: 15rpx;
      font-size: 40rpx;
      font-weight: 700;
      color: $uni-color;

      &-line {
        width: 18rpx;
        height: 52rpx;
        border-radius: 9rpx;
        background-image: linear-gradient(#E2DDFF, #6851A7);
      }
    }

    &-content {
      margin-top: 37rpx;

      .paragraph {
        width: 100%;
        padding: 30rpx;
        box-sizing: border-box;
        white-space: pre-line;
        font-size: 24rpx;
        color: #595757;
        background: linear-gradient(to right, rgba($color: #E2DDFF, $alpha: 0.54), rgba($color: #C8C3FD, $alpha: 0.54));
        border-radius: 15rpx;
      }

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

        &-row {
          display: grid;
          grid-template-columns: 218rpx auto;
          background: rgba($color: #C8C3FD, $alpha: 0.63);

          &:nth-child(2n) {
            background: rgba($color: #C8C3FD, $alpha: 0.26);
          }
        }

        &-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;
          line-height: 1.5;
          // font-size: 28rpx;
          white-space: pre-wrap;
          // color: #080808;
          font-size: 18rpx;
          color: #595757;

          &:first-child {
            align-items: center;
            text-align: center;
            font-size: 22rpx;
            line-height: 1.4;
            font-weight: 600;
            border-right: 1rpx solid #E5E5E5;
          }
        }

      }

      &.direction {
        /deep/ .uv-read-more__toggle {
          // justify-content: flex-end;
          padding: 10rpx 0;
          background: linear-gradient(to right, rgba($color: #E2DDFF, $alpha: 0.67), rgba($color: #C8C3FD, $alpha: 0.67), rgba($color: #E1DCFF, $alpha: 0.67));
        }
        /deep/ .uv-read-more__toggle__text .uv-text__value {
          color: #9D9DF9 !important;
          font-size: 20rpx !important;
        }
      }

      &.teachers {

        .card {
          display: flex;
          align-items: center;
          // column-gap: 12rpx;
          background: linear-gradient(to right, rgba($color: #E2DDFF, $alpha: 0.14), rgba($color: #C8C3FD, $alpha: 0.14));
          border-radius: 15rpx;
          box-shadow: 0rpx 3rpx 6rpx 0rpx rgba(0,0,0,0.16); 

          .info {
            flex: 1;
            padding: 30rpx 30rpx 0 30rpx;
            font-size: 0;

            .title {
              align-items: flex-start;
              color: #000000;
              transform: translateX(-30rpx);

              .name {
                margin-bottom: 20rpx;
                display: inline-block;
                padding: 4rpx 60rpx 4rpx 28rpx;
                font-size: 30rpx;
                font-weight: 700;
                line-height: 1.2;
                color: #FFFFFF;
                background: rgba($color: #6851A7, $alpha: 0.69);
                border-top-right-radius: 21rpx;
                border-bottom-right-radius: 21rpx;
              }

              .label {
                margin-bottom: 14rpx;
                padding: 0 4rpx 4rpx 30rpx;
                box-sizing: border-box;
                font-size: 22rpx;
                font-weight: 500;
                color: rgba($color: #6851A7, $alpha: 0.68);
                border-bottom: 4rpx solid rgba($color: #6851A7, $alpha: 0.69);
              }
            }

            .tag {
              justify-content: flex-start;
              margin-bottom: 12rpx;
              column-gap: 12rpx;
              padding-left: 4rpx;
              font-size: 28rpx;
              font-weight: 600;
              color: #6851A7;

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

            .desc {
              font-size: 18rpx;
              font-weight: 500;
              white-space: pre-wrap;
              color: #000000;
              background: #ECEAFF;
              // border-radius: 16rpx;

              &-title {
                display: inline-block;
                padding: 4rpx 30rpx 4rpx 12rpx;
                font-size: 20rpx;
                font-weight: 600;
                color: #FFFFFF;
                background: #B7ACDC;
                border-top-right-radius: 15rpx;
                border-bottom-right-radius: 15rpx;
              }

              &-top {
                padding: 32rpx 24rpx 0 0;
                border-top-left-radius: 10rpx;
                border-top-right-radius: 10rpx;
              }
              &-bottom {
                margin-bottom: 30rpx;
                padding: 20rpx 24rpx 32rpx 24rpx;
                border-bottom-left-radius: 10rpx;
                border-bottom-right-radius: 10rpx;
              }
            }
          }

          .pic {
            // margin: 48rpx 9rpx 48rpx 0;
            margin: 0 0 30rpx 52rpx;
            width: 291rpx;
            height: 454rpx;
            // border-radius: 127rpx;
            border-radius: 10rpx;
            overflow: hidden;
            float: right;

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

            .info {
              
              .title {
                align-items: flex-end;
                transform: translateX(30rpx);

                .name {
                  padding: 4rpx 28rpx 4rpx 60rpx;
                  border-top-right-radius: 0;
                  border-bottom-right-radius: 0;
                  border-top-left-radius: 21rpx;
                  border-bottom-left-radius: 21rpx;
                }

                .label {
                  padding: 0 30rpx 4rpx 4rpx;
                }
              }

              .tag {
                justify-content: flex-end;
                padding-right: 24rpx;
              }

              .desc {
                &-title {
                  padding: 4rpx 15rpx 4rpx 26rpx;
                  border-top-right-radius: 0;
                  border-bottom-right-radius: 0;
                  border-top-left-radius: 15rpx;
                  border-bottom-left-radius: 15rpx;
                }

                &-top {
                  padding: 32rpx 0 0 24rpx;
                  text-align: right;
                }
              }
            }

            .pic {
              // margin: 44rpx 14rpx 0 0;
              margin: 0 52rpx 30rpx 0;
              float: left;
            }
          }
        }

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

          .card {
            padding: 32rpx 26rpx 22rpx 26rpx;
            background: linear-gradient(to right, rgba($color: #E2DDFF, $alpha: 0.14), rgba($color: #C8C3FD, $alpha: 0.14));
            border-radius: 15rpx;
            box-shadow: 4rpx 4rpx 6rpx 0rpx rgba(0,0,0,0.105); 

            .top {
              position: relative;
              min-height: 265rpx;

              .pic {
                position: absolute;
                left: 10rpx;
                bottom: 0;
                width: 236rpx;
                height: 356rpx;
                background: linear-gradient(rgba($color: #E2DDFF, $alpha: 0.54), rgba($color: #C8C3FD, $alpha: 0.54));
                border-radius: 6rpx;

                .img {
                  width: 100%;
                  height: 100%;
                  border-radius: 6rpx;
                  transform: translate(-10rpx, -10rpx);
                }
              }

              .info {
                min-height: 181rpx;
                padding: 0 0 0 278rpx;

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

                .desc {
                  margin-top: 24rpx;
                  padding: 16rpx 20rpx;
                  box-sizing: border-box;
                  // font-size: 28rpx;
                  font-size: 24rpx;
                  line-height: 1.5;
                  white-space: pre-wrap;
                  font-weight: 700;
                  color: #595757;
                  background: rgba($color: #C8C3FD, $alpha: 0.26);
                  border-radius: 6rpx;
                  // overflow: hidden;
                  // text-overflow: ellipsis;
                  // display:-webkit-box; //作为弹性伸缩盒子模型显示。
                  // -webkit-box-orient:vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
                  // -webkit-line-clamp:3; //显示的行
                }
              }
              
            }

            .main {
              margin-top: 18rpx;
              padding: 20rpx;
              font-size: 18rpx;
              line-height: 1.5;
              white-space: pre-wrap;
              color: #595757;
              background: rgba($color: #C8C3FD, $alpha: 0.26);
              // border-radius: 30rpx 0rpx 30rpx 0rpx;
              border-radius: 6rpx;
            }

          }
          
          &:nth-child(2n + 1) {

            .card {

              .top {
                .info {
                  padding: 0 278rpx 0 0;
                }

                .pic {
                  left: unset;
                  right: 0;
                }
              }

            }
          }
        }

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

      &.attachment {

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

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

          &-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: $uni-color;
            border-radius: 27rpx;
          }
        }

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

      }

    }
  }

  .bottom {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100vw;
    height: 94rpx;
		padding-bottom: env(safe-area-inset-bottom);
    background: #FFFFFF;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16); 

    .btns {
      column-gap: 34rpx;
    }

    .btn {
      padding: 12rpx 70rpx;
      font-size: 32rpx;
      font-weight: 600;
      line-height: 1.2;
      color: #FFFFFF;
      background: $uni-color;
      border-radius: 30rpx;

      &-share {
        background: #9E96CC;
      }

    }

  }

</style>