index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. <template>
  2. <div class="app-container">
  3. <!-- 查询表单 -->
  4. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  5. <el-form-item label="链接名称" prop="linkName">
  6. <el-input
  7. v-model="queryParams.linkName"
  8. placeholder="请输入链接名称"
  9. clearable
  10. size="small"
  11. @keyup.enter.native="handleQuery"
  12. />
  13. </el-form-item>
  14. <el-form-item label="企业微信" prop="corpName">
  15. <el-input
  16. v-model="queryParams.corpName"
  17. placeholder="请输入企业微信"
  18. clearable
  19. size="small"
  20. @keyup.enter.native="handleQuery"
  21. />
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  25. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  26. </el-form-item>
  27. </el-form>
  28. <el-row :gutter="10" class="mb8">
  29. <el-col :span="1.5">
  30. <el-button
  31. type="primary"
  32. plain
  33. icon="el-icon-plus"
  34. size="mini"
  35. @click="handleAdd"
  36. >新增</el-button>
  37. </el-col>
  38. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  39. </el-row>
  40. <!-- 列表 -->
  41. <el-table v-loading="loading" :data="list" border>
  42. <el-table-column label="链接名称" align="center" prop="linkName" />
  43. <el-table-column label="企业微信" align="center" prop="corpName" />
  44. <el-table-column label="渠道链接" align="center" prop="url" show-overflow-tooltip />
  45. <el-table-column label="创建人" align="center" prop="createBy" />
  46. <el-table-column label="创建时间" align="center" prop="createTime" />
  47. <el-table-column label="最后修改人" align="center" prop="updateBy" />
  48. <el-table-column label="修改时间" align="center" prop="updateTime" />
  49. <el-table-column label="今日添加数" align="center" prop="toDayAddNum" />
  50. <el-table-column label="累积添加数" align="center" prop="countAddNum" />
  51. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  52. <template slot-scope="scope">
  53. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)">编辑</el-button>
  54. <el-button size="mini" type="text" icon="el-icon-view" @click="handleViewChannel(scope.row)">查看渠道</el-button>
  55. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
  56. </template>
  57. </el-table-column>
  58. </el-table>
  59. <!-- 分页 -->
  60. <pagination
  61. v-show="total>0"
  62. :total="total"
  63. :page.sync="queryParams.pageNum"
  64. :limit.sync="queryParams.pageSize"
  65. @pagination="getList"
  66. />
  67. <!-- 新增/编辑对话框 -->
  68. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body @close="cancel">
  69. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  70. <el-form-item label="链接名称" prop="linkName">
  71. <el-input v-model="form.linkName" placeholder="请输入链接名称" />
  72. </el-form-item>
  73. <el-form-item label="企业微信" prop="corpId">
  74. <el-select v-model="form.corpId" placeholder="请选择企业微信" @change="handleCorpChange">
  75. <el-option v-for="item in qwCompanyList" :key="item.corpId" :label="item.corpName" :value="item.corpId" />
  76. </el-select>
  77. </el-form-item>
  78. <el-form-item label="自动通过好友" prop="skipVerify">
  79. <div style="display: flex; align-items: center; height: 32px;">
  80. <el-switch v-model="form.skipVerify" :active-value="1" :inactive-value="0" />
  81. </div>
  82. </el-form-item>
  83. <el-form-item label="员工选择" prop="linkUser">
  84. <el-select v-model="form.selectedUserIds" placeholder="请先选择企业微信" :disabled="!form.corpId" multiple @change="handleUserChange">
  85. <el-option v-for="item in qwUserList" :key="item.id" :label="item.qwUserName" :value="item.id" />
  86. </el-select>
  87. </el-form-item>
  88. </el-form>
  89. <div slot="footer" class="dialog-footer">
  90. <el-button type="primary" @click="submitForm">确 定</el-button>
  91. <el-button @click="cancel">取 消</el-button>
  92. </div>
  93. </el-dialog>
  94. <!-- 查看渠道链接对话框 -->
  95. <el-dialog title="查看渠道链接" :visible.sync="channelDialogOpen" width="900px" append-to-body @close="cancelChannel">
  96. <!-- 查询表单 -->
  97. <el-form :model="channelQueryParams" ref="channelQueryForm" :inline="true" v-show="channelShowSearch" label-width="68px">
  98. <el-form-item label="渠道名称" prop="linkName">
  99. <el-input
  100. v-model="channelQueryParams.linkName"
  101. placeholder="请输入渠道名称"
  102. clearable
  103. size="small"
  104. @keyup.enter.native="getChannelList"
  105. />
  106. </el-form-item>
  107. <el-form-item>
  108. <el-button type="primary" icon="el-icon-search" size="mini" @click="getChannelList">搜索</el-button>
  109. <el-button icon="el-icon-refresh" size="mini" @click="resetChannelQuery">重置</el-button>
  110. </el-form-item>
  111. </el-form>
  112. <el-row :gutter="10" class="mb8">
  113. <el-col :span="1.5">
  114. <el-button
  115. type="primary"
  116. plain
  117. icon="el-icon-plus"
  118. size="mini"
  119. @click="handleAddChannel"
  120. >新增</el-button>
  121. </el-col>
  122. <right-toolbar :showSearch.sync="channelShowSearch" @queryTable="getChannelList"></right-toolbar>
  123. </el-row>
  124. <!-- 渠道列表 -->
  125. <el-table v-loading="channelLoading" :data="channelList" border>
  126. <el-table-column label="渠道名称" align="center" prop="linkName" />
  127. <el-table-column label="渠道链接" align="center" prop="url" show-overflow-tooltip />
  128. <el-table-column label="今日添加数" align="center" prop="toDayAddNum" />
  129. <el-table-column label="累积添加数" align="center" prop="countAddNum" />
  130. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  131. <template slot-scope="scope">
  132. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeleteChannel(scope.row)">删除</el-button>
  133. </template>
  134. </el-table-column>
  135. </el-table>
  136. <!-- 分页 -->
  137. <pagination
  138. v-show="channelTotal>0"
  139. :total="channelTotal"
  140. :page.sync="channelQueryParams.pageNum"
  141. :limit.sync="channelQueryParams.pageSize"
  142. @pagination="getChannelList"
  143. />
  144. <div slot="footer" class="dialog-footer">
  145. <el-button @click="cancelChannel">关 闭</el-button>
  146. </div>
  147. </el-dialog>
  148. <!-- 新增渠道对话框 -->
  149. <el-dialog title="选择渠道" :visible.sync="selectChannelDialogOpen" width="900px" append-to-body>
  150. <el-row :gutter="20">
  151. <!-- 左侧:分组和渠道选择 -->
  152. <el-col :xs="24" :sm="12">
  153. <div style="border-right: 1px solid #dcdfe6; padding-right: 20px;">
  154. <h4 style="margin-top: 0; margin-bottom: 15px;">分组管理</h4>
  155. <div style="margin-bottom: 15px;">
  156. <el-input
  157. v-model="selectChannelQueryParams.channelName"
  158. placeholder="搜索分组"
  159. clearable
  160. size="small"
  161. @input="loadGroupList"
  162. />
  163. </div>
  164. <div style="border: 1px solid #dcdfe6; border-radius: 4px; max-height: 400px; overflow-y: auto;">
  165. <div
  166. v-for="item in groupList"
  167. :key="item.id"
  168. :class="['group-item', { active: selectedGroupId === item.id }]"
  169. @click="selectGroup(item)"
  170. style="padding: 10px 15px; cursor: pointer; border-bottom: 1px solid #f0f0f0; user-select: none;"
  171. >
  172. <span>{{ item.channelName }}</span>
  173. </div>
  174. <div v-if="groupList.length === 0" style="padding: 20px; text-align: center; color: #909399;">暂无分组</div>
  175. </div>
  176. </div>
  177. </el-col>
  178. <!-- 中间:渠道列表 -->
  179. <el-col :xs="24" :sm="12">
  180. <div style="padding: 0 20px;">
  181. <h4 style="margin-top: 0; margin-bottom: 15px;">渠道模板</h4>
  182. <div v-if="!selectedGroupId" style="padding: 40px 0; text-align: center; color: #909399;">
  183. 请上方选择分组
  184. </div>
  185. <div v-else>
  186. <div style="border: 1px solid #dcdfe6; border-radius: 4px; max-height: 400px; overflow-y: auto;">
  187. <div
  188. v-for="item in selectChannelList"
  189. :key="item.id"
  190. style="padding: 10px 15px; border-bottom: 1px solid #f0f0f0; display: flex; align-items: center; user-select: none; cursor: pointer; background-color: #fff; transition: all 0.3s;"
  191. :style="{ backgroundColor: isChannelSelected(item) ? '#e6f7ff' : '#fff' }"
  192. @click="toggleChannelSelection(item)"
  193. >
  194. <el-checkbox
  195. :value="isChannelSelected(item)"
  196. style="margin-right: 8px;"
  197. />
  198. <span>{{ item.channelName }}</span>
  199. </div>
  200. <div v-if="selectChannelList.length === 0" style="padding: 20px; text-align: center; color: #909399;">暂无渠道</div>
  201. </div>
  202. </div>
  203. </div>
  204. </el-col>
  205. </el-row>
  206. <!-- 右侧:已选渠道 -->
  207. <div style="margin-top: 20px; padding-top: 20px; border-top: 1px solid #dcdfe6;">
  208. <h4 style="margin-top: 0; margin-bottom: 10px;">已选渠道({{ selectedChannels.length }})</h4>
  209. <div style="border: 1px solid #dcdfe6; border-radius: 4px; padding: 10px; min-height: 80px; max-height: 150px; overflow-y: auto;">
  210. <el-tag
  211. v-for="(item, index) in selectedChannels"
  212. :key="item.channelId || index"
  213. closable
  214. @close="removeSelectedChannel(item)"
  215. style="margin: 5px; cursor: pointer;"
  216. >
  217. {{ item.channelName }}
  218. </el-tag>
  219. <div v-if="selectedChannels.length === 0" style="color: #909399; text-align: center; padding: 20px 0;">未选择任何渠道</div>
  220. </div>
  221. </div>
  222. <div slot="footer" class="dialog-footer">
  223. <el-button @click="selectChannelDialogOpen = false">取 消</el-button>
  224. <el-button type="primary" @click="confirmAddChannel">确 定</el-button>
  225. </div>
  226. </el-dialog>
  227. </div>
  228. </template>
  229. <script>
  230. import {
  231. pageCustomerLink,
  232. createOrUpdateCustomerLink,
  233. deleteCustomerLink,
  234. pageCustomerLinkChannel,
  235. createCustomerLinkChannel,
  236. deleteCustomerLinkChannel
  237. } from '@/api/qw/customerLink'
  238. import { getMyQwCompanyList, listUser } from '@/api/qw/user'
  239. import { pageProject } from '@/api/adv/channel'
  240. import Pagination from '@/components/Pagination'
  241. import RightToolbar from '@/components/RightToolbar'
  242. export default {
  243. name: 'CustomerLink',
  244. components: {
  245. Pagination,
  246. RightToolbar
  247. },
  248. data() {
  249. return {
  250. // 加载状态
  251. loading: false,
  252. channelLoading: false,
  253. // 是否显示查询表单
  254. showSearch: true,
  255. channelShowSearch: true,
  256. // 列表数据
  257. list: [],
  258. total: 0,
  259. // 查询参数
  260. queryParams: {
  261. pageNum: 1,
  262. pageSize: 10,
  263. linkName: undefined,
  264. corpName: undefined
  265. },
  266. // 表单参数
  267. form: {},
  268. // 表单验证规则
  269. rules: {
  270. linkName: [
  271. { required: true, message: '请输入链接名称', trigger: 'blur' }
  272. ],
  273. corpId: [
  274. { required: true, message: '请选择企业微信', trigger: 'change' }
  275. ],
  276. linkUser: [
  277. { required: true, message: '请选择员工', trigger: 'change' }
  278. ]
  279. },
  280. // 对话框
  281. open: false,
  282. title: '',
  283. // 企业微信列表
  284. qwCompanyList: [],
  285. // 企业微信员工列表
  286. qwUserList: [],
  287. // 选中的企业微信ID
  288. selectedCorpId: undefined,
  289. // 渠道链接对话框
  290. channelDialogOpen: false,
  291. channelList: [],
  292. channelTotal: 0,
  293. channelQueryParams: {
  294. pageNum: 1,
  295. pageSize: 10,
  296. linkName: undefined,
  297. sysLinkId: undefined
  298. },
  299. // 新增渠道对话框
  300. selectChannelDialogOpen: false,
  301. selectChannelParams: {
  302. channelId: undefined
  303. },
  304. channelOptions: [],
  305. currentSysLinkId: undefined,
  306. // 渠道选择相关数据
  307. groupList: [], // 分组列表
  308. selectedGroupId: null, // 选中的分组ID
  309. selectChannelList: [], // 当前分组的渠道列表
  310. selectChannelLoading: false, // 渠道列表加载中
  311. selectedChannels: [], // 已选择的渠道列表(右侧)
  312. selectChannelPageNum: 1,
  313. selectChannelPageSize: 10,
  314. selectChannelTotal: 0,
  315. selectChannelQueryParams: {
  316. channelName: ''
  317. }
  318. }
  319. },
  320. created() {
  321. this.getList()
  322. this.loadQwCompanyList()
  323. },
  324. methods: {
  325. // 查询列表
  326. getList() {
  327. this.loading = true
  328. pageCustomerLink(this.queryParams).then(response => {
  329. this.list = response.data.records || []
  330. this.total = response.data.total || 0
  331. this.loading = false
  332. }).catch(() => {
  333. this.loading = false
  334. })
  335. },
  336. // 搜索
  337. handleQuery() {
  338. this.queryParams.pageNum = 1
  339. this.getList()
  340. },
  341. // 重置查询
  342. resetQuery() {
  343. this.resetForm('queryForm')
  344. this.handleQuery()
  345. },
  346. // 新增
  347. handleAdd() {
  348. this.reset()
  349. this.open = true
  350. this.title = '新增渠道管理'
  351. },
  352. // 编辑
  353. handleUpdate(row) {
  354. this.reset()
  355. this.form = Object.assign({}, row)
  356. this.selectedCorpId = row.corpId
  357. this.loadQwUserList(row.corpId)
  358. this.open = true
  359. this.title = '编辑渠道管理'
  360. },
  361. // 删除
  362. handleDelete(row) {
  363. this.$confirm('确定删除该渠道吗?', '提示', {
  364. confirmButtonText: '确定',
  365. cancelButtonText: '取消',
  366. type: 'warning'
  367. }).then(() => {
  368. deleteCustomerLink(row.id).then(response => {
  369. this.$message.success('删除成功')
  370. this.getList()
  371. })
  372. }).catch(() => {})
  373. },
  374. // 查看渠道链接
  375. handleViewChannel(row) {
  376. this.channelDialogOpen = true
  377. this.currentSysLinkId = row.id
  378. this.channelQueryParams.sysLinkId = row.id
  379. this.getChannelList()
  380. },
  381. // 查询渠道链接列表
  382. getChannelList() {
  383. this.channelLoading = true
  384. pageCustomerLinkChannel(this.channelQueryParams).then(response => {
  385. this.channelList = response.data.records || []
  386. this.channelTotal = response.data.total || 0
  387. this.channelLoading = false
  388. }).catch(() => {
  389. this.channelLoading = false
  390. })
  391. },
  392. // 重置渠道查询
  393. resetChannelQuery() {
  394. this.channelQueryParams = {
  395. pageNum: 1,
  396. pageSize: 10,
  397. linkName: undefined,
  398. sysLinkId: this.currentSysLinkId
  399. }
  400. this.getChannelList()
  401. },
  402. // 新增渠道链接
  403. handleAddChannel() {
  404. this.selectChannelDialogOpen = true
  405. this.selectedChannels = []
  406. this.selectedGroupId = null
  407. this.selectChannelList = []
  408. this.selectChannelQueryParams.channelName = ''
  409. this.loadGroupList()
  410. },
  411. // 加载分组列表
  412. loadGroupList() {
  413. const params = { pageNum: 1, pageSize: 1000, parentId: 0 }
  414. pageProject(params).then(response => {
  415. this.groupList = response.data.records || []
  416. }).catch(() => {
  417. this.groupList = []
  418. })
  419. },
  420. // 选择分组
  421. selectGroup(group) {
  422. this.selectedGroupId = group.id
  423. this.selectChannelPageNum = 1
  424. this.getSelectChannelList()
  425. },
  426. // 获取渠道列表
  427. getSelectChannelList() {
  428. if (!this.selectedGroupId) return
  429. this.selectChannelLoading = true
  430. const params = { pageNum: this.selectChannelPageNum, pageSize: this.selectChannelPageSize, parentId: this.selectedGroupId }
  431. if (this.selectChannelQueryParams.channelName) {
  432. params.channelName = this.selectChannelQueryParams.channelName
  433. }
  434. pageProject(params).then(response => {
  435. this.selectChannelList = response.data.records || []
  436. this.selectChannelTotal = response.data.total || 0
  437. this.selectChannelLoading = false
  438. }).catch(() => {
  439. this.selectChannelLoading = false
  440. })
  441. },
  442. // 勾选渠道
  443. toggleChannelSelection(channel) {
  444. const index = this.selectedChannels.findIndex(item => item.channelId === channel.id)
  445. if (index > -1) {
  446. // 已选中,取消选择
  447. this.selectedChannels.splice(index, 1)
  448. } else {
  449. // 未选中,添加选择
  450. this.selectedChannels.push({ channelId: channel.id, channelName: channel.channelName })
  451. }
  452. },
  453. // 判断渠道是否已选择
  454. isChannelSelected(channel) {
  455. return this.selectedChannels.some(item => item.channelId === channel.id)
  456. },
  457. // 删除已选渠道
  458. removeSelectedChannel(channel) {
  459. const index = this.selectedChannels.findIndex(item => item.channelId === channel.channelId)
  460. if (index > -1) {
  461. this.selectedChannels.splice(index, 1)
  462. }
  463. },
  464. // 加载渠道选项
  465. loadChannelOptions() {
  466. // 这里需要加载渠道列表,根据实际接口调整
  467. // 暂时使用空数组,需要后续实现
  468. this.channelOptions = []
  469. },
  470. // 确认新增渠道
  471. confirmAddChannel() {
  472. if (this.selectedChannels.length === 0) {
  473. this.$message.error('请选择渠道')
  474. return
  475. }
  476. const data = {
  477. sysLinkId: this.currentSysLinkId,
  478. channelList: this.selectedChannels
  479. }
  480. createCustomerLinkChannel(data).then(response => {
  481. this.$message.success('新增成功')
  482. this.selectChannelDialogOpen = false
  483. this.getChannelList()
  484. })
  485. },
  486. // 删除渠道链接
  487. handleDeleteChannel(row) {
  488. this.$confirm('确定删除该渠道链接吗?', '提示', {
  489. confirmButtonText: '确定',
  490. cancelButtonText: '取消',
  491. type: 'warning'
  492. }).then(() => {
  493. deleteCustomerLinkChannel(row.id).then(response => {
  494. this.$message.success('删除成功')
  495. this.getChannelList()
  496. })
  497. }).catch(() => {})
  498. },
  499. // 关闭渠道链接对话框
  500. cancelChannel() {
  501. this.channelDialogOpen = false
  502. this.currentSysLinkId = undefined
  503. },
  504. // 表单提交
  505. submitForm() {
  506. this.$refs.form.validate(valid => {
  507. if (valid) {
  508. const data = {
  509. linkName: this.form.linkName,
  510. corpId: this.form.corpId,
  511. corpName: this.form.corpName,
  512. skipVerify: this.form.skipVerify,
  513. linkUser: this.form.linkUser
  514. }
  515. if (this.form.id) {
  516. data.id = this.form.id
  517. }
  518. createOrUpdateCustomerLink(data).then(response => {
  519. this.$message.success(this.form.id ? '编辑成功' : '新增成功')
  520. this.open = false
  521. this.getList()
  522. })
  523. }
  524. })
  525. },
  526. // 重置表单
  527. reset() {
  528. this.form = {
  529. linkName: undefined,
  530. corpId: undefined,
  531. corpName: undefined,
  532. skipVerify: 0,
  533. selectedUserIds: [],
  534. linkUser: []
  535. }
  536. this.qwUserList = []
  537. this.selectedCorpId = undefined
  538. if (this.$refs.form) {
  539. this.$refs.form.clearValidate()
  540. }
  541. },
  542. // 取消
  543. cancel() {
  544. this.open = false
  545. this.reset()
  546. },
  547. // 加载企业微信列表
  548. loadQwCompanyList() {
  549. getMyQwCompanyList().then(response => {
  550. this.qwCompanyList = response.data || []
  551. }).catch(() => {
  552. this.qwCompanyList = []
  553. })
  554. },
  555. // 企业微信改变
  556. handleCorpChange(corpId) {
  557. this.form.selectedUserIds = []
  558. this.form.linkUser = []
  559. this.qwUserList = []
  560. const selectedCompany = this.qwCompanyList.find(item => item.corpId === corpId)
  561. if (selectedCompany) {
  562. this.form.corpName = selectedCompany.corpName
  563. }
  564. this.loadQwUserList(corpId)
  565. },
  566. // 加载企业微信员工列表
  567. loadQwUserList(corpId) {
  568. if (!corpId) {
  569. this.qwUserList = []
  570. return
  571. }
  572. listUser({ corpId: corpId }).then(response => {
  573. this.qwUserList = response.rows || []
  574. }).catch(() => {
  575. this.qwUserList = []
  576. })
  577. },
  578. // 员工改变
  579. handleUserChange(userIds) {
  580. // 根据选中的用户ID列表构建员工信息数组
  581. this.form.linkUser = userIds.map(userId => {
  582. const selectedUser = this.qwUserList.find(item => item.id === userId)
  583. return {
  584. sysQwUserId: selectedUser.id,
  585. qwUserName: selectedUser.qwUserName,
  586. qwUserId: selectedUser.qwUserId
  587. }
  588. })
  589. },
  590. // 表单重置
  591. resetForm(refName) {
  592. if (this.$refs[refName]) {
  593. this.$refs[refName].resetFields()
  594. }
  595. }
  596. }
  597. }
  598. </script>
  599. <style scoped>
  600. </style>