Browse Source

出差管理提交

duy 2 years ago
parent
commit
9b56c31a3a

+ 9 - 1
src/api/modules/attendance/business-trip.js

@@ -41,12 +41,20 @@ export default {
             params: form
         }, msg);
    },
+     //出差草稿信息详情
+  async draftDetail(form, msg = true) {
+    return httpApi({
+        url: '/api/blade-control/attendance/trip/draft/detail',
+        method: 'get',
+        params: form
+    }, msg);
+},
      //出差信息上报撤销
   async cancel(form, msg = true) {
     return httpApi({
         url: '/api/blade-control/attendance/trip/cancel',
         method: 'post',
-        data: form
+        params: form
     }, msg);
   }  ,
 }

+ 59 - 15
src/views/attendance/business-trip/index.vue

@@ -3,8 +3,8 @@
   <HcCard>
     <template #header>
       <div class="w-36 ml-2">
-                <el-select v-model="searchForm.peoplename" block clearable placeholder="项目名称" size="large">
-                    <el-option v-for="item in peopleoption" :label="item.name" :value="item.key"/>
+                <el-select v-model="searchForm.projectId" block clearable placeholder="项目名称" size="large">
+                    <el-option v-for="item in projectType" :label="item.projectName" :value="item.projectId"/>
                 </el-select>
       </div>
      
@@ -24,7 +24,7 @@
     <template  #extra>
         <el-button type="warning" @click="toImportTempClick" size="large">
           <HcIcon name="delete-bin-2"/>
-                    <span>草稿箱</span>
+                    <span>草稿箱{{draftNum > 0 ? `(${draftNum})` : ''}}</span>
          </el-button>
          <el-button type="primary" size="large" class="ml-2" @click="addinfoClick">
                     <HcIcon name="add"/>
@@ -33,11 +33,21 @@
     </template>
     <HcTable :column="tableColumn" :datas="tableData" :loading="tableLoading">
       <template #tripDesc="{row}">
-                <span class="text-blue text-hover" @click="rowClick(row)">{{row.tripDesc}}</span>
+                <span class="text-blue text-hover">{{row.tripDesc}}</span>
         </template>
-      <template #action="{row, index}">
+      <!-- <template #action="{row, index}">
          <el-button hc-btn type="primary" size="small">撤销</el-button>
-       </template>
+       </template> -->
+       <template #action="{row,index}">
+                <el-popconfirm title="是否确认撤销?" hide-icon @confirm="rowCancel(row)">
+                    <template #reference>
+                        <el-button size="small" type="primary"
+                                   :disabled="row.status !== 1"
+                                   :loading="row.isCancelLoading"
+                        >撤销</el-button>
+                    </template>
+                </el-popconfirm>
+        </template>
       </HcTable>
       <template #action>
             <HcPages :pages="searchForm" @change="pageChange"></HcPages>
@@ -63,13 +73,16 @@ import {ref, watch,onMounted} from  'vue'
 import dayjs from "dayjs"
 import 'dayjs/locale/zh-cn'
 import {useRouter} from 'vue-router'
-import {getTokenHeader} from "~src/api/request/header";
+
 import businessApi from '~api/attendance/business-trip.js';
 import {getArrValue} from "js-fast-way"
 import {getProjectList, getDictInfo} from "~api/other";
