Item.vue 7.66 KB
Newer Older
耿迪迪's avatar
耿迪迪 committed
1 2 3 4 5
<template>
  <div class="item-wrapper flex" v-loading="loading">
    <div class="item flex" :class="{ active: isActive }">
      <div class="left flex">
        <div class="left-item flex" :class="{ active: isActive }">
6 7 8 9 10 11 12 13 14
          <div class="text flex">
            <div class="i-wrapper">
              <i class="iconfont icon-24gl-checklist" />
            </div>
            <div ref="tp" class="text-center-wrapper flex">
              <div ref="t" style="margin-right: 10px" v-if="!isActive">
                {{ infoData.planName }}
              </div>
            </div>
耿迪迪's avatar
耿迪迪 committed
15

16
            <!-- <el-input
耿迪迪's avatar
耿迪迪 committed
17 18 19 20 21
              v-else
              size="mini"
              v-model="infoData.planName"
              placeholder="请输入内容"
              style="width: 120px"
22
            ></el-input> -->
耿迪迪's avatar
耿迪迪 committed
23 24 25
          </div>
        </div>
      </div>
26 27 28 29 30 31 32
      <div class="right flex" style="line-height: 110px">
        <div style="margin-left: 20px" v-if="infoData.personnelType == 1">
          员工培训
        </div>
        <div style="margin-left: 20px" v-if="infoData.personnelType == 2">
          承包商培训
        </div>
33
      </div>
耿迪迪's avatar
耿迪迪 committed
34 35
      <div class="middle flex">
        <div>
36
          <div class="top">参与培训人员({{ personnelOptions.length }})</div>
耿迪迪's avatar
耿迪迪 committed
37
          <div class="bottom">
纪泽龙's avatar
纪泽龙 committed
38
            <!-- <el-checkbox-group class="" v-model="infoData.postIds"> -->
39 40 41 42 43 44 45 46
            <el-checkbox
              :disabled="!isActive"
              v-model="personnel.ischeck"
              v-for="personnel in personnelOptions"
              :label="personnel.postId"
              :key="personnel.postId"
              >{{ personnel.postName }}</el-checkbox
            >
纪泽龙's avatar
纪泽龙 committed
47
            <!-- </el-checkbox-group> -->
耿迪迪's avatar
耿迪迪 committed
48 49 50 51 52 53
          </div>
        </div>
      </div>
      <div class="right flex">
        <template v-if="!isActive">
          <div>
54 55 56
            <el-button type="text" @click="edit(personnelOptions)"
              >编辑</el-button
            >
耿迪迪's avatar
耿迪迪 committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
            <el-button type="text" @click="deletePlan">删除</el-button>
          </div>
        </template>
        <template v-else>
          <div>
            <el-button type="text" @click="save">保存</el-button>
            <el-button type="text" @click="cancel">取消</el-button>
          </div>
        </template>
      </div>
    </div>
  </div>
</template>

