index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="公司名称" prop="companyId" >
  5. <el-select v-model="queryParams.companyId" placeholder="请选择所属公司" filterable size="small">
  6. <el-option v-for="(option, index) in companyList" :key="index" :value="option.dictValue" :label="option.dictLabel"></el-option>
  7. </el-select>
  8. </el-form-item>
  9. <el-form-item label="会话标识" prop="sessionCode">
  10. <el-input
  11. v-model="queryParams.sessionCode"
  12. placeholder="请输入会话标识"
  13. clearable
  14. size="small"
  15. @keyup.enter.native="handleQuery"
  16. />
  17. </el-form-item>
  18. <el-form-item label="客户名称" prop="nickName">
  19. <el-input
  20. v-model="queryParams.nickName"
  21. placeholder="请输入客户名称"
  22. clearable
  23. size="small"
  24. @keyup.enter.native="handleQuery"
  25. />
  26. </el-form-item>
  27. <el-form-item label="客服角色" prop="roleId">
  28. <el-select v-model="queryParams.kfId" placeholder="请选择客服角色" clearable size="small">
  29. <el-option
  30. v-for="item in roles"
  31. :key="item.kfId"
  32. :label="item.roleName"
  33. :value="item.kfId"
  34. />
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item label="状态 " prop="status">
  38. <el-select v-model="queryParams.status" placeholder="请选择" clearable size="small">
  39. <el-option
  40. v-for="item in sessionStatusOptions"
  41. :key="item.dictValue"
  42. :label="item.dictLabel"
  43. :value="item.dictValue"
  44. />
  45. </el-select>
  46. </el-form-item>
  47. <el-form-item label="查看状态" prop="isLook">
  48. <el-select v-model="queryParams.isLook" placeholder="请选择" clearable size="small">
  49. <el-option
  50. v-for="item in sessionLookOptions"
  51. :key="item.dictValue"
  52. :label="item.dictLabel"
  53. :value="item.dictValue"
  54. />
  55. </el-select>
  56. </el-form-item>
  57. <el-form-item label="接待时间" prop="createTime">
  58. <el-date-picker
  59. style="width:220px"
  60. clearable size="small"
  61. v-model="dateRange"
  62. type="daterange"
  63. value-format="yyyy-MM-dd"
  64. start-placeholder="开始日期"
  65. end-placeholder="结束日期"
  66. @change="changeTime">
  67. </el-date-picker>
  68. </el-form-item>
  69. <el-form-item>
  70. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  71. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  72. </el-form-item>
  73. </el-form>
  74. <el-row :gutter="10" class="mb8">
  75. <el-col :span="1.5">
  76. <el-button
  77. type="primary"
  78. plain
  79. icon="el-icon-plus"
  80. size="mini"
  81. @click="handleAdd"
  82. v-hasPermi="['chat:chatSession:add']"
  83. >新增</el-button>
  84. </el-col>
  85. <el-col :span="1.5">
  86. <el-button
  87. type="success"
  88. plain
  89. icon="el-icon-edit"
  90. size="mini"
  91. :disabled="single"
  92. @click="handleUpdate"
  93. v-hasPermi="['chat:chatSession:edit']"
  94. >修改</el-button>
  95. </el-col>
  96. <el-col :span="1.5">
  97. <el-button
  98. type="danger"
  99. plain
  100. icon="el-icon-delete"
  101. size="mini"
  102. :disabled="multiple"
  103. @click="handleDelete"
  104. v-hasPermi="['chat:chatSession:remove']"
  105. >删除</el-button>
  106. </el-col>
  107. <el-col :span="1.5">
  108. <el-button
  109. type="warning"
  110. plain
  111. icon="el-icon-download"
  112. size="mini"
  113. :loading="exportLoading"
  114. @click="handleExport"
  115. v-hasPermi="['chat:chatSession:export']"
  116. >导出</el-button>
  117. </el-col>
  118. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  119. </el-row>
  120. <el-table border v-loading="loading" :data="chatSessionList" @selection-change="handleSelectionChange">
  121. <el-table-column type="selection" width="55" align="center" />
  122. <el-table-column label="ID" align="center" prop="sessionId" />
  123. <el-table-column label="会话标识" align="center" prop="sessionCode" />
  124. <el-table-column label="咨询客户" align="center" prop="nickname" />
  125. <el-table-column label="客服账号" align="center" prop="roleName" />
  126. <el-table-column label="所属公司" align="center" prop="companyName" />
  127. <el-table-column label="接待时间" align="center" prop="createTime" >
  128. <template slot-scope="scope">
  129. <span v-if="!scope.row.updateTime && scope.row.status === 1">
  130. {{ scope.row.createTime }} - 未结束
  131. </span>
  132. <span v-else>
  133. {{ scope.row.createTime }} - {{ scope.row.updateTime }}
  134. </span>
  135. </template>
  136. </el-table-column>
  137. <el-table-column label="服务状态" align="center" prop="status">
  138. <template slot-scope="scope">
  139. <el-tag prop="status" v-for="(item, index) in sessionStatusOptions" v-if="scope.row.status==item.dictValue">{{item.dictLabel}}</el-tag>
  140. </template>
  141. </el-table-column>
  142. <el-table-column label="查看状态" align="center" prop="isLook">
  143. <template slot-scope="scope">
  144. <el-tag prop="isLook" v-for="(item, index) in sessionLookOptions" v-if="scope.row.isLook==item.dictValue">{{item.dictLabel}}</el-tag>
  145. </template>
  146. </el-table-column>
  147. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  148. <template slot-scope="scope">
  149. <el-button
  150. size="mini"
  151. type="text"
  152. v-hasPermi="['chat:chatSession:query']"
  153. @click="handledetails(scope.row)"
  154. >查看</el-button>
  155. </template>
  156. </el-table-column>
  157. </el-table>
  158. <pagination
  159. v-show="total>0"
  160. :total="total"
  161. :page.sync="queryParams.pageNum"
  162. :limit.sync="queryParams.pageSize"
  163. @pagination="getList"
  164. />
  165. <!-- 添加或修改会话对话框 -->
  166. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  167. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  168. <el-form-item label="会话标识" prop="sessionCode">
  169. <el-input v-model="form.sessionCode" placeholder="请输入会话标识" />
  170. </el-form-item>
  171. <el-form-item label="客户ID" prop="userId">
  172. <el-input v-model="form.userId" placeholder="请输入客户ID" />
  173. </el-form-item>
  174. <el-form-item label="客服ID" prop="kfId">
  175. <el-input v-model="form.kfId" placeholder="请输入客服ID" />
  176. </el-form-item>
  177. <el-form-item label="状态 1会话中 2已结束">
  178. <el-radio-group v-model="form.status">
  179. <el-radio label="1">请选择字典生成</el-radio>
  180. </el-radio-group>
  181. </el-form-item>
  182. </el-form>
  183. <div slot="footer" class="dialog-footer">
  184. <el-button type="primary" @click="submitForm">确 定</el-button>
  185. <el-button @click="cancel">取 消</el-button>
  186. </div>
  187. </el-dialog>
  188. <el-drawer
  189. :with-header="false"
  190. size="75%" @close="handleDrawerClose"
  191. :title="show.title" :visible.sync="show.open">
  192. <chatMsgDetails ref="Details" />
  193. </el-drawer>
  194. </div>
  195. </template>
  196. <script>
  197. import { listChatSession, getChatSession, delChatSession, addChatSession, updateChatSession, exportChatSession } from "@/api/chat/chatSession";
  198. import chatMsgDetails from '../components/chatMsgDetails.vue';
  199. import { getAllRoleList } from "@/api/chat/chatRole";
  200. import {allList}from "@/api/company/company";
  201. export default {
  202. name: "ChatSession",
  203. components:{chatMsgDetails},
  204. data() {
  205. return {
  206. roles:[],
  207. companyList:[],
  208. show:{
  209. title:"聊天详情",
  210. open:false,
  211. },
  212. dateRange:[],
  213. sessionStatusOptions:[],
  214. sessionLookOptions:[],
  215. // 遮罩层
  216. loading: true,
  217. // 导出遮罩层
  218. exportLoading: false,
  219. // 选中数组
  220. ids: [],
  221. // 非单个禁用
  222. single: true,
  223. // 非多个禁用
  224. multiple: true,
  225. // 显示搜索条件
  226. showSearch: true,
  227. // 总条数
  228. total: 0,
  229. // 会话表格数据
  230. chatSessionList: [],
  231. // 弹出层标题
  232. title: "",
  233. // 是否显示弹出层
  234. open: false,
  235. // 查询参数
  236. queryParams: {
  237. pageNum: 1,
  238. pageSize: 10,
  239. sessionCode: null,
  240. userId: null,
  241. kfId: null,
  242. status: null,
  243. isLook:null
  244. },
  245. // 表单参数
  246. form: {},
  247. // 表单校验
  248. rules: {
  249. }
  250. };
  251. },
  252. created() {
  253. this.getList();
  254. this.getDicts("sys_chat_session_status").then(response => {
  255. this.sessionStatusOptions = response.data;
  256. });
  257. this.getDicts("sys_chat_session_look").then(response => {
  258. this.sessionLookOptions = response.data;
  259. });
  260. getAllRoleList().then(response => {
  261. this.roles = response.data;
  262. });
  263. this.getAllCompany();
  264. },
  265. methods: {
  266. getAllCompany() {
  267. allList().then(response => {
  268. this.companyList = response.rows;
  269. this.companyList.push({dictLabel: "无",
  270. dictValue: "0"})
  271. });
  272. },
  273. handleDrawerClose(){
  274. this.getList();
  275. },
  276. handledetails(row){
  277. this.show.open=true;
  278. setTimeout(() => {
  279. this.$refs.Details.getDetails(row.sessionId);
  280. }, 500);
  281. },
  282. /** 查询会话列表 */
  283. getList() {
  284. this.loading = true;
  285. listChatSession(this.queryParams).then(response => {
  286. this.chatSessionList = response.rows;
  287. this.total = response.total;
  288. this.loading = false;
  289. });
  290. },
  291. // 取消按钮
  292. cancel() {
  293. this.open = false;
  294. this.reset();
  295. },
  296. // 表单重置
  297. reset() {
  298. this.form = {
  299. sessionId: null,
  300. sessionCode: null,
  301. userId: null,
  302. kfId: null,
  303. createTime: null,
  304. updateTime: null,
  305. status: 0
  306. };
  307. this.resetForm("form");
  308. },
  309. changeTime(){
  310. if(this.dateRange!=null){
  311. this.queryParams.beginTime=this.dateRange[0];
  312. this.queryParams.endTime=this.dateRange[1];
  313. }else{
  314. this.queryParams.beginTime=null;
  315. this.queryParams.endTime=null;
  316. }
  317. },
  318. /** 搜索按钮操作 */
  319. handleQuery() {
  320. this.queryParams.pageNum = 1;
  321. this.getList();
  322. },
  323. /** 重置按钮操作 */
  324. resetQuery() {
  325. this.dateRange = [];
  326. this.queryParams.beginTime=null;
  327. this.queryParams.endTime=null;
  328. this.resetForm("queryForm");
  329. this.handleQuery();
  330. },
  331. // 多选框选中数据
  332. handleSelectionChange(selection) {
  333. this.ids = selection.map(item => item.sessionId)
  334. this.single = selection.length!==1
  335. this.multiple = !selection.length
  336. },
  337. /** 新增按钮操作 */
  338. handleAdd() {
  339. this.reset();
  340. this.open = true;
  341. this.title = "添加会话";
  342. },
  343. /** 修改按钮操作 */
  344. handleUpdate(row) {
  345. this.reset();
  346. const sessionId = row.sessionId || this.ids
  347. getChatSession(sessionId).then(response => {
  348. this.form = response.data;
  349. this.open = true;
  350. this.title = "修改会话";
  351. });
  352. },
  353. /** 提交按钮 */
  354. submitForm() {
  355. this.$refs["form"].validate(valid => {
  356. if (valid) {
  357. if (this.form.sessionId != null) {
  358. updateChatSession(this.form).then(response => {
  359. this.msgSuccess("修改成功");
  360. this.open = false;
  361. this.getList();
  362. });
  363. } else {
  364. addChatSession(this.form).then(response => {
  365. this.msgSuccess("新增成功");
  366. this.open = false;
  367. this.getList();
  368. });
  369. }
  370. }
  371. });
  372. },
  373. /** 删除按钮操作 */
  374. handleDelete(row) {
  375. const sessionIds = row.sessionId || this.ids;
  376. this.$confirm('是否确认删除会话编号为"' + sessionIds + '"的数据项?', "警告", {
  377. confirmButtonText: "确定",
  378. cancelButtonText: "取消",
  379. type: "warning"
  380. }).then(function() {
  381. return delChatSession(sessionIds);
  382. }).then(() => {
  383. this.getList();
  384. this.msgSuccess("删除成功");
  385. }).catch(() => {});
  386. },
  387. /** 导出按钮操作 */
  388. handleExport() {
  389. const queryParams = this.queryParams;
  390. this.$confirm('是否确认导出所有会话数据项?', "警告", {
  391. confirmButtonText: "确定",
  392. cancelButtonText: "取消",
  393. type: "warning"
  394. }).then(() => {
  395. this.exportLoading = true;
  396. return exportChatSession(queryParams);
  397. }).then(response => {
  398. this.download(response.msg);
  399. this.exportLoading = false;
  400. }).catch(() => {});
  401. }
  402. }
  403. };
  404. </script>