<template>
  <div>
    <div class="contenttitle">
      浏览器 /<span class="contenttitleBold">本地设置</span>
    </div>
    <el-tabs tab-position="left" :style="`margin-top: 5px;height: ${window.pageHeight - 150}px;`">
      <el-tab-pane label="常规设置">
        <el-form label-width="140px" size="size">
          <el-row>
            <el-col :span="12">
              <el-form-item label="显示调试工具">
                <el-checkbox v-model="LocalConfig.normal.isDevTool" size="small" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="分页时单页记录数">
                <el-input type="number" v-model="LocalConfig.normal.maxResultCount" size="small" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="人员登记">
        <el-form label-width="140px" size="size">
          <el-row>
            <el-col :span="12">
              <el-form-item label="人员登记组件">
                <el-select v-model="LocalConfig.patientRegister.edit" placeholder="请选择" size="small" filterable>
                  <el-option label="标准版" value="standard" />
                  <el-option label="青藏铁路版" value="qztl" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="与标准版高度差">
                <el-input type="number" v-model="LocalConfig.patientRegister.editHeight" size="small" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="保存即发送收费申请">
                <el-checkbox v-model="LocalConfig.patientRegister.immediateToHisCharge" size="small" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="保存打指引单与条码">
                <el-checkbox-group v-model="printGuideLabel">
                  <el-checkbox label="guide">指引单</el-checkbox>
                  <el-checkbox label="patient">人员条码</el-checkbox>
                  <el-checkbox label="pacs">检查条码</el-checkbox>
                  <el-checkbox label="lis">检验条码</el-checkbox>
                </el-checkbox-group>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="启用人名查重">
                <el-checkbox v-model="LocalConfig.patientRegister.findPatientByName" size="small" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="单位树显示编码">
                <el-checkbox v-model="LocalConfig.patientRegister.dispCustomerOrgCode" true-label="Y" false-label="N"
                  size="small" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="检验条码">
        <el-form label-width="100px" size="medium">
          <el-row>
            <el-col :span="24">
              <el-form-item label="预览上移">
                <el-input type="number" v-model="LocalConfig.lisLabel.MarginTop" size="small" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="医生诊台">
        <el-form label-width="100px" size="medium">
          <el-row>            
            <el-col :span="6">
              <el-form-item label="全选录入框">
                <el-checkbox v-model="LocalConfig.doctorCheck.isSelectAll" size="small" true-label="Y"
                  false-label="N" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-tooltip content="医生诊台保存结果后，自动跳至下一个项目" placement="top">
                <el-form-item label="自动下个项目">
                  <el-checkbox v-model="LocalConfig.doctorCheck.isAutoNext" size="small" true-label="Y"
                    false-label="N" />
                </el-form-item>
              </el-tooltip>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="是否显示图片">
                <el-checkbox v-model="LocalConfig.doctorCheck.isCheckPicture" size="small" />
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="pacs看图分类">
                <el-select v-model="LocalConfig.doctorCheck.pacsType" placeholder="pacs图片分类" clearable filterable
                  size="small">
                  <el-option v-for="item in localDict.pacsTypes" :key="item.value" :label="item.label"
                    :value="item.value" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="pacs看图描述">                
                <el-input type="number" v-model="LocalConfig.doctorCheck.pacsDescLines" size="small" >
                  <template slot="append">控件行数</template>
                </el-input>                  
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="pacs看图描述">                
                <el-input type="number" v-model="LocalConfig.doctorCheck.pacsDescLineH" size="small" >
                  <template slot="append">控件行高</template>
                </el-input>                
              </el-form-item>
            </el-col> 
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-tooltip content="医生诊台和pacs看图字体大小设置" placement="top">
                <el-form-item label="pacs看图字体">                
                  <el-input type="number" v-model="LocalConfig.doctorCheck.pacsDescFontSize" size="small" >
                    <template slot="append">px 字体大小</template>
                  </el-input>                
                </el-form-item>
              </el-tooltip>
            </el-col>
            <el-col :span="6">
              <el-form-item label="有无扩展屏">
                <el-checkbox v-model="LocalConfig.doctorCheck.isHaveExternal" size="small" true-label="Y"
                  false-label="N" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="启用分诊排队">
                <el-checkbox v-model="LocalConfig.doctorCheck.isQueue" size="small" true-label="Y" false-label="N" />
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="默认分诊房间">
                <el-select v-model="LocalConfig.doctorCheck.queueRoom" placeholder="分诊房间" clearable filterable
                  size="small">
                  <el-option v-for="item in dict.room" :key="item.id" :label="item.displayName" :value="item.id" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="7">
              <el-form-item label="项目类别">
                <el-cascader :options="dict.itemTypeTree" v-model="LocalConfig.doctorCheck.queueItemTypeIds"
                  popper-class="example" style="width:240px;" :props="{
                    checkStrictly: true, expandTrigger: 'hover', label: 'displayName', value: 'id',
                    id: 'id', children: 'treeChildren', multiple: true
                  }" clearable filterable size="small" collapse-tags>
                </el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="排队叫号播音">
                <el-checkbox v-model="LocalConfig.doctorCheck.isBroadcast" size="small" true-label="Y"
                  false-label="N" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="发送worklist">
                <el-checkbox v-model="LocalConfig.doctorCheck.isPacsWorklist" size="small" true-label="Y"
                  false-label="N" />
              </el-form-item>
            </el-col>
            <el-col :span="6" v-if="LocalConfig.doctorCheck.isPacsWorklist == 'Y'">
              <el-form-item label="scheduledAet">
                <el-input v-model="LocalConfig.doctorCheck.scheduledAet" size="small" />
              </el-form-item>
            </el-col>
            <el-col :span="6" v-if="LocalConfig.doctorCheck.isPacsWorklist == 'Y'">
              <el-form-item label="设备ID">
                <el-select v-model="LocalConfig.doctorCheck.deviceId" placeholder="设备" clearable filterable
                  size="small">
                  <el-option v-for="item in localDict.deviceList" :key="item.id" :label="item.displayName"
                    :value="item.id" />
                </el-select>
              </el-form-item>
            </el-col>  
          </el-row>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="采血室">
        <el-form label-width="100px" size="medium">
          <el-row>
            <el-col :span="6">
              <el-form-item label="默认标本类型">
                <el-select v-model="LocalConfig.lisLab.specimens" placeholder="请选择" clearable filterable
                  size="small" multiple collapse-tags>
                  <el-option v-for="item in dict.specimens" :key="item.id" :label="item.displayName"
                    :value="item.id" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </el-tabs>

    <div style="margin: 10px; display: flex;justify-content: space-between;">
      <div></div>
      <el-button type="primary" @click="btnOk" class="commonbutton" size="small">确定</el-button>
    </div>
  </div>
