<!-- <template>
    <div class="page_newCourse">
        <van-sticky>
            <div class="newCourseTitle">
                <i class="iconfont icon-zuojiantou jiantou" @click="toReturn()"></i>
                <span class="titleName">新增病程</span>
                <span @click="saveCourseManagement">完成</span>
            </div>
        </van-sticky>
        <div>

            <van-cell title="病程日期" is-link v-model="startTime" @click="clickstartShow()" />
            <van-field required v-model="title" label="病程标题" />
        </div>
        <div class="grey"></div>
        <div class="courseMain">
            <div class="courseMainTitle">病程内容</div>
            <div class="templateTitle" @click="typeShow=true">{{course_content}}</div>
            <textarea style="width: 100%;margin-top: 10px;border: 1px solid #e5e5e5;border-radius: 5px;padding: 10px;" name="" id="" cols="30" rows="10" v-model="content"></textarea>
        </div>

         <van-popup
            v-model="startShow"
            position="bottom"
            :style="{ height: '40%' }"
        >
            <van-datetime-picker
            v-model="currentDate"
            type="datetime"
            :min-date="minDate"
            :max-date="maxDate"
            @confirm="getstartTime"
            @cancel="startShow = false"
            />
       </van-popup>

        <van-popup
          v-model="typeShow"
          position="bottom"
          :style="{ height: '40%' }"
        >
          <van-picker
            show-toolbar
            :columns="columns"
            @cancel="onCancel"
            @confirm="onConfirm"
          />
        </van-popup>
    </div>
</template>
<script>
import { saveCourseManagement } from '@/api/patient/patient'
import { Toast } from 'vant'
export default {
  data () {
    return {
      title: '',
      startShow: false,
      typeShow: false,
      minDate: new Date(1970, 0, 1),
      maxDate: new Date(2025, 10, 1),
      currentDate: new Date(),
      startTime: '请选择',
      start_time: '',
      columns: [],
      course_content: '',
      content: '',
      patientid: 0,
      template: '',
      seacherActive: 0
    }
  },
  methods: {
    getstartTime (value) {
      this.page = 1
      let year = value.getFullYear()
      let month = value.getMonth() + 1
      let day = value.getDate()
      let hour = value.getHours()
      let minuters = value.getMinutes()
      if (month >= 1 && month <= 9) {
        month = `0${month}`
      }
      if (day >= 1 && day <= 9) {
        day = `0${day}`
      }

      if (hour >= 1 && hour <= 9) {
        hour = `0${hour}`
      }

      if (minuters >= 1 && minuters <= 9) {
        minuters = `0${minuters}`
      }

      this.startTime = `${year}-${month}-${day} ${hour}:${minuters}`
      this.start_time = `${year}-${month}-${day} ${hour}:${minuters}`
      this.startShow = false
    },
    clickstartShow () {
      this.startShow = true
    },
    onCancel () {
      this.typeShow = false
    },

    onConfirm (value) {
      var content = ''
      for (let i = 0; i < this.template.length; i++) {
        if (value == this.template[i].title) {
          content = this.template[i].content
        }
      }
      this.content = content.replace(/<[^>]+>/g, '')
      this.course_content = value
      this.typeShow = false
    },
    saveCourseManagement () {
      if (this.start_time == '') {
        this.$toast('请选择病程日期')
        return false
      }
      if (this.title == '') {
        this.$toast('请选择病程标题')
        return false
      }
      if (this.content == '') {
        this.$toast('请选择病程内容')
        return false
      }
      const params = {
        start_time: this.start_time,
        title: this.title,
        course_content: this.course_content,
        content: this.content,
        patientid: this.patientid
      }
      saveCourseManagement(params).then(response => {
        if (response.data.state == 1) {
          var record = response.data.data.record
          // console.log('record', record)
          this.$toast('保存成功')
          this.$router.push('/patientdetail?patientid=' + this.patientid + '&seacherActive=' + this.seacherActive + '&active=' + 5)
        }
      })
    },
    toReturn () {
      this.$router.push('/patientdetail?patientid=' + this.patientid + '&seacherActive=' + this.seacherActive + '&active=' + 5)
    }

  },
  created () {
    this.patientid = parseInt(this.$route.query.patientid)
    this.seacherActive = parseInt(this.$route.query.seacherActive)
    // 获取病程内容
    var template = this.$store.getters.configlist.course_disease
    console.log('template', template)
    this.template = template
    var name = []
    for (let i = 0; i < template.length; i++) {
      name.push(template[i].title)
    }
    this.columns = name
  }
}
</script>
<style lang="scss" scoped>
.page_newCourse{
  height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  .newCourseTitle {
    background: #fff;
    padding: 0 1.125rem;
    height: 3.125rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .jiantou {
    font-size: 1.5rem;
    font-weight: 600;
  }
  .titleName {
    font-size: 1.125rem;
    font-weight: 600;
  }
  .grey{
      height: 1.25rem;
      background: #fafafa;
  }
  .courseMain{
      height: 100%;
      background: #fff;
      padding: .625rem 1rem;
  }
  .courseMainTitle{
      font-size: 1rem;
  }
  .templateTitle{
      width:100%;
      height: 3.125rem;
      line-height: 3.125rem;
      padding: 0 .625rem;
      border: 1px solid #e5e5e5;
      margin-top: .625rem;
      border-radius: 5px;
      display: inline-block;
      white-space: nowrap;
      width: 100%; overflow:
      hidden; text-overflow:ellipsis;
  }
  .van-cell__title::before {
    position: absolute;
    left: 8px;
    color: #ee0a24;
    font-size: 14px;
    content: "*";
  }

}
</style>

<style lang="scss">
.page_newCourse{
  .van-field__body{
    height:100%
  }
  .van-field__control{
    height:100%;
  }
}
</style> -->
