smart.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <div class="business-visit-smart-container layout-pd">
  3. <el-card shadow="never">
  4. <el-form :model="state.queryParams" ref="ruleFormRef" inline @submit.native.prevent>
  5. <el-form-item label="任务名称" prop="Keyword">
  6. <el-input v-model="state.queryParams.Keyword" placeholder="回访任务名称" clearable @keyup.enter="handleQuery" class="keyword-input" />
  7. </el-form-item>
  8. <el-form-item label="任务状态" prop="AiOrderVisitTaskState">
  9. <el-select v-model="state.queryParams.AiOrderVisitTaskState" placeholder="请选择任务状态" @change="handleQuery" clearable>
  10. <el-option v-for="item in aiOrderVisitTaskState" :value="item.key" :key="item.key" :label="item.value" />
  11. </el-select>
  12. </el-form-item>
  13. <el-form-item label="创建时间" prop="crTime">
  14. <el-date-picker
  15. v-model="state.queryParams.crTime"
  16. type="datetimerange"
  17. unlink-panels
  18. range-separator="至"
  19. start-placeholder="开始时间"
  20. end-placeholder="结束时间"
  21. :shortcuts="shortcuts"
  22. @change="handleQuery"
  23. value-format="YYYY-MM-DD[T]HH:mm:ss"
  24. :default-time="defaultTimeStartEnd"
  25. />
  26. </el-form-item>
  27. <el-form-item>
  28. <el-button type="primary" @click="handleQuery" :loading="state.loading"> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
  29. <el-button @click="resetQuery(ruleFormRef)" class="default-button"> <SvgIcon name="ele-Refresh" class="mr5" />重置 </el-button>
  30. </el-form-item>
  31. </el-form>
  32. </el-card>
  33. <el-card shadow="never">
  34. <ProTable
  35. ref="proTableRef"
  36. :columns="columns"
  37. :data="state.tableData"
  38. @updateTable="queryList"
  39. :loading="state.loading"
  40. :total="state.total"
  41. v-model:page-index="state.queryParams.PageIndex"
  42. v-model:page-size="state.queryParams.PageSize"
  43. :toolButton="['refresh', 'setting', 'exportCurrent', 'exportAll']"
  44. @export-current="exportTable($event)"
  45. @export-all="exportTable($event, true)"
  46. >
  47. <template #tableHeader="scope">
  48. <el-button type="primary" @click="onAddVisit" v-auth="'business:visit:smart:add'">
  49. <SvgIcon name="ele-Plus" class="mr5" /> 创建任务
  50. </el-button>
  51. </template>
  52. <!-- 表格操作 -->
  53. <template #operation="{ row }">
  54. <el-button link type="primary" @click="onDetail(row)" title="回访明细"> 回访明细 </el-button>
  55. <el-button
  56. link
  57. type="primary"
  58. v-if="[5].includes(row.taskState)"
  59. @click="onTermination(row)"
  60. title="终止回访任务"
  61. v-auth="'business:visit:smart:termination'"
  62. >
  63. 终止任务
  64. </el-button>
  65. <el-button
  66. link
  67. type="primary"
  68. v-if="[5].includes(row.taskState)"
  69. @click="onStart(row)"
  70. title="启动任务"
  71. v-auth="'business:visit:smart:start'"
  72. >
  73. 启动
  74. </el-button>
  75. <el-button
  76. link
  77. type="primary"
  78. v-if="[1, 2].includes(row.taskState)"
  79. @click="onPause(row)"
  80. title="暂停任务"
  81. v-auth="'business:visit:smart:pause'"
  82. >
  83. 暂停
  84. </el-button>
  85. </template>
  86. </ProTable>
  87. </el-card>
  88. <!-- 选择需要智能回访的工单 -->
  89. <smart-visit-add ref="smartVisitAddRef" @updateList="queryList" />
  90. <!-- 回访明细 -->
  91. <smart-visit-detail ref="smartVisitDetailRef" @updateList="queryList" />
  92. </div>
  93. </template>
  94. <script lang="tsx" setup name="businessVisitSmart">
  95. import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
  96. import { ElMessage, ElMessageBox, FormInstance } from 'element-plus';
  97. import { formatDate } from '@/utils/formatTime';
  98. import { getSmartVisitBaseData, getSmartVisitExport, getSmartVisitList } from "@/api/smartVisit";
  99. import { smartCallOutTaskExport, smartCallOutTaskPause, smartCallOutTaskStart, smartCallOutTaskStop } from "@/api/auxiliary/smartCallOut";
  100. import { defaultTimeStartEnd, shortcuts } from '@/utils/constants';
  101. import Other from '@/utils/other';
  102. import { downloadFileByStream } from '@/utils/tools';
  103. import { exportOrder } from '@/api/business/order';
  104. // 引入组件
  105. const SmartVisitAdd = defineAsyncComponent(() => import('@/views/business/visit/component/Smart-visit-add.vue')); // 选择需要智能回访的工单
  106. const SmartVisitDetail = defineAsyncComponent(() => import('@/views/business/visit/component/Smart-visit-Detail.vue')); // 回访明细
  107. const proTableRef = ref<RefType>(); // 表格ref
  108. // 表格配置项
  109. const columns = ref<any[]>([
  110. { prop: 'name', label: '回访任务名称' },
  111. { prop: 'hasVisitCount', label: '回访任务总数量' },
  112. { prop: 'visitedCount', label: '回访任务成功数量' },
  113. { prop: 'visitedFailCount', label: '回访任务失败数量' },
  114. { prop: 'taskStateText', label: '任务完成状态' },
  115. { prop: 'creatorName', label: '创建人' },
  116. {
  117. prop: 'creationTime',
  118. label: '创建时间',
  119. width: 170,
  120. render: (scope: any) => {
  121. return <span>{formatDate(scope.row.creationTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
  122. },
  123. },
  124. { prop: 'operation', label: '操作', fixed: 'right', width: 210, align: 'center' },
  125. ]);
  126. // 定义变量内容
  127. const state = reactive<any>({
  128. loading: false, // 加载状态
  129. queryParams: {
  130. // 查询参数
  131. PageIndex: 1,
  132. PageSize: 10,
  133. Keyword: null,
  134. AiOrderVisitTaskState: null,
  135. crTime: [],
  136. StartTime: null,
  137. EndTime: null,
  138. },
  139. total: 0, // 总条数
  140. tableData: [], // 表格数据
  141. });
  142. const ruleFormRef = ref<RefType>(null); // 表单ref
  143. // 手动查询,将页码设置为1
  144. const handleQuery = () => {
  145. state.queryParams.PageIndex = 1;
  146. queryList();
  147. };
  148. // 获取参数列表
  149. const queryList = () => {
  150. state.loading = true;
  151. let request = Other.deepClone(state.queryParams);
  152. request.StartTime = state.queryParams.crTime === null ? null : state.queryParams.crTime[0];
  153. request.EndTime = state.queryParams.crTime === null ? null : state.queryParams.crTime[1];
  154. Reflect.deleteProperty(request, 'crTime');
  155. getSmartVisitList(request)
  156. .then((res) => {
  157. state.loading = false;
  158. state.tableData = res.result.items ?? [];
  159. state.total = res.result.total ?? 0;
  160. })
  161. .finally(() => {
  162. state.loading = false;
  163. });
  164. };
  165. // 页面基础数据
  166. const aiOrderVisitTaskState = ref([]);
  167. const getBaseData = async () => {
  168. try {
  169. const { result } = await getSmartVisitBaseData();
  170. aiOrderVisitTaskState.value = result.aiOrderVisitTaskState;
  171. } catch (e) {
  172. console.log(e);
  173. }
  174. };
  175. // 重置表单
  176. const resetQuery = (formEl: FormInstance | undefined) => {
  177. if (!formEl) return;
  178. formEl.resetFields();
  179. queryList();
  180. };
  181. // 新增回访任务
  182. const smartVisitAddRef = ref<RefType>();
  183. const onAddVisit = () => {
  184. smartVisitAddRef.value.openDialog();
  185. };
  186. // 回访明细
  187. const smartVisitDetailRef = ref<RefType>();
  188. const onDetail = (row: any) => {
  189. smartVisitDetailRef.value.openDialog(row);
  190. };
  191. // 终止智能回访任务
  192. const onTermination = (row: any) => {
  193. ElMessageBox.confirm(`您确定要终止回访任务【${row.name}】吗?`, '提示', {
  194. confirmButtonText: '确定',
  195. cancelButtonText: '取消',
  196. type: 'warning',
  197. draggable: true,
  198. cancelButtonClass: 'default-button',
  199. autofocus: false,
  200. })
  201. .then(() => {
  202. state.loading = true;
  203. // 1 :智能回访 2:批量外呼
  204. smartCallOutTaskStop({ id: row.id, typeId: 1 })
  205. .then(() => {
  206. ElMessage({
  207. type: 'success',
  208. message: '终止任务成功',
  209. });
  210. queryList();
  211. state.loading = false;
  212. })
  213. .catch(() => {
  214. state.loading = false;
  215. });
  216. })
  217. .catch(() => {
  218. // 取消
  219. });
  220. };
  221. // 启动任务
  222. const onStart = (row: any) => {
  223. ElMessageBox.confirm(`您确定要启动回访任务【${row.name}】吗?`, '提示', {
  224. confirmButtonText: '确定',
  225. cancelButtonText: '取消',
  226. type: 'warning',
  227. draggable: true,
  228. cancelButtonClass: 'default-button',
  229. autofocus: false,
  230. })
  231. .then(() => {
  232. smartCallOutTaskStart({ id: row.id, typeId: 1 })
  233. .then(() => {
  234. ElMessage({
  235. type: 'success',
  236. message: '启动任务成功',
  237. });
  238. queryList();
  239. state.loading = false;
  240. })
  241. .catch(() => {
  242. state.loading = false;
  243. });
  244. })
  245. .catch(() => {
  246. // 取消
  247. });
  248. };
  249. // 暂停任务
  250. const onPause = (row: any) => {
  251. ElMessageBox.confirm(`您确定要暂停回访任务【${row.name}】吗?`, '提示', {
  252. confirmButtonText: '确定',
  253. cancelButtonText: '取消',
  254. type: 'warning',
  255. draggable: true,
  256. cancelButtonClass: 'default-button',
  257. autofocus: false,
  258. })
  259. .then(() => {
  260. smartCallOutTaskPause({ id: row.id, typeId: 1 })
  261. .then(() => {
  262. ElMessage({
  263. type: 'success',
  264. message: '暂停任务成功',
  265. });
  266. queryList();
  267. state.loading = false;
  268. })
  269. .catch(() => {
  270. state.loading = false;
  271. });
  272. })
  273. .catch(() => {
  274. // 取消
  275. });
  276. };
  277. // 表格导出
  278. const exportTable = (val: any, isExportAll = false) => {
  279. let request = Other.deepClone(state.queryParams);
  280. request.StartTime = state.queryParams.crTime === null ? null : state.queryParams.crTime[0];
  281. request.EndTime = state.queryParams.crTime === null ? null : state.queryParams.crTime[1];
  282. Reflect.deleteProperty(request, 'crTime');
  283. const columnInfos = val.map((item: any) => {
  284. return {
  285. prop: item.prop,
  286. name: item.label,
  287. };
  288. });
  289. const req = {
  290. queryDto: request,
  291. columnInfos,
  292. isExportAll,
  293. };
  294. state.loading = true;
  295. getSmartVisitExport(req)
  296. .then((res: any) => {
  297. state.loading = false;
  298. downloadFileByStream(res);
  299. })
  300. .catch(() => {
  301. state.loading = false;
  302. });
  303. };
  304. // 页面加载时
  305. onMounted(() => {
  306. getBaseData();
  307. queryList();
  308. });
  309. </script>