<template>
  <div>
    <el-form :model="form" label-width="80px" ref="form">
      <el-form-item
        label="分部"
        prop="organId"
        :rules="[{ required: true, message: '请选择分部' }]"
      >
        <el-select
          v-model.trim="form.organId"
          filterable
          clearable
          placeholder="请选择分部"
          @change="changeSection"
        >
          <el-option
            v-for="(item, index) in selects.branchs"
            :key="index"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>

      <el-form-item
        label="合作单位"
        prop="school"
        :rules="[{ required: true, message: '请选择合作单位' }]"
      >
        <el-select
          v-model.trim="form.school"
          :disabled="!form.organId"
          filterable
          clearable
        >
          <el-option
            v-for="(item, index) in cooperationList"
            :key="index"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { queryByOrganId } from "@/api/systemManage";
import { addReplacement } from "../api"
export default {
  data() {
    return {
      form: {
        organId: "",
        school: "",
      },
      cooperationList: [],
    };
  },
  methods: {
    changeSection(val) {
      this.form.school = "";
      queryByOrganId({ organId: val }).then((res) => {
        if (res.code == 200) {
          this.cooperationList = res.data;
        }
      });
    },
   submit() {
      this.$refs.form.validate( async(res) => {
        if (res) {
          try{
          const res = await addReplacement({cooperationOrganId:this.form.school,organId:this.form.organId})
          this.$message.success('生成链接成功')
           this.$emit('getList')
          this.$emit('close')
          }catch(e){
          console.log(e)
          }

        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
