瀏覽代碼

feat:app独立发课-同步销售数据

caoliqin 6 天之前
父節點
當前提交
85b179f099

+ 16 - 0
src/api/app/customerMember/index.js

@@ -34,3 +34,19 @@ export function delCustomerMember(ids) {
     method: 'delete'
   })
 }
+
+// 同步销售(异步)
+export function syncSalesCustomerMember() {
+  return request({
+    url: '/app/cusrole/member/syncSales',
+    method: 'post'
+  })
+}
+
+// 查询同步销售任务状态
+export function getSyncSalesCustomerMemberStatus() {
+  return request({
+    url: '/app/cusrole/member/syncSales/status',
+    method: 'get'
+  })
+}

+ 97 - 11
src/views/app/customerMember/index.vue

@@ -33,16 +33,16 @@
     </el-form>
 
     <el-row :gutter="10" class="mb8">
-      <el-col :span="1.5">
-        <el-button
-          type="primary"
-          plain
-          icon="el-icon-plus"
-          size="mini"
-          v-hasPermi="['app:customerMember:add']"
-          @click="handleAdd"
-        >新增</el-button>
-      </el-col>
+<!--      <el-col :span="1.5">-->
+<!--        <el-button-->
+<!--          type="primary"-->
+<!--          plain-->
+<!--          icon="el-icon-plus"-->
+<!--          size="mini"-->
+<!--          v-hasPermi="['app:customerMember:add']"-->
+<!--          @click="handleAdd"-->
+<!--        >新增</el-button>-->
+<!--      </el-col>-->
       <el-col :span="1.5">
         <el-button
           type="success"
@@ -65,6 +65,24 @@
           @click="handleDelete()"
         >删除</el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="warning"
+          plain
+          icon="el-icon-refresh"
+          size="mini"
+          :loading="syncLoading"
+          v-hasPermi="['app:customerMember:add']"
+          @click="handleSyncSales"
+        >同步销售</el-button>
+        <el-tooltip
+          effect="dark"
+          content="该按钮初次同步可能较慢,后续再次同步只会新增新的销售数据"
+          placement="top"
+        >
+          <i class="el-icon-question sync-sales-tip"></i>
+        </el-tooltip>
+      </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
 
@@ -212,7 +230,9 @@ import {
   listCustomerMember,
   addCustomerMember,
   updateCustomerMember,
-  delCustomerMember
+  delCustomerMember,
+  syncSalesCustomerMember,
+  getSyncSalesCustomerMemberStatus
 } from '@/api/app/customerMember'
 import { listCustomerRoleOptions } from '@/api/app/customerRole'
 import { getCompanyList, getCompanyUserList } from '@/api/company/companyUser'
@@ -224,6 +244,8 @@ export default {
   data() {
     return {
       loading: true,
+      syncLoading: false,
+      syncTimer: null,
       showSearch: true,
       total: 0,
       ids: [],
@@ -272,7 +294,64 @@ export default {
     this.loadRoleOptions()
     this.getList()
   },
+  beforeDestroy() {
+    this.clearSyncTimer()
+  },
   methods: {
+    clearSyncTimer() {
+      if (this.syncTimer) {
+        clearInterval(this.syncTimer)
+        this.syncTimer = null
+      }
+    },
+    handleSyncSales() {
+      this.$confirm('是否确认同步销售数据', '提示', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        this.syncLoading = true
+        return syncSalesCustomerMember()
+      }).then(response => {
+        if (response.code !== 200) {
+          this.syncLoading = false
+          this.msgError(response.msg || '提交同步任务失败')
+          return
+        }
+        this.msgSuccess('同步任务已提交,同步中。。。')
+        this.clearSyncTimer()
+        this.syncTimer = setInterval(() => {
+          this.pollSyncSalesStatus()
+        }, 2000)
+        this.pollSyncSalesStatus()
+      }).catch(() => {
+        this.syncLoading = false
+      })
+    },
+    pollSyncSalesStatus() {
+      getSyncSalesCustomerMemberStatus().then(response => {
+        if (response.code !== 200) {
+          return
+        }
+        const data = response.data || {}
+        if (data.status === 'running') {
+          return
+        }
+        this.clearSyncTimer()
+        this.syncLoading = false
+        if (data.status === 'success') {
+          this.msgSuccess(data.message || '同步完成')
+          this.getList()
+          this.loadRoleOptions()
+        } else if (data.status === 'fail') {
+          this.msgError(data.message || '同步失败')
+        }
+      }).catch(() => {
+        this.clearSyncTimer()
+        this.syncLoading = false
+        this.msgError('查询同步状态失败')
+      })
+    },
     parseRoleId(value) {
       if (value === null || value === undefined || value === '') {
         return null
@@ -472,4 +551,11 @@ export default {
 .el-input__icon {
   cursor: pointer;
 }
+.sync-sales-tip {
+  margin-left: 6px;
+  color: #909399;
+  cursor: pointer;
+  font-size: 14px;
+  vertical-align: middle;
+}
 </style>

+ 13 - 13
src/views/app/customerRole/index.vue

@@ -16,19 +16,19 @@
       </el-form-item>
     </el-form>
 
-    <el-row :gutter="10" class="mb8">
-      <el-col :span="1.5">
-        <el-button
-          type="primary"
-          plain
-          icon="el-icon-plus"
-          size="mini"
-          v-hasPermi="['app:customerRole:add']"
-          @click="handleAdd"
-        >新增</el-button>
-      </el-col>
-      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
-    </el-row>
+<!--    <el-row :gutter="10" class="mb8">-->
+<!--      <el-col :span="1.5">-->
+<!--        <el-button-->
+<!--          type="primary"-->
+<!--          plain-->
+<!--          icon="el-icon-plus"-->
+<!--          size="mini"-->
+<!--          v-hasPermi="['app:customerRole:add']"-->
+<!--          @click="handleAdd"-->
+<!--        >新增</el-button>-->
+<!--      </el-col>-->
+<!--      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
+<!--    </el-row>-->
 
     <el-table v-loading="loading" :data="roleList" border>
       <el-table-column label="客服组名称" align="center" prop="roleName" min-width="140" />

+ 1 - 0
src/views/his/user/indexProject.vue

@@ -288,6 +288,7 @@
       :total="total"
       :page.sync="queryParams.pageNum"
       :limit.sync="queryParams.pageSize"
+      :page-sizes="[10, 20, 30, 50, 100, 200, 300, 500]"
       @pagination="getList"
     />