<template>
  <div class="main-contain">
    <div class="position">
      <bread-crumb :crumbs="crumbs"></bread-crumb>
    </div>
    <div class="app-container">
        <!--<div class="configBox">-->
            <!--<p>收费发药</p>-->
            <!--<p style="font-size:14px;margin-top:5px;">开启收费发药分离后，处方发药的工作需要到收费发药页面完成</p>-->
            <!--<p style="margin-top:20px;">收费，发药分离：-->
                <!--<el-switch v-model="value"></el-switch>-->
            <!--</p>-->
        <!--</div>-->
        <div class="configBox">
            <p style="font-size:18px;font-weight:bold">门诊打印</p>
            <p style="font-size:14px;margin-top:5px;color:#333;">开启直接打印后，门诊病历、处方、治疗单、处置单、收费清单等打印时跳过打印预览，直接连接打印机打印。</p>
            <p style="margin-top:20px;">直接打印：
                <el-switch v-model="is_open_print" @change="changeFuncPrint"></el-switch>
            </p>
        </div>
        <div class="configBox">
          <p style="font-size:18px;font-weight:bold">医嘱同步</p>
          <p style="font-size:14px;margin-top:5px;color:#333;">开启门诊处方同步到透析医嘱后，同一个患者，门诊医生站开的药品类处方自动同步到透析管理临时医嘱中，同时在透析管理中，给患者开长期医嘱和临时医嘱的功能失效，医生只能在门诊医生站开处方，只有同时使用门诊管理和透析管理的机构方可开启。</p>
          <p style="margin-top:20px;">门诊处方同步到透析医嘱：
          <el-switch v-model="is_open_xt_his" @change="changeFuncOne"></el-switch>
          <p style="margin-top:20px;">门诊处方和临时医嘱同步到透析医嘱：
          <el-switch v-model="is_open_advice_xt_his" @change="changeFuncSix"></el-switch>
          <p style="margin-top:20px;" v-if="is_open_advice_xt_his==true">是否出库：
          <el-switch v-model="is_open_prescription_xt_his" @change="changeFuncSeven"></el-switch>
          </p>
        </div>

        <div class="configBox">
            <p style="font-size:18px;font-weight:bold">处方项目同步到临时医嘱</p>
            <p style="font-size:14px;margin-top:5px;color:#333;">开启门诊处方的项目同步后，护士则在血透的临时医嘱中可以看到相关的耗材/检验检查数据</p>
            <p style="margin-top:20px;">门诊处方项目同步到透析医嘱：
                <el-switch v-model="is_open_xt_his_project" @change="changeFuncProject"></el-switch>
            </p>
            <p style="margin-top:20px;">耗材先出库再执行：
                <el-switch v-model="is_open_is_type" @change="changeFuncType"></el-switch>
            </p>
            <p style="margin-top:20px;">药品在保存处方时出库：
                <el-switch v-model="drug_out_open" @change="changeDrugOpen"></el-switch>
            </p>
        </div>


        <!-- <div class="configBox">
          <p style="font-size:18px;font-weight:bold">血压数据自动获取</p>
          <p style="font-size:14px;margin-top:5px;color:#333;">在联机的状态下,开启透析监测-血压数据自动获取功能后,则不需要手动输入,数据会自动上传到监测中</p>
          <p style="margin-top:20px;">透析监测-血压数据自动获取：
          <el-switch v-model="is_open_monitor" @change="changeFuncTwo"></el-switch>
          </p>
        </div>

        <div class="configBox">
          <p style="font-size:18px;font-weight:bold">透析机数据自动获取</p>
          <p style="font-size:14px;margin-top:5px;color:#333;">在联机的状态下,开启透析监测-透析机数据自动获取功能后,则不需要手动输入,数据会自动上传到监测中</p>
          <p style="margin-top:20px;">透析监测-血压数据自动获取：
          <el-switch v-model="is_open_order" @change="changeFuncThree"></el-switch>
          </p>
        </div> -->
        <!--<div class="configBox">-->
            <!--<p>药品，耗材出库</p>-->
            <!--<p style="font-size:14px;margin-top:5px;">开启药品，耗材出库自动扣减则医生开完医嘱或处方可直接出库，不开启则由发药动作或出库按钮手动出库</p>-->
            <!--<div style="display:flex;margin-top:20px;">-->
                <!--<p style="margin-right:20px;">药品出库：-->
                    <!--<el-switch v-model="value" @change="changeFuncTwo"></el-switch>-->
                <!--</p>-->
                <!--<p>耗材出库：-->
                    <!--<el-switch v-model="value"></el-switch>-->
                <!--</p>-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="configBox">-->
            <!--<p style="margin-bottom:20px;">药品有效期预警设置(药品即将失效的预警提示)</p>-->
            <!--<el-select v-model="value" placeholder="请选择">-->
                <!--<el-option-->
                <!--v-for="item in options"-->
                <!--:key="item.value"-->
                <!--:label="item.label"-->
                <!--:value="item.value">-->
                <!--</el-option>-->
            <!--</el-select>-->
        <!--</div>-->
        <!--<div class="configBox">-->
            <!--<p>处方单价锁定</p>-->
            <!--<p style="font-size:14px;margin-top:5px;">开启处方单价锁定后，开处方是无法修改药品或者诊疗项目以及附加费用单价</p>-->
            <!--<p style="margin-top:20px;">收费单价锁定：-->
                <!--<el-switch v-model="value"></el-switch>-->
            <!--</p>-->
        <!--</div>-->

    </div>
  </div>
