useRuleList.vue 13 KB

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