<template>
  <el-dialog append-to-body title="绑定组织" :visible.sync="dialogFormVisible">
    <el-form
      ref="dataForm"
      :rules="rules"
      :model="dataForm"
      label-width="100px"
      label-well-code="right"
    >
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="绑定组织" prop="deptId">
            <dept-select
              v-model="dataForm.deptId"
              :need-top="deptShowTop"
              dept-type="03"
              placeholder="选择组织机构"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="saveData">
        保存
      </el-button>
      <el-button @click="dialogFormVisible = false">
        取消
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import { relatedDept } from '@/api/system/tenant'
import DeptSelect from '@/components/DeptSelect/index'
export default {
  name: 'RelateDept',
  components: { DeptSelect },
  data() {
    return {
      dialogFormVisible: false, // 对话框显示隐藏
      deptShowTop: false,
      // 表单内容
      dataForm: {
        tenantId: '',
        deptId: ''
      },
      // 表单校验规则
      rules: {
        deptId: [{ required: true, message: '	组织机构必选', trigger: ['blur', 'change'] }]
      }
    }
  },
  methods: {
    // 重置表单
    resetForm() {
      this.dataForm = {
        tenantId: '',
        deptId: ''
      }
    },
    // 父子组件通信
    initDialog(row = null) {
      this.dialogFormVisible = true
      if (row) {
        this.dataForm = {
          tenantId: row.id,
          deptId: row.deptId
        }
      }
    },
    // 保存数据
    saveData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          debugger
          relatedDept(this.dataForm).then(res => {
            if (res.code === 200) {
              this.$message.success('绑定成功')
              this.$emit('watchChild')
              this.dialogFormVisible = false
            }
          })
        }
      })
    }
  }
}
</script>

<style>
  .el-select__tags {
    flex-wrap: inherit !important;
    overflow-x: auto !important;
  }
  ::-webkit-scrollbar {
    height: 4px;
  }
  /* //滚动条的滑块 */
  ::-webkit-scrollbar-thumb {
    background-color: #eaecf1;
    border-radius: 3px;
  }
</style>
