useRuleList.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. <style>
  2. .rule-tree-select .ant-form-item-control {
  3. line-height: inherit;
  4. }
  5. </style>
  6. <template>
  7. <div class="ruleSetList">
  8. <div class="tabBody">
  9. <a-tabs v-model="tabKey" @change="tabChange">
  10. <a-tab-pane key="1" tab="模板列表"></a-tab-pane>
  11. <a-tab-pane key="2" tab="我的模板"> </a-tab-pane>
  12. <a-button slot="tabBarExtraContent" type="link" @click="toHistory"> 预警历史 </a-button>
  13. </a-tabs>
  14. </div>
  15. <div class="tableBody">
  16. <!-- <div class="opt" v-if="tabKey == '1'">
  17. <a-button type="primary" @click="createNewRule">新建空白规则模板</a-button>
  18. <p class="title">已创建的规则模板</p>
  19. </div> -->
  20. <!-- <div class="opts" v-else>
  21. <a-input-search
  22. placeholder="请输入规则id"
  23. style="width: 350px"
  24. v-model="rulesId"
  25. enter-button
  26. @search="onSearch"
  27. />
  28. </div> -->
  29. <div class="table-page-search-wrapper" v-if="tabKey == '2'">
  30. <a-form layout="inline">
  31. <a-row :gutter="24">
  32. <a-col :md="6" :sm="8">
  33. <a-form-item label="账户名称">
  34. <Treeselect :appId.sync="projectId" :multiple="false" ref="treeSelect" style="width: 100%" />
  35. </a-form-item>
  36. </a-col>
  37. <a-col :md="6" :sm="8">
  38. <a-form-item label="绑定人">
  39. <a-input placeholder="请输入绑定的运营" v-model="userName"></a-input>
  40. </a-form-item>
  41. </a-col>
  42. <a-col :md="6" :sm="8">
  43. <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
  44. <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
  45. <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
  46. </span>
  47. </a-col>
  48. </a-row>
  49. </a-form>
  50. </div>
  51. <div class="table">
  52. <a-table
  53. size="middle"
  54. :columns="columns"
  55. :dataSource="data"
  56. bordered
  57. id="outTable"
  58. :pagination="ipagination"
  59. :scroll="{ x: scrollX }"
  60. :loading="loading"
  61. style="word-break: break-all"
  62. >
  63. <span slot="status" slot-scope="text, record">
  64. <a-spin :spinning="record.spin" size="small">
  65. <div class="spin-content">
  66. <a-switch size="default" :checked="text" @change="switchChange(text, record)" />
  67. </div>
  68. </a-spin>
  69. <!-- <a-switch size="default" :checked=text @change="switchChange(text,record)"/> -->
  70. </span>
  71. <span slot="mediaType" slot-scope="text">
  72. {{ text | handleMediaType }}
  73. </span>
  74. <span slot="accountStatus" slot-scope="text">
  75. <span class="bohui" v-if="text == 1"></span>
  76. <span class="shenhe" v-if="text == 0"></span>
  77. {{ text ? '暂停' : '投放中' }}
  78. </span>
  79. <span slot="processMethod" slot-scope="text">
  80. {{ text == 'SEND' ? '仅发送通知' : '发送并关停组' }}
  81. </span>
  82. <span slot="options" slot-scope="text, record">
  83. <a href="javascript:;" @click="editRule(record)">预览模板</a>
  84. <a-divider type="vertical" />
  85. <a href="javascript:;" @click="pushRule(record)">推送模板</a>
  86. </span>
  87. <span slot="optionsTwo" slot-scope="text, record">
  88. <a href="javascript:;" @click="editRule(record)">编辑模板</a>
  89. <a-divider type="vertical" />
  90. <a-popconfirm :title="`当前删除会解除此账户绑定模板,确定删除吗?`" @confirm="deleteRule(record)">
  91. <a href="javascript:;">删除模板</a>
  92. </a-popconfirm>
  93. </span>
  94. </a-table>
  95. </div>
  96. </div>
  97. <!-- pushRuleVisible -->
  98. <a-modal
  99. v-model="pushRuleVisible"
  100. title="推送账户选择"
  101. @ok="handleOk"
  102. @cancel="cancelPush"
  103. :confirmLoading="confirmLoading"
  104. width="60%"
  105. >
  106. <a-form layout="inline" class="rule-tree-select">
  107. <a-form-item
  108. label="请选择账户"
  109. :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
  110. :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
  111. >
  112. <Treeselect :appId.sync="accountId" :multiple="false" ref="treeSelect" style="width: 100%" />
  113. </a-form-item>
  114. </a-form>
  115. </a-modal>
  116. </div>
  117. </template>
  118. <script>
  119. import moment from 'moment'
  120. import Treeselect from './pushTreeSelect.vue'
  121. import { getAction, postAction, downFile, downFilePost, deleteAction, putAction } from '@/api/manage'
  122. let existColumns = [
  123. // {
  124. // title: '运行/暂停',
  125. // dataIndex: 'status',
  126. // align: 'center',
  127. // width:100,
  128. // key: 'status',
  129. // scopedSlots: { customRender: 'status' }
  130. // },
  131. {
  132. title: '模板id',
  133. dataIndex: 'id',
  134. align: 'center',
  135. key: 'id',
  136. scopedSlots: { customRender: 'id' },
  137. },
  138. {
  139. title: '模板名称',
  140. dataIndex: 'templateName',
  141. align: 'center',
  142. key: 'templateName',
  143. scopedSlots: { customRender: 'templateName' },
  144. },
  145. {
  146. title: '应用媒体',
  147. dataIndex: 'mediaType',
  148. align: 'center',
  149. key: 'mediaType',
  150. scopedSlots: { customRender: 'mediaType' },
  151. },
  152. {
  153. title: '操作',
  154. dataIndex: 'options',
  155. align: 'center',
  156. key: 'options',
  157. scopedSlots: { customRender: 'options' },
  158. },
  159. ]
  160. let recordsColumns = [
  161. {
  162. title: '运行/暂停',
  163. dataIndex: 'status',
  164. align: 'center',
  165. width: 100,
  166. key: 'status',
  167. scopedSlots: { customRender: 'status' },
  168. },
  169. {
  170. title: '模板名称',
  171. dataIndex: 'templateName',
  172. align: 'center',
  173. key: 'templateName',
  174. scopedSlots: { customRender: 'templateName' },
  175. },
  176. {
  177. title: '模板Id',
  178. dataIndex: 'templateId',
  179. align: 'center',
  180. key: 'templateId',
  181. scopedSlots: { customRender: 'templateId' },
  182. },
  183. {
  184. title: '账户',
  185. dataIndex: 'authName',
  186. align: 'center',
  187. key: 'authName',
  188. scopedSlots: { customRender: 'authName' },
  189. },
  190. {
  191. title: '账户Id',
  192. dataIndex: 'accountId',
  193. align: 'center',
  194. key: 'accountId',
  195. scopedSlots: { customRender: 'accountId' },
  196. },
  197. {
  198. title: '账户状态',
  199. dataIndex: 'accountStatus',
  200. align: 'center',
  201. key: 'accountStatus',
  202. scopedSlots: { customRender: 'accountStatus' },
  203. },
  204. {
  205. title: '运营',
  206. dataIndex: 'userName',
  207. align: 'center',
  208. key: 'userName',
  209. scopedSlots: { customRender: 'userName' },
  210. },
  211. {
  212. title: '操作',
  213. dataIndex: 'optionsTwo',
  214. align: 'center',
  215. key: 'optionsTwo',
  216. scopedSlots: { customRender: 'optionsTwo' },
  217. },
  218. ]
  219. export default {
  220. name: 'useRuleList',
  221. data() {
  222. return {
  223. projectId: '',
  224. userName: '',
  225. relationCount: 2,
  226. pushRuleVisible: false,
  227. confirmLoading: false,
  228. accountId: '',
  229. templateId: '',
  230. tabKey: '1',
  231. rulesId: undefined,
  232. data: [],
  233. columns: [...existColumns],
  234. scrollX: 0,
  235. loading: false,
  236. ipagination: {
  237. current: 1,
  238. pageSize: 10,
  239. // pageSizeOptions: ['10', '20', '30'],
  240. showTotal: (total, range) => {
  241. return range[0] + '-' + range[1] + ' 共' + total + '条'
  242. },
  243. showQuickJumper: true,
  244. // showSizeChanger: true,
  245. // pageSizeOptions: ['10', '30', '50'],
  246. total: 0,
  247. onChange: (current, pageSize) => {
  248. // 切换分页时的回调,
  249. // 当在页面定义change事件时,切记要把此处的事件清除,因为这两个事件重叠了,可能到时候会导致一些莫名的bug
  250. this.ipagination.current = current
  251. this.ipagination.pageSize = pageSize
  252. let url = ''
  253. if (this.tabKey == '1') {
  254. this.columns = [...existColumns]
  255. url = '/ruleTemplate/list'
  256. } else {
  257. this.columns = [...recordsColumns]
  258. url = '/ruleAccountTemplate/getTemplateApplied'
  259. }
  260. this.getTableListHttp(url)
  261. },
  262. },
  263. url: {
  264. list: '/ruleTemplate/list',
  265. delete: '/ruleTemplate/delete',
  266. getRelationAccountById: '/ruleAccountTemplate/getRelationAccountById',
  267. edit: '',
  268. },
  269. }
  270. },
  271. components: {
  272. Treeselect,
  273. },
  274. methods: {
  275. toHistory() {
  276. this.$router.replace({ path: '/earlyWarningRules/historyWarning' })
  277. },
  278. searchQuery() {
  279. this.ipagination.current = 1
  280. let url = ''
  281. if (this.tabKey == '1') {
  282. this.columns = [...existColumns]
  283. url = '/ruleTemplate/list'
  284. } else {
  285. this.columns = [...recordsColumns]
  286. url = '/ruleAccountTemplate/getTemplateApplied'
  287. }
  288. this.getTableListHttp(url)
  289. },
  290. searchReset() {
  291. this.ipagination.current = 1
  292. this.projectId = ''
  293. this.userName = ''
  294. let url = ''
  295. if (this.tabKey == '1') {
  296. this.columns = [...existColumns]
  297. url = '/ruleTemplate/list'
  298. } else {
  299. this.columns = [...recordsColumns]
  300. url = '/ruleAccountTemplate/getTemplateApplied'
  301. }
  302. this.getTableListHttp(url)
  303. },
  304. moment,
  305. onSearch(value) {
  306. console.log(value)
  307. },
  308. tabChange(key) {
  309. console.log(key)
  310. this.projectId = ''
  311. this.userName = ''
  312. this.ipagination.current = 1
  313. let url = ''
  314. if (key == '1') {
  315. this.columns = [...existColumns]
  316. url = '/ruleTemplate/list'
  317. } else {
  318. this.columns = [...recordsColumns]
  319. url = '/ruleAccountTemplate/getTemplateApplied'
  320. }
  321. this.getTableListHttp(url)
  322. },
  323. createNewRule() {
  324. this.$router.push('/earlyWarningRules/configRules')
  325. },
  326. sort(pagination, filters, sorter, { currentDataSource }) {
  327. this.ipagination.current = pagination.current
  328. this.ipagination.pageSize = pagination.pageSize
  329. let url = this.tabKey == '1' ? this.url.existUrl : this.url.resultRecordUrl
  330. this.getTableListHttp(url)
  331. },
  332. editRule(record) {
  333. console.log(record)
  334. if (this.tabKey == '1') {
  335. var data = { id: record.id, edit: false }
  336. } else {
  337. var data = { id: record.templateId, edit: true, accountId: record.accountId }
  338. }
  339. localStorage.setItem('getRuleDetail', JSON.stringify(data))
  340. this.$router.push('/earlyWarningRules/ruleModule')
  341. },
  342. pushRule(item) {
  343. // this.confirmLoading
  344. this.accountId = ''
  345. this.templateId = item.id
  346. this.pushRuleVisible = true
  347. },
  348. handleOk() {
  349. if (this.accountId) {
  350. this.confirmLoading = true
  351. getAction('/ruleAccountTemplate/checkAccountTemplate', { accountId: this.accountId }).then((res) => {
  352. console.log(res)
  353. if (res.success) {
  354. if (!res.result.isApplication) {
  355. postAction('/ruleAccountTemplate/pushTemplateToAccount', {
  356. templateId: this.templateId,
  357. accountId: this.accountId,
  358. }).then((r) => {
  359. if (r.success) {
  360. var data = { id: this.templateId, edit: true, accountId: this.accountId }
  361. localStorage.setItem('getRuleDetail', JSON.stringify(data))
  362. this.$router.push('/earlyWarningRules/ruleModule')
  363. this.confirmLoading = false
  364. this.accountId = undefined
  365. } else {
  366. this.$message.error(r.message)
  367. }
  368. })
  369. } else {
  370. // this.accountId = ''
  371. this.$message.error(`此账户下已绑定模板${res.result.templateName},请重新选择账户`)
  372. this.confirmLoading = false
  373. }
  374. } else {
  375. // this.accountId = ''
  376. this.$message.error(res.message)
  377. this.confirmLoading = false
  378. }
  379. })
  380. } else {
  381. this.$message.error('请选择需要推送的账户')
  382. }
  383. },
  384. cancelPush() {
  385. this.accountId = ''
  386. },
  387. // recordsRule(record){
  388. // console.log(record);
  389. // },
  390. showRelativeCount(record) {
  391. getAction(this.url.getRelationAccountById, {
  392. id: record.id,
  393. }).then((res) => {
  394. console.log(res)
  395. if (res.success) {
  396. this.relationCount = res.result.relationCount
  397. // getAction(this.url.delete,{
  398. // id:record.id
  399. // }).then(res=>{
  400. // console.log(res);
  401. // if(res.success){
  402. // this.getTableListHttp(this.url.list)
  403. // }else{
  404. // this.$message.error('删除失败')
  405. // }
  406. // })
  407. }
  408. })
  409. },
  410. deleteRule(record) {
  411. console.log(record)
  412. deleteAction('/ruleAccountTemplate/delete', {
  413. id: record.id,
  414. }).then((res) => {
  415. if (res.success) {
  416. this.getTableListHttp('/ruleAccountTemplate/getTemplateApplied')
  417. // getAction(this.url.delete,{
  418. // id:record.id
  419. // }).then(res=>{
  420. // console.log(res);
  421. // if(res.success){
  422. // this.getTableListHttp(this.url.list)
  423. // }else{
  424. // this.$message.error('删除失败')
  425. // }
  426. // })
  427. }
  428. })
  429. },
  430. switchChange(text, record) {
  431. console.log(text, record)
  432. if (record.accountStatus == 0 || (record.accountStatus == 1 && text)) {
  433. record.spin = true
  434. let templateStatus = 0
  435. if (text) {
  436. templateStatus = 1
  437. } else {
  438. templateStatus = 0
  439. }
  440. putAction('/ruleAccountTemplate/edit', {
  441. id: record.id,
  442. templateStatus,
  443. }).then((res) => {
  444. console.log(res)
  445. record.spin = false
  446. if (res.success) {
  447. // this.getTableListHttp()
  448. if (text) {
  449. record.status = false
  450. templateStatus = 1
  451. this.$message.success('修改成功')
  452. } else {
  453. record.status = true
  454. templateStatus = 0
  455. this.$message.success('修改成功')
  456. }
  457. } else {
  458. this.$message.error('修改失败')
  459. // this.getTableListHttp()
  460. }
  461. })
  462. } else {
  463. this.$message.error('当前账户已关停,预警规则不支持开启!')
  464. }
  465. },
  466. getTableListHttp(url) {
  467. this.data = []
  468. this.loading = true
  469. // let url='/alarm/alarmEventRule/list'
  470. var params = {}
  471. if (this.tabKey == '2') {
  472. params.accountId = this.projectId
  473. params.userName = this.userName
  474. }
  475. getAction(url, {
  476. pageNo: this.ipagination.current,
  477. pageSize: this.ipagination.pageSize,
  478. ...params,
  479. }).then((res) => {
  480. console.log(res)
  481. this.loading = false
  482. if (res.success) {
  483. if (this.tabKey == '1') {
  484. this.data = res.result.records.map((item) => {
  485. return {
  486. ...item,
  487. status: item.templateStatus == 0 ? true : false,
  488. spin: false,
  489. }
  490. })
  491. } else {
  492. this.data = res.result.list.map((item) => {
  493. return {
  494. ...item,
  495. status: item.templateStatus == 0 ? true : false,
  496. spin: false,
  497. }
  498. })
  499. }
  500. this.ipagination.total = res.result.total
  501. }
  502. })
  503. },
  504. },
  505. mounted() {
  506. this.getTableListHttp(this.url.list)
  507. },
  508. activated() {
  509. this.getTableListHttp(this.url.list)
  510. },
  511. filters: {
  512. handleMediaType(val) {
  513. switch (val) {
  514. case 1:
  515. return '头条'
  516. break
  517. case 2:
  518. return '快手'
  519. break
  520. case 3:
  521. return '头条'
  522. break
  523. case 4:
  524. return '快手内广'
  525. break
  526. default:
  527. break
  528. }
  529. },
  530. },
  531. }
  532. </script>
  533. <style lang="scss" scoped>
  534. .ruleSetList {
  535. background: white;
  536. padding: 20px;
  537. .tabBody {
  538. margin-bottom: 5px;
  539. }
  540. .tableBody {
  541. .opt {
  542. .title {
  543. margin: 15px 0;
  544. height: 57px;
  545. font-size: 16px;
  546. color: #333;
  547. line-height: 57px;
  548. background: #ffffff;
  549. padding-left: 15px;
  550. border-radius: 4px 4px 0 0;
  551. font-weight: 600;
  552. border-bottom: 1px solid #DADFE3;
  553. }
  554. }
  555. .opts {
  556. margin-bottom: 15px;
  557. }
  558. .shenhe {
  559. width: 6px;
  560. height: 6px;
  561. display: inline-block;
  562. background: #52C41A;
  563. border-radius: 50%;
  564. position: relative;
  565. top: -2px;
  566. }
  567. .bohui {
  568. width: 6px;
  569. height: 6px;
  570. display: inline-block;
  571. background: #F5222D;
  572. border-radius: 50%;
  573. position: relative;
  574. top: -2px;
  575. }
  576. }
  577. }
  578. </style>