<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-model="form.value"
            active-color="#4BC4D7"
            inactive-color="#ff4949"
            @change="handleChange($event,form.value)"
            :disabled="disabled"
          ></el-switch>
        </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
    };
  },
  created() {
    this.getHospitalId();
  },
  methods: {
    // 关联
    handleChange($event, isCorre) {
      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 => {
          this.$message({
            showClose: true,
            message: '操作失败!',
            type: 'error'
          });
          this.disabled = false;
        });
    },

    // 获取医院id
    getHospitalId() {
      api.getHospitalInfo().then(res => {
        this.hospitalId = res.data.data.id;
      });
    }
  }
};
</script>

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