审查视图

src/views/wms/UNcode.vue 6.0 KB
朱兆平 authored
1 2 3 4 5 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 31 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 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 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 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
<template>
  <div>
    <!-- 查询区域 -->
    <el-row :gutter="10" class="toolbar">
      <el-col :span="7">
        <el-input v-model="queryInfo.unCode" prefix-icon="el-icon-search" size="small"
                  placeholder="联合国危险品代码" clearable></el-input>
      </el-col>
      <el-col :span="6">
        <el-button type="primary" icon="el-icon-search" size="small" @click="search">查询</el-button>
        <el-button type="success" icon="el-icon-plus" size="small" @click="applyAdd()">新增</el-button>
      </el-col>
    </el-row>

    <!-- 表格区域 -->
    <el-table :data="tableData" border stripe style="width: 100%" size="small"
              :header-cell-style="{background:'#6F8294',color:'#FFFFFF'}">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="id" label="主键ID" width="100"></el-table-column>
      <el-table-column prop="unCode" label="联合国危险品代码"></el-table-column>
      <el-table-column prop="cnDes" label="危险品中文描述"></el-table-column>
      <el-table-column prop="enDes" label="危险品英文描述"></el-table-column>
      <el-table-column prop="classType" label="危险品项别/类别"></el-table-column>
      <el-table-column prop="secondaryRisk" label="次要危险性"></el-table-column>
      <el-table-column prop="packingLevel" label="包装等级"></el-table-column>
      <el-table-column fixed="right" label="操作">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="applyEdit(scope.row)">编辑</el-button>
          <el-button type="danger" size="mini" @click="applyDelete(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页区域 -->
    <el-pagination
        background
        layout="prev, pager, next"
        :total="total"
        :current-page="queryInfo.pageNum"
        :page-size="queryInfo.pageSize"
        @current-change="handlePageChange">
    </el-pagination>

    <!-- 对话框 -->
    <el-dialog :title="dialogStateMap[dialogType]" :visible.sync="showDialog" width="80%">
      <el-form ref="formRef" :model="formData" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="联合国危险品代码" prop="unCode">
              <el-input v-model="formData.unCode"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="危险品中文描述" prop="cnDes">
              <el-input v-model="formData.cnDes"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="危险品英文描述" prop="enDes">
              <el-input v-model="formData.enDes"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="危险品项别/类别" prop="classType">
              <el-input v-model="formData.classType"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="次要危险性" prop="secondaryRisk">
              <el-input v-model="formData.secondaryRisk"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="包装等级" prop="packingLevel">
              <el-input v-model="formData.packingLevel"></el-input>
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
                <el-button @click="showDialog = false">取消</el-button>
                <el-button type="primary" @click="submitForm(dialogType)">确定</el-button>
            </span>
    </el-dialog>
  </div>
</template>

<script>
import { insertUnCodeInfo, updateUnCodeInfo, deleteUnCodeById, getAllUnCodesByPage } from '@/api/wms/uncodeAPI';

export default {
  data() {
    return {
      queryInfo: {
        pageNum: 1,
        pageSize: 10,
        unCode: ''
      },
      tableData: [],
      total: 0,
      showDialog: false,
      dialogType: 'add',
      dialogStateMap: {
        view: '查看',
        edit: '编辑',
        add: '新增'
      },
      formData: {},
      rules: {
        unCode: [
          { required: true, message: '请输入联合国危险品代码', trigger: 'blur' }
        ],
        cnDes: [
          { required: true, message: '请输入危险品中文描述', trigger: 'blur' }
        ]
        // 其他字段的规则类似
      },
    };
  },
  methods: {
    search() {
      getAllUnCodesByPage({unCode:this.queryInfo.unCode},{pageNum:this.queryInfo.pageNum, pageSize:this.queryInfo.pageSize}).then(response => {
        const data = response.data;
        if (data.code === "200") {
          this.tableData = data.data.list || [];
          this.total = data.data.total || 0;
        }
      });
    },
    applyAdd() {
      this.dialogType = 'add';
      this.showDialog = true;
      this.formData = {};
    },
    applyEdit(row) {
      this.dialogType = 'edit';
      this.showDialog = true;
      this.formData = { ...row };
    },
    applyDelete(id) {
      deleteUnCodeById(id).then(response => {
        if (response.data.code === "200") {
          this.search();
        }
      });
    },
    submitForm(type) {
      let method;
      switch (type) {
        case 'add':
          method = insertUnCodeInfo;
          break;
        case 'edit':
          method = updateUnCodeInfo;
          break;
        default:
          return;
      }

      this.$refs['formRef'].validate(valid => {
        if (valid) {
          method(this.formData).then(response => {
            if (response.data.code === "200") {
              this.showDialog = false;
              this.search();
            }
          }).catch(e =>{
            this.$message.error(e)
          });
        } else {
          console.log('验证失败');
          return false;
        }
      });
    },
    handlePageChange(page) {
      this.queryInfo.pageNum = page;
      this.search();
    }
  },
};
</script>