<template>
  <div v-if="visibility" class="Dialog newLongDialog">
    <div class="DialogTit">
      <div class="back" @click="cancle()">
        <span class="iconfont">&#xe720;</span>返回
      </div>
      <h1 class="name">提交申请</h1>
      <span @click="comfirm" class="success">保存</span>
    </div>

    <div class="CheckBox">
     
      <div style="font-size:18px;padding-left:10px;margin-top:6px;">
        <span style="font-weight: bold;color: #409eff;">申请时间:</span>
        <span style="display: inline-block;border: 1px solid #ccc;padding: 10px 20px;border-radius: 5px;"
              @click="changeStartTime">{{ advice_start_time }}</span>
      </div>
       <van-field v-model="remark" @focus="inputFocus"  label="备注:"  class="bgField"  rows="1" autosize type="textarea" placeholder="请输入">
                     
      </van-field>
    </div>

    <mt-datetime-picker
      class="longAdvicePicker"
      ref="advice_picker"
      type="datetime"
      yearFormat="{value}"
      monthFormat="{value}"
      dateFormat="{value}"
      hourFormat="{value}"
      minuteFormat="{value}"
      @confirm="handleStartTimeConfirm"
      v-model="start_time"
    ></mt-datetime-picker>
  </div>
</template>

<script>
import {parseTime} from '@/utils'

export default {
  name: 'LongAdviceSubMenu',
  created () {

  },
  mounted () {

  },
  data () {
    return {
      advice_start_time: '',
      result: [],
      id: 0,
      selectName: '',
      start_time: '',
      remark:'',
      predialysis:{}
    }
  },
  props: {
    propsForm: {
      type: Object
    },
    visibility: {
      type: Boolean,
      default: true
    },
  },
  methods: {
      inputFocus: function (event) {
      var input = event.target
      setTimeout(function () {
        input.scrollIntoView()
      }, 0)

      if (input.setSelectionRange) {
        setTimeout(function () {
          input.setSelectionRange(0, input.value.length)
        }, 0)
      } else if (input.createTextRange) {
        var rng = input.createTextRange()
        rng.move('character', input.value.length)
        rng.select()
      }
    },
    handleStartTimeConfirm (val) {
      let date = new Date(val)
      let Str = date.getFullYear() + '-' +
          (date.getMonth() + 1) + '-' +
          date.getDate() + ' ' +
          date.getHours() + ':' +
          date.getMinutes()

      var year = date.getFullYear() // 获取完整的年份(4位)
      var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1).toString() : date.getMonth() + 1 // 获取当前月份(0-11,0代表1月)
      var day = date.getDate() < 10 ? '0' + date.getDate().toString() : date.getDate() // 获取当前日(1-31)
      var hour = date.getHours() < 10 ? '0' + date.getHours().toString() : date.getHours() // 获取当前日(1-31)
      var min = date.getMinutes() < 10 ? '0' + date.getMinutes().toString() : date.getMinutes() // 获取当前日(1-31)

      this.advice_start_time = year + '-' + month + '-' + day + ' ' + hour + ':' + min

      this.start_time = year + '-' + month + '-' + day + ' ' + hour + ':' + min
    },
    changeStartTime () {
      this.$refs.advice_picker.open()
    },
    getDoctorName (doctor_id) {
      for (let i = 0; i < this.propsForm.operators.length; i++) {
        if (this.propsForm.operators[i].id == doctor_id) {
          return this.propsForm.operators[i].name
        }
      }
    },
    getTime (val) {
      return parseTime(val, '{y}-{m}-{d} {h}:{i}')
    },
    getContent (val) {
      let prescribing_number = ''
      let single_dose = ''
      let advice_desc = ''

      if (val.prescribing_number > 0) {
        prescribing_number =
            val.prescribing_number + val.prescribing_number_unit
      }
      if (val.single_dose > 0) {
        single_dose = ' 单次用量 ' + val.single_dose + val.single_dose_unit
      }

      if (val.advice_desc > 0 || val.advice_desc.length > 0) {
        advice_desc = val.advice_desc + val.drug_spec_unit
      }

      let name = ''
      if (val.child.length > 0) {
        for (let i = 0; i < val.child.length; i++) {
          if (val.child[i].prescribing_number > 0) {
            val.child[i]['presc'] =
                val.child[i].prescribing_number +
                val.child[i].prescribing_number_unit
          } else {
            val.child[i]['presc'] = ''
          }

          if (val.child[i].single_dose > 0) {
            val.child[i]['single'] =
                ' ' +
                ' 单次用量 ' +
                ' ' +
                val.child[i].single_dose +
                val.child[i].single_dose_unit
          } else {
            val.child[i]['single'] = ''
          }
          name =
              name +
              '▲' +
              val.child[i].advice_name +
              '' +
              val.child[i].advice_desc +
              val.child[i].drug_spec_unit +
              val.child[i].presc +
              val.child[i].single
        }
        return (
          val.advice_name +
            '  ' +
            advice_desc +
            ' ' +
            val.drug_spec_unit +
            prescribing_number +
            ' ' +
            single_dose +
            ' ' +
            ' ' +
            val.delivery_way +
            ' ' +
            val.execution_frequency +
            val.remark +
            name
        )
      } else {
        return (
          val.advice_name +
            '  ' +
            advice_desc +
            prescribing_number +
            ' ' +
            single_dose +
            ' ' +
            ' ' +
            val.delivery_way +
            ' ' +
            val.execution_frequency +
            val.remark
        )
      }
    },

    cancle: function () {
      this.$emit('menu-cancle-three')
    },
    comfirm: function () {
      this.$emit('menu-comfirm-three',this.advice_start_time,this.remark)
    },
    getValue: function () {
      let form = {}
      let results = []
      for (let i = 0; i < this.propsForm.list.length; i++) {
        for (let a = 0; a < this.propsForm.result.length; a++) {
          if (this.propsForm.list[i].id == this.propsForm.result[a]) {
            results.push(this.propsForm.list[i])
          }
        }
      }
      var obj5 = {}
      results = results.reduce((cur, next) => {
        obj5[next.id] ? '' : (obj5[next.id] = true && cur.push(next))
        return cur
      }, [])
      return results
    }
  },
  watch: {
    visibility: {
      handler (val, oldVal) {
        // 初始化数据操作
        if (val) {
          var nowDate = new Date()
          var nowYear = nowDate.getFullYear()
          var nowMonth = nowDate.getMonth() + 1
          var nowDay = nowDate.getDate()

          var hours = nowDate.getHours()
          var min = nowDate.getMinutes()

          var nowTime =
              nowYear +
              '-' +
              (nowMonth < 10 ? '0' + nowMonth : nowMonth) +
              '-' +
              (nowDay < 10 ? '0' + nowDay : nowDay) + ' ' + (hours < 10 ? '0' + hours : hours) +
              ':' + (min < 10 ? '0' + min : min)

          this.advice_start_time = nowTime
          this.start_time = nowTime
          
        }
        
      },
      immediate: true
    }
  }
}
</script>

