Browse Source

请假类型,单位,时间联动

jbb 2 years ago
parent
commit
d02ac0e886
1 changed files with 51 additions and 16 deletions
  1. 51 16
      src/views/activiti/form/demoForm2.vue

+ 51 - 16
src/views/activiti/form/demoForm2.vue

@@ -435,7 +435,7 @@ export default {
         },
         defualtData(item){
                            if(item[1].label =='today'){
-                               item[0].value =moment(new Date()).format('YYYY-MM-DD')
+                               item[0].value =moment(new Date().toLocaleDateString()).format('YYYY-MM-DD HH:mm')
                                var that = this
                                setTimeout(function(){
                                that.$refs.KFB.setData({[item[0].label]:item[0].value})   
@@ -481,24 +481,54 @@ export default {
                     })   
                })
          },
-        // 表单字段数值发生改变事件
-        handleChange (value, key) {  
-            //改变的表单是主子表类型时
-            if((value instanceof Array) && (key.indexOf('child&')!==-1)){
-                this.tableCalculation(value)
-            }
-            //请假类型与单位
-            if((key == 'leave_category' && value == '1') || (key == 'leave_category' && value == '3')){
-                var that = this
+         specialTerms(value,key){
+            var that = this
+             //请假类型与单位
+            //事假
+            if(key == 'leave_category' && value == '1'){
+                setTimeout(function(){
+                var time1 = that.$refs.KFB.form.getFieldValue('start_date')
+                var time2 = that.$refs.KFB.form.getFieldValue('end_date')
+                var timeC=that.timeDifference(time1,time2,'min') //获取时间差
+                if(timeC>180){
+                    that.$refs.KFB.setData({unit:'2'})
+                    that.$refs.KFB.setData({leave_category:'2'})
+                }else{
+                    that.$refs.KFB.setData({unit:'1'})   
+                }
+                },0)
+            }else if(key == 'leave_category' && value == '3'){  //病假
                 setTimeout(function(){
                  that.$refs.KFB.setData({unit:'1'})   
                 },0)
             }else if(key == 'leave_category'){
-                 var that = this
                 setTimeout(function(){
                     that.$refs.KFB.setData({unit:'2'})   
                 },0)
             }
+            //时间间隔和类型
+            if(key =='start_date' || key =='end_date'){
+                setTimeout(function(){
+                    var time2 = that.$refs.KFB.form.getFieldValue('end_date')
+                    var time1 = that.$refs.KFB.form.getFieldValue('start_date')
+                    var timeC=that.timeDifference(time1,time2,'min')
+                    var lx=that.$refs.KFB.form.getFieldValue('leave_category')
+                     if(timeC>180&&lx=='1'){
+                        that.$refs.KFB.setData({unit:'2'})
+                          that.$refs.KFB.setData({leave_category:'2'})
+                     }
+                },0)
+                
+            }
+         },
+        // 表单字段数值发生改变事件
+        handleChange (value, key) {  
+            //改变的表单是主子表类型时
+            if((value instanceof Array) && (key.indexOf('child&')!==-1)){
+                this.tableCalculation(value)
+            }
+            //特别字段
+            this.specialTerms(value,key)
             //代码赘余,日后维护
             //保存发生改变字段名对应的key 
             var cc ='',
@@ -536,9 +566,9 @@ export default {
                             var state = ''
                             state = event.bn[3].label
                             event.bn[0].value = this.timeDifference(event.bn[1].value,event.bn[2].value,state)
-                            if(event.bn[0].value == 0){
-                                event.bn[0].value = 1
-                            }
+                            // if(event.bn[0].value == 0){
+                            //     event.bn[0].value = 1
+                            // }
                         }
                        }else{
                         if(event.bn[3].label =="+"){
@@ -958,7 +988,7 @@ export default {
               let endTime = (new Date(end).getTime()) / 1000;
                //计算天数
               var timediff = endTime - beginTime;
-              var days = parseInt(timediff / 86400)+1;
+              var days = parseInt(timediff / 86400);
              //计算小时数
              var remain = timediff % 86400 ;
              var hours = parseInt(remain / 3600);
@@ -971,7 +1001,12 @@ export default {
              }else if(state == 'hour'){
                  return days*24+hours+mins/60
              }else if(state == 'day'){
-                  return days+hours/24+mins/60/24
+                 if(start.split(' ').length==1 && end.split(' ').length == 1){
+                      return days+1+hours/24+mins/60/24
+                 }else{
+                     return days+hours/24+mins/60/24
+                 }
+                  
              }else if(state == 'day/hour/min'){
                  return days+'天'+hours+'小时'+mins+'分'
              }else if(state == 'hour/min'){