coys il y a 2 ans
Parent
commit
ad9f33568b

+ 1 - 1
src/config/env.development.js

@@ -2,7 +2,7 @@
 module.exports = {
   title: 'soc-app-dev',
   baseUrl: 'http://localhost:9018', // 项目地址
-  baseApi: '/luowei', // 本地api请求地址,注意:如果你使用了代理,请设置成'/'
+  baseApi: '/jingyuanchao', // 本地api请求地址,注意:如果你使用了代理,请设置成'/'
   APPID: 'xxx',
   APPSECRET: 'xxx',
   $cdn: 'https://www.sunniejs.cn/static'  //静态资源

+ 95 - 44
src/views/menu/training/components/addTraining.vue

@@ -37,7 +37,12 @@
         @click="showStartDate = true"
       />
       <van-popup v-model="showStartDate" position="bottom">
-        <van-datetime-picker v-model="startDateTime" type="datetime" @confirm="onConfirmDate" @cancel="showStartDate = false" />
+        <van-datetime-picker
+          v-model="startDateTime"
+          type="datetime"
+          @confirm="onConfirmDate"
+          @cancel="showStartDate = false"
+        />
       </van-popup>
       <!-- 培训结束时间 -->
       <van-field
@@ -52,7 +57,12 @@
         @click="showEndDate = true"
       />
       <van-popup v-model="showEndDate" position="bottom">
-        <van-datetime-picker v-model="endDateTime" type="datetime" @confirm="onConfirmEndDate" @cancel="showEndDate = false" />
+        <van-datetime-picker
+          v-model="endDateTime"
+          type="datetime"
+          @confirm="onConfirmEndDate"
+          @cancel="showEndDate = false"
+        />
       </van-popup>
       <!-- 培训内容 -->
       <van-field
@@ -78,11 +88,24 @@
       />
 
       <!-- 参与人员 -->
- 
+
       <!-- 必填 -->
-      <CheckPeople ref="checkPeople" :userList="userPeopleList" :organizationId="trainingData.orgId" :isRequired="true" @userList="userListHandler"></CheckPeople>
+      <CheckPeople
+        ref="checkPeople"
+        :userList="userPeopleList"
+        :organizationId="trainingData.orgId"
+        :isRequired="true"
+        @userList="userListHandler"
+      ></CheckPeople>
       <!-- 缺席人员 -->
-      <CheckPeople ref="checkPeople" :userList="lackPeopleList" :inpitLabel="'缺席人员'" :organizationId="trainingData.orgId" :isRequired="false" @userList="lackUserListHandler"></CheckPeople>
+      <CheckPeople
+        ref="checkPeople"
+        :userList="lackPeopleList"
+        :inpitLabel="'缺席人员'"
+        :organizationId="trainingData.orgId"
+        :isRequired="false"
+        @userList="lackUserListHandler"
+      ></CheckPeople>
       <!-- 上传 -->
       <van-field readonly clickable name="uploader" label="上传图片">
         <template #input>
@@ -106,14 +129,14 @@ import { Dialog, Toast } from 'vant'
 export default {
   name: 'SocAppAddTraining',
   components: {
-    NavBar, 
+    NavBar,
     Upload,
     CheckPeople
   },
   data() {
     return {
-      startDateTime:new Date(),
-      endDateTime:new Date(),
+      startDateTime: new Date(),
+      endDateTime: new Date(),
       falg: false, //校验是否通过
       username: '',
       password: '',
@@ -142,32 +165,34 @@ export default {
       let { code, data, msg } = res
       if (code == 200) {
         this.trainingData = data
-        if(!data.taskUserList){
-          data.taskUserList=[]
+        if (!data.taskUserList) {
+          data.taskUserList = []
         }
-        if(!data.imageList){
-          data.imageList=[]
-        }else{
-          data.imageList=[data.imageList]
+        if (!data.imageList) {
+          data.imageList = []
+        } else {
+          data.imageList = [data.imageList]
         }
         Object.assign(this.form, data)
         // checkPeople
-        
-        this.form.taskUserList.map(item=>{
-          if(item.type===1){
-            this.userPeopleList.push(item)
-            return item.userName
-          }
-        }).join(',')
 
-        this.form.taskUserList.map(item=>{
-          if(item.type===2){
-            this.lackPeopleList.push(item)
-            return item.userName
-          }
-        }).join(',')
-       
-        
+        this.form.taskUserList
+          .map(item => {
+            if (item.type === 1) {
+              this.userPeopleList.push(item)
+              return item.userName
+            }
+          })
+          .join(',')
+
+        this.form.taskUserList
+          .map(item => {
+            if (item.type === 2) {
+              this.lackPeopleList.push(item)
+              return item.userName
+            }
+          })
+          .join(',')
       }
     })
   },
@@ -214,14 +239,13 @@ export default {
       this.showEndDate = false
     },
     userListHandler(list) {
-      
       list.forEach(item => {
         ;(item.type = 1), (item.userId = item.id)
         item.userName = item.username
         item.name = item.userName
         delete item.username
       })
-      
+
       this.userPeopleList = list
     },
     lackUserListHandler(list) {
@@ -243,22 +267,49 @@ export default {
 
       let endDate = JSON.parse(JSON.stringify(this.form.trainingEndDateTime))
       endDate = Date.parse(new Date(endDate))
-      if(startDate>endDate){
+      if (startDate > endDate) {
         Toast('开始时间不能大于结束时间')
         this.falg = true
         return
       }
 
-      if (this.form.imageList.length==0) {
+      if (this.form.imageList.length == 0) {
         Toast('上传图片不能为空')
         this.falg = true
         return
       }
-      if (this.userPeopleList.length==0) {
+      if (this.userPeopleList.length == 0) {
         Toast('参与人员不能为空!')
         this.falg = true
         return
       }
+      if (this.userPeopleList.length > this.lackPeopleList.length) {
+        let isTrue = false
+        this.userPeopleList.forEach(item => {
+          this.lackPeopleList.forEach(i => {
+            if (item.userId == i.userId) {
+              isTrue = true
+            }
+          })
+        })
+        if (isTrue) {
+          Toast('参与人员与缺席人员存在同一个人请修正!')
+          this.falg = true
+        }
+      } else {
+        let isTrue = false
+        this.lackPeopleList.forEach(item => {
+          this.userPeopleList.forEach(i => {
+            if (item.userId == i.userId) {
+              isTrue = true
+            }
+          })
+        })
+        if (isTrue) {
+          Toast('参与人员与缺席人员存在同一个人请修正!')
+          this.falg = true
+        }
+      }
     },
     //表单提交校验
     submitHandler(type) {
@@ -267,9 +318,10 @@ export default {
         message: `是否${type === 2 ? '提交' : '保存'}培训数据?`
       })
         .then(() => {
-          this.beforSubmitV()//校验
-          if (!this.falg) {//校验通过触发
-            
+          this.beforSubmitV() //校验
+          if (!this.falg) {
+            //校验通过触发
+
             if (type === 1) {
               //type 1保存2提交
               this.submitHandlerConfirm(type)
@@ -287,24 +339,23 @@ export default {
     // 表单提交
     submitHandlerConfirm(type) {
       let obj = JSON.parse(JSON.stringify(this.form))
-      
+
       obj.imageList = obj.imageList.map(item => item.imgPath).join(',')
-      obj.taskUserList=[]
+      obj.taskUserList = []
       obj.taskUserList.push(...this.userPeopleList, ...this.lackPeopleList)
-      
+
       edittrainingInfo({
         id: this.trainingData.id,
         type: this.trainingData.type,
         submitType: type,
-      
+
         ...obj
       }).then(res => {
         let { code, msg } = res
-        if(code==200){
-
+        if (code == 200) {
           Toast('登记成功')
           this.$router.push('/training')
-        }else{
+        } else {
           Toast(msg)
         }
       })