<template>
  <div id="operation-record" style=" background: #fff; padding: 10px 20px 50px 20px;page-break-after:always">
    <div v-if="!onlyRead" class="btnBox">
      <el-button size="small" @click="doPrint">打印</el-button>
      <el-button type="primary" size="small" @click="handleSaveTable">保存</el-button>
      <el-button type="danger" size="small" @click="handleDelete">删除</el-button>
    </div>
    <div id="optomeFunc" style="width: 840px;padding-right: 8px" class="printBox">
      <p style="color:#000000;font-size:32px;margin:0 0 30px 0;text-align:center;">
        验光报告单
      </p>
      <div style="display: flex;justify-content: space-around">
        <span>登记号：<el-input v-model="dataForm.number" style="width: 80px" size="small" clearable placeholder="" /></span>
        <span>姓名：<el-input v-model="dataForm.name" style="width: 80px" size="small" clearable placeholder="" /></span>
        <span>性别：<el-input v-model="dataForm.sex" style="width: 60px" size="small" clearable placeholder="" /></span>
        <span>年龄：<el-input v-model="dataForm.age" style="width: 60px" size="small" clearable placeholder="" /></span>
        <span>屈光发育档案：<el-input v-model="dataForm.file" style="width: 60px" size="small" clearable placeholder="" /></span>
        <span>档案号：<el-input v-model="dataForm.fileNUm" style="width: 80px" size="small" clearable placeholder="" /></span>
      </div>
      <div class="operation-record-table">
        <el-table :data="tableData" :span-method="objectSpanMethod" border style="width: 100%; margin-top: 20px">
          <el-table-column label="" width="" align="center" :resizable="false">
            <template slot-scope="scope">
              <div v-if="scope.row.name == 1">
                <div class="width-180 center">
                  瞳孔
                </div>
              </div>
              <div v-else-if="scope.row.name == 2">
                <div class="width-180 center">
                  检查方法
                </div>
              </div>
              <div v-else-if="scope.row.name == 3">
                <div class="width-180 center">
                  右眼
                </div>
              </div>
              <div v-else-if="scope.row.name == 4">
                <div class="width-180 center">
                  左眼
                </div>
              </div>
              <div v-else-if="scope.row.name == 5">
                <div class="width-180 center">
                  右眼
                </div>
              </div>
              <div v-else-if="scope.row.name == 6">
                <div class="width-180 center">
                  左眼
                </div>
              </div>
              <div v-else-if="scope.row.name == 7" style="display: flex;justify-content: space-between">
                <div class="width-180" style="text-align: left">
                  <el-input v-model="scope.row.a" placeholder="">
                    <template slot="prepend">视光师:</template>
                  </el-input>
                </div>
                <div class="width-180" style="text-align: left">
                  <el-input v-model="scope.row.b" placeholder="">
                    <template slot="prepend">医师:</template>
                  </el-input>
                </div>
                <div class="width-180" style="text-align: left">
                  日期：<el-date-picker
                    v-model="scope.row.c"
                    type="date"
                    placeholder="选择日期"
                  />
                </div>
              </div>
              <p v-else>{{ scope.row.name }}</p>
            </template>
          </el-table-column>
          <el-table-column label="" width="" :resizable="false">
            <template slot-scope="scope">
              <div v-if="scope.row.name == '1'">
                <div class="width-180">
                  <el-checkbox-group v-model="scope.row.pupil">
                    <el-checkbox label="正常瞳孔" />
                    <el-checkbox label="复方托吡卡胺" />
                    <el-checkbox label="美多丽" />
                    <el-checkbox label="赛飞杰" />
                    <el-checkbox label="阿托品" />
                  </el-checkbox-group>
                </div>
              </div>
              <div v-if="scope.row.name == '2'">
                <div class="width-180">
                  <el-checkbox-group v-model="scope.row.examine">
                    <el-checkbox label="检影" />
                    <el-checkbox label="综合" />
                  </el-checkbox-group>
                </div>
              </div>
              <div v-if="scope.row.name == '3'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.a" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '4'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.a" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '5'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.a" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '6'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.a" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '基本信息'">
                <div class="width-100 center">
                  裸眼视力
                </div>
              </div>
              <div v-if="scope.row.name == '最终处方'">
                <div class="width-100">
                  <el-checkbox-group v-model="scope.row.value">
                    <el-checkbox label="远用" />
                    <el-checkbox label="近用" />
                  </el-checkbox-group>
                </div>
              </div>
              <div v-if="scope.row.name == '配镜建议'">
                <div style="display: flex">
                  <el-checkbox-group v-model="scope.row.suggest">
                    <el-checkbox label="单光" />
                    <el-checkbox label="离焦镜片" />
                    <el-checkbox label="软镜" />
                    <el-checkbox label="RGP" />
                    <el-checkbox label="OK镜" />
                  </el-checkbox-group>
                  <p style="margin-left: 16px">
                    <el-input v-model="scope.row.value" placeholder="">
                      <template slot="prepend">其他:</template>
                    </el-input>
                  </p>
                </div>
              </div>
              <div v-if="scope.row.name == '备注'">
                <div class="width-180">
                  <el-input v-model="scope.row.value" placeholder="" />
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="" width="" :resizable="false">
            <template slot-scope="scope">
              <div v-if="scope.row.name == '基本信息'">
                <div class="width-180 center">
                  右眼
                </div>
              </div>
              <div v-if="scope.row.name == '验光检查'">
                <div class="width-180 center">
                  球镜(DS)
                </div>
              </div>
              <div v-if="scope.row.name == '3'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.b" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '4'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.b" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '5'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.b" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '6'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.b" placeholder="" />
                </div>
              </div>
              <!--            <div v-if="scope.row.name == '最终处方'">-->
              <!--              <div class="width-100 center">-->
              <!--                恢复点：<el-input v-model="scope.row.value" placeholder="" />-->
              <!--              </div>-->
              <!--            </div>-->
              <!--            <div v-if="scope.row.name == '立体视(stereo)'">-->
              <!--              <div class="width-100 center">-->
              <!--                TNO(近)：<el-input v-model="scope.row.value" placeholder="" />-->
              <!--              </div>-->
              <!--            </div>-->

            </template>
          </el-table-column>
          <el-table-column label="" width="" :resizable="false">
            <template slot-scope="scope">
              <div v-if="scope.row.name == '基本信息'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.od" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '验光检查'">
                <div class="width-100 center">
                  柱镜(DC)
                </div>
              </div>
              <div v-if="scope.row.name == '3'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.c" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '4'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.c" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '5'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.c" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '6'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.c" placeholder="" />
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="" width="" :resizable="false">
            <template slot-scope="scope">
              <div v-if="scope.row.name == '基本信息'">
                <div class="width-180 center">
                  左眼
                </div>
              </div>
              <div v-if="scope.row.name == '验光检查'">
                <div class="width-180 center">
                  轴位(A)
                </div>
              </div>
              <div v-if="scope.row.name == '3'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.d" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '4'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.d" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '5'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.d" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '6'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.d" placeholder="" />
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="" width="" :resizable="false">
            <template slot-scope="scope">
              <div v-if="scope.row.name == '基本信息'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.os" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '验光检查'">
                <div class="width-180 center">
                  矫正视力(VA)
                </div>
              </div>
              <div v-if="scope.row.name == '3'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.e" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '4'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.e" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '5'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.e" placeholder="" />
                </div>
              </div>
              <div v-if="scope.row.name == '6'">
                <div class="width-100 center">
                  <el-input v-model="scope.row.e" placeholder="" />
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="" width="" :resizable="false">
            <template slot-scope="scope">
              <div v-if="scope.row.name == '验光检查'">
                <div class="width-180 center">
                  下加光(ADD)
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
        <p style="text-align: left;margin-top: 3px">说明：1.持本报告但配镜仅供参考。              2.本报告单有效期3个月</p>
      </div>
    </div>
  </div>
