useRuleList.vue 13 KB

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