Browse Source

必填校验

jbb 2 years ago
parent
commit
fe4614f345
2 changed files with 201 additions and 65 deletions
  1. 107 38
      src/views/oa/modules/SyCarryModal.vue
  2. 94 27
      src/views/oa/modules/SyCottonYarnModal.vue

+ 107 - 38
src/views/oa/modules/SyCarryModal.vue

@@ -8,6 +8,7 @@
     :getContainer ='()=>$refs.replyModal'
     @ok="handleOk"
     @cancel="handleCancel"
+    destroyOnClose
    >
     <div class="table-page-search-wrapper">
       <a-form-model layout="inline" ref="form" :model="formState" :rules="validatorRules">
@@ -18,12 +19,12 @@
               </a-form-model-item>
             </a-col>
             <a-col :md="8" :sm="8">
-              <a-form-model-item label="名称"  prop="userId">
+              <a-form-model-item label="名称"  prop="name">
                 <a-input placeholder="请输入名称" v-model="formState.name"/>
               </a-form-model-item>
            </a-col>
             <a-col :md="8" :sm="8">
-              <a-form-model-item label="合计"  prop="code">
+              <a-form-model-item label="合计"  prop="totalNum">
                  <a-input placeholder="请输入" v-model="formState.totalNum" readOnly/>
                </a-form-model-item>
             </a-col>
@@ -74,6 +75,30 @@
         :scroll="{x: 1800,y:300 }"
         :pagination="false"
       >
+         <!-- 表头--日期 -->
+          <span slot="orderDateTitle" class="form-table-heard">
+             日期
+          </span>
+          <!-- 表头--总件数 -->
+          <span slot="allNumTitle" class="form-table-heard">
+             总件数
+          </span>
+           <!-- 表头--集装箱号 -->
+          <span slot="containerNoTitle" class="form-table-heard">
+             集装箱号
+          </span>
+           <!-- 表头--发票号 -->
+          <span slot="invoiceNoTitle" class="form-table-heard">
+             发票号
+          </span>
+           <!-- 表头--价格 -->
+          <span slot="priceTitle" class="form-table-heard">
+             价格
+          </span>
+           <!-- 表头--计划员 -->
+          <span slot="jhyByDataTitle" class="form-table-heard">
+             计划员
+          </span>
         <!-- 日期 -->
          <span slot="orderDate" slot-scope="text, record,index">
                 <a-date-picker
@@ -180,24 +205,31 @@
         activeKey: 'syCarryB',
         jhyNameOption:[],
         dateFormat: 'YYYY-MM-DD',