+import {delMessage} from "~uti/tools";
 const router = useRouter()
 onMounted(()=>{
+  getProjectData()
   getTableData()
+  getdraftTableData()
 })
 
 const tableColumn = [
@@ -79,7 +92,7 @@ const tableColumn = [
     {key: 'durationAll', name: '出差天数'},
     {key: 'fellowTravelerUserNames', name: '同行人'},
     {key: 'approvalResultName', name: '审批结果'},
-    {key: 'approvalStatusName	', name: '审批状态'},
+    {key: 'approvalStatusName', name: '审批状态'},
     {key: 'createName', name: '创建人'},
     {key: 'createTime', name: '创建时间'},
     {key: 'action', name: '操作'  }
@@ -95,11 +108,23 @@ const searchForm = ref({
   
     current: 1, size: 20, total: 0
 })
-const peopleoption=ref([
-    {name: '张三', key: '1'},
-    {name: '李四', key: '2'},
+//项目类型
+const projectType = ref([
+
 ])
 
+//获取项目数据
+
+const getProjectData = async () => {
+    const {error, code, data} = await getProjectList()
+    //判断状态
+    if (!error && code === 200) {
+        projectType.value = getArrValue(data)
+    } else {
+        projectType.value = []
+    }
+}
+
 //分页被点击
 const pageChange = ({current, size}) => {
     searchForm.value.current = current
@@ -112,7 +137,7 @@ const getTableData = async() => {
     const {error, code, data} = await businessApi.getPage(searchForm.value)
     tableLoading.value = false
     if (!error && code === 200) {
-        tableData.value = getArrValue(data)
+        tableData.value = getArrValue(data['records'])
         searchForm.value.total = data['total'] || 0
     } else {
         tableData.value = []
@@ -133,7 +158,9 @@ const defaultTime = ref([
   new Date(2000, 1, 1, 0, 0, 0),
   new Date(2000, 2, 1, 23, 59, 59),
 ])
-//导入数据弹窗
+//草稿箱
+//草稿箱数据
+const draftNum = ref(0)
 const importModal=ref(false)
 const importModalClose=()=>{
   importModal.value=false
@@ -156,6 +183,7 @@ const getdraftTableData = async() => {
     draftLoad.value = false
     if (!error && code === 200) {
       drafttableData.value = getArrValue(data)
+      draftNum.value=getArrValue(data).length
      
     } else {
       drafttableData.value = []
@@ -191,8 +219,8 @@ const editinfoClick=(row)=>{
   router.push({
         name: 'attendance-business-trip-info',
         query: {
-          id: row.id,
-            type: 'edit'
+          id: row.emdraftIds,
+          type: 'draft'
         }
     })
 }
@@ -206,6 +234,22 @@ const rowClick = (row) => {
         }
     })
 }
+
+//撤销
+const rowCancel = async (row) => {
+    row.isCancelLoading = true
+    const {error, code, msg} = await businessApi.cancel({
+        id: row.id
+    })
+    //判断状态
+    row.isCancelLoading = false
+    if (!error && code === 200) {
+        window.$message?.success(msg)
+        getTableData().then()
+    } else {
+        window.$message?.error(msg)
+    }
+}
 </script>
 <style lang='scss' scoped>
 </style>

+ 151 - 10
src/views/attendance/business-trip/info.vue

@@ -141,11 +141,11 @@
                     </el-scrollbar>
                 </div>
                 <div class="action">
-                    <el-button type="warning" hc-btn @clicl="saveClick" :loading="saveLoading">
+                    <el-button type="warning" hc-btn @click="tempDraftData" :loading="tempLoading">
                         <HcIcon name="draft"/>
                         <span>暂存草稿</span>
                     </el-button>
-                    <el-button type="primary" hc-btn @click="saveClick">
+                    <el-button type="primary" hc-btn @click="saveClick" :loading="saveLoading">
                         <HcIcon name="check-double"/>
                         <span>提交出差申请</span>
                     </el-button>
@@ -175,6 +175,7 @@ import {ref, onActivated} from "vue";
 import {useRoute, useRouter} from 'vue-router'
 import {getProjectList, getDictInfo} from "~api/other";
 import {arrIndex, deepClone, formValidate, getArrValue} from "js-fast-way";
+import businessApi from '~api/attendance/business-trip.js';
 
 const router = useRouter()
 const useRoutes = useRoute()
@@ -189,11 +190,79 @@ onActivated(() => {
   dataId.value = useRoutes?.query?.id ?? ''
   getTrafficType()
   getProjectData()
+  getDetailsData()
 })
-const journeyList=ref([
-  {},
+const getDetailsData = async () => {
+    if (dataType.value === 'view') {
+        //预览详情
+        let newDetails = {}, newDetails1 = {}
+        const {error, code, data, msg} = await businessApi.detail({
+            id: dataId.value
+        })
+        //判断状态
+        if (!error && code === 200) {
+            const res = getObjValue(data)
+            //基础数据
+            Object.keys(detailsObj).forEach(key => {
+                newDetails[key] = res[key]
+            })
+            //明细数据
+            Object.keys(detailsObj1).forEach(key => {
+                newDetails1[key] = res[key]
+            })
+            newDetails1.id = res?.id
+         
+            newDetails.details = [newDetails1]
+        } else {
+            newDetails = detailsObj
+            newDetails.details = [detailsObj1]
+      
+            window.$message?.error(msg)
+        }
+        detailsData.value = newDetails
+    } else if (dataType.value === 'draft') {
+        //草稿详情
+        const {error, code, data} = await businessApi.draftDetail({
+            eMDraftIds: dataId.value
+        })
+        //判断状态
+        const res = getArrValue(data)
+        if (!error && code === 200 && res.length > 0) {
+            let newDetails = {}, newDetailsArr = []
+            res.forEach((item, index) => {
+                //基础数据
+                if (index === 0) {
+                    Object.keys(detailsObj).forEach(key => {
+                        newDetails[key] = item[key]
+                    })
+                }
+                //明细数据
+                let newDetails1 = {}
+                Object.keys(detailsObj1).forEach(key => {
+                    newDetails1[key] = item[key]
+                })
+                newDetails1.id = item?.id
+                newDetailsArr.push(newDetails1)
+              
+            })
+            newDetails.journeyList = newDetailsArr
+            console.log(formModel.value,'formModel.value');
+            formModel.value = newDetails
+        } else {
+          
+            formModel.value = {
+                ...detailsObj,
+                details: [detailsObj1]
+            }
+        }
+    } else {
 
-])
+        formModel.value = {
+            ...detailsObj,
+            details: [detailsObj1]
+        }
+    }
+}
 //行程表单
 const formItemRules = {
     isSingletonType: {
@@ -265,8 +334,8 @@ const delJourney=(item,index)=>{
 }
 //单程往返
 const wayType = ref([
-  {name: '单程', key: '1'},
-  {name: '往返', key: '2'},
+  {name: '单程', key: 1},
+  {name: '往返', key: 2},
  
 ])
 //交通工具
@@ -398,14 +467,65 @@ const tableBudgetData = ref([
     {id: 3, key1: 'xxxx'},
     {id: 4, key1: 'xxxx'},
 ])
+//行程
+const detailsObj1 = {
+    trafficType: '',             // 交通工具
+    isSingletonType: '',       // 单程往返
+    startCity: '',    // 出发城市
+    endCity: '',        //目的城市
+    startDate: null,           // 开始时间
+    endDate: null,           // 结束时间
+    duration: null,           // 时长
+    //details: [detailsObj1],
+}
+//基础详情
+const detailsObj = {
+  
+    tripDesc: '',             // 出差事由
+    durationAll: 0,       // 出差天数
+    fellowTravelerUserIds: '',    // 同行人
+    remarks: '',        //出差备注
+    projectId: '',     // 所属项目
+    submitStatus: null,           // 审提交状态 1=暂存 2=提交审批
+    journeyList: [detailsObj1],
+}
+
+//处理表单数据
+const getFormData = (submitStatus = 1) => {
+    const res = deepClone(formModel.value)
+  
+    const ccUserList = [{userId: ''}]           //抄送人列表
+    const personnelUser = {userId: ''}  //人事
+    const financeUser = {userId: ''}            //财务人员
+    const responsibleUser = {userId: ''}        //部门负责人
+    //----处理数据----
+    let newFormData = [], newDetails = {}
+    //基础数据
+    Object.keys(detailsObj).forEach(key => {
+        newDetails[key] = res[key]
+    })
+    //组装为数组集合的表单数据
+    const list = res?.journeyList
+    list.forEach(item => {
+        newFormData.push({
+            ...newDetails,
+            ...item,
+            ccUserList,
+            personnelUser,
+            financeUser,
+            responsibleUser,
+            submitStatus //提交状态 1=暂存 2=提交审批
+        })
+    })
+    return newFormData
+}
 const saveLoading=ref(false)
 const saveClick=async()=>{
-    // console.log('提交',formModel.value);
     const res = await formValidate(formRef.value)
     if (!res) return false;
     //处理明细表单效验
     saveLoading.value = true
-    const form = formModel.value.journeyList
+    const form = getFormData(2)
     for (let i = 0; i < form.length; i++) {
         const refs = await getFormRef(i)
         const res = await formValidate(refs)
@@ -413,11 +533,32 @@ const saveClick=async()=>{
             saveLoading.value = false
             return
         }else{
-            console.log(formModel.value,'11111');
+            const {error, code, msg} = await businessApi.submit(form)
+            //判断状态
+            tempLoading.value = false
+            if (!error && code === 200) {
+                window.$message?.success('保存成功')
+            } else {
+                window.$message?.error(msg)
+             }
         }
     }
     //发起请求
 }
+//暂存数据
+const tempLoading = ref(false)
+const tempDraftData = async () => {
+    tempLoading.value = true
+    const form = getFormData(1)
+    const {error, code, msg} = await businessApi.submit(form)
+    //判断状态
+    tempLoading.value = false
+    if (!error && code === 200) {
+        window.$message?.success('暂存成功')
+    } else {
+        window.$message?.error(msg)
+    }
+}
 </script>
 
 <style lang="scss" scoped>