index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
  4. <el-form-item label="工作流名称" prop="workflowName">
  5. <el-input
  6. v-model="queryParams.workflowName"
  7. placeholder="请输入工作流名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="工作流类型" prop="workflowType">
  14. <el-select v-model="queryParams.workflowType" placeholder="请选择类型" clearable size="small">
  15. <el-option
  16. v-for="dict in workflowTypeOptions"
  17. :key="dict.dictValue"
  18. :label="dict.dictLabel"
  19. :value="dict.dictValue"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="状态" prop="status">
  24. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
  25. <el-option
  26. v-for="dict in statusOptions"
  27. :key="dict.dictValue"
  28. :label="dict.dictLabel"
  29. :value="dict.dictValue"
  30. />
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item>
  34. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  35. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  36. </el-form-item>
  37. </el-form>
  38. <el-row :gutter="10" class="mb8">
  39. <el-col :span="1.5">
  40. <el-button
  41. type="primary"
  42. plain
  43. icon="el-icon-plus"
  44. size="mini"
  45. @click="handleAdd"
  46. v-hasPermi="['his:aiWorkflow:add']"
  47. >新增</el-button>
  48. </el-col>
  49. <el-col :span="1.5">
  50. <el-button
  51. type="danger"
  52. plain
  53. icon="el-icon-delete"
  54. size="mini"
  55. :disabled="multiple"
  56. @click="handleDelete"
  57. v-hasPermi="['his:aiWorkflow:remove']"
  58. >删除</el-button>
  59. </el-col>
  60. <el-col :span="1.5">
  61. <el-button
  62. type="warning"
  63. plain
  64. icon="el-icon-download"
  65. size="mini"
  66. :loading="exportLoading"
  67. @click="handleExport"
  68. v-hasPermi="['his:aiWorkflow:export']"
  69. >导出</el-button>
  70. </el-col>
  71. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  72. </el-row>
  73. <el-table v-loading="loading" border :data="workflowList" @selection-change="handleSelectionChange">
  74. <el-table-column type="selection" width="55" align="center" />
  75. <el-table-column label="ID" align="center" prop="workflowId" width="80" />
  76. <el-table-column label="工作流名称" align="center" prop="workflowName" min-width="150" show-overflow-tooltip />
  77. <el-table-column label="描述" align="center" prop="workflowDesc" min-width="200" show-overflow-tooltip />
  78. <el-table-column label="类型" align="center" prop="workflowType" width="100">
  79. <template slot-scope="scope">
  80. <dict-tag :options="workflowTypeOptions" :value="scope.row.workflowType"/>
  81. </template>
  82. </el-table-column>
  83. <el-table-column label="状态" align="center" prop="status" width="80">
  84. <template slot-scope="scope">
  85. <el-switch
  86. v-model="scope.row.status"
  87. :active-value="1"
  88. :inactive-value="0"
  89. @change="handleStatusChange(scope.row)"
  90. />
  91. </template>
  92. </el-table-column>
  93. <el-table-column label="版本" align="center" prop="version" width="60" />
  94. <el-table-column label="创建时间" align="center" prop="createTime" width="160">
  95. <template slot-scope="scope">
  96. <span>{{ parseTime(scope.row.createTime) }}</span>
  97. </template>
  98. </el-table-column>
  99. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="200">
  100. <template slot-scope="scope">
  101. <el-button
  102. size="mini"
  103. type="text"
  104. icon="el-icon-edit"
  105. @click="handleEdit(scope.row)"
  106. v-hasPermi="['his:aiWorkflow:edit']"
  107. >设计</el-button>
  108. <el-button
  109. size="mini"
  110. type="text"
  111. icon="el-icon-user"
  112. @click="handleBindSales(scope.row)"
  113. >绑定销售</el-button>
  114. <el-button
  115. size="mini"
  116. type="text"
  117. icon="el-icon-document-copy"
  118. @click="handleCopy(scope.row)"
  119. v-hasPermi="['his:aiWorkflow:add']"
  120. >复制</el-button>
  121. <el-button
  122. size="mini"
  123. type="text"
  124. icon="el-icon-delete"
  125. @click="handleDelete(scope.row)"
  126. v-hasPermi="['his:aiWorkflow:remove']"
  127. >删除</el-button>
  128. </template>
  129. </el-table-column>
  130. </el-table>
  131. <pagination
  132. v-show="total > 0"
  133. :total="total"
  134. :page.sync="queryParams.pageNum"
  135. :limit.sync="queryParams.pageSize"
  136. @pagination="getList"
  137. />
  138. <!-- 绑定销售弹窗 -->
  139. <el-dialog title="绑定销售" :visible.sync="bindSalesOpen" width="500px" append-to-body>
  140. <!-- 当前绑定的销售 -->
  141. <div class="current-sales">
  142. <div class="section-title">当前绑定销售</div>
  143. <div v-if="currentBindUserList && currentBindUserList.length > 0" class="bind-info">
  144. <el-tag
  145. v-for="(user, index) in currentBindUserList"
  146. :key="index"
  147. type="success"
  148. style="margin-right: 8px; margin-bottom: 8px;"
  149. >
  150. {{ user.userName || user.user_name }}({{ user.nickName || user.nick_name }})
  151. </el-tag>
  152. </div>
  153. <div v-else class="no-bind">
  154. <el-tag type="info">暂未绑定销售</el-tag>
  155. </div>
  156. </div>
  157. <!-- 可选销售列表 -->
  158. <div class="sales-list">
  159. <div class="section-title">选择销售</div>
  160. <el-input
  161. v-model="salesSearchKey"
  162. placeholder="搜索昵称"
  163. size="small"
  164. prefix-icon="el-icon-search"
  165. clearable
  166. style="margin-bottom: 10px"
  167. />
  168. <el-table
  169. :data="filteredCompanyUserList"
  170. v-loading="salesLoading"
  171. border
  172. height="300"
  173. :row-key="getSalesRowKey"
  174. :row-class-name="salesRowClassName"
  175. @selection-change="handleSalesSelectionChange"
  176. ref="salesTable"
  177. >
  178. <el-table-column type="selection" width="55" align="center" :selectable="checkSelectable" :reserve-selection="true" />
  179. <el-table-column label="用户名" align="center" prop="userName" />
  180. <el-table-column label="昵称" align="center" prop="nickName" />
  181. </el-table>
  182. </div>
  183. <div slot="footer" class="dialog-footer">
  184. <el-button @click="handleBindSalesCancel">取 消</el-button>
  185. <el-button type="primary" :disabled="selectedSalesList.length === 0" @click="confirmBindSales">确 定</el-button>
  186. </div>
  187. </el-dialog>
  188. </div>
  189. </template>
  190. <script>
  191. import { listWorkflow, delWorkflow, updateWorkflowStatus, copyWorkflow, exportWorkflow, getBindCompanyUserByWorkflowId, listCompanyUser, updateWorkflowBindCompanyUser } from '@/api/his/aiWorkflow'
  192. export default {
  193. name: 'AiWorkflow',
  194. data() {
  195. return {
  196. // 遮罩层
  197. loading: true,
  198. // 导出遮罩层
  199. exportLoading: false,
  200. // 选中数组
  201. ids: [],
  202. // 非单个禁用
  203. single: true,
  204. // 非多个禁用
  205. multiple: true,
  206. // 显示搜索条件
  207. showSearch: true,
  208. // 总条数
  209. total: 0,
  210. // 工作流表格数据
  211. workflowList: [],
  212. // 工作流类型字典
  213. workflowTypeOptions: [
  214. { dictValue: '1', dictLabel: '对话流程' },
  215. { dictValue: '2', dictLabel: '任务流程' },
  216. { dictValue: '3', dictLabel: '审批流程' }
  217. ],
  218. // 状态字典
  219. statusOptions: [
  220. { dictValue: '1', dictLabel: '启用' },
  221. { dictValue: '0', dictLabel: '禁用' }
  222. ],
  223. // 查询参数
  224. queryParams: {
  225. pageNum: 1,
  226. pageSize: 10,
  227. workflowName: null,
  228. workflowType: null,
  229. status: null
  230. },
  231. // 绑定销售弹窗
  232. bindSalesOpen: false,
  233. // 销售列表加载
  234. salesLoading: false,
  235. // 当前操作的工作流
  236. currentWorkflow: null,
  237. // 当前绑定的用户列表
  238. currentBindUserList: [],
  239. // 销售列表
  240. companyUserList: [],
  241. // 选中的销售列表
  242. selectedSalesList: [],
  243. // 销售搜索关键字
  244. salesSearchKey: ''
  245. }
  246. },
  247. computed: {
  248. // 过滤后的销售列表
  249. filteredCompanyUserList() {
  250. if (!this.salesSearchKey) {
  251. return this.companyUserList
  252. }
  253. const key = this.salesSearchKey.toLowerCase()
  254. return this.companyUserList.filter(item => {
  255. return (item.nickName && item.nickName.toLowerCase().includes(key))
  256. })
  257. }
  258. },
  259. created() {
  260. this.getList()
  261. // 如果有字典配置,可以使用以下方式获取
  262. // this.getDicts("ai_workflow_type").then(response => {
  263. // this.workflowTypeOptions = response.data
  264. // })
  265. },
  266. methods: {
  267. /** 查询工作流列表 */
  268. getList() {
  269. this.loading = true
  270. listWorkflow(this.queryParams).then(response => {
  271. this.workflowList = response.rows
  272. this.total = response.total
  273. this.loading = false
  274. })
  275. },
  276. /** 搜索按钮操作 */
  277. handleQuery() {
  278. this.queryParams.pageNum = 1
  279. this.getList()
  280. },
  281. /** 重置按钮操作 */
  282. resetQuery() {
  283. this.resetForm('queryForm')
  284. this.handleQuery()
  285. },
  286. // 多选框选中数据
  287. handleSelectionChange(selection) {
  288. this.ids = selection.map(item => item.workflowId)
  289. this.single = selection.length !== 1
  290. this.multiple = !selection.length
  291. },
  292. /** 新增按钮操作 */
  293. handleAdd() {
  294. this.$router.push('/his/aiWorkflow/design')
  295. },
  296. /** 设计按钮操作 */
  297. handleEdit(row) {
  298. this.$router.push('/his/aiWorkflow/design/' + row.workflowId)
  299. },
  300. /** 复制按钮操作 */
  301. handleCopy(row) {
  302. this.$confirm('是否确认复制该工作流?', '提示', {
  303. confirmButtonText: '确定',
  304. cancelButtonText: '取消',
  305. type: 'warning'
  306. }).then(() => {
  307. return copyWorkflow(row.workflowId)
  308. }).then(() => {
  309. this.getList()
  310. this.msgSuccess('复制成功')
  311. }).catch(() => {})
  312. },
  313. /** 状态修改 */
  314. handleStatusChange(row) {
  315. const text = row.status === 1 ? '启用' : '停用'
  316. this.$confirm('确认要"' + text + '"该工作流吗?', '警告', {
  317. confirmButtonText: '确定',
  318. cancelButtonText: '取消',
  319. type: 'warning'
  320. }).then(() => {
  321. return updateWorkflowStatus(row.workflowId, row.status)
  322. }).then(() => {
  323. this.msgSuccess(text + '成功')
  324. }).catch(() => {
  325. row.status = row.status === 1 ? 0 : 1
  326. })
  327. },
  328. /** 删除按钮操作 */
  329. handleDelete(row) {
  330. const workflowIds = row.workflowId || this.ids
  331. this.$confirm('是否确认删除工作流编号为"' + workflowIds + '"的数据项?', '警告', {
  332. confirmButtonText: '确定',
  333. cancelButtonText: '取消',
  334. type: 'warning'
  335. }).then(() => {
  336. return delWorkflow(workflowIds)
  337. }).then(() => {
  338. this.getList()
  339. this.msgSuccess('删除成功')
  340. }).catch(() => {})
  341. },
  342. /** 导出按钮操作 */
  343. handleExport() {
  344. const queryParams = this.queryParams
  345. this.$confirm('是否确认导出所有工作流数据项?', '警告', {
  346. confirmButtonText: '确定',
  347. cancelButtonText: '取消',
  348. type: 'warning'
  349. }).then(() => {
  350. this.exportLoading = true
  351. return exportWorkflow(queryParams)
  352. }).then(response => {
  353. this.download(response.msg)
  354. this.exportLoading = false
  355. }).catch(() => {})
  356. },
  357. /** 绑定销售按钮操作 */
  358. handleBindSales(row) {
  359. this.currentWorkflow = row
  360. this.currentBindUserList = []
  361. this.selectedSalesList = []
  362. this.salesSearchKey = ''
  363. this.bindSalesOpen = true
  364. this.salesLoading = true
  365. console.log(11111)
  366. // 获取当前绑定的销售列表
  367. getBindCompanyUserByWorkflowId(row.workflowId).then(res => {
  368. this.currentBindUserList = res.data.data || []
  369. }).catch(() => {})
  370. console.log(this.currentBindUserList)
  371. // 获取销售列表
  372. listCompanyUser().then(res => {
  373. this.companyUserList = res.data || res.rows || []
  374. this.salesLoading = false
  375. }).catch(() => {
  376. this.salesLoading = false
  377. })
  378. },
  379. /** 销售勾选变化 */
  380. handleSalesSelectionChange(selection) {
  381. this.selectedSalesList = selection
  382. },
  383. /** 获取销售行key */
  384. getSalesRowKey(row) {
  385. return row.userId || row.companyUserId || row.id
  386. },
  387. /** 取消绑定销售弹窗 */
  388. handleBindSalesCancel() {
  389. this.bindSalesOpen = false
  390. this.selectedSalesList = []
  391. this.$refs.salesTable && this.$refs.salesTable.clearSelection()
  392. },
  393. /** 销售行样式 */
  394. salesRowClassName({ row }) {
  395. if (this.isCurrentBindUser(row)) {
  396. return 'disabled-row'
  397. }
  398. return ''
  399. },
  400. /** 判断是否为当前绑定用户 */
  401. isCurrentBindUser(row) {
  402. if (!this.currentBindUserList || this.currentBindUserList.length === 0) {
  403. return false
  404. }
  405. const rowUserId = row.userId || row.companyUserId || row.user_id
  406. return this.currentBindUserList.some(user => {
  407. const bindUserId = user.userId || user.companyUserId || user.user_id
  408. return bindUserId == rowUserId
  409. })
  410. },
  411. /** 检查是否可选 */
  412. checkSelectable(row) {
  413. return !this.isCurrentBindUser(row)
  414. },
  415. /** 确认绑定销售 */
  416. confirmBindSales() {
  417. if (this.selectedSalesList.length === 0) {
  418. this.msgWarning('请选择要绑定的销售')
  419. return
  420. }
  421. const workflowId = this.currentWorkflow.workflowId
  422. const companyUserIds = this.selectedSalesList.map(item => item.userId || item.companyUserId)
  423. this.doBindSales(workflowId, companyUserIds)
  424. },
  425. /** 执行绑定销售 */
  426. doBindSales(workflowId, companyUserIds) {
  427. updateWorkflowBindCompanyUser({
  428. workflowId: workflowId,
  429. companyUserIds: companyUserIds
  430. }).then(() => {
  431. this.msgSuccess('绑定成功')
  432. this.bindSalesOpen = false
  433. this.getList()
  434. })
  435. }
  436. }
  437. }
  438. </script>
  439. <style lang="scss" scoped>
  440. .current-sales {
  441. margin-bottom: 20px;
  442. padding-bottom: 15px;
  443. border-bottom: 1px solid #eee;
  444. .section-title {
  445. font-weight: 600;
  446. margin-bottom: 10px;
  447. color: #333;
  448. }
  449. .bind-info {
  450. .el-tag {
  451. font-size: 14px;
  452. padding: 8px 15px;
  453. height: auto;
  454. line-height: 1.5;
  455. white-space: normal;
  456. }
  457. }
  458. .no-bind {
  459. .el-tag {
  460. font-size: 14px;
  461. padding: 8px 15px;
  462. height: auto;
  463. }
  464. }
  465. }
  466. .sales-list {
  467. .section-title {
  468. font-weight: 600;
  469. margin-bottom: 10px;
  470. color: #333;
  471. }
  472. }
  473. </style>
  474. <style lang="scss">
  475. .el-table .disabled-row {
  476. background-color: #f5f5f5;
  477. color: #999;
  478. &:hover > td {
  479. background-color: #f5f5f5 !important;
  480. }
  481. }
  482. </style>