瀏覽代碼

提交新建任务的函数封装

Lijy 1 年之前
父節點
當前提交
51dac64750

+ 30 - 0
fhKeeper/formulahousekeeper/customerBuler-crm/src/components/TaskModal/taskFunction.ts

@@ -0,0 +1,30 @@
+import { dayjs } from 'element-plus';
+import { post } from "@/utils/request";
+import { getFromValue } from '@/utils/tools';
+import { ADD_TASK } from '@/pages/tasks/api';
+
+// 封装新建任务请求
+export async function createTask(submitData: any, isClose: boolean) : Promise<TaskResponse> {
+    return new Promise((resolve, reject) => {
+        const { executorId, startDate, endDate, repeatEndDate } = submitData;
+        let params = {
+            ...submitData,
+            startDate: startDate && dayjs(startDate).format('YYYY-MM-DD 00:00:00'),
+            endDate: endDate && dayjs(endDate).format('YYYY-MM-DD 23:59:59'),
+            repeatEndDate: repeatEndDate && dayjs(repeatEndDate).format('YYYY-MM-DD 23:59:59')
+        }
+        if (executorId) {
+            params = {
+                ...params,
+                executorId: executorId.join(','),
+                taskLogs: []
+            }
+        }
+
+        post(ADD_TASK, getFromValue(params)).then(() => {
+            resolve({ saveLoading: '3', isClose })
+        }).catch((err) => {
+            reject({ saveLoading: '4', isClose, message: err.message })
+        })
+    })
+}

+ 1 - 1
fhKeeper/formulahousekeeper/customerBuler-crm/src/components/TaskModal/type.d.ts

@@ -50,4 +50,4 @@ export interface Emits {
    * @param isClose 是否关闭弹窗
    */
   (event: "submit", submitData: Object, isClose: boolean): void;
-}
+}

+ 33 - 2
fhKeeper/formulahousekeeper/customerBuler-crm/src/pages/business/index.vue

@@ -83,7 +83,7 @@
             <el-table-column label="操作" fixed="right" width="200">
               <template #default="scope">
                 <el-button link type="primary" size="large" @click="editShowVisible('newBusinessisible', scope.row)">编辑</el-button>
-                <el-button link type="primary" size="large">新建任务</el-button>
+                <el-button link type="primary" size="large" @click="newTask(scope.row)">新建任务</el-button>
                 <el-button link type="danger" size="large">删除</el-button>
               </template>
             </el-table-column>
@@ -116,6 +116,10 @@
         <RelatedProducts ref="relatedProductsRef" :productTableList="productTableList" />
       </div>
     </el-dialog>
+
+    <!-- 新建任务 -->
+    <TaskModal :visible="allVisible.taskModalVisible" :edit-form="taskModalForm" :save-loading="taskLoading"
+      @close="closeVisible('taskModalVisible')" @submit="submitForm" :title="'新建任务'" :disabled-list="['taskType', 'businessOpportunityId']" />
   </div>
 </template>
 
@@ -126,10 +130,12 @@ import { useRouter, useRoute } from "vue-router";
 import { GETSYSFILED, MOD, GETPERSONNEL, GETGENERATEFOEM, GETBUSINESSLIST, UPDATEINSET } from './api'
 import { GETTABLELIST } from '@/pages/product/api'
 import { post, get } from "@/utils/request";
-import { getAllListByCode, getFromValue, resetFromValue, getFirstDayOfMonth, getLastDayOfMonth, formatDate } from '@/utils/tools'
+import { getAllListByCode, getFromValue, resetFromValue, getFirstDayOfMonth, createTaskFromType, formatDate } from '@/utils/tools'
+import { createTask } from '@/components/TaskModal/taskFunction'
 import { formatDateTime } from '@/utils/times'
 import { GenerateForm } from '@zmjs/form-design';
 import RelatedProducts from './component/relatedProducts.vue'
+import TaskModal from '@/components/TaskModal/index.vue'
 
 const route = useRoute()
 const router = useRouter()
@@ -150,11 +156,15 @@ const allLoading = reactive({
 const allVisible = reactive({
   newBusinessisible: false,
   recycleVisible: false,
+  taskModalVisible: false
 })
 const allText = reactive({
   newBusinessisibleText: '新建商机'
 }) // 所有文本
 
+const taskModalForm = ref({}) // 任务弹窗表单
+const taskLoading = ref<saveLoadingType>("1");
+
 const businessOpportunityForm = reactive<businessOpportunityFormType>({
   name: '',
   stageId: '',
@@ -201,6 +211,27 @@ function editShowVisible(type: keyof typeof allVisible, item: any) {
   showVisible(type)
 }
 
+function newTask(item: any) {
+  const { id } = item
+  taskModalForm.value = { ...createTaskFromType(1), businessOpportunityId: id, }
+  showVisible('taskModalVisible')
+}
+
+function submitForm(submitData: any, isClose: boolean) { // 任务提交
+  taskLoading.value = '2'
+  createTask(submitData, isClose).then((res) => {
+    const { saveLoading, isClose } = res
+    taskLoading.value = saveLoading
+    allVisible.taskModalVisible = isClose
+    globalPopup?.showSuccess('新增成功')
+  }).catch((err) => {
+    const { saveLoading, isClose, message } = err
+    taskLoading.value = saveLoading
+    allVisible.taskModalVisible = isClose
+    globalPopup?.showSuccess(message)
+  })
+}
+
 function showVisible(type: keyof typeof allVisible) { // 显示弹窗
   allVisible[type] = true
 }

+ 3 - 1
fhKeeper/formulahousekeeper/customerBuler-crm/src/type.d.ts

@@ -26,4 +26,6 @@ type saveLoadingType = "1" | "2" | "3" | "4"; //1是没有保存, 2是正在保
 type TASK_VALUE_TYPE = 0 | 1 | 2 | 3; //0是客户, 1是商机, 2是销售订单 ,3是线索
 type REPEAT_VALUE_TYPE = 0 | 1 | 2 | 3 | 4; //0是每天, 1是每周, 2是每月, 3是自定义周期, 4是自定义日期
 
-type componentType = "success" | "info" | "warning" | "error"
+type componentType = "success" | "info" | "warning" | "error"
+
+type TaskResponse = { saveLoading: saveLoadingType, isClose: boolean, message?: string }