<style style="stylesheet/scss" lang="scss" scoped>
  .optionsBox {
  background: #fff;
  max-height: 10rem;
  min-height: 5rem;
  @media only screen and (max-width: 812px) {
  min-height: 8rem !important;
  }
  ul {
  overflow-y: scroll;
  max-height: 9rem;
  li {
  height: 1.1rem;
  line-height: 1.1rem;
  border-bottom: 1px #e5e5e5 solid;
  padding: 0 0.38rem;
  font-size: 0.36rem;
  color: $title-color;
  }
  .tick {
  position: relative;
  &::before {
  content: "";
  display: inline-block;
  border: 2px solid $main-color;
  border-top-width: 0;
  border-right-width: 0;
  width: 0.3rem;
  height: 0.15rem;
  -webkit-transform: rotate(-50deg);
  position: absolute;
  top: 0.38rem;
  right: 0.44rem;
  }
  }
  }
  }
  .CheckBox {
  background: #fff;
  max-height: 6.8rem;
  min-height: 5rem;
  overflow-y: scroll;
  @media only screen and (max-width: 812px) {
  max-height: 14.8rem !important;
  min-height: 8rem !important;
  }

  ul {
  li {
  line-height: 1rem;
  }
  }
  }
</style>

<style lang="scss">
.newLongDialog{
  font-size: 14px !important;
  .DialogTit {
    font-size: 14px !important;
    .name{
      font-size: 14px !important;
    }
    .back{
      font-size: 14px !important;
    }
    .success{
      font-size: 14px !important;
    }
  }
  .van-checkbox__label{
    font-size: 14px !important;
  }
  .longAdvicePicker{
    z-index: 4011 !important;
    .picker-item{
      font-size: 14px !important;
      height: 44px;
      line-height: 44px;

    }
    .mint-datetime-action{
      font-size: 15px !important;
    }
  }

}


.van-field__label{
    // width: 9.375rem;
    width: initial;
}
.bgField{
    .van-field__control{
        border:1px solid #ccc;
        background: #f6f6f6;
        border-radius: 4px;
        min-height: 6.25rem !important;
    }
    ::placeholder{  //通过这个设置
        color: #999 !important;
    }
}


</style>
