<template>
  <div style="display: flex;">
    <div style="width:50%;">
      <el-table id="tableSummary" row-key="id" :data="sumDoctorCheck.summaryList" width="100%" :height="sumHeight" border
        size="small">
        <el-table-column type="index" width="20" align="center" />
        <el-table-column prop="summaryTitle" label="综述">
          <template slot-scope="scope">
            <div>
              <el-input v-model="scope.row.summaryTitle" placeholder="请输入综述" disabled></el-input>
              <el-table :id="scope.row.id" :row-key="scope.$index + scope.row.id" style="margin-left: 10px;"
                :data="scope.row.details" border @row-click="rowClick" :show-header="false">
                <el-table-column width="30">
                  <template slot-scope="scope2">
                    <div>{{ scope2.$index + 1 }})</div>
                  </template>
                </el-table-column>
                <el-table-column prop="summaryContent" label="综述" min-width="200">
                  <template slot-scope="scope2">
                    <!--:autosize="{ minRows: 1, maxRows: 20 } "-->
                    <el-input type="textarea" v-model="scope2.row.summaryContent" placeholder="请输入综述" disabled
                      :autosize="{ minRows: 1, maxRows: 20 }">
                    </el-input>
                  </template>
                </el-table-column>
                <el-table-column width="8" />
              </el-table>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="position: absolute; top: 0px; right: 2px; display: flex;z-index: 3;">
      <div style="margin-right: 5px;">
        <el-button style="height: 28px;" class="commonbutton" @click="btnCollapseAll" :disabled="sumBtnDisabled()">{{
          collapse ?
          '展开' : '折叠' }}全部建议</el-button>
      </div>
      <div v-show="checkPagePriv(pagePriv.privs, '新增建议')">
        <el-button style="height: 28px;" class="commonbutton" @click="addSuggtion"
          :disabled="sumBtnDisabled()">新增建议</el-button>
      </div>
    </div>

    <div style="width:50%;">
      <el-table id="tableSuggestion" row-key="id" :data="sumDoctorCheck.suggestionList" width="100%" :height="sumHeight"
        border size="small" ref="tableSuggestion">
        <el-table-column type="index" width="20" align="center">
        </el-table-column>
        <el-table-column prop="suggestionTitle" label="建议">
          <template slot="header">
            <div style="display: flex;justify-content:space-between;">
              <div>建议</div>
              <div></div>
            </div>
          </template>
          <template slot-scope="scope">
            <div>
              <div style="display: flex;">
                <el-input v-model="scope.row.suggestionTitle" placeholder="请输入建议标题" :ref="scope.row.id" :id="scope.row.id"
                  :disabled="sumBtnDisabled()">
                </el-input>
                <el-button type="danger" :icon="scope.row.collapse ? 'el-icon-arrow-down' : 'el-icon-arrow-up'"
                  style="min-width:21px;height:21px;padding:2px;" @click="btnCollapse(scope.$index)"
                  :disabled="sumBtnDisabled()"></el-button>
                <el-button v-show="checkPagePriv(pagePriv.privs, '删除建议')" type="danger" icon="el-icon-delete"
                  style="margin-left: 2px;min-width:21px;height:21px;padding:2px;" @click="delSugHead(scope.$index)"
                  :disabled="sumBtnDisabled()"></el-button>
              </div>
              <div v-show="!scope.row.collapse">
                <div style="display: flex;margin-top: 2px;">
                  <div style="width:60px;">诊断</div>
                  <el-select v-model="scope.row.diagnosisIds" multiple placeholder="请选择" style="width: 100%;"
                    :disabled="sumBtnDisabled()" @change="changeDiagnosis" filterable>
                    <el-option v-for="item in diagnosises" :key="item.id" :value="item.id" :label="item.displayName"
                      :disabled="disabledDiagnosis(item.id, scope.$index)" />
                  </el-select>
                </div>
                <div style="display: flex;margin-top: 2px;">
                  <div style="width:60px;">医学解释</div>
                  <el-tooltip content="新增医学解释" placement="top">
                    <el-button v-show="checkPagePriv(pagePriv.privs, '新增医学解释')" type="success" icon="el-icon-plus"
                      style="min-width:21px;height:21px;padding:2px;" @click="addSug(scope.$index, 0)"
                      :disabled="sumBtnDisabled()">
                    </el-button>
                  </el-tooltip>
                  <el-table :id="'0_sug' + scope.row.id" row-key="displayOrder" style="margin-left: 5px;"
                    :data="scope.row.medicalInterpretations" border @row-click="rowClickSug0" :show-header="false">
                    <el-table-column width="30">
                      <template slot-scope="scope2">
                        <div>{{ scope2.$index + 1 }}).</div>
                      </template>
                    </el-table-column>
                    <el-table-column prop="suggestionContent" label="建议" min-width="200">
                      <template slot-scope="scope2">
                        <el-input type="textarea" v-model="scope2.row.suggestionContent" placeholder="请输入建议内容"
                          :disabled="sumBtnDisabled()" :autosize="{ minRows: 1, maxRows: 10 }">
                        </el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="操作" width="25">
                      <template slot-scope="scope2">
                        <el-button v-show="checkPagePriv(pagePriv.privs, '删除医学解释')" type="danger"
                          style="min-width:21px;height:21px;padding:2px;" icon="el-icon-delete"
                          @click="delSug(scope.row.medicalInterpretations, scope2.$index)" :disabled="sumBtnDisabled()"
                          size="small"></el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
                <div style="display: flex;margin-top: 2px;">
                  <div style="width:60px;">常见原因</div>
                  <el-tooltip content="新增常见原因" placement="top">
                    <el-button v-show="checkPagePriv(pagePriv.privs, '新增常见原因')" type="danger" icon="el-icon-plus"
                      style="min-width:21px;height:21px;padding:2px;" @click="addSug(scope.$index, 1)"
                      :disabled="sumBtnDisabled()">
                    </el-button>
                  </el-tooltip>
                  <el-table :id="'1_sug' + scope.row.id" row-key="displayOrder" style="margin-left: 5px;"
                    :data="scope.row.commonReasons" border @row-click="rowClickSug1" :show-header="false">
                    <el-table-column width="30">
                      <template slot-scope="scope2">
                        <div>{{ scope2.$index + 1 }}).</div>
                      </template>
                    </el-table-column>
                    <el-table-column prop="suggestionContent" label="建议" min-width="200">
                      <template slot-scope="scope2">
                        <el-input type="textarea" v-model="scope2.row.suggestionContent" placeholder="请输入建议内容"
                          :disabled="sumBtnDisabled()" :autosize="{ minRows: 1, maxRows: 10 }">
                        </el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="操作" width="25">
                      <template slot-scope="scope2">
                        <el-button v-show="checkPagePriv(pagePriv.privs, '删除常见原因')" type="danger"
                          style="min-width:21px;height:21px;padding:2px;" icon="el-icon-delete"
                          @click="delSug(scope.row.commonReasons, scope2.$index)" :disabled="sumBtnDisabled()"
                          size="small"></el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
                <div style="display: flex;margin-top: 2px;">
                  <div style="width:60px;">健康指导</div>
                  <el-tooltip content="新增健康指导" placement="top">
                    <el-button v-show="checkPagePriv(pagePriv.privs, '新增健康指导')" type="danger" icon="el-icon-plus"
                      style="min-width:21px;height:21px;padding:2px;" @click="addSug(scope.$index, 2)"
                      :disabled="sumBtnDisabled()">
                    </el-button>
                  </el-tooltip>
                  <el-table :id="'2_sug' + scope.row.id" row-key="displayOrder" style="margin-left: 5px;"
                    :data="scope.row.healthGuidances" border @row-click="rowClickSug2" :show-header="false">
                    <el-table-column width="30">
                      <template slot-scope="scope2">
                        <div>{{ scope2.$index + 1 }}).</div>
                      </template>
                    </el-table-column>
                    <el-table-column prop="suggestionContent" label="建议" min-width="200">
                      <template slot-scope="scope2">
                        <el-input type="textarea" v-model="scope2.row.suggestionContent" placeholder="请输入健康指导"
                          :disabled="sumBtnDisabled()" :autosize="{ minRows: 1, maxRows: 10 }">
                        </el-input>
                      </template>
                    </el-table-column>
                    <el-table-column label="操作" width="25">
                      <template slot-scope="scope2">
                        <el-button v-show="checkPagePriv(pagePriv.privs, '删除健康指导')" type="danger"
                          style="min-width:21px;height:21px;padding:2px;" icon="el-icon-delete"
                          @click="delSug(scope.row.healthGuidances, scope2.$index)" :disabled="sumBtnDisabled()"
                          size="small"></el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import { mapState } from 'vuex';
