<template>
  <div class="importDisWrapper clearfix">
    <crumbs title="关联维护设置" class="topBack" style="min-width: 980px"></crumbs>
    <div class="importDisBox">
      <el-form ref="form" :model="form" label-width="120px">
        <el-form-item label="术语关联：">
          <el-switch
            v-if="showInfo"
            v-model="form.value"
            active-color="#4BC4D7"
            inactive-color="#BBBBBB"
            @change="handleChange($event,form.value)"
            :disabled="disabled"
          ></el-switch>
          <span class="showInfo">{{showInfo}}</span>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import api from '@api/icss.js';
import config from '@api/config.js';
import utils from '@api/utils.js';
export default {
  data() {
    return {
      form: {
        value: true
      },
      hospitalId: '',
      disabled: false,
      showInfo: ''
    };
  },
  created() {
    this.getHospital();
  },
  methods: {
    // 关联
    handleChange($event, isCorre) {
      this.showInfo = $event ? '开' : '关';
      this.disabled = true;
      let params = {
        id: this.hospitalId,
        connect: $event ? 1 : 0 //0-不对接，1-对接
      };
      api
        .saveHospitalInfoRecord(params)
        .then(res => {
          if (res.data.code === '0') {
            this.$message({
              showClose: true,
              message: '操作成功!',
              type: 'success'
            });
            setTimeout(() => {
              this.disabled = false;
            }, 1500);
          }
        })
        .catch(err => {
          if (err.code === '900010001') {
            return false;
          }
          this.$message({
            showClose: true,
            message: '操作失败!',
            type: 'error'
          });
          this.disabled = false;
        });
    },

    // 获取医院信息
    getHospital() {
      api.getHospitalInfo().then(res => {
        this.hospitalId = res.data.data.id;
        this.showInfo = res.data.data.connect === 1 ? '开' : '关';
        this.form.value = res.data.data.connect === 1 ? true : false;
      });
    }
  }
};
</script>

<style  lang="less" scoped>
.importDisWrapper {
  min-width: 940px;
  color: #606266;
  .topBack {
    top: 0;
  }
  .importDisBox {
    padding: 80px 60px 120px 60px;
    margin: 70px 20px 0 20px;
    background: #fff;
  }
  .showInfo {
    margin-left: 10px;
  }
}
</style>