<!-- 用户编辑弹窗 -->
<template>
  <el-dialog
    class="ele-dialog-form"
    :title="'设置班次'"
    :visible.sync="visible"
    :before-close="handleClose"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    width="500px"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="班次" prop="code" style="margin-bottom: 22px">
        <el-select v-model="form.teamTimeId" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" :loading="loading" @click="save">
        保存
      </el-button>
    </template>
  </el-dialog>
</template>
  
  <script>
import { getPullDown, settingTeamTime } from '@/api/workforceManagement/team';
export default {
  data() {
    const defaultForm = {
      teamIds: [],
      teamTimeId: ''
    };
    return {
      defaultForm,
      // 表单数据
      form: { ...defaultForm },
      // 表单验证规则
      rules: {
        teamTimeId: [{ required: true, message: '请输入', trigger: 'blur' }]
      },
      visible: false,
      loading: false,
      options: []
    };
  },
  methods: {
    async open(row) {
      this.visible = true;
      this.form.teamIds = row;
      this.getPullDown();
    },
    /* 保存编辑 */
    save() {
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return false;
        }
        this.loading = true;
        settingTeamTime(this.form)
          .then((msg) => {
            this.$message.success(msg);
            this.handleClose();
            this.$emit('done');
          })
          .catch((e) => {
            this.$message.error(e.message);
          })
          .finally(() => {
            this.loading = false;
          });
      });
    },
    // 重置表单
    restForm() {
      this.$refs.form.clearValidate();
      this.form = { ...this.defaultForm };
    },
    handleClose() {
      this.restForm();
      this.visible = false;
    },
    getPullDown() {
      getPullDown().then((res) => {
        this.options = res;
      });
    }
  }
};
</script>
  <style lang="scss" scoped>
.location-warp {
  display: flex;
  .detail {
    margin-left: 10px;
  }
}
</style>
  