trfficcodes.vue 6.87 KB
<template>
  <div class="contentBox">
    <div class="content">
      <div>
        <span class="selectBox">
          <el-select
            v-model="curCateUnid"
            placeholder="请选择"
            @change="cateChange"
            :popper-append-to-body="false"
          >
            <el-option
              v-for="item in catesData"
              :key="item"
              :value="item.cate_unid"
              :label="item.name"
            ></el-option>
          </el-select>
        </span>
        <span class="addbox">
          <el-button type="primary" @click="addcode">添加code</el-button>
        </span>
      </div>
      <div class="mt10">
        <el-table
          height="574"
          :data="tableData"
          stripe
          border
          style="width: 100%"
        >
          <el-table-column
            type="index"
            align="center"
            label="#"
            width="40"
          ></el-table-column>
          <el-table-column align="center" prop="code_unid" label="code_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="operation" label="操作">
            <template slot-scope="scope">
              <el-tooltip
                content="编辑"
                placement="bottom"
                effect="light"
                :visible-arrow="false"
              >
                <span
                  class="iconfont icon-xiugai editIcon"
                  @click="editCode(scope.$index, scope.row)"
                ></span>
              </el-tooltip>
              <el-tooltip
                content="删除"
                placement="bottom"
                effect="light"
                :visible-arrow="false"
              >
                <span
                  class="iconfont icon-detail  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="trfficform"
        :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-item
          label="备注"
          prop="note"
          :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 {
      detailData: [],
      total: 0,
      page: 1,
      curCateUnid: "",
      pageSize: 20,
      tableData: [],
      catesData: [],
      selectDevs: "",
      detailVisible: false,
      codeStatus: 0,
      codeData: {}
    };
  },
  components: {},
  created() {
    this.getCates();
  },
  methods: {
    cateChange(cateunid) {
      let offset = (this.page - 1) * this.pageSize;
      let obj = {
        limit: this.pageSize,
        offset: offset
      };
      this.$api.codes
        .codes(obj, cateunid)
        .then(res => {
          this.tableData = res.list_data;
        })
        .catch(err => {});
    },
    addcode() {
      this.codeStatus = 0;
      this.detailVisible = true;
      this.codeData.catename = this.getCateName(this.curCateUnid);
    },
    editCode(index, row) {
      this.codeStatus = 1;
      this.detailVisible = true;
      this.codeData = row;
      this.codeData.catename = this.getCateName(this.curCateUnid);
    },
    getCateName(cateunid) {
      let name = "";
      this.catesData.forEach(ele => {
        if (ele.cate_unid === cateunid) {
          name = ele.name;
        }
      });
      return name;
    },
    getCates() {
      this.$api.codes.cates().then(res => {
        this.catesData = res.list_data;
      });
    },
    saveCode() {
      this.$refs["trfficform"].validate(valid => {
        if (valid) {
          if (this.editStatus === 0) {
            this.saveAddCode();
          }
          if (this.editStatus === 1) {
            this.saveEditCode();
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    saveAddCode() {
      this.$api.codes
        .addTrafficCode(this.codeData, this.curCateUnid)
        .then(res => {
          console.log(res);
        });
    },
    saveEditCode() {
      this.$api.codes
        .editTrafficCode(
          this.codeData,
          this.curCateUnid,
          this.codeData.code_unid
        )
        .then(res => {
          console.log(res);
        });
    },
    deleteCode(index, row) {
      this.$api.codes
        .editTrafficCode(row, this.curCateUnid, row.code_unid)
        .then(res => {
          console.log(res);
        });
    },
    handleSizeChange(val) {
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.page = val;
    }
  }
};
</script>
<style lang="scss" scoped>
.addbox {
  float: right;
  margin-right: 10px;
}
.code-btn {
  margin-bottom: 10px;
  float: right;
  margin-right: 10px;
}
.del-btn {
  padding-left: 20px;
}
</style>