import Sortable from "sortablejs";
import { getapi, postapi, putapi, deletapi } from "@/api/api";
import { getPagePriv, checkPagePriv, deepCopy, arrayExistObj } from '../../utlis/proFunc';
export default {
  components: {},
  props: ["patientRegisterId", "curGetFocusSuggestionId"],
  data() {
    return {
      pagePriv: {
        routeUrlorPageName: 'sumDoctorCheck', //当前页面归属路由或归属页面权限名称
        privs: [] // 页面权限
      },
      sumDetails: [],
      suggestionCurRow: 0, //当前操作建议的行
      diagnosises: [], // 诊断
      collapse: true,  // 折叠/展开全部建议
    };
  },

  created() {
    //获取用户当前页面的权限
    let userPriv = window.sessionStorage.getItem('userPriv')
    if (userPriv) this.pagePriv.privs = deepCopy(getPagePriv(this.pagePriv.routeUrlorPageName))
  },

  //挂载完成
  mounted() {
    this.rowDrop();
    this.rowDropSuggestion();

    this.dictInit()
    // document.addEventListener('DOMContentLoaded', function () {
    //   const textarea = document.querySelector('textarea');
    //   textarea.addEventListener('input', function () {
    //     // 当文本域内容变化时调整大小
    //     console.log('textarea.addEventListener',textarea.style.height)
    //     textarea.style.height = 'auto'; // 重置高度
    //     // textarea.style.height = textarea.scrollHeight + 'px'; // 根据滚动高度调整高度
    //   });
    // });

    this.summaryList(this.dataTransOpts.tableS.patient_register.id)
    this.suggestionList(this.dataTransOpts.tableS.patient_register.id)
  },

  computed: {
    ...mapState(['window', 'dict', 'dataTransOpts', 'doctorCheck', 'sumDoctorCheck']),

    sumHeight() {
      let tempHeight = this.window.pageHeight < 600 ? 600 : this.window.pageHeight
      return tempHeight - 335
    },
  },

  methods: {
    checkPagePriv,

    // textareaResize() {
    //   const textarea = document.querySelectorAll('textarea');
    //   textarea.forEach(e => {
    //     e.style.height = 'auto'; // 重置高度        
    //   });      
    // },

    // 获取诊断数据
    dictInit() {
      postapi('/api/app/diagnosis/getlistinsuggestion', {}).then(res => {
        if (res.code > -1) {
          this.diagnosises = res.data
        }
      })
    },

    //增加建议
    addSuggtion() {
      let id = String(new Date().getTime())
      let pojo = {
        id,
        patientRegisterId: this.dataTransOpts.tableS.patient_register.id,
        diagnosisIds: [],
        medicalInterpretations: [
          {
            sumSuggestionHeaderId: id, // 拖拽用到
            diagnosisId: '',  // 关联诊断用到
            suggestionContent: '',
          }
        ],
        commonReasons: [
          {
            sumSuggestionHeaderId: id, // 拖拽用到
            diagnosisId: '',
            suggestionContent: '',
          }
        ],
        healthGuidances: [
          {
            sumSuggestionHeaderId: id, // 拖拽用到
            diagnosisId: '',
            suggestionContent: '',
          }
        ],
      }

      this.sumDoctorCheck.suggestionList.push(pojo);
      this.$nextTick(() => {
        this.$refs[id].focus();
      })
    },

    // 单个折叠展开建议
    btnCollapseAll() {
      this.collapse = !this.collapse
      this.sumDoctorCheck.suggestionList.forEach(e => {
        e.collapse = this.collapse
      });
    },

    // 单个折叠展开建议
    btnCollapse(index) {
      this.sumDoctorCheck.suggestionList[index]['collapse'] = !this.sumDoctorCheck.suggestionList[index]['collapse']
      this.$nextTick(() => {
        this.$refs['tableSuggestion'].doLayout()
      })
    },

    // 获取人员是否已总检过
    getHaveSumData(patientRegisterId) {
      this.sumDoctorCheck.summaryList = [];
      this.sumDoctorCheck.suggestionList = [];
      if (!patientRegisterId) return

      if (this.dataTransOpts.tableS.patient_register.completeFlag == '3') {
        this.summaryList(patientRegisterId, 'Y')
        this.suggestionList(patientRegisterId, 'Y')
        return
      }
      postapi('/api/app/patientregister/GetHaveSumData', { patientRegisterId })
        .then(async (res) => {
          if (res.code > -1) {
            let isGetExistData = res.data
            if (res.data == 'Y') {
              try {
                await this.$confirm('检测到该人员已经生成过总检信息。', '确认信息', {
                  distinguishCancelAndClose: true,
                  confirmButtonText: '重新生成总检信息',
                  cancelButtonText: '获取上次总检信息'
                })
                isGetExistData = 'N'
              } catch (error) {
                //console.log()
              }
            }
            this.summaryList(patientRegisterId, isGetExistData)
            this.suggestionList(patientRegisterId, isGetExistData)
          }
        })
    },




    //获取综述
    summaryList(RegisterId, isGetExistData) {
      if (!RegisterId) {
        this.sumDoctorCheck.summaryList = [];
        return
      }

      // 旧接口： console.log(`/api/app/sumsummaryheader/getsumsummarylist?PatientRegisterId=${RegisterId}`)
      let body = {
        patientRegisterId: RegisterId,
        isGetExistData,
      }
      postapi('/api/app/sumsummaryheader/getsumsummarylist', body)
        .then((res) => {
          console.log("summaryList", res.data);
          if (res.code > -1) {
            let summaryList = []
            res.data.forEach((e, i) => {
              let details = []
              e.details.forEach((e2, i2) => {
                details.push({ id: `summaryDetails_${i2}`, summaryContent: ' ' })
              });
              summaryList.push({ id: `summary_${i}`, summaryTitle: ' ', details })
            });
            this.sumDoctorCheck.summaryList = deepCopy(summaryList)
            // 自动高度有问题，需要这样处理一下
            setTimeout(() => {
              this.sumDoctorCheck.summaryList = deepCopy(res.data);
              this.sumDoctorCheck.summaryList.forEach((e, i) => {
                e.id = `summary_${i}`
                e.details.forEach((e2, i2) => {
                  e2.id = `summaryDetails_${i2}`
                });
              });
            }, 10);
            // this.sumDoctorCheck.summaryList = res.data;
            // this.textareaResize()
          }
        })
        .catch((err) => {
          this.$message({ type: "error", message: `操作失败，原因：${err}` });
        });
    },

    //获取建议
    suggestionList(RegisterId, isGetExistData) {
      if (!RegisterId) {
        this.sumDoctorCheck.suggestionList = [];
        return;
      };

      // {
      //   "patientRegisterId": "3a11ee70-02cb-c5e6-a087-79ecdd0356b6",
      //   "isGetExistData": "Y"
      // }
      let body = {
        patientRegisterId: RegisterId,
        isGetExistData,
      }
      // 旧接口： console.log(`/api/app/sumsuggestionheader/getsumsuggestionlist?PatientRegisterId=${RegisterId}`)
      postapi('/api/app/sumsuggestionheader/getsumsuggestionlist', body)
        .then((res) => {
          console.log("suggestionList", res.data);
          if (res.code > -1) {
            this.sumDoctorCheck.suggestionList = res.data;
            // 处理拖动排序使用
            this.sumDoctorCheck.suggestionList.forEach((e, i) => {
              e.id = `suggestion_${i}`
              e.collapse = true
              if (e.medicalInterpretations) {
                e.medicalInterpretations.forEach((e0, i0) => {
                  e0.sumSuggestionHeaderId = `suggestion_${i}`
                  e0.id = `medicalInterpretations_${i0}`
                });
              }
              if (e.commonReasons) {
                e.commonReasons.forEach((e0, i0) => {
                  e0.sumSuggestionHeaderId = `suggestion_${i}`
                  e0.id = `commonReasons_${i0}`
                });
              }
              if (e.healthGuidances) {
                e.healthGuidances.forEach((e0, i0) => {
                  e0.sumSuggestionHeaderId = `suggestion_${i}`
                  e0.id = `healthGuidances_${i0}`
                });
              }
            });
          }
        })
        .catch((err) => {
          this.$message({ type: "error", message: `操作失败，原因：${err}` });
        });
    },

    // 按钮可用
    sumBtnDisabled() {
      let patientRegister = this.dataTransOpts.tableS.patient_register
      let ret = true

      //' 请选择体检人员'
      if (!patientRegister.id) return ret
      // '人员已锁定，不可执行此操作'
      if (!patientRegister.isLock) return ret

      if (patientRegister.completeFlag && patientRegister.completeFlag != '3') ret = false

      return ret
    },

    // 可选诊断处理
    disabledDiagnosis(diagnosisId, index) {
      let ret = false
      let diagnosisIds = []
      this.sumDoctorCheck.suggestionList.forEach((e, i) => {
        if (i != index) {
          if (e.diagnosisIds) diagnosisIds = diagnosisIds.concat(e.diagnosisIds)
        }
      });
      if (diagnosisIds.indexOf(diagnosisId) > -1) ret = true
      return ret
    },

    // 诊断选择
    changeDiagnosis(v) {
      console.log('changeDiagnosis', v)
      let suggestionTitle = []
      if (v.length == 0) {
        this.sumDoctorCheck.suggestionList[this.suggestionCurRow]['suggestionTitle'] = ''
        return
      }
      //先找到是操作的建议行
      let lv = `${v}`
      let suggestionList = deepCopy(this.sumDoctorCheck.suggestionList)
      suggestionList.forEach(e => {
        e.diagnosisIds = `${e.diagnosisIds}`
      });
      let lfind = arrayExistObj(suggestionList, 'diagnosisIds', lv)
      if (lfind == -1) return
      this.suggestionCurRow = lfind
      let sumSuggestionHeaderId = this.sumDoctorCheck.suggestionList[lfind].id
      v.forEach(e => {
        let ld = arrayExistObj(this.diagnosises, 'id', e)
        if (ld > -1) {
          suggestionTitle.push(this.diagnosises[ld]["displayName"])
          //添加医学解释
          let medicalInterpretations = this.diagnosises[ld]['medicalInterpretations']
          if (medicalInterpretations) {
            if (!this.sumDoctorCheck.suggestionList[lfind]['medicalInterpretations']) this.sumDoctorCheck.suggestionList[lfind]['medicalInterpretations'] = []
            medicalInterpretations.forEach(e2 => {
              let lf = arrayExistObj(this.sumDoctorCheck.suggestionList[lfind]['medicalInterpretations'], "suggestionContent", e2.suggestionContent)
              if (lf == -1) {
                this.sumDoctorCheck.suggestionList[lfind]['medicalInterpretations'].push({
                  sumSuggestionHeaderId,
                  suggestionContent: e2.suggestionContent,
                  displayOrder: Math.random(),
                })
              }
            });
          }

          //添加常见原因
          let commonReasons = this.diagnosises[ld]['commonReasons']
          if (commonReasons) {
            if (!this.sumDoctorCheck.suggestionList[lfind]['commonReasons']) this.sumDoctorCheck.suggestionList[lfind]['commonReasons'] = []
            commonReasons.forEach(e2 => {
              let lf = arrayExistObj(this.sumDoctorCheck.suggestionList[lfind]['commonReasons'], "suggestionContent", e2.suggestionContent)
              if (lf == -1) {
                this.sumDoctorCheck.suggestionList[lfind]['commonReasons'].push({
                  sumSuggestionHeaderId,
                  suggestionContent: e2.suggestionContent,
                  displayOrder: Math.random(),
                })
              }
            });
          }

          //添加常见原因
          let healthGuidances = this.diagnosises[ld]['healthGuidances']
          if (healthGuidances) {
            if (!this.sumDoctorCheck.suggestionList[lfind]['healthGuidances']) this.sumDoctorCheck.suggestionList[lfind]['healthGuidances'] = []
            healthGuidances.forEach(e2 => {
              let lf = arrayExistObj(this.sumDoctorCheck.suggestionList[lfind]['healthGuidances'], "suggestionContent", e2.suggestionContent)
              if (lf == -1) {
                this.sumDoctorCheck.suggestionList[lfind]['healthGuidances'].push({
                  sumSuggestionHeaderId,
                  suggestionContent: e2.suggestionContent,
                  displayOrder: Math.random(),
                })
              }
            });
          }
        }
      });
      this.sumDoctorCheck.suggestionList[this.suggestionCurRow]['suggestionTitle'] = `${suggestionTitle}`
    },

    //增加建议明细
    addSug(index, contentType) {
      this.suggestionCurRow = index

      let lcontentType = 'healthGuidances'
      switch (contentType) {
        case 0:
          lcontentType = 'medicalInterpretations'
          break;
        case 1:
          lcontentType = 'commonReasons'
          break;
        default:
          break;
      }
      if (!this.sumDoctorCheck.suggestionList[index][lcontentType]) this.sumDoctorCheck.suggestionList[index][lcontentType] = []
      this.sumDoctorCheck.suggestionList[index][lcontentType].push({
        sumSuggestionHeaderId: this.sumDoctorCheck.suggestionList[index].id,  // 拖拽用到
        suggestionContent: '',
        displayOrder: Math.random(),
      })
      console.log('this.sumDoctorCheck.suggestionList', index, this.sumDoctorCheck.suggestionList)
    },

    //删除建议头及明细
    delSugHead(index) {
      this.$confirm("此操作将删除该记录, 是否继续?", "提示", {
        confirmButtonText: "是",
        cancelButtonText: "否",
        type: "warning",
      }).then(() => {
        //删除建议
        this.sumDoctorCheck.suggestionList.splice(index, 1)
      }).catch((err) => {
        if (err == 'cancel') {
          console.log(`已取消 ${err}`)
        } else {
          this.$message.error(`操作失败 ${err}`)
        }
      });
    },

    //删除建议明细
    delSug(details, indexD) {
      this.$confirm("此操作将删除该记录, 是否继续?", "提示", {
        confirmButtonText: "是",
        cancelButtonText: "否",
        type: "warning",
      }).then(() => {
        //删除建议明细
        details.splice(indexD, 1);
      }).catch((err) => {
        if (err == 'cancel') {
          console.log(`已取消 ${err}`)
        } else {
          this.$message.error(`操作失败 ${err}`)
        }
      });

    },
    //选择组合项目
    rowClick(row) {
      console.log('rowClick row', row)
      let lfind = arrayExistObj(this.sumDoctorCheck.summaryList, 'id', row.sumSummaryHeaderId)
      if (lfind > -1) {
        this.sumDetails = this.sumDoctorCheck.summaryList[lfind].details
        this.rowDropSumDetail(row.sumSummaryHeaderId)
      }
      console.log('this.sumDetails', this.sumDetails)
    },

    //综述明细拖拽
    rowDropSumDetail(id) {
      this.$nextTick(() => {
        const fEl = document.getElementById(id)  // document.querySelector(`#${id} tbody`) querySelector为静态方法不支持动态传参;
        console.log('rowDropSumDetail tbody', fEl, fEl.children) //el.childNodes,el.children
        const el = this.findEl(fEl, 'TBODY')
        console.log('rowDropSumDetail tbody', el) //el.childNodes,el.children
        const that = this;
        Sortable.create(el, {
          animation: 150, // ms, number 单位：ms，定义排序动画的时间
          //拖拽结束
          onEnd({ newIndex, oldIndex }) {
            that.isshow = false;
            const currRow = that.sumDetails.splice(oldIndex, 1)[0];
            that.sumDetails.splice(newIndex, 0, currRow);
          },
        });
      });
    },

    findEl(fEl, nodeName) {
      let el = null
      for (let i = 0; i < fEl.children.length; i++) {
        console.log(fEl.children[i].nodeName)
        if (fEl.children[i].nodeName == nodeName) {
          el = fEl.children[i]
          break
        } else {
          el = this.findEl(fEl.children[i], nodeName)
        }
        if (el) break
      }
      return el
    },

    rowClickSug0(row) {
      this.rowClickSug(row, 0)
    },
    rowClickSug1(row) {
      this.rowClickSug(row, 1)
    },
    rowClickSug2(row) {
      this.rowClickSug(row, 2)
    },

    rowClickSug(row, contentType) {
      console.log('rowClick row', row, contentType)
      let lcontentType = 'healthGuidances'
      switch (contentType) {
        case 0:
          lcontentType = 'medicalInterpretations'
          break;
        case 1:
          lcontentType = 'commonReasons'
          break;
        default:
          break;
      }
      let lfind = arrayExistObj(this.sumDoctorCheck.suggestionList, 'id', row.sumSuggestionHeaderId)
      if (lfind > -1) {
        this.sugDetails = this.sumDoctorCheck.suggestionList[lfind][lcontentType]
        this.rowDropSugDetail(contentType, row.sumSuggestionHeaderId)
      }
      console.log('this.sumDetails', lfind, this.sugDetails)
    },

    //建议明细拖拽
    rowDropSugDetail(contentType, id) {
      this.$nextTick(() => {
        const fEl = document.getElementById(`${contentType}_sug${id}`)  // document.querySelector(`#${id} tbody`) querySelector为静态方法不支持动态传参;
        console.log('rowDropSumDetail tbody', fEl, fEl.children) //el.childNodes,el.children
        const el = this.findEl(fEl, 'TBODY')
        console.log('rowDropSumDetail tbody', el) //el.childNodes,el.children
        const that = this;
        if (this.detailsDrag) this.detailsDrag.destroy()
        this.detailsDrag = Sortable.create(el, {
          animation: 150, // ms, number 单位：ms，定义排序动画的时间
          //拖拽结束
          onEnd({ newIndex, oldIndex }) {
            that.isshow = false;
            const currRow = that.sugDetails.splice(oldIndex, 1)[0];
            that.sugDetails.splice(newIndex, 0, currRow);
          },
        });
      });
    },

    //拖拽
    rowDrop() {
      this.$nextTick(() => {
        const el = document.querySelector("#tableSummary tbody");
        console.log('tbody', el)
        const that = this;
        Sortable.create(el, {
          animation: 150, // ms, number 单位：ms，定义排序动画的时间
          //拖拽结束
          onEnd({ newIndex, oldIndex }) {
            that.isshow = false;
            const currRow = that.sumDoctorCheck.summaryList.splice(oldIndex, 1)[0];
            that.sumDoctorCheck.summaryList.splice(newIndex, 0, currRow);
          },
        });
      });
    },

    //拖拽
    rowDropSuggestion() {
      this.$nextTick(() => {
        const el = document.querySelector("#tableSuggestion tbody");
        console.log('tbody', el)
        const that = this;
        Sortable.create(el, {
          animation: 150, // ms, number 单位：ms，定义排序动画的时间
          //拖拽结束
          onEnd({ newIndex, oldIndex }) {
            that.isshow = false;
            const currRow = that.sumDoctorCheck.suggestionList.splice(oldIndex, 1)[0];
            that.sumDoctorCheck.suggestionList.splice(newIndex, 0, currRow);
          },
        });
      });
    },

  },

  //监听事件
  watch: {
    // 虚拟表 触发强制刷新 （sumDoctor.M 合并包含：综述、建议、对比、历史等，不包含总检诊断）
    "dataTransOpts.refresh.sumDoctor.M": {
      // immediate:true,
      handler(newVal, oldVal) {
        console.log(`watch 总检--综述建议 newVal: ${newVal}, oldVal: ${oldVal} patientRegisterId: ${this.dataTransOpts.tableS.patient_register.id}`);
        this.getHaveSumData(this.dataTransOpts.tableS.patient_register.id)
      }
    },
  },
};
</script>
<style scoped>
@import '../../assets/css/global_table.css';

/* 设置单元格内内容顶对齐 */
::v-deep .el-table__cell {
  display: table-cell;
  /* 使单元格表现为表格单元 */
  vertical-align: top;
  /* 顶对齐 el-table_2_column_2   el-table__cell */
}

::v-deep .el-textarea__inner {
  min-height: 23px;
  height: 23px;
  line-height: 1.25;
  padding: 1px 15px 1px 2px;
}

::v-deep .el-input__inner {
  min-height: 23px;
  height: 23px;
  padding: 1px 15px 1px 2px;
}
</style>
  