<template>
  <div class="visitDetail">
    <van-cell
      class="visit-item"
      center
    >
      <template #icon>
        <img class="user-logo" v-if="userInfo.avatar" :src="userInfo.avatar" alt="" />
        <img
          v-else
          class="user-logo"
          src="../../assets/images/icon_student.png"
          alt=""
        />
      </template>
      <template #title>
        <div class="title">
          <p class="name">{{ userInfo.username }}</p>
          <p class="time">
            {{ userInfo.classDate }}
            <span class="tips"><i class="icon_dot"></i>教学内容未达标</span>
          </p>
        </div>
      </template>
      <template #right-icon>
        <a :href="'tel:' + userInfo.phone"><van-icon :name="icon_phone" size="18" /></a>
      </template>
    </van-cell>

    <Item v-if="dataInfo.courseScheduleId" :dataInfo="dataInfo" />

    <van-cell-group class="section">
      <p class="work title">
        <van-icon :name="icon_content" size="22" style="padding-right: .06rem;" />
        教学内容
      </p>
      <van-field
        rows="1"
        type="textarea"
        disabled
        v-model="memo"
        placeholder="请输入本课程教学内容"
      />
    </van-cell-group>

    <div class="button-group">
      <van-button type="primary" round size="large" @click="submitReview">
        添加回访
      </van-button>
    </div>
  </div>
</template>

<script>
import Item from "../afterClassEvaluate/modal/item.vue";
import { getReviewInfo, getCurrentCourseDetail } from '../afterClassEvaluate/api';
export default {
  name: "visitDetail",
  components: { Item },
  data() {
    const query = this.$route.query || {};
    return {
      userInfo: query || {},
      icon_content: require('@/views/afterClassEvaluate/images/icon_content.png'),
      icon_phone: require('@/views/afterClassEvaluate/images/icon_phone.png'),
      memo: null,
      dataInfo: {}
    }
  },
  computed: {
    isReview() {
      return this.$route.query.reviewId && this.$route.query.reviewId > 0;
    }
  },
  async mounted() {
    try {
      const detail = await getCurrentCourseDetail({ courseID: this.userInfo.courseScheduleId });
      const resultDetail = detail.data
      let tempMemo = resultDetail.coursePlan
      this.dataInfo = {
        classStartTime: resultDetail.startClassTime,
        classEndTime: resultDetail.endClassTime,
        courseType: resultDetail.courseType,
        courseName: resultDetail.courseScheduleName,
        teachMode: resultDetail.teachMode,
        schoolName: resultDetail.address,
        courseScheduleId: resultDetail.courseScheduleId
      }
      if(this.isReview) {
        const res = await getReviewInfo({ id: this.userInfo.reviewId });
        const result = res.data
        tempMemo = result.courseScheduleReview.memo
      }
      this.memo = tempMemo || '该课程未设置教学内容'
    } catch {
      //
    }
    // let params = {}
    // if(this.isReview) {
    //   const res = await getReviewInfo({ id: this.userInfo.reviewId });
    //   const result = res.data
    //   console.log(result, 'result')
    //   let info = result.teacherClassHeadInfo;
    //   params = {
    //     classStartTime: info.classDate + ' ' + info.startClassTime + ':00',
    //     classEndTime: info.endClassTime + ':00',
    //     courseType: info.courseScheduleType,
    //     courseName: info.classGroupName,
    //     teachMode: info.teachMode,
    //     schoolName: null,
    //     courseScheduleId: result.courseScheduleReview.courseScheduleId
    //   }
    //   this.memo = result.courseScheduleReview.memo || '该课程未设置教学内容'
    // }
    // this.dataInfo = params
    // console.log(this.dataInfo)
  },
  methods: {
    submitReview() {
      let { userId, ...query } = this.$route.query
      this.$router.push({
        path: "/addVisit",
        query: {
          beforeId: this.userInfo.userId,
          ...query
        }
      });
    }
  }
};
</script>

<style lang="less" scoped>
.visitDetail {
  min-height: 100vh;
  background: #f3f4f8;
  overflow: hidden;
}
.visit-item {
  margin: 0.1rem 0.12rem;
  border-radius: 0.1rem;
  padding: 0.18rem 0.12rem;
  width: auto;
  .user-logo {
    width: 0.42rem;
    height: 0.42rem;
    border-radius: 50%;
  }
  .title {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding-left: 0.1rem;
    color: #666666;
    font-size: 0.13rem;
    .name {
      font-size: 0.16rem;
      color: #1a1a1a;
    }
    .time {
      display: flex;
      align-items: center;
    }
    .tips {
      font-size: 0.12rem;
      color: #ff5a5f;
      background: #fff3f3;
      border-radius: 3px;
      margin-left: 0.05rem;
      padding: 0 0.05rem 0 0.03rem;
      line-height: 0.18rem;
      display: inline-block;
      display: flex;
      align-items: center;
      .icon_dot {
        display: inline-block;
        margin-right: 0.03rem;
        width: 0.1rem;
        height: 0.1rem;
        background: url("../afterClassEvaluate/images/dot.png") no-repeat center;
        background-size: contain;
      }
    }
  }
}

.section {
  margin: 0.1rem 0.12rem 0;
  border-radius: .1rem;
  overflow: hidden;
  .work {
    display: flex;
    align-items: center;
    font-size:16px;
    color: #333;
  }
  .title {
    padding: 12px 16px 0;
  }

  .student-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
  }
  .titleStyle {
    font-size: 16px;
    color: #666666;
    span {
      color: #1A1A1A;
      padding: 0 .1rem;
    }
  }
}

.button-group {
  padding: 0.2rem .16rem 0.15rem;
  background: #f3f4f8;
  border: 0.01rem solid #f3f4f8;
  .van-button--primary {
    font-size: 0.18rem;
    height: 0.48rem;
    line-height: 0.48rem;
  }
}
</style>