+        passVerification:'yes',
+         validatorRules: {
+              name:[{required: true, message: '名称不能为空!'}],
+              code:[{required: true, message: '编号不能为空!'}],
+        },
         // 搬运装卸费用-搬运工对账单-子表
         syCarryBTable: {
           loading: false,
           dataSource: [],
           columns: [
             {
-            title: '日期',
+            // title: '日期',
             align: "center",
             dataIndex: 'orderDate',
             width: '9%',
             scopedSlots: { customRender: 'orderDate' },
+            slots:{title:'orderDateTitle'}
           },
            {
-            title: '总件数',
+            // title: '总件数',
             dataIndex: 'allNum',
             width: '9%',
              scopedSlots: { customRender: 'allNum' },
-             className: 'replacecolor'
+             className: 'replacecolor',
+            slots:{title:'allNumTitle'}
            },
            {
             title: '明细',
@@ -216,36 +248,40 @@
              className: 'replacecolor'
            },
            {
-            title: '集装箱号',
+            // title: '集装箱号',
             dataIndex: 'containerNo',
            width: '9%',
              ellipsis: true,
              scopedSlots: { customRender: 'containerNo' },
-             className: 'replacecolor'
+             className: 'replacecolor',
+            slots:{title:'containerNoTitle'}
            },
            {
-            title: '发票号',
+            // title: '发票号',
             dataIndex: 'invoiceNo',
-           width: '9%',
+            width: '9%',
              ellipsis: true,
              scopedSlots: { customRender: 'invoiceNo' },
-             className: 'replacecolor'
+             className: 'replacecolor',
+            slots:{title:'invoiceNoTitle'}
            },
            {
-            title: '价格',
-            dataIndex: 'price',
-           width: '9%',
+            // title: '价格',
+             dataIndex: 'price',
+             width: '9%',
              ellipsis: true,
              scopedSlots: { customRender: 'price' },
-             className: 'replacecolor'
+             className: 'replacecolor',
+            slots:{title:'priceTitle'}
            },
            {
-            title: '计划员',
+            // title: '计划员',
             dataIndex: 'jhyByData',
              width: '9%',
              ellipsis: true,
              scopedSlots: { customRender: 'jhyByData' },
-             className: 'replacecolor'
+             className: 'replacecolor',
+            slots:{title:'jhyByDataTitle'}
            },
            {
             title: '签名',
@@ -398,19 +434,19 @@
       },
       //保存
       handleOk(){
-        var obj = this.formState
-        this.syCarryBTable.dataSource.map(item=>{
-          if(item.orderDate!==''&&item.orderDate){
-             item.orderDate = moment(item.orderDate).format('YYYY-MM-DD HH:mm:ss');
-          }
-          // if(!item.name){
-          //   item.name = ''
-          // }
-        })
-        obj.syCarryBList = this.syCarryBTable.dataSource
-        if(this.defultMethods == 'add'){
-          subimtList(obj).then(res => {
-                    if (res.success) {
+         this.$refs.form.validate(async valid => {
+         if(valid){
+            var obj = this.formState
+            this.syCarryBTable.dataSource.map(item=>{
+              if(item.orderDate!==''&&item.orderDate){
+                item.orderDate = moment(item.orderDate).format('YYYY-MM-DD HH:mm:ss');
+              }
+            })
+            obj.syCarryBList = this.syCarryBTable.dataSource
+            await this.judageTablez(obj.syCarryBList)
+            if(this.defultMethods == 'add' && this.passVerification == 'yes'){
+                subimtList(obj).then(res => {
+                     if (res.success) {
                       this.$message.success('新增成功')
                       this.handleCancel()
                       this.$emit('close')
@@ -418,18 +454,47 @@
                        this.$message.error(res.message);
                     }
                 })
+            }else if(this.passVerification == 'yes'){
+                putAction('/oa/syCarry/edit', obj).then((res) => {
+                   if(res.success){
+                      this.$message.success('编辑成功')
+                      this.handleCancel()
+                      this.$emit('close')
+                   }else{
+                       this.$message.warning(res.message)
+                     }
+                 })
+            }
+         }
+         })
+       
+        
+      },
+      judageTablez(data){
+        this.passVerification = 'yes'
+        if(data.length == 0){
+          this.$message.error('请添加子表数据!');
+          this.passVerification = 'no'
         }else{
-          putAction('/oa/syCarry/edit', obj).then((res) => {
-          if(res.success){
-            this.$message.success('编辑成功')
-            this.handleCancel()
-            this.$emit('close')
-          }else{
-            this.$message.warning(res.message)
+          for (var i=0; i<data.length;i++){
+             var tableRow = data[i];
+             var required = [
+              {key:'orderDate',value:'日期'},
+              {key:'allNum',value:'总件数'},
+              {key:'containerNo',value:'集装箱号'},
+              {key:'invoiceNo',value:'发票号'},
+              {key:'price',value:'价格'},
+              {key:'jhyByData',value:'计划员'},
+              ]
+             for(var j=0 ; j<required.length;j++){
+                if(tableRow[required[j].key] == null || tableRow[required[j].key] == "" || tableRow[required[j].key] == undefined){
+                  this.$message.error('第'+(i+1)+'行'+required[j].value+'无值,无法保存');
+                  this.passVerification = 'no'
+                  return
+                }
+             }
           }
-        })
         }
-        
       },
       //关闭
       handleCancel(){
@@ -499,4 +564,8 @@
 /deep/ .ant-table-tbody {
   text-align: center;
 }
+.form-table-heard:before {
+      content: '*';
+      color: red;
+}
 </style>

+ 94 - 27
src/views/oa/modules/SyCottonYarnModal.vue

@@ -8,7 +8,8 @@
     :confirmLoading="confirmLoading"
     :getContainer ='()=>$refs.replyModal'
     @ok="handleOk"
-    @cancel="handleCancel">
+    @cancel="handleCancel"
+    destroyOnClose>
      <div class="table-page-search-wrapper">
       <!-- 主表单区域 -->
        <a-form-model layout="inline" ref="form" :model="formState" :rules="validatorRules">
@@ -19,12 +20,12 @@
               </a-form-model-item>
             </a-col>
             <a-col :md="8" :sm="8">
-              <a-form-model-item label="名称"  prop="userId">
+              <a-form-model-item label="名称"  prop="name">
                 <a-input placeholder="请输入名称" v-model="formState.name"/>
               </a-form-model-item>
            </a-col>
             <a-col :md="8" :sm="8">
-              <a-form-model-item label="合计"  prop="code">
+              <a-form-model-item label="合计"  prop="totalNum">
                  <a-input placeholder="请输入" v-model="formState.totalNum" readOnly/>
                </a-form-model-item>
             </a-col>
@@ -50,6 +51,29 @@
            :scroll="{x: 1800,y:300 }"
            :pagination="false"
           >
+          <!-- 表头--日期 -->
+          <span slot="orderDateTitle" class="form-table-heard">
+             日期
+          </span>
+          <!-- 表头--入库单号 -->
+          <span slot="receiptNoTitle" class="form-table-heard">
+             入库单号
+          </span>
+          <!-- 表头--每吨纱价格 -->
+          <span slot="priceTitle" class="form-table-heard">
+            每吨纱价格
+          </span>
+          <!-- 表头--集装箱号 -->
+          <span slot="containerNoTitle" class="form-table-heard">
+             集装箱号
+          </span>
+           <span slot="reasonTitle" class="form-table-heard">
+             原因
+          </span>
+          <!-- 表头--总价 -->
+          <span slot="totalPriceTitle" class="form-table-heard">
+             总价
+          </span>
           <!-- 日期 -->
            <span slot="orderDate" slot-scope="text, record,index">
                 <a-date-picker
@@ -123,30 +147,35 @@
         // 新增时子表默认添加几行空数据
         addDefaultRowNum: 1,
         validatorRules: {
+              name:[{required: true, message: '名称不能为空!'}],
+              code:[{required: true, message: '编号不能为空!'}],
         },
         refKeys: ['syCottonYarnB', ],
         activeKey: 'syCottonYarnB',
         formState:{},
         defultMethods:'add',
         zhuId:'',
+        passVerification:'yes',
         // 搬运装卸费用-棉纱-子表
         syCottonYarnBTable: {
           loading: false,
           dataSource: [],
           columns: [
             {
-            title: '日期',
+            // title: '日期',
             align: "center",
             dataIndex: 'orderDate',
             width: '9%',
             scopedSlots: { customRender: 'orderDate' },
+            slots:{title:'orderDateTitle'}
           },
           {
-            title: '入库单号',
+            // title: '入库单号',
             align: "center",
             dataIndex: 'receiptNo',
             width: '9%',
             scopedSlots: { customRender: 'receiptNo' },
+            slots:{title:'receiptNoTitle'}
           },
           {
             title: '吨数',
@@ -163,32 +192,36 @@
             scopedSlots: { customRender: 'cabinets' },
           },
           {
-            title: '每吨纱价格',
+            // title: '每吨纱价格',
             align: "center",
             dataIndex: 'price',
             width: '9%',
             scopedSlots: { customRender: 'price' },
+            slots:{title:'priceTitle'}
           },
            {
-            title: '集装箱号',
+            // title: '集装箱号',
             align: "center",
             dataIndex: 'containerNo',
             width: '9%',
             scopedSlots: { customRender: 'containerNo' },
+            slots:{title:'containerNoTitle'}
           },
           {
-            title: '原因',
+            // title: '原因',
             align: "center",
             dataIndex: 'reason',
             width: '9%',
             scopedSlots: { customRender: 'reason' },
+            slots:{title:'reasonTitle'}
           },
           {
-            title: '总价',
+            // title: '总价',
             align: "center",
             dataIndex: 'totalPrice',
             width: '9%',
             scopedSlots: { customRender: 'totalPrice' },
+            slots:{title:'totalPriceTitle'}
           },
           {
             title: '签字',
@@ -286,15 +319,18 @@
       },
        //保存
       handleOk(){
-        var obj = this.formState
-        this.syCottonYarnBTable.dataSource.map(item=>{
-          if(item.orderDate!==''&&item.orderDate){
-             item.orderDate = moment(item.orderDate).format('YYYY-MM-DD HH:mm:ss');
-          }
-        })
-        obj.syCottonYarnBList = this.syCottonYarnBTable.dataSource
-        if(this.defultMethods == 'add'){
-         postAction(this.url.add, obj).then(res => {
+        this.$refs.form.validate(async valid => {
+         if(valid){
+           var obj = this.formState
+           this.syCottonYarnBTable.dataSource.map(item=>{
+             if(item.orderDate!==''&&item.orderDate){
+               item.orderDate = moment(item.orderDate).format('YYYY-MM-DD HH:mm:ss');
+             }
+           })
+           obj.syCottonYarnBList = this.syCottonYarnBTable.dataSource
+           await this.judageTablez(obj.syCottonYarnBList)
+           if(this.defultMethods == 'add' && this.passVerification == 'yes'){
+              postAction(this.url.add, obj).then(res => {
                     if (res.success) {
                       this.$message.success('新增成功')
                       this.handleCancel()
@@ -303,18 +339,45 @@
                        this.$message.error(res.message);
                     }
                 })
-        }else{
-          putAction(this.url.edit, obj).then((res) => {
-          if(res.success){
-            this.$message.success('编辑成功')
-            this.handleCancel()
-            this.$emit('close')
-          }else{
+           }else if(this.passVerification == 'yes'){
+             putAction(this.url.edit, obj).then((res) => {
+             if(res.success){
+             this.$message.success('编辑成功')
+             this.handleCancel()
+             this.$emit('close')
+            }else{
             this.$message.warning(res.message)
+            }  
+            })
+           }
+         }
+         })
+      },
+      judageTablez(data){
+        this.passVerification = 'yes'
+        if(data.length == 0){
+          this.$message.error('请添加子表数据!');
+          this.passVerification = 'no'
+        }else{
+          for (var i=0; i<data.length;i++){
+             var tableRow = data[i];
+             var required = [
+              {key:'orderDate',value:'日期'},
+              {key:'receiptNo',value:'入库单号'},
+              {key:'price',value:'每吨纱价格'},
+              {key:'containerNo',value:'集装箱号'},
+              {key:'reason',value:'原因'},
+              {key:'totalPrice',value:'总价'},
+              ]
+             for(var j=0 ; j<required.length;j++){
+                if(tableRow[required[j].key] == null || tableRow[required[j].key] == "" || tableRow[required[j].key] == undefined){
+                  this.$message.error('第'+(i+1)+'行'+required[j].value+'无值,无法保存');
+                  this.passVerification = 'no'
+                  return
+                }
+             }
           }
-        })
         }
-        
       },
         //关闭
       handleCancel(){
@@ -336,4 +399,8 @@
 /deep/ .td{
   text-align:center;
 }
+.form-table-heard:before {
+      content: '*';
+      color: red;
+}
 </style>