index.vue 7.73 KB
Newer Older
耿迪迪's avatar
耿迪迪 committed
1 2 3 4
<!--
 * @Author: 纪泽龙 jizelong@qq.com
 * @Date: 2022-09-16 17:07:30
 * @LastEditors: 纪泽龙 jizelong@qq.com
纪泽龙's avatar
纪泽龙 committed
5
 * @LastEditTime: 2022-12-28 15:04:15
耿迪迪's avatar
耿迪迪 committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 * @FilePath: /danger-manage-web/src/views/trainingProgram/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="training-wrapper">
    <div class="top-title flex">
      <div class="item">
        <div class="text">培训管理</div>
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="addClick"
        >
          新增
        </el-button>
      </div>
    </div>

    <div>
      <Item
        v-for="item in list"
        :key="item.planId"
        :infoData="item"
31
        :personnelOptions="item.postIds"
耿迪迪's avatar
耿迪迪 committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
        @edit="edit"
        @save="itemSave"
        @deletePlan="deletePlan"
        @cancel="itemCancel"
        :isActiveId="isActiveId"
      />
    </div>

    <!-- <div v-for="item in list" :key="item.title">{{item.title}}</div> -->
    <el-dialog
      :title="dilogTitle"
      :visible.sync="addOpen"
      width="800px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-form ref="form" :rules="rules" :model="form" label-width="120px">
        <el-form-item label="新增培训名称" prop="planName">
          <el-input v-model="form.planName"></el-input>
        </el-form-item>
        <el-form-item label="参与培训人员" prop="postIds">
          <el-checkbox-group v-model="form.postIds">
            <el-checkbox
              v-for="personnel in personnelOptions"
              :label="personnel.postId"
              :key="personnel.postId"
              >{{ personnel.postName }}</el-checkbox
            >
          </el-checkbox-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogSubmitForm">确 定</el-button>
        <el-button @click="dialogCancel">取 消</el-button>
      </div>
    </el-dialog>
68 69 70 71 72
    <Dia
      ref="Dia"
      :componentsNum.sync="componentsNum"
      :bankId.sync="bankId"
      :visible.sync="dilogFlag"
纪泽龙's avatar
纪泽龙 committed
73
      :jsonData='jsonData'
74
    />
耿迪迪's avatar
耿迪迪 committed
75 76 77 78
  </div>
</template>

<script>
79
  import Dia from "./components/Dia";