</template>
<script>
import { getLodop } from '@/utils/LodopFuncs'
export default {
  props: {
    formContent: {
      type: Object,
      default: () => { }
    },
    onlyRead: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      dataForm: {
        number: '',
        name: '',
        sex: '',
        age: '',
        file: '',
        fileNUm: ''
      },
      tableData: [
        {
          name: '基本信息',
          od: '',
          os: '',
          type: ''
        }, {
          name: '1',
          pupil: [],
          type: ''
        }, {
          name: '2',
          examine: [],
          type: ''
        }, {
          name: '验光检查',
          type: ''
        }, {
          name: '3',
          a: '',
          b: '',
          c: '',
          d: '',
          e: '',
          type: ''
        }, {
          name: '4',
          type: '',
          a: '',
          b: '',
          c: '',
          d: '',
          e: ''
        }, {
          name: '最终处方',
          value: [],
          type: ''
        }, {
          name: '5',
          type: '',
          a: '',
          b: '',
          c: '',
          d: '',
          e: ''
        }, {
          name: '6',
          type: '',
          a: '',
          b: '',
          c: '',
          d: '',
          e: ''
        }, {
          name: '配镜建议',
          suggest: [],
          value: ''
        }, {
          name: '备注',
          value: ''
        }, {
          name: '7',
          a: '',
          b: '',
          c: ''
        }],
      print: {
        id: 'optomeFunc'
        // preview: true
      }
    }
  },
  computed: {
    operationRecord: {
      get() {
        return this.$store.getters.operationRecord
      }
    }
  },
  watch: {
    operationRecord: {
      handler(value) {
      },
      deep: true,
      immediate: true
    }
  },
  created() {
    // this.queryData()
  },
  methods: {
    doPrint() {
      const html = document.getElementById('optomeFunc').innerHTML
      const lodop = getLodop()
      console.log(lodop)
      lodop.ADD_PRINT_HTM('2%', '5%', '100%', '100%', html)
      lodop.SET_PRINT_PAGESIZE(2, 0, 0, 'A5')
      lodop.PREVIEW()
    },
    setData() {
      this.dataForm = this.formContent.a
      this.tableData = this.formContent.b
      console.log(this.tableData)
    },
    reSet() {
      this.dataForm = {
        number: '',
        name: '',
        sex: '',
        age: '',
        file: '',
        fileNUm: ''
      }
      this.tableData = [
        {
          name: '基本信息',
          od: '',
          os: '',
          type: ''
        }, {
          name: '1',
          pupil: [],
          type: ''
        }, {
          name: '2',
          examine: [],
          type: ''
        }, {
          name: '验光检查',
          type: ''
        }, {
          name: '3',
          a: '',
          b: '',
          c: '',
          d: '',
          e: '',
          type: ''
        }, {
          name: '4',
          type: '',
          a: '',
          b: '',
          c: '',
          d: '',
          e: ''
        }, {
          name: '最终处方',
          value: [],
          type: ''
        }, {
          name: '5',
          type: '',
          a: '',
          b: '',
          c: '',
          d: '',
          e: ''
        }, {
          name: '6',
          type: '',
          a: '',
          b: '',
          c: '',
          d: '',
          e: ''
        }, {
          name: '配镜建议',
          suggest: [],
          value: ''
        }, {
          name: '备注',
          value: ''
        }, {
          name: '7',
          a: '',
          b: '',
          c: ''
        }]
    },
    queryData() {
      const ws = new WebSocket('ws://192.168.4.24:8036/xiangan-crf/websocket/0071')
      ws.onopen = function() {
        console.log('连接成功')
      }
      ws.onerror = function() {
        console.log('连接失败')
      }
      // ws.send()
      ws.onmessage = function(msg) {
        const data = JSON.parse(JSON.stringify(msg.data))
        // console.log(msg.data)
        console.log(data)
      }
    },
    handleSaveTable() {
      const data = {
        a: this.dataForm,
        b: this.tableData
      }
      this.$emit('save', data)
    },
    handleDelete() {
      this.$emit('del')
    },
    //   签名
    singHandle(text) {
      const value = {
        text: text,
        pageName: 'operationRecord'
      }
      this.$store.commit('beginSign', value)
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (rowIndex === 0 || rowIndex === 3 || rowIndex === 6) {
          // [0,0][0,3][0,6] 合并单元格 3行合并1列
          return {
            rowspan: 3,
            colspan: 1
          }
        }
        // [0,11] 最后一行 7列合并城1行
        if (rowIndex === 11) {
          return {
            rowspan: 1,
            colspan: 7
          }
        }
      } else if (columnIndex === 1) {
        if (rowIndex === 6 || rowIndex === 9 || rowIndex === 10) {
          return {
            rowspan: 1,
            colspan: 6
          }
        }
        if (rowIndex === 1 || rowIndex === 2) {
          return {
            rowspan: 1,
            colspan: 6
          }
        }
      } else if (columnIndex === 4) {
        if (rowIndex === 0) {
          return {
            rowspan: 1,
            colspan: 2
          }
        }
      } else if (rowIndex === 6 || rowIndex === 9 || rowIndex === 10) {
        if (columnIndex === 2 || columnIndex === 3 || columnIndex === 4 || columnIndex === 5 || columnIndex === 6) {
          return {
            rowspan: 0,
            colspan: 0
          }
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.printBox{
  page-break-inside: avoid !important;
  .el-input__inner {
    border-bottom: 1px solid #ccc;
    border-radius: 0;
    padding: 0;
  }
}
//@media print{
//  @page {
//    size:A5 landscape !important;
//  }
//}
#operation-record {
  //height: 93%;
  // overflow: auto;
  .operation-record-table {
    width: 100%;
    .operation-text {
      font-weight: 700;
    }
    .text {
      font-weight: 700;
    }
    .sign {
      cursor: pointer;
      color: #46a1ff;
      font-weight: 400;
    }
  }
  .center {
    text-align: center;
  }
  .left {
    text-align: left;
  }

  .width-50 {
    .el-input {
      width: 50px;
    }
  }
  .width-70 {
    .el-input {
      width: 70px;
    }
  }

  .width-100 {
    .el-input {
      width: 100px;
    }
  }
  .width-120 {
    .el-input {
      width: 120px;
    }
  }
  .width-180 {
    .el-input {
      width: 180px;
    }
  }
  .el-input__inner {
    border: none;
    height: 26px !important;
    line-height: 26px !important;
    text-align: center;
  }

  .el-input__inner {
    border-bottom: 1px solid #ccc;
    border-radius: 0;
    padding: 0;
  }
  .el-input__prefix {
    display: none;
  }
  .el-date-editor.el-input,
  .el-date-editor.el-input__inner {
    width: 140px;
  }
  .el-input__suffix {
    top: -7px;
  }
  .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #606266;
  }
  .el-checkbox__input.is-checked .el-checkbox__inner,
  .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background: #767676;
    border-color: #767676;
  }
  .el-checkbox__inner:hover,
  .el-checkbox__inner {
    border-color: #767676;
  }
  .el-radio__input.is-checked + .el-radio__label {
    color: #606266;
  }
  .el-radio__input.is-checked .el-radio__inner {
    background: #767676;
    border-color: #767676;
  }
  .el-radio {
    margin-right: 8px;
    display: block;
  }
  .el-radio__inner {
    border: 1px solid #767676 !important;
  }
  .el-radio__inner:hover {
    border-color: #767676;
  }
  .el-table--enable-row-hover .el-table__body tr:hover>td.el-table__cell {
    background: none !important;
  }
  .has-gutter {
    display: none;
    .cell {
      font-weight: 700;
    }
    .el-table__cell {
      background: #ced4d9;
    }
  }
  ::v-deep .el-table .el-table__cell{
    padding: 5px 0;
  }
  // .el-table--border .el-table__cell, .el-table__body-wrapper .el-table--border.is-scrolling-left~.el-table__fixed {
  //   border-right: 1px solid #808080;
  // }
  // .el-table td.el-table__cell, .el-table th.el-table__cell.is-leaf {
  //   border-bottom: 1px solid #808080 !important;
  // }
  // .el-table--border, .el-table--group {
  //   border: 1px solid #808080;
  // }
  // .el-table--border {
  //   border-bottom: 0;
  // }
}
</style>
