eventcodes.vue 7.84 KB
<template>
  <div class="contentBox">
    <span>
      <el-select
        class="selectBox"
        v-model="curcate"
        placeholder="请选择"
        @change="cateChange"
        :popper-append-to-body="false"
      >
        <el-option
          v-for="(item, index) in eventCateData"
          :key="index"
          :value="item.event_cate_unid"
          :label="item.name"
        ></el-option>
      </el-select>
    </span>
    <span class="code-btn">
      <el-button type="primary" @click="addCodes">添加code</el-button>
    </span>
    <div class="content">
      <div>
        <el-table
          height="574"
          :data="tableData"
          stripe
          border
          style="width: 100%"
        >
          <el-table-column type="index" label="#" align="center" width="40">
          </el-table-column>
          <el-table-column
            align="center"
            prop="event_type_unid"
            label="event_type_unid"
          >
          </el-table-column>
          <el-table-column prop="code" align="center" label="code">
          </el-table-column>
          <el-table-column align="center" prop="name" label="名称">
          </el-table-column>
          <el-table-column
            align="center"
            prop="event_cate_unid"
            label="类型"
            :formatter="cateFormatter"
          >
          </el-table-column>
          <el-table-column align="center" prop="operation" label="操作">
            <template slot-scope="scope">
              <el-tooltip
                content="编辑"
                placement="bottom"
                effect="light"
                :visible-arrow="false"
              >
                <span
                  class="icon-fanxing-xiugai editIcon"
                  @click="editCode(scope.$index, scope.row)"
                ></span>
              </el-tooltip>
              <el-tooltip
                content="删除"
                placement="bottom"
                effect="light"
                :visible-arrow="false"
              >
                <span
                  class="el-icon-delete  delIcon del-btn"
                  @click="deleteCode(scope.$index, scope.row)"
                ></span>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
        <div style="margin-top: 28px;">
          <el-pagination
            style="float: right;"
            background
            prev-text="上一页"
            next-text="下一页"
            :page-sizes="[20, 30, 50, 100, 200]"
            layout="prev, pager, next,sizes"
            :current-page="page"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :total="total"
          >
          </el-pagination>
          <div style="clear: both;"></div>
        </div>
      </div>
    </div>
    <el-dialog title="设置CODE" :visible.sync="detailVisible" width="400px">
      <el-form
        ref="eventform"
        :model="codeData"
        label-position="left"
        label-width="80px"
      >
        <el-form-item
          label="类型"
          prop="catename"
          :rules="[
            { required: true, message: '类型不能为空!', trigger: 'blur' }
          ]"
        >
          <el-input v-model="codeData.catename" disabled></el-input>
        </el-form-item>
        <el-form-item
          label="CODE"
          prop="code"
          :rules="[
            { required: true, message: 'code不能为空!', trigger: 'blur' }
          ]"
        >
          <el-input v-model="codeData.code"></el-input>
        </el-form-item>
        <el-form-item
          label="名称"
          prop="name"
          :rules="[
            { required: true, message: '名称不能为空!', trigger: 'blur' }
          ]"
        >
          <el-input v-model="codeData.name"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="detailVisible = false">取 消</el-button>
        <el-button size="small" type="primary" @click="saveCode"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      total: 0,
      page: 1,
      pageSize: 20,
      tableData: [],
      detailVisible: false,
      eventCateData: [],
      curcate: "",
      catename: "",
      codeData: {
        name: "",
        code: "",
        catename: ""
      },
      editStatus: 0,
      event_type_unid: ""
    };
  },
  components: {},
  created() {
    // this.getEventList();
    this.getEventCate();
  },
  methods: {
    getEventList() {
      this.$api.codes.eventTypes({}).then(res => {
        this.tableData = res.list_data;
      });
    },
    cateChange() {
      this.$api.codes.eventType({}, this.curcate).then(res => {
        this.tableData = res.list_data;
      });
    },
    getEventCate() {
      this.$api.codes.eventCates({}).then(res => {
        this.eventCateData = res.list_data;
      });
    },
    addCodes() {
      this.eventCateData.forEach(ele => {
        if (ele.event_cate_unid === this.curcate) {
          this.codeData.catename = ele.name;
        }
      });
      this.detailVisible = true;
      this.editStatus = 0;
    },
    cateFormatter(row) {
      return this.getCateName(row.event_cate_unid);
    },
    editCode(index, row) {
      this.event_type_unid = row.event_type_unid;
      this.detailVisible = true;
      this.editStatus = 1;
      this.codeData = {
        name: row.name,
        code: row.code,
        catename: this.getCateName(this.curcate),
        event_cate_unid: row.event_cate_unid
      };
    },
    deleteCode(index, row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$api.codes.deleteEventType({}, row.event_type_unid).then(res => {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.cateChange();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    getCateName(cateunid) {
      let name = "";
      this.eventCateData.forEach(ele => {
        if (ele.event_cate_unid === cateunid) {
          name = ele.name;
        }
      });
      return name;
    },
    saveCode() {
      this.$refs["eventform"].validate(valid => {
        if (valid) {
          if (this.editStatus === 0) {
            this.saveAddCode();
          }
          if (this.editStatus === 1) {
            this.saveEditCode();
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    saveAddCode() {
      let data = {
        event_cate_unid: this.curcate,
        code: this.codeData.code,
        name: this.codeData.name
      };
      this.$api.codes.addEventTypes(data).then(res => {
        this.detailVisible = false;
        this.$refs["eventform"].resetFields();
        this.cateChange();
      });
    },
    saveEditCode() {
      let obj = {
        event_cate_unid: this.curcate,
        code: this.codeData.code,
        name: this.codeData.name,
        note: ""
      };
      this.$api.codes
        .editEventType(this.codeData, this.event_type_unid)
        .then(res => {
          this.detailVisible = false;
          this.$refs["eventform"].resetFields();
          this.cateChange();
          this.editStatus = 0;
        });
    },
    handleSizeChange(val) {
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.page = val;
    }
  }
};
</script>
<style lang="scss" scoped>
.code-btn {
  margin-bottom: 10px;
  float: right;
  margin-right: 10px;
}
.del-btn {
  padding-left: 20px;
}
</style>