耿迪迪's avatar
耿迪迪 committed
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
import Item from "./components/Item";
import {
  getPersonnel,
  addPlan,
  getPlanList,
} from "@/api/educationPlanExam/trainingProgram";
// 培训计划管理
const personnelOptions = [
  "管理人员",
  "主要负责人",
  "入场新员工",
  "值组组长",
  "车间主任",
  "承包商",
  "实习学生",
  "参观人员",
  "专职应急救援人员",
];
export default {
  name: "trainingProgram",
  components: {
101
    Item,Dia
耿迪迪's avatar
耿迪迪 committed
102 103 104 105
  },
  data() {
    return {
      personnelOptions,
纪泽龙's avatar
纪泽龙 committed
106 107
      // 选人复显示
      jsonData:null,
耿迪迪's avatar
耿迪迪 committed
108 109 110 111 112 113 114 115 116 117
      isActiveId: 999,
      list: [],
      // 当点击编辑的时候,会记录最初始的
      oldInfoData: null,
      addOpen: false,
      dilogTitle: "新增培训",
      form: {
        planName: "",
        postIds: [],
      },
118 119 120 121
      componentsNum: 2,
      // 点击的id,如果是新增为空
      bankId: null,
      dilogFlag: false,
耿迪迪's avatar
耿迪迪 committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
      rules: {
        planName: [
          {
            required: true,
            message: "新增培训名称不能为空",
            trigger: "change",
          },
        ],
        postIds: [
          {
            required: true,
            message: "最少选择一种参与培训人员",
            trigger: "change",
          },
        ],
      },
    };
  },
  mounted() {
    this.init();
  },
  methods: {
    async init() {
      await this.getPersonnel();
      await this.getPlanList();
    },
    getPersonnel() {
      getPersonnel().then((res) => {
        this.personnelOptions = res.data.map((item) => {
          return {
            postId: item.postId,
            postName: item.postName,
          };
        });
      });
    },
    getPlanList() {
159
    this.dilogFlag = false;
耿迪迪's avatar
耿迪迪 committed
160 161 162 163 164 165
      return getPlanList().then((res) => {
        console.log(res.data);
        this.list = res.data.map((item) => {
          return {
            planId: item.planId,
            planName: item.planName,
166
            personnelType:item.personnelType,
167 168
            postIds: item.postList,
            postList: item.postList
耿迪迪's avatar
耿迪迪 committed
169 170 171 172
              .filter((item) => item.ischeck)
              .map((item) => item.postId),
          };
        });
173
        console.log(this.list);
耿迪迪's avatar
耿迪迪 committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
      });
    },
    addPlan(plan) {
      return addPlan(plan).then((res) => {
        if (res.code == 200) {
          console.log(res.data);
          const planId = +res.data;
          const obj = { planId, ...this.form };
          this.list.push(obj);
          this.addOpen = false;
          this.formReset();
        }
      });
    },
    edit(e) {
      // console.log(e);
      // 如果已经记录过oldInfoData
      if (this.oldInfoData) {
        // 就让上一个的那个数据还原
        this.itemCancel(this.oldInfoData, true);
      }
      // 然后记录一下
      const data = JSON.parse(e);
      this.oldInfoData = e;
      // 编辑状态改变
      console.log(e);
      this.isActiveId = data.planId;
    },
    itemSave(newValue) {
      // const data = JSON.parse(newValue);
      // editPlan(data).

      this.itemCancel(newValue);
    },
    // 删除
    deletePlan(value) {
      const data = JSON.parse(value);
      const index = this.list.findIndex((item) => item.planId == data.planId);
      this.list.splice(index, 1);
      // 只删除,别的什么也不干
      if(this.oldInfoData){
        // 如果有正在编辑还未保存,就让他还原
        // this.itemCancel(this.oldInfoData)
      }

    },
    // 取消,第二个值用来判断是否让isActiveId=999;
    itemCancel(value, isActiveIdChange = false) {
      // console.log(e);
      // 在这里转换,防止污染
      const data = JSON.parse(value);
      // 找到下标,然后改成初始值
      const index = this.list.findIndex((item) => item.planId == data.planId);
      this.list.splice(index, 1, data);
      // 取消的时候清空这里存储的初始值
      this.oldInfoData = null;
      if (isActiveIdChange) return;
      this.isActiveId = 999;
    },
    changeList() {},
纪泽龙's avatar
纪泽龙 committed
234
    addClick(form,json) {
235 236 237 238 239 240 241 242 243

    this.$refs.Dia.title = "新增培训计划";
    this.componentsNum = 2;
    this.bankId = null;
    this.dilogFlag = true;
    if(form.planId!=undefined){
      //console.log("=======")
      this.$refs.Dia.title = "修改培训计划";
      this.bankId  = form.planId;
纪泽龙's avatar
纪泽龙 committed
244 245 246 247 248 249 250
      this.jsonData = json.map(item=>{
        return {
          peoPleId:item.postId,
          peoPleName:item.postName,
        }
      })

251 252
    }
      //this.addOpen = true;
耿迪迪's avatar
耿迪迪 committed
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
    },
    dialogSubmitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          console.log(this.form);
          this.addPlan(this.form);
          // alert("submit!");
          // this.form.id = 10;
          // this.list.push(this.form);
          // this.addOpen = false;
          // this.formReset();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    dialogCancel() {
      this.addOpen = false;
      // this.formReset();
    },
    formReset() {
      this.form = {
        planName: "",
        postIds: [],
      };
    },
  },
};
</script>
<style lang="scss" scoped>
.training-wrapper {
  // width: 91.3%;
  width: 100%;
  height: calc(100vh - 50px);
  // background-color: red;
  overflow: auto;
  .top-title {
    padding-top: 14px;
    padding-bottom: 14px;
    width: 100%;
    justify-content: center;
    .item {
      width: 93.2%;
      max-width: 1600px;
      .text {
        margin-bottom: 10px;
      }
    }
  }
}
</style>