<template>
  <div v-if="visibility" class="Dialog">
    <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">
      <ul>
        <li>
          <van-checkbox-group v-model="propsForm.result">
            <van-checkbox
              style="border-bottom: 1px #e5e5e5 solid;padding: 0 0.38rem"
              v-for="(advice, index) in propsForm.list"
              :key="index"
              :name="advice.id"
            >
             <div style="padding-top: 15px;padding-left: 10px">开嘱医生&nbsp;{{ getDoctorName(advice.advice_doctor) }}</div><br/>
              <div style="padding-left: 10px">开嘱时间&nbsp;{{ getTime(advice.created_time) }}</div><br/>
              <div style="padding-bottom: 15px;padding-left: 10px"> 医嘱内容&nbsp;{{getContent(advice)}}</div>

            </van-checkbox>
          </van-checkbox-group>
        </li>
      </ul>
    </div>
  </div>
</template>

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

  export default {
    name: 'LongAdviceSubMenu',
    created () {
    },
    data () {
      return {
        result: [],
        id: 0,
        selectName: ''
      }
    },
    props: {
      propsForm: {
        type: Object
      },
      visibility: {
        type: Boolean,
        default: false
      },
    },
    methods: {
      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 = ''
        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
        }
        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].drug_spec
              + val.child[i].drug_spec_unit
              + val.child[i].presc
              + val.child[i].single
          }
          return  val.advice_name +"  "+ val.drug_spec+" "
            + val.drug_spec_unit
            + prescribing_number
            + " "+single_dose+" "+ " "+val.delivery_way+" "+ val.execution_frequency + val.remark +name

        } else {
          return val.advice_name +"  "+ val.drug_spec+" "
            + val.drug_spec_unit
            + 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.getValue())
      },
      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
        }, [])

        results

        return results
      },

    },
    watch: {
      visibility (val) {
        //初始化数据操作
      }
    }
  }
</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: 8rem !important;
  min-height: 8rem !important;
  }

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