useRuleList.vue 14 KB

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