</template>
<script>

import { deepCopy, objCopy, tcdate } from "../../utlis/proFunc";
import { mapState } from "vuex";
import { getapi, postapi, putapi, deletapi } from "@/api/api";


export default {
  data() {
    return {
      printGuideLabel: ["guide", "pacs", "lis"],
      LocalConfig: {
        normal: {
          isDevTool: false, // 壳端是否显示打开调试工具按钮
          maxResultCount: 100, //分页时单页记录数
          PatientRegisterEdit: 'standard', //standard/qztl 人员登记组件版本
          PatientRegisterEditHeight: 0,  // 相较与标准版，选组合项目组件，减少高度
        },
        patientRegister: {
          edit: 'standard', //standard/qztl 人员登记组件版本
          editHeight: 0,  // 相较与标准版，选组合项目组件，减少高度
          immediateToHisCharge: false,  // 人员登记保存后，立即发送收费申请
          findPatientByName: true, // 人员登记，启有人名查询
          printGuideLabel: ["guide", "pacs", "lis"], // 保存后打印指引单与条码
          dispCustomerOrgCode: 'N', // 人员登记列表--单位树是否显示 customerOrgCode
        },
        lisLabel: { // 检验条码打印
          MarginTop: 56, //
        },
        doctorCheck: { // 医生诊台
          isCheckPicture: false, // 是否显示检查图片
          isSelectAll: 'N', // 录入结果时，是否全选
          isAutoNext: 'N',
          pacsType: 'image',

          isQueue: 'N',  //启用分诊排队
          queueRoom: '',  //默认分诊房间
          queueItemTypeIds: [], // 检查类别
          isBroadcast: 'N', // 是否广播            

          isPacsWorklist: 'N', // 是否启用 DCM-worklist 申请
          scheduledAet: '',  //scheduledAet    
          deviceId:"",  // 设备ID 
          pacsDescLines:'5', //行数
          pacsDescLineH:'18', //行高
          pacsDescFontSize: 14, //描述控件的字体大小
          isHaveExternal:'N', //是否有扩展屏 （一般pacs看图可能会有副屏）

        },
        lisLab: {
          specimens: [], // 默认标本类型ID
        }
      },
      LocalConfigInit: {},
      localDict: {
        room: [], // 分诊排队房间  
        pacsTypes: [{ label: 'dcm', value: 'dcm' }, { label: '图片', value: 'image' }],
        deviceList:[], // pacs设备列表
      }
    };
  },


  computed: {
    ...mapState(["window", "dict", "dialogWin"]),
  },
  //创建组件后
  created() {
    this.LocalConfigInit = deepCopy(this.LocalConfig)
    let LocalConfig = window.localStorage.getItem("LocalConfig") || null
    try {
      console.log('JSON.parse(LocalConfig)', JSON.parse(LocalConfig))
      this.LocalConfig = Object.assign({}, this.LocalConfigInit, JSON.parse(LocalConfig) || {})
      if (this.LocalConfig && this.LocalConfig.patientRegister && this.LocalConfig.patientRegister.printGuideLabel) {
        this.printGuideLabel = deepCopy(this.LocalConfig.patientRegister.printGuideLabel)
      }      
    } catch (error) {
      console.log('window.localStorage.getItem("LocalConfig")', error)
    }
  },

  //挂载组件完成
  mounted() {
    this.dictInit()
  },

  methods: {
    btnOk() {
      this.LocalConfig.patientRegister.printGuideLabel = deepCopy(this.printGuideLabel)
      window.localStorage.setItem("LocalConfig", JSON.stringify(this.LocalConfig))
    },

    // 获取字典数据
    dictInit() {
      // 获取分诊叫号房间（启用）
      postapi('/api/app/Room/GetList')
        .then((res) => {
          if (res.code > -1) {
            this.dict.room = res.data
          }
        })

      // 项目类别 树结构
      getapi("/api/app/item-type/by-code-all").then((res) => {
        if (res.code != -1) {
          this.dict.itemTypeTree = res.data;
          tcdate(this.dict.itemTypeTree);
        }
      });

      // 标本类型
      getapi("/api/app/sample-type/in-filter").then((res) => {
        if (res.code != -1) {
          this.dict.specimens = res.data;
        }
      });

      // 设备列表
      /*
      postapi("/api/app/PacsBusiness/GetDeviceListByCheckTypeFlag",{checkTypeFlag:'1'}).then((res) => {
        if (res.code != -1) {
          this.localDict.deviceList = res.data;
        }
      });
      */

    },
  },
  watch: {

  },
};
</script>
<style lang="scss" scoped>
@import "../../assets/css/global_dialog.css";
@import "../../assets/css/global_input.css";
@import "../../assets/css/global.css";
@import "../../assets/css/global_form.css";
</style>