Browse Source

utils/validate

戴艳蓉 3 years ago
parent
commit
2869bd1ce5

+ 46 - 54
src/components/number-range/main.vue

@@ -1,20 +1,20 @@
 <template>
   <div class="fl ageInput">
     <el-input
-      type="text"
-      :size="size"
-      :style="{ width: width }"
-      v-model="lowerNum"
+      type="number"
+      :size="size || 'medium'"
+      :style="{ width: width || '170px' }"
+      v-model="lower"
       @change="numChange()"
       @input="accountInput($event, 1)"
       :placeholder="title + '下限'"
     /><samp style="padding: 0 3px; margin: 0">至</samp>
     <el-input
-      type="text"
-      :size="size"
+      type="number"
+      :size="size || 'medium'"
       @input="accountInput($event, 2)"
-      :style="{ width: width }"
-      v-model="onlineNum"
+      :style="{ width: width || '170px' }"
+      v-model="online"
       :placeholder="title + '上限'"
       @change="numChange()"
     />
@@ -26,45 +26,37 @@
 // timeReturned 返回值{startTime: Number,endTime: Number}
 export default {
   name: "numBerRange",
-  props: {
-    title: {
-      type: String,
-      default: "",
-    },
-    lower: {
-      type: String,
-      default: "",
-    },
-    online: {
-      type: String,
-      default: "",
-    },
-    disabled: {
-      type: Boolean,
-      default: false,
-    },
-    size: {
-      type: String,
-      default: "mini",
-    },
-    width: {
-      type: String,
-      default: "170px",
-    },
-  },
+  props: ["title", "lower", "online", "disabled", "size", "width"],
+  // props: {
+  //   title: {
+  //     type: String,
+  //     default: "",
+  //   },
+  //   lower: {
+  //     type: String,
+  //     default: "",
+  //   },
+  //   online: {
+  //     type: String,
+  //     default: "",
+  //   },
+  //   disabled: {
+  //     type: Boolean,
+  //     default: false,
+  //   },
+  //   size: {
+  //     type: String,
+  //     default: "mini",
+  //   },
+  //   width: {
+  //     type: String,
+  //     default: "170px",
+  //   },
+  // },
   data() {
     return {
-      isEdit: this.disabled,
-      lowerNum: this.lower,
-      onlineNum: this.online,
     };
   },
-  watch: {
-    disabled(a, b) {
-      this.isEdit = a;
-      //  console.log(a, b,this.isEdit);
-    },
-  },
   mounted() {},
   methods: {
     accountInput(val, type) {
@@ -79,22 +71,22 @@ export default {
         }
       }
       if (type === 1) {
-        this.lowerNum = str;
+        this.lower = str;
       } else {
-        this.onlineNum = str;
+        this.online = str;
       }
     },
     numChange() {
       if (
-        this.lowerNum !== "" &&
-        this.lowerNum !== null &&
-        this.onlineNum !== "" &&
-        this.onlineNum !== null
+        this.lower !== "" &&
+        this.lower !== null &&
+        this.online !== "" &&
+        this.online !== null
       ) {
-        if (parseInt(this.onlineNum) - parseInt(this.lowerNum) <= 0) {
+        if (parseInt(this.online) - parseInt(this.lower) <= 0) {
           this.$message.error(`${this.title}上限应大于${this.title}下限!`);
-          this.lowerNum = "";
-          this.onlineNum = "";
+          this.lower = "";
+          this.online = "";
           this.numReturned();
         } else {
           this.numReturned();
@@ -105,8 +97,8 @@ export default {
     },
     numReturned() {
       this.$emit("numReturned", {
-        lower: this.lowerNum == null ? "" : this.lowerNum,
-        online: this.onlineNum == null ? "" : this.onlineNum,
+        lower: this.lower == null ? "" : this.lower,
+        online: this.online == null ? "" : this.online,
       });
     },
   },

+ 14 - 8
src/components/search-stock-good-modal/columns.js

@@ -12,16 +12,22 @@ export default [
   },
 
   {
-    prop: "gys_code",
-    label: "供应商编码",
-    width: "142",
-  },
-  {
-    prop: "supplier_name",
-    label: "供货商",
-    "min-width": "160",
+    prop: "usable_stock",
+    label: "可用库存",
+    width: "120",
   },
   // {
+  //   prop: "gys_code",
+  //   label: "供应商编码",
+  //   width: "142",
+  // },
+  
+  // {
+  //   prop: "supplier_name",
+  //   label: "供货商",
+  //   "min-width": "160",
+  // },
+  // {
   //   prop: "cg_saler",
   //   label: "采购员",
   //   width: "60",

+ 2 - 2
src/views/stock/allot/addEdit.vue

@@ -4,7 +4,7 @@
     :center="true"
     align="left"
     top="5vh"
-    width="700px"
+    width="1040px"
     @close="closeModel"
     :close-on-click-modal="false"
     :visible.sync="showModelThis"
@@ -13,7 +13,7 @@
     element-loading-spinner="el-icon-loading"
     element-loading-background="rgba(0, 0, 0, 0.8)"
   >
-    <el-row :gutter="10">
+    <el-row :gutter="10" style="margin-top:-20px">
       <el-col :span="24">
         <add-form :id="id" @closeModel="closeModel" />
       </el-col>

+ 269 - 161
src/views/stock/allot/components/addForm.vue

@@ -1,101 +1,166 @@
 <template>
-  <div class="addForm">
-    <el-row :gutter="10">
-      <el-col :span="24">
-        <el-form
-          :model="ruleForm"
-          status-icon
-          :rules="rulesThis"
-          ref="ruleForm"
-          label-width="150px"
-          class="demo-ruleForm"
+  <el-row class="addForm">
+    <el-col :span="24">
+      <el-form
+        :model="ruleForm"
+        status-icon
+        :rules="rulesThis"
+        ref="ruleForm"
+        :size="'mini'"
+        label-width="60px"
+        class="demo-ruleForm"
+      >
+        <el-row>
+          <el-col :span="12">
+            <div class="label-title-model">出库仓库信息:</div>
+            <el-form-item label="公司" prop="supplier_code">
+              <search-supplier
+                :value="ruleForm.supplier_code"
+                :placeholder="'请选择公司'"
+                @searchChange="selectSupplier"
+              />
+            </el-form-item>
+            <el-form-item label="仓库" prop="stock_code">
+              <search-stock
+                :value="ruleForm.stock_code"
+                :isDetail="true"
+                :disabled="isDisabled"
+                :placeholder="'请选择仓库'"
+                :isRelation="true"
+                :companyCode="supplier_code"
+                :names="''"
+                @searchChange="selectStock"
+              />
+            </el-form-item>
+          </el-col>
+          <el-col :span="12">
+            <div class="label-title-model">入库仓库信息:</div>
+            <el-form-item label="公司" prop="supplier_in_code">
+              <search-supplier
+                :value="ruleForm.supplier_in_code"
+                :placeholder="'请选择公司'"
+                @searchChange="selectSupplierIn"
+              />
+            </el-form-item>
+            <el-form-item label="仓库" prop="stock_in_code">
+              <search-stock
+                :value="ruleForm.stock_in_code"
+                :isDetail="true"
+                :disabled="isDisabledIn"
+                :placeholder="'请选择仓库'"
+                :isRelation="true"
+                :companyCode="stock_in_code"
+                :names="''"
+                @searchChange="selectStockIn"
+              />
+            </el-form-item>
+          </el-col>
+        </el-row>
+
+        <el-form-item
+          label="商品"
+          prop="product_go"
+          :size="'mini'"
+          class="product_go"
         >
-          <!-- 出库供应商 -->
-          <el-form-item label="出库供应商名称" prop="supplier_code">
-            <search-supplier
-              style="width: calc(100% - 150px)"
-              :value="ruleForm.supplier_code"
-              :placeholder="'请选择供应商'"
-              @searchChange="selectSupplier"
-            />
-          </el-form-item>
-          <!-- 出库仓库 -->
-          <el-form-item label="出库仓库名称" prop="stock_code">
-            <search-stock
-              style="width: calc(100% - 150px)"
-              :value="ruleForm.stock_code"
-              :isDetail="true"
-              :disabled="isDisabled"
-              :placeholder="'请选择出口仓库'"
-              :isRelation="true"
-              :companyCode="supplier_code"
-              :names="''"
-              @searchChange="selectStock"
-            />
-          </el-form-item>
-          <!-- 入库供应商 -->
-          <el-form-item label="入库供应商名称" prop="supplier_in_code">
-            <search-supplier
-              style="width: calc(100% - 150px)"
-              :value="ruleForm.supplier_in_code"
-              :placeholder="'请选择供应商'"
-              @searchChange="selectSupplierIn"
-            />
-          </el-form-item>
-          <!-- 入库仓库 -->
-          <el-form-item label="入库仓库名称" prop="stock_in_code">
-            <search-stock
-              style="width: calc(100% - 150px)"
-              :value="ruleForm.stock_in_code"
-              :isDetail="true"
-              :disabled="isDisabledIn"
-              :placeholder="'请选择入口仓库'"
-              :isRelation="true"
-              :companyCode="stock_in_code"
-              :names="''"
-              @searchChange="selectStockIn"
-            />
-          </el-form-item>
-          <el-form-item label="出库商品" prop="tableData">
-            <el-table :data="tableData" border :size="'mini'">
-              <el-table-column
-                fixed
-                prop="date"
-                :label="item.label"
-                v-for="(item, index) in columns"
-                :key="index"
+          <el-row>
+            <el-col :span="24" style="padding: 0 0 10px 0">
+              <el-button
+                :size="'mini'"
+                type="primary"
+                class="fr"
+                @click="openGoodsModel"
+                >添加商品</el-button
+              ></el-col
+            >
+            <el-col :span="24">
+              <!-- row-key="key" -->
+              <el-table
+                :data="ruleForm.product_go"
+                border
+                :size="'mini'"
+                max-height="400px"
               >
-              </el-table-column>
-              <el-table-column fixed="right" label="操作" width="100">
-                <template slot-scope="scope">
-                  <el-button
-                    @click.native.prevent="deleteRow(scope.$index, tableData)"
-                    type="text"
-                    size="small"
-                    >删除</el-button
-                  >
-                </template>
-              </el-table-column>
-            </el-table>
-          </el-form-item>
-          isDisabled:{{ isDisabled }}-----isDetail:{{ isDetail }}---id:{{ id }}
-        </el-form>
-      </el-col>
-      <el-col :span="24" style="text-align: right">
-        <el-button type="primary" @click="submitForm" v-if="!isDetail"
-          >保 存
-        </el-button>
-        <el-button @click="closeModel">{{
-          isDetail ? "关 闭" : "取 消"
-        }}</el-button>
-      </el-col>
-    </el-row>
-    <!-- <search-good-modal
-      :show-model="showGoodsModel"
-      @cancel="showGoodsModel = false"
-      @resultList="addGoodsRes"
-    /> -->
-  </div>
+                <el-table-column
+                  show-overflow-tooltip
+                  :prop="item.prop"
+                  :label="item.label"
+                  :width="item.width"
+                  :min-width="item.minWidth"
+                  v-for="(item, index) in columns"
+                  :key="item.prop + index"
+                >
+                  <template slot-scope="scope">
+                    <el-form-item
+                      :prop="'list.' + scope.$index + '.' + scope.row.id"
+                      :size="'mini'"
+                    >
+                      <el-input
+                        :size="'mini'"
+                        v-model="scope.row[item.prop]"
+                        v-if="scope.row.edit && item.prop === 'allot_num'"
+                      ></el-input>
+                      <span v-else>{{ scope.row[item.prop] }}</span>
+                    </el-form-item>
+                  </template>
+                </el-table-column>
+                <el-table-column fixed="right" label="操作" width="80">
+                  <template slot-scope="scope">
+                    <el-tooltip
+                      effect="dark"
+                      content="编辑"
+                      v-if="!scope.row.edit"
+                      placement="top"
+                    >
+                      <i
+                        class="el-icon-edit tb-icon"
+                        @click="editRow(scope.$index)"
+                      ></i>
+                    </el-tooltip>
+
+                    <el-tooltip
+                      effect="dark"
+                      content="保存"
+                      v-if="scope.row.edit"
+                      placement="top"
+                    >
+                      <i
+                        class="el-icon-circle-check tb-icon"
+                        @click="checkRow(scope.$index)"
+                      ></i>
+                    </el-tooltip>
+
+                    <el-tooltip effect="dark" content="删除" placement="top">
+                      <i
+                        class="el-icon-delete tb-icon"
+                        @click="deleteRow(scope.$index, ruleForm.product_go)"
+                      ></i>
+                    </el-tooltip>
+                  </template>
+                </el-table-column>
+              </el-table>
+            </el-col>
+          </el-row>
+        </el-form-item>
+      </el-form>
+    </el-col>
+    <el-col :span="24" style="text-align: right">
+      <el-button type="primary" @click="submitForm" v-if="!isDetail"
+        >保 存
+      </el-button>
+      <el-button @click="closeModel">{{
+        isDetail ? "关 闭" : "取 消"
+      }}</el-button>
+    </el-col>
+    <el-col :span="24">
+      <search-stock-good-modal
+        :show-model="showGoodsModel"
+        :code="stockCode"
+        @cancel="showGoodsModel = false"
+        @searchChange="addGoodsRes"
+      />
+    </el-col>
+  </el-row>
 </template>
    <script>
 import asyncRequest from "@/apis/service/stock/allot";
@@ -106,6 +171,7 @@ export default {
   mixins: [resToken],
   data() {
     return {
+      showGoodsModel: false,
       id: "",
       supplier_code: "",
       stock_in_code: "",
@@ -115,13 +181,11 @@ export default {
       title: "新建调拨申请",
       showModelThis: this.showModel,
       ruleForm: {
-        supplier_code: [], //出库供应商名称
-        stock_code: [], //出库仓库名称
-        supplier_in_code: [], //入库供应商名称
-        stock_in_code: [], //入库仓库名称
-        product_go: [], //出库商品选择
-        product_type_code: "", //商品属性code
-        status: "", //审核状态
+        supplier_code: [], //出库供应商code
+        stock_code: [], //出库仓库code
+        supplier_in_code: [], //入库供应商code
+        stock_in_code: [], //入库仓库code
+        product_go: [], //出库商品
       },
       rulesThis: this.rules,
       rules: {
@@ -168,52 +232,45 @@ export default {
       },
       columns: [
         {
-          prop: "product_sn",
-          label: "商品编号",
+          prop: "good_code",
+          label: "商品编码",
+          width: "150",
         },
         {
-          prop: "product_name",
+          prop: "good_name",
           label: "商品名称",
+          minWidth: "170",
         },
         {
-          prop: "product_num",
-          label: "总数量",
+          prop: "usable_stock",
+          label: "可用库存数",
+          width: "110",
         },
-      ],
-      tableData: [
         {
-          date: "2016-05-02",
-          name: "王小虎",
-          province: "上海",
-          city: "普陀区",
-          address: "上海市普陀区金沙江路 1518 弄",
-          zip: 200333,
+          prop: "allot_num",
+          label: "调拨数量",
+          width: "130",
+        },
+
+        {
+          prop: "unit",
+          label: "单位",
+          width: "45",
         },
         {
-          date: "2016-05-04",
-          name: "王小虎",
-          province: "上海",
-          city: "普陀区",
-          address: "上海市普陀区金沙江路 1517 弄",
-          zip: 200333,
+          prop: "color",
+          label: "商品颜色",
         },
         {
-          date: "2016-05-01",
-          name: "王小虎",
-          province: "上海",
-          city: "普陀区",
-          address: "上海市普陀区金沙江路 1519 弄",
-          zip: 200333,
+          prop: "material",
+          label: "商品材质",
         },
         {
-          date: "2016-05-03",
-          name: "王小虎",
-          province: "上海",
-          city: "普陀区",
-          address: "上海市普陀区金沙江路 1516 弄",
-          zip: 200333,
+          prop: "brand",
+          label: "品牌",
         },
       ],
+      tableData: [],
     };
   },
   watch: {
@@ -232,7 +289,7 @@ export default {
   mounted() {
     console.log("asd");
     this.id = this.$route.query.id;
-    this.getValue();
+    // this.getValue();
     this.initForm();
   },
   methods: {
@@ -252,10 +309,16 @@ export default {
       //   console.log(index, rows);
       rows.splice(index, 1);
     },
-    // 通知弹窗关闭
     closeModel() {
       this.$emit("closeModel");
     },
+    openGoodsModel() {
+      if (this.ruleForm.stock_code.length === 0) {
+        this.$message.warning("请选择出库仓库!");
+        return;
+      }
+      this.showGoodsModel = true;
+    },
 
     async initForm() {
       this.loading = true;
@@ -294,18 +357,12 @@ export default {
           this.$refs.ruleForm.resetFields();
           this.$refs.ruleForm.clearValidate();
           this.ruleForm = {
-            stock_code: [], //出库仓库编码
-            supplier_code: [], //出库供应商编码
-            supplier_in_code: [], //入库供应商编码
-            stock_in_code: [], //入库仓库编码
+            supplier_code: [], //出库供应商code
+            stock_code: [], //出库仓库code
+            supplier_in_code: [], //入库供应商code
+            stock_in_code: [], //入库仓库code
             product_go: [], //出库商品
-            product_type_code: "", //商品属性code
-            status: "", //审核状态
           };
-          if (this.id === "add" || this.isDetail) {
-            // this.rules.username[0].required = false;
-            console.log("当前是add或者 this.isDetail是true");
-          }
         }
       });
     },
@@ -313,6 +370,10 @@ export default {
     async submitForm() {
       await this.$refs.ruleForm.validate(async (valid) => {
         if (valid) {
+          if (this.stockCode == this.stock_in_code) {
+            this.$message.warning("出入库仓库不能相同!");
+            return;
+          }
           this.loading = true;
           //   const { username, name, mobile, email, role_id, status } = JSON.parse(
           //     JSON.stringify(this.ruleForm)
@@ -334,7 +395,7 @@ export default {
               },
             ],
           };
-          console.log(model);
+          // console.log(model);
           let res = {};
           if (this.id === "add") {
             delete model["id"];
@@ -363,16 +424,50 @@ export default {
         }
       });
     },
-
+    //保存某一行
+    checkRow(rowIndex) {
+      const { usable_stock, allot_num } = this.ruleForm.product_go[rowIndex];
+      let num = allot_num === "" ? "0" : allot_num;
+      if (allot_num === "0") {
+        this.$message.warning("调拨数量不能为0!");
+        return;
+      }
+      if (allot_num === "") {
+        this.$message.warning("调拨数量不能为空!");
+        return;
+      }
+      if (parseInt(num) > parseInt(usable_stock)) {
+        this.$message.warning("调拨数量不大于可用库存数!");
+        return;
+      }
+      this.ruleForm.product_go[rowIndex].edit = false;
+    },
+    //编辑某一行
+    editRow(rowIndex) {
+      let index = this.ruleForm.product_go.findIndex((v) => v.edit);
+      if (index !== -1) {
+        this.$message.warning("请保存其他行!");
+        return;
+      } else {
+        this.ruleForm.product_go[rowIndex].edit = true;
+      }
+      console.log(index);
+    },
     // 执行点击商品名称的抛出事件
     addGoodsRes(e) {
-      console.log(e);
-
-      let { good_code, good_name, type_code } = e[0];
-      // this.ruleForm.goods_name = good_name;
-      // this.ruleForm.good_type_code = type_code;
-      // this.ruleForm.good_code = good_code;
-      // this.$refs.ruleForm.validateField("goods_name");
+      let oldList = JSON.parse(JSON.stringify(this.ruleForm.product_go)),
+        addList = JSON.parse(JSON.stringify(e)),
+        newList = [].concat(...oldList);
+      addList.forEach((v1, index) => {
+        let oldindex = oldList.findIndex((v2) => v1.good_code === v2.good_code);
+        if (oldindex === -1) {
+          addList[index].allot_num = addList[index].usable_stock;
+          addList[index].edit = false;
+          newList.push(addList[index]);
+        }
+      });
+      this.ruleForm.product_go = [].concat(...newList);
+      this.$refs.ruleForm.validateField("product_go");
     },
 
     // 选择出库仓库
@@ -380,13 +475,6 @@ export default {
       if (e && e.id) {
         this.ruleForm.stock_code = [e.code];
         this.stockCode = e.code;
-        if (this.stockCode == this.stock_in_code) {
-          this.$message({
-            message: "出库供应商仓库不能和入库供应商仓库相同",
-            type: "warning",
-          });
-          return;
-        }
       } else {
         this.ruleForm.stockCode = [];
         this.stockCode = "";
@@ -439,4 +527,24 @@ export default {
 };
 </script>
 
+
+<style lang="scss" scoped>
+.allot {
+  .label-title-model {
+    line-height: 30px;
+    width: 100%;
+    color: #909399;
+    font-weight: bold;
+    font-size: 15px;
+    padding-bottom: 12px;
+    text-align: center;
+  }
+  .product_go {
+    .el-form-item--mini.el-form-item {
+      margin: 0 !important;
+    }
+  }
+}
+</style>
+
    

+ 10 - 43
src/views/stock/allot/index.vue

@@ -133,7 +133,7 @@
           >
             <i
               class="el-icon-view tb-icon"
-              @click="handleClick(scope.row.id)"
+              @click="routeGoto('allotFlow',{id:scope.row.id})"
             ></i>
           </el-tooltip>
         </template>
@@ -236,6 +236,7 @@ export default {
       }
       if (this.parmValue.start !== "" && this.parmValue.end !== "") {
         this.parmValue.page = 1;
+        this.pageInfo.curr = 1;
         await this.searchList();
       }
     },
@@ -269,20 +270,16 @@ export default {
       this.modelId = id;
       this.isDetail = isDetail;
     },
-    // 点击详情按钮
-    handleClick(id) {
-      window.vm.$router.push({
-        path: "allotFlow",
-        query: {
-          id,
-        },
-      });
-    },
     // 获取调拨列表
     async searchList() {
+      if (
+        (this.parmValue.start !== "" && this.parmValue.end === "") ||
+        (this.parmValue.start === "" && this.parmValue.end !== "")
+      ) {
+        this.$message.warning("时间区间不完整!");
+        return;
+      }
       this.loading = true;
-      console.log(this.parmValue);
-
       const res = await asyncRequest.list(this.parmValue);
       if (res && res.code === 0 && res.data) {
         this.tableData = res.data.list;
@@ -296,37 +293,7 @@ export default {
       this.loading = false;
     },
 
-    async statusConfirm(id, status) {
-      // let str = status === "1" ? "禁用" : "启用";
-      // await this.$confirm("确定要改为" + str + "?", {
-      //   confirmButtonText: "确定",
-      //   cancelButtonText: "取消",
-      //   type: "warning",
-      // })
-      //   .then(async () => {
-      //     this.loading = true;
-      //     const model = {
-      //       id: id,
-      //       status: status === "1" ? "0" : "1",
-      //     };
-      //     const res = await asyncRequest.status(model);
-      //     if (res && res.code === 0) {
-      //       this.loading = false;
-      //       this.$notify.success({
-      //         title: "状态修改成功!",
-      //         message: "",
-      //       });
-      //       await this.searchList();
-      //     } else if (res && res.code >= 100 && res.code <= 104) {
-      //       await this.logout();
-      //     } else {
-      //       this.$message.warning(res.message);
-      //     }
-      //   })
-      //   .catch(() => {
-      //     console.log("取消");
-      //   });
-    },
+   
   },
 };
 </script>