<script>
import { editPlan, deletePlan } from "@/api/educationPlanExam/trainingProgram";
export default {
  name: "trainingProgram-item",
  props: {
    personnelOptions: {
      type: Array,
    },
    isActiveId: {
      type: [String, Number],
      default: 999,
    },
    infoData: {
      type: Object,
      default: () => {
        return {
          planId: 1,
          planName: "安全岗位生产",
          postIds: [1, 2, 3, 4],
        };
      },
    },
  },
  computed: {
    isActive() {
      return this.isActiveId === this.infoData.planId;
    },
  },
99 100 101 102 103 104 105 106 107 108 109 110
  mounted() {
    console.log(this.$refs.t.offsetHeight);
    // 如果子元素的高大于父元素的高,就改变上下居中策略,改为滚动条展示
    if (this.$refs.t.offsetHeight > this.$refs.tp.offsetHeight) {
      console.log(this.$refs.tp.style);
      this.$refs.tp.style.overflow = "auto";
      this.$refs.tp.style.alignItems = "";
    } else {
      // console.log(this.$refs.t.offsetHeight)
      // this.$refs.t.style.alignItems='center'
    }
  },
耿迪迪's avatar
耿迪迪 committed
111 112 113 114 115 116 117 118 119
  data() {
    return {
      // 记录初始的选项
      oldInfoData: JSON.stringify(this.infoData),
      // isActive: false,
      loading: false,
    };
  },
  methods: {
纪泽龙's avatar
纪泽龙 committed
120
    edit(personnelOptions) {
耿迪迪's avatar
耿迪迪 committed
121
      // 编辑
纪泽龙's avatar
纪泽龙 committed
122
      console.log(personnelOptions);
123
      this.$parent.addClick(this.infoData, personnelOptions);
124
      //this.$emit("edit", this.oldInfoData);
耿迪迪's avatar
耿迪迪 committed
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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 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
    },
    save() {
      if (this.infoData.planName == "") {
        this.$message({
          message: "请输入培训计划名称",
          type: "warning",
        });
        return;
      }
      if (this.infoData.postIds.length == 0) {
        this.$message({
          message: "请选择至少一种参与培训人员",
          type: "warning",
        });
        return;
      }
      this.$confirm("请确定更改培训计划", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.loading = true;

          return editPlan(this.infoData);
        })
        .then((res) => {
          if (res.code == 200) {
            // 成功也要将oldInfoData 变成最新的
            // this.oldInfoData = "newInfoData";
            const dataJson = JSON.stringify(this.infoData);
            this.$emit("save", dataJson);
            // 成功之后
            this.oldInfoData = dataJson;
            this.$message({
              message: "修改培训计划成功",
              type: "success",
            });
          }
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    deletePlan() {
      console.log(this.infoData);
      this.$confirm("请确定删除当前培训计划", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return deletePlan({ planId: this.infoData.planId });
        })
        .then((res) => {
          if (res.code == 200) {
            this.$emit("deletePlan", this.oldInfoData);
            this.$message({
              message: "删除成功",
              type: "success",
            });
          }
        });
    },
    // 当bool为true时候,监听用的,不去改videoID,这样就不会监听锁死
    // 当bool为false时,是取消用的,会变成999
    cancel() {
      this.$emit("cancel", this.oldInfoData);
    },
  },
};
</script>
<style lang="scss" scoped>
.item-wrapper {
  width: 100%;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
  .item {
    transition: all 0.5s;
    width: 93.2%;
    max-width: 1600px;
208
    min-height: 111px;
耿迪迪's avatar
耿迪迪 committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
    border: 1px solid #cecece;
    box-shadow: -4px 0px 0px 0px rgba(0, 0, 0, 0.1);
    background: linear-gradient(
      180deg,
      rgba(255, 255, 255, 1) 0%,
      rgba(255, 255, 255, 1) 100%
    );

    border-radius: 5px;
    &.active {
      box-shadow: -4px 0px 0px 0px #1d84ff, 0px 2px 6px 0px rgba(0, 0, 0, 0.15);
    }
    // background: blue;
    .left {
      width: 225px;
      height: 100%;
      align-items: center;
      justify-content: right;
227
      margin-top: 25px;
228

耿迪迪's avatar
耿迪迪 committed
229 230 231 232
      .left-item {
        transition: all 0.5s;
        width: 200px;
        height: 60px;
233
        // line-height: 60px;
耿迪迪's avatar
耿迪迪 committed
234 235 236 237 238 239 240 241 242 243 244 245 246 247
        font-size: 14px;
        padding-left: 25px;
        border: 1px solid #efefef;
        border-radius: 5px;
        box-sizing: border-box;
        background: linear-gradient(
          180deg,
          rgba(255, 255, 255, 0) 8%,
          rgba(239, 239, 239, 1) 100%
        );
        &.active {
          background: #1d84ff;
          color: #fff;
        }
248 249 250 251 252 253 254 255 256 257
        .i-wrapper {
          height: 60px;
          line-height: 60px;
          padding-right: 10px;
        }
        .text-center-wrapper {
          height: 100%;
          width: 100%;
          // overflow: auto;
          align-items: center;
耿迪迪's avatar
耿迪迪 committed
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
        }
      }
    }
    .middle {
      flex: 1;
      // flex-direction: column;
      align-items: center;

      // background: white;
      padding-left: 25px;
      // padding-top: 25px;
      padding-right: 25px;
      .top {
        font-size: 14px;
        margin-bottom: 9px;
      }
      .bottom {
        justify-content: space-between;
        font-size: 14px;
      }
    }
    .right {
      padding-right: 20px;
      width: 120px;
      height: 100%;
      justify-items: center;
      align-items: center;
    }
  }
}
</style>