<template>
  <div class="projectect-attendance-drawer">
    <el-drawer
      v-if="isOpen"
      :visible.sync="isOpen"
      direction="rtl"
      size="30%"
      style="padding-left: 20px"
    >
      <template slot="title">
        <div>{{ title + " 【部门在册人员】" }}</div>
      </template>
      <el-tabs v-model="activeName" style="padding-left: 20px" @tab-click="loadData">
        <el-tab-pane
          v-for="(it, idx) in nodes"
          :label="it.unitName + ''"
          :name="it.unitId + ''"
          :key="idx"
        ></el-tab-pane>
      </el-tabs>
      <el-form label-width="120px" ref="form" :rules="rules">
        <el-form-item label="劳务人员" prop="servicePersonnel">
          <el-input-number
            style="width: 80%"
            v-model="form.servicePersonnel"
            :min="0"
            :max="10000"
            label="请输入劳务人员"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="监理人员" prop="supervisorPersonnel">
          <el-input-number
            style="width: 80%"
            v-model="form.supervisorPersonnel"
            :min="0"
            :max="10000"
            label="请输入监理人员"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="总包人员" prop="contractorPersonnel">
          <el-input-number
            style="width: 80%"
            v-model="form.contractorPersonnel"
            :min="0"
            :max="10000"
            label="请输入总包人员"
          ></el-input-number>
        </el-form-item>
      </el-form>
      <div style="text-align: center" v-if="isUnit">
        <el-button type="primary" @click="doOk">确定</el-button>
        <el-button @click="doCanel">取消</el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import {
  deptWroksViewData,
  updateProjectDeptWroks,
} from "@/api/project/projectDeptWroks";
export default {
  name: "RuoyiUiProjectDeptWroksDrawer",
  data() {
    return {
      isOpen: false,
      project: null,
      title: "",
      isUnit: true,
      nodes: [],
      form: {
        oldServicePersonnel: 0,
        oldSupervisorPersonnel: 0,
        oldContractorPersonnel: 0,
      },
      rules: {},
      activeName: "",
    };
  },
  computed: {
    ...mapGetters(["dept"]),
  },
  mounted() {},

  methods: {
    doOk() {
      updateProjectDeptWroks(this.form).then((response) => {
        this.$modal.msgSuccess("保存成功");
        this.isOpen = false;
      });
    },
    doCanel() {
      this.isOpen = false;
    },
    show(project) {
      this.form.servicePersonnel = 0;
      this.form.supervisorPersonnel = 0;
      this.form.contractorPersonnel = 0;
      this.project = project;
      this.title = project.projectName;
      this.isOpen = true;
      this.$api.publics
        .queryUnitList({
          projectId: project.id,
          unitType: 2,
        })
        .then((d) => {
          this.nodes = d.rows;
          if (d.rows.length > 0) {
            this.activeName = this.nodes[0].unitId + "";
            this.isUnit = true;
            this.loadData();
          } else {
            this.$message.error("当前项目未分配总包单位，不能维护在册人员");
            this.isUnit = false;
          }
        });
    },
    // 页签点击
    loadData() {
      deptWroksViewData({
        projectId: this.project.id,
        nowDept: this.activeName,
      }).then((d) => {
        if (d.rows.length > 0) {
          this.form = d.rows[0];
          this.form.oldServicePersonnel = this.form.servicePersonnel;
          this.form.oldSupervisorPersonnel = this.form.supervisorPersonnel;
          this.form.oldContractorPersonnel = this.form.contractorPersonnel;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped></style>