</template>

<script>
import BreadCrumb from "@/xt_pages/components/bread-crumb";
import { getAllIsOpenInit,postXtHisIsOpen,postMonitorIsOpen,changeFuncPrint,getDataPrintList,postXtHisProjectIsOpen,changeStockSetting,changeAdviceConfig,changePrescriptionConfig,changeDrugOpenConfig} from '@/api/config'

export default {
  name: "printTemplate",
  components: { BreadCrumb},
  data() {
    return {
      showViewer:false,
      crumbs: [
        { path: false, name: "管理中心" },
        { path: false, name: "基础配置" }
      ],
      value:false,
      is_open_xt_his:false,
      is_open_monitor:false,
      is_open_order:false,
      is_open_print:false,
      is_open_xt_his_project: false,
      is_open_is_type:false,
      is_open_advice_xt_his:false,
      is_open_prescription_xt_his:false,
      drug_out_open:false,
    };
  },
  methods: {
    getInitIsOpenConfig(){
      getAllIsOpenInit().then(
        response => {
          if (response.data.state === 1) {
            if(response.data.data.is_open_xt_his == 1) {
              this.is_open_xt_his = true

            }else{
              this.is_open_xt_his = false
            }

            if(response.data.data.is_open_xt_his_project == 1) {
              this.is_open_xt_his_project = true

            }else{
              this.is_open_xt_his_project = false
            }

            if(response.data.data.is_open_stock == 1){
              this.is_open_is_type = true
            }else{
              this.is_open_is_type = false
            }

            if(response.data.data.is_open_advice == 1){
              this.is_open_advice_xt_his = true
            }else{
              this.is_open_advice_xt_his = false
            }

            if(response.data.data.is_prescription_advice == 1){
               this.is_open_prescription_xt_his = true
            }else{
              this.is_open_prescription_xt_his = false
            }

            if(response.data.data.is_open == 1){
              this.drug_out_open = true
            }else{
              this.drug_out_open = false
            }

          } else {
            this.$message.error(response.data.msg)
          }
        }
      )

    },
    changeFuncOne(val){
      if(this.is_open_xt_his){
        let params={
          is_open:this.is_open_xt_his
        }
        postXtHisIsOpen(params).then(
          response => {
            if (response.data.state === 1) {
              this.is_open_xt_his = response.data.data.is_open

            } else {
              this.$message.error(response.data.msg)
            }
          }
        )
      }else{
        let params={
          is_open:this.is_open_xt_his
        }
        postXtHisIsOpen(params).then(
          response => {
            if (response.data.state === 1) {
              this.is_open_xt_his = response.data.data.is_open

            } else {
              this.$message.error(response.data.msg)
            }
          }
        )
      }
    },
    changeFuncProject(val){
      if(this.is_open_xt_his_project){
        let params={
          is_open:this.is_open_xt_his_project
        }
        postXtHisProjectIsOpen(params).then(
          response => {
            if (response.data.state === 1) {
              this.is_open_xt_his_project = response.data.data.is_open

            } else {
              this.$message.error(response.data.msg)
            }
          }
        )
      }else{
        let params={
          is_open:this.is_open_xt_his_project
        }
        postXtHisProjectIsOpen(params).then(
          response => {
            if (response.data.state === 1) {
              this.is_open_xt_his_project = response.data.data.is_open

            } else {
              this.$message.error(response.data.msg)
            }
          }
        )
      }
    },
    changeFuncTwo(){
      var is_open = 0
      if(this.is_open_monitor == true){
          is_open = 1
       }
       if(this.is_open_monitor == false){
         is_open = 2
       }
      let params = {
         is_open:is_open,
       }
      postMonitorIsOpen(params).then(response=>{
         if(response.data.state == 1){
            var config = response.data.data.config
            this.$message.success("成功")
            this.getMonitorConfig()
         }
      })
    },
    getMonitorConfig(){
      getMonitorConfig().then(response=>{
         if(response.data.state == 1){
           var config =  response.data.data.config
           if (config.is_open == 1) {
              this.is_open_monitor = true
           }
           if (config.is_open == 2) {
              this.is_open_monitor = false
           }
         }
      })
    },

    changeFuncThree(){
      var is_open = 0
      if(this.is_open_order == true){
          is_open = 1
       }
       if(this.is_open_order == false){
         is_open = 2
       }
      let params = {
         is_open:is_open,
       }
      addOrderConfig(params).then(response=>{
         if(response.data.state == 1){
           var config = response.data.data.config
           this.$message.success("成功")
           this.getOrderConfig()
         }
      })
    },
    getOrderConfig(){
      getOrderConfig().then(response=>{
        if(response.data.state == 1){
           var config =  response.data.data.config
          if (config.is_open == 1) {
              this.is_open_order = true
           }
           if (config.is_open == 2) {
              this.is_open_order = false
           }
        }
      })
    },

    changeFuncPrint(val){
      var is_open  = 0
      if(val == true){
         is_open = 1
      }
      if(val == false){
        is_open = 0
      }
      var params = {
        is_open:is_open,
      }

      changeFuncPrint(params).then(response=>{
         if(response.data.state == 1){
           var dataPrint =  response.data.data.dataPrint
           this.$message.success("保存成功")
           this.getDataPrintList()
         }
      })
    },

    getDataPrintList(){
      getDataPrintList().then(response=>{
         if(response.data.state ==1){
           var dataPrint = response.data.data.dataPrint
           if(dataPrint.is_open == 1){
              this.is_open_print = true
           }
           if(dataPrint.is_open == 0){
              this.is_open_print = false
           }
         }
      })
    },
    changeFuncType(){
       var is_type = 2
       if(this.is_open_is_type == false){
         is_type = 2
       }
       if(this.is_open_is_type == true){
         is_type = 1
       }
       var params = {
         is_type:is_type,
       }
      changeStockSetting(params).then(response=>{
        if(response.data.state == 1){
           this.$message.success("保存成功!")
        }
      })
    },
    changeFuncSix(){
      var is_advice_open = 2
      if(this.is_open_advice_xt_his == false){
        is_advice_open = 2
      }
      if(this.is_open_advice_xt_his == true){
        is_advice_open = 1
      }
      var params = {
        is_advice_open:is_advice_open,
      }
      changeAdviceConfig(params).then(response=>{
         if(response.data.state == 1){
          var msg =  response.data.data.msg
          this.$message.success("保存成功!")
         }
      })
    },
    changeFuncSeven(){
      var is_open_prescription_xt_his = 0
      if(this.is_open_prescription_xt_his == false){
        is_open_prescription_xt_his = 2
      }
      if(this.is_open_prescription_xt_his == true){
        is_open_prescription_xt_his = 1
      }
      var params = {
        is_open_prescription_xt_his:is_open_prescription_xt_his,
      }
      console.log("param22332323232",params)
      changePrescriptionConfig(params).then(response=>{
          if(response.data.state == 1){
            var msg =  response.data.data.msg
            this.$message.success("保存成功!")
          }
      })
    },
    changeDrugOpen(){
      var drug_out_open = 0
      if(this.drug_out_open == false){
        drug_out_open = 2
      }
      if(this.drug_out_open == true){
        drug_out_open = 1
      }
      var params = {
        drug_out_open:drug_out_open,
      }
      changeDrugOpenConfig(params).then(response=>{
        if(response.data.state == 1){
           var msg =  response.data.data.msg
           this.$message.success("保存成功!")
        }
      })

    }

  },
  created() {
    this.getInitIsOpenConfig()
    // this.getMonitorConfig()
    // this.getOrderConfig()
    this.getDataPrintList()
  }
};
</script>

<style lang="scss" scoped>
.configBox{
    padding-bottom:20px;
    margin-top:10px;
    border-bottom: 1px solid #000;
}
</style>


