index.vue 3.97 KB
Newer Older
张成 committed
1
<template>
lixiaomin committed
2
  <el-dialog title="选择原料" :visible.sync="open" width="700px" append-to-body>
张成 committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="原料名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入原料名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
        </el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="materialList" ref="table" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="原料名称" align="center" prop="name" />
      <el-table-column label="原料数量" align="center" prop="quantity">
        <template slot-scope="scope">
lixiaomin committed
17
          <div style="display: flex;align-items: center;">
lixiaomin committed
18
            <el-input v-model="scope.row.quantity" placeholder="请输入原料数量" />
lixiaomin committed
19 20 21 22
            <div style="margin-left: 5px">
              <span> {{scope.row.unit}}</span>
            </div>            
          </div>          
张成 committed
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
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listMaterial } from "@/api/system/material";

export default {
  name: "Material",
  data() {
    return {
      open: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      materialList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
lixiaomin committed
63
        state: 1,
张成 committed
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
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listMaterial(this.queryParams).then((response) => {
        this.materialList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    openModal() {
      this.getList()
      this.open = true;
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection;
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 提交按钮 */
    submitForm() {
lixiaomin committed
101
      let subTag=true;
lixiaomin committed
102 103
      this.ids.map((item) => {     
        if(item.quantity==="" || item.quantity==undefined){          
lixiaomin committed
104
          let name=item.name;
lixiaomin committed
105
          this.$message.error(''+name+"原料名称的原料数量不能为空!");
lixiaomin committed
106 107
          subTag=false;
          return;
lixiaomin committed
108
        }else{                         
lixiaomin committed
109
          const regular = /^([0-9]*)+(.[0-9]{1,2})?$/;  //正数(包括小数)        
lixiaomin committed
110
          if (!regular.test(item.quantity)) {
lixiaomin committed
111
            this.$message.error(''+item.name+"原料名称的原料数量不是大于等于0的数字,最多保留2位小数!")
lixiaomin committed
112 113 114
            subTag=false;
            return;         
          }     
lixiaomin committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128
        }
      }); 
      if(subTag){
        this.$emit(
          "callback",
          this.ids.map((item) => {
            item.materialId = item.id;
            item.materialName = item.name;
            return item;
          })
        );
        this.$refs.table.clearSelection();
        this.open = false;
      }
张成 committed
129 130 131 132
    },
  },
};
</script>