<template>
  <div class="pain-panel">
    <p class="symptom-title"><span>疼痛部位<sup>*</sup></span><span></span></p>
    <el-input @change="updatePain" v-if="!readonly" size="mini" v-model="obj.painLocation" placeholder="" maxlength="50"></el-input>
    <p class="readonly-text" v-if="readonly"><pre>{{obj.painLocation}}</pre></p>
    <p class="symptom-title"><span>性质<sup>*</sup></span><span v-if="!readonly">(多选)</span></p>
    <el-select class="pain-select" @change="setObj(obj.painNature,'painNature')" v-if="!readonly" v-model="obj.painNature" :popper-append-to-body="true" style="width:100%" size="mini" placeholder="请选择" multiple collapse-tags>
      <el-option v-for="i in natureArr" :label="i" :value="i" :key="i"></el-option>
    </el-select>
    <div v-if="readonly && obj.painNature && obj.painNature.length" class="nature-box">
      <!-- <span v-for="item in obj.painNature.split(',')" :key="item">{{item}}</span> -->
      <span v-for="item in obj.painNature" :key="item">{{item}}</span>
    </div>
    <p class="symptom-title"><span>评分<sup>*</sup></span><span></span></p>
    <el-slider
      @change="updatePain" 
      class="pain-sider"
      :disabled="readonly"
      :show-tooltip="false"
      v-model="obj.score"
      :min="1"
      :step="1"
      :max="10"
      show-stops
      :marks="marks">
    </el-slider>
    <p class="symptom-title"><span>是否影响睡眠<sup>*</sup></span><span></span></p>
    <el-radio-group  @change="updatePain" style="margin-top:5px" v-model="obj.sleep" :disabled="readonly">
      <el-radio :label="1">是</el-radio>
      <el-radio :label="0">否</el-radio>
    </el-radio-group>
    <p class="symptom-title"><span>是否吃止疼药<sup>*</sup></span><span></span></p>
    <el-radio-group @change="setObj(obj.anodyne,'anodyne')" style="margin-top:5px" v-model="obj.anodyne" :disabled="readonly">
      <el-radio :label="1">是</el-radio>
      <el-radio :label="0">否</el-radio>
    </el-radio-group>
    <template v-if="obj.anodyne == 1">
      <p style="margin:12px 0 0;border-bottom:1px dashed #eee"></p>
      <p class="symptom-title"><span>具体药物及剂量<sup>*</sup></span><span></span></p>
      <el-input @change="updatePain" v-if="!readonly" size="mini" v-model="obj.drugDose" placeholder="" maxlength="100" show-word-limit></el-input>
      <p class="readonly-text" v-if="readonly"><pre>{{obj.drugDose}}</pre></p>
    </template>
  </div>
</template>
<script>
const natureArr = ['刺痛','钝痛','闷痛','抽痛','压痛','烧灼痛','胀痛','麻痛','酸痛']
export default {
  name: 'AeglePain',
  
  props: {
    readonly:{
      type: Boolean,
      default: false
    },
    item: {
      type: Object,
      default: () => {
        return {
          pain: '',       //疼痛 0：否  1：是
          painLocation: '', //疼痛位置
          painNature: '', //疼痛性质
          score: '',       //评分
          sleep: '',      //是否影响睡眠 0：否  1：是
          anodyne: '',        //止痛药 0：否  1：是
          drugDose:''    //药物剂量
        }
      }
    }
  },
  watch: {
    item: {
      handler(v){
        if(v) {
          this.painNature = v.painNature ? v.painNature.split(',') : [];
          this.obj = {
            ...v,
            score: Number(v.score),
            painNature: v.painNature ? v.painNature.split(',') : []
          }
        }
      },
      deep: true
    }
  },
  data() {
    return {
      natureArr,
      value: '',
      painNature: [],
      obj: {
        painLocation: '', //疼痛位置
        painNature: '', //疼痛性质
        score: 0,       //评分
        sleep: '',      //是否影响睡眠 0：否  1：是
        anodyne: '',        //止痛药 0：否  1：是
        drugDose:''
      },
      marks: {
        0:'0',
        1:'1',
        2:'2',3:'3',4:'4',5:'5',6:'6',7:'7',8:'8',9:'9',10:'10'
      }
    }
  },
  methods: {
    setObj(e,type){
      if(type == 'isPill'){
        this.obj.pill = ''
      } else if(type == 'painNature'){
        // this.obj.painNature = this.painNature.toString()
      }
      this.updatePain()
    },
    updatePain() {
      this.$emit('change', {...this.obj,painNature: this.obj.painNature.toString()})
    },
  },
  mounted() {
    this.obj = {
      ...this.item,
      score: Number(this.item.score),
      painNature: this.item.painNature ? this.item.painNature.split(',') : []
    }
  }
}
</script>
<style lang="less">
.pain-sider {
  padding: 0 2px;
  .el-slider__runway {
    height: 6px;
    background: rgba(0,0,0,0.06);
    .el-slider__stop {
      box-sizing: border-box;
      height: 6px;
      width: 6px;
      border: 1px solid rgba(0,0,0,0.06);
    }
    &.disabled {
      .el-slider__button {
        border-color: #1890ff;
      }
      .el-slider__bar {
        background-color: #1890ff;
      }
      .el-slider__stop {
        // background-color: rgba(0,0,0,0.06);
      }
    }
    
  }
  .el-slider__button {
    box-sizing: border-box;
    width: 10px;
    height: 10px;
    border: 1px solid #1890ff;
  }
  .el-slider__marks-text {
    font-size: 12px;
    font-family: PingFangSC, PingFangSC-Regular;
    color: rgba(0,0,0,0.80);
    margin-top: 8px;
    &:last-child {
      left: 99%!important;
    }
  }
}
.pain-select {
  .el-tag {
    font-size: 12px;
    font-family: PingFangSC, PingFangSC-Regular;
    height: 18px;
    line-height: 16px;
    background: rgba(24,144,255,0.10);
    border: 1px solid rgba(24,144,255,0.20);
    border-radius: 2px;
    color: #1890FF;
    .el-tag__close.el-icon-close {
      background-color: transparent;
      color: #1890FF;
      font-size: 18px;
      line-height: 18px;
      right: -3px;
      &:hover {
        background: rgba(24,144,255,0.10);
      }
    }
  }
}
</style>
<style lang="less" scoped>
.pain-panel {
  font-family: PingFangSC, PingFangSC-Regular;
  .symptom-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 14px;
    font-family: PingFangSC, PingFangSC-Regular;
    font-weight: 400;
    text-align: left;
    color: rgba(0,0,0,0.60);
    margin: 12px 0 4px;
    sup {
      color: #E92626;
    }
    span:first-child {
      display: flex;
    }
    span:last-child {
      color: rgba(0,0,0,0.40);
    }
  }
  .readonly-text {
    margin: 0;
    font-size: 14px;
    font-weight: 400;
    text-align: left;
    color: rgba(0,0,0,0.80);
    white-space: wrap;
    pre {
      font-family: PingFangSC, PingFangSC-Regular;
      margin: 0;
      white-space: pre-wrap;
      line-height: 20px;
      letter-spacing: 0.21px;
    }
  }
  .nature-box {
    display: flex;
    flex-wrap: wrap;
    span {
      font-size: 12px;
      text-align: center;
      height: 18px;
      line-height: 16px;
      background: rgba(24,144,255,0.10);
      border: 1px solid rgba(24,144,255,0.20);
      border-radius: 2px;
      padding: 0 8px;
      color: #1890ff;
      margin-bottom: 2px;
    }
    span + span {
      margin-left: 3px;
    }
  }
}
</style>