index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. <template>
  2. <div class="app-container">
  3. <el-row>
  4. <el-col :span="24">
  5. <div class="cell">
  6. <div class="cell-title">
  7. <div class="title-left">
  8. <div class="title">招商资讯</div>
  9. </div>
  10. </div>
  11. <div class="cell-body">
  12. <div class="controls">
  13. <el-form :inline="true" :model="formInline" class="demo-form-inline">
  14. <el-form-item label="">
  15. <el-input v-model="formInline.keyword" style="width: 150px;" prefix-icon="el-icon-search" clearable
  16. placeholder="请输入关键字"></el-input>
  17. </el-form-item>
  18. <el-form-item>
  19. <el-button type="primary" class="btn-search" @click="btn_search">查询</el-button>
  20. </el-form-item>
  21. <el-form-item label="发布时间">
  22. <el-date-picker v-model="formInline.search_datatime" type="daterange" align="right" start-placeholder="开始日期"
  23. end-placeholder="结束日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd" @change="btn_search">
  24. </el-date-picker>
  25. </el-form-item>
  26. <el-form-item label="是否置顶">
  27. <el-select v-model="formInline.is_top" clearable placeholder="请选择" style="width: 120px;" @change="btn_search">
  28. <el-option v-for="item in formInline.options" :key="item.is_top" :label="item.label" :value="item.is_top">
  29. </el-option>
  30. </el-select>
  31. </el-form-item>
  32. </el-form>
  33. <div class="btns">
  34. <el-button type="primary" class="btn-article-del" @click="article_del">删除</el-button>
  35. <el-button type="primary" class="btn-update-get-article" @click="article_update">更新</el-button>
  36. <el-button type="primary" class="btn-update-get-article" @click="article_get">获取文章</el-button>
  37. </div>
  38. </div>
  39. <el-table :data="tableData" height="564" style="width: 100%" :cell-style="cell_style" :key='Math.random()'
  40. :header-cell-style="header_cell_style" @selection-change="handle_table_change">
  41. <el-table-column type="selection" width="50"></el-table-column>
  42. <el-table-column label="标题" align="center">
  43. <template slot-scope="scope">
  44. <span><el-link type="primary" :underline="false"
  45. @click="show_article_detail(scope.row)">{{ scope.row.title }}</el-link></span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="封面图" align="center">
  49. <template slot-scope="scope">
  50. <span v-if="scope.row.first_img != ''">
  51. <viewer>
  52. <img style="height: 100px; cursor: pointer;" :src="scope.row.first_img" />
  53. </viewer>
  54. </span>
  55. <span v-else>
  56. <el-image>
  57. <div slot="error" class="image-slot"><i class="el-icon-picture-outline"></i></div>
  58. </el-image>
  59. </span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="内容" width="600">
  63. <template slot-scope="scope">
  64. <span v-text="removeHtmlTags(scope.row.content)"></span>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="发布时间" align="center" width="100">
  68. <template slot-scope="scope">
  69. <span>{{ scope.row.update_time }}</span>
  70. </template>
  71. </el-table-column>
  72. <el-table-column label="是否置顶" align="center" width="90">
  73. <template slot-scope="scope">
  74. <span>{{ scope.row.is_top }}</span>
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="操作" width="130" align="center">
  78. <template slot-scope="scope">
  79. <el-button v-if="scope.row.is_top == 0" @click.native.prevent="handle_top(scope.row.id, 1)" type="text"
  80. size="small">置顶</el-button>
  81. <el-button v-else @click.native.prevent="handle_top(scope.row.id, 0)" type="text" size="small">取消置顶</el-button>
  82. </template>
  83. </el-table-column>
  84. </el-table>
  85. <div class="pagination-table">
  86. <el-pagination @current-change="currentPageChange" :current-page.sync="pagination.currentPage" :page-size="pagination.pageSize"
  87. layout="prev, pager, next, jumper" :total="pagination.total">
  88. </el-pagination>
  89. </div>
  90. </div>
  91. </div>
  92. </el-col>
  93. </el-row>
  94. <el-dialog custom-class="dialog-qingzhang" :visible.sync="dialog_del_article" :close-on-click-modal="false" :close-on-press-escape="false"
  95. :show-close="false">
  96. <div slot="" class="dialog-qingzhang-body">
  97. <img src="../../icons/serveAC/del_warning.png" alt="">
  98. <div class="dialog-qingzhang-body-txt">删除后的文章将不在民宿小程序<br>上进行展示,确定删除吗?</div>
  99. </div>
  100. <div slot="footer" class="dialog-footer">
  101. <el-button class="add-user-cancel-btn" @click="dialog_del_article = false"> 取消 </el-button>
  102. <el-button class="add-user-confirm-btn" @click="handle_del_article"> 确定 </el-button>
  103. </div>
  104. </el-dialog>
  105. <el-dialog custom-class="dialog-qingzhang" :visible.sync="dialog_update_article" :close-on-click-modal="false" :close-on-press-escape="false"
  106. :show-close="false">
  107. <div slot="" class="dialog-qingzhang-body">
  108. <img src="../../icons/serveAC/del_warning.png" alt="">
  109. <div class="dialog-qingzhang-body-txt">确定对选中的文章进行更新吗?</div>
  110. </div>
  111. <div slot="footer" class="dialog-footer">
  112. <el-button class="add-user-cancel-btn" @click="dialog_update_article = false"> 取消 </el-button>
  113. <el-button class="add-user-confirm-btn" @click="handle_update_article"> 确定 </el-button>
  114. </div>
  115. </el-dialog>
  116. <el-dialog custom-class="dialog-qingzhang" :visible.sync="dialog_get_article" :close-on-click-modal="false" :close-on-press-escape="false"
  117. :show-close="false">
  118. <div slot="" class="dialog-qingzhang-body">
  119. <img src="../../icons/serveAC/del_warning.png" alt="">
  120. <div class="dialog-qingzhang-body-txt">确定从公众号获取最新文章数据吗?</div>
  121. </div>
  122. <div slot="footer" class="dialog-footer">
  123. <el-button class="add-user-cancel-btn" @click="dialog_get_article = false"> 取消 </el-button>
  124. <el-button class="add-user-confirm-btn" @click="handle_get_article"> 确定 </el-button>
  125. </div>
  126. </el-dialog>
  127. <el-dialog :visible.sync="dialog_show_article" title="文章详情" width="50%">
  128. <div>
  129. <h3 style="text-align: center;">{{ article_detail.title }}</h3>
  130. <p style="text-align: center;">作者:{{ article_detail.author }}</p>
  131. <p style="text-align: center;">时间:{{ article_detail.time }}</p>
  132. <div v-html="article_detail.content" style="height: 500px; overflow: auto; border: 1px solid #e3e3e3; padding: 10px 10px 10px 30px;"></div>
  133. </div>
  134. </el-dialog>
  135. </div>
  136. </template>
  137. <script>
  138. import {
  139. getTableData,
  140. getArticle,
  141. updateArticle,
  142. delArticle,
  143. topArticle
  144. } from '@/api/businessInfo'
  145. import {
  146. isEmpty
  147. } from '@/js/common'
  148. export default {
  149. data() {
  150. return {
  151. currentUserLevel: this.$store.state.user.level, // 当前用户的权限
  152. dialogImageUrl: '',
  153. formLabelWidth: '120px',
  154. sumAccount: '', // 总金额
  155. // 表格单元格样式
  156. cell_style: {
  157. color: '#1A202B',
  158. 'font-size': '14px',
  159. 'font-family': 'Microsoft YaHei-3970(82674968)'
  160. },
  161. // 表格头部样式
  162. header_cell_style: {
  163. background: '#E6ECFE',
  164. color: '#1A202B',
  165. 'font-size': '16px',
  166. 'font-family': 'Microsoft YaHei-3970(82674968)'
  167. },
  168. // 查询数据
  169. formInline: {
  170. options: [{
  171. is_top: 0,
  172. label: '否'
  173. }, {
  174. is_top: 1,
  175. label: '是'
  176. }],
  177. is_top: '',
  178. search_datatime: '',
  179. keyword: ''
  180. },
  181. tableData: [],
  182. cond_data: {},
  183. // 分页参数
  184. pagination: {
  185. currentPage: 1,
  186. pageSize: 4,
  187. total: 0
  188. },
  189. // 文章删除、更新、获取的参数
  190. dialog_del_article: false,
  191. del_ids: [],
  192. dialog_update_article: false,
  193. update_ids: [],
  194. dialog_get_article: false,
  195. dialog_show_article: false,
  196. article_detail: {
  197. title: '',
  198. author: '',
  199. time: '',
  200. content: ''
  201. }
  202. }
  203. },
  204. created() {
  205. // 检测权限
  206. if (this.currentUserLevel !== 2) {
  207. this.$router.replace({
  208. path: '/data'
  209. })
  210. return
  211. }
  212. // 获取消费记录,表格数据
  213. this.get_table_data('list')
  214. },
  215. mounted() {
  216. document.getElementsByClassName("el-pagination__jump")[0].childNodes[0].nodeValue = "跳至";
  217. },
  218. methods: {
  219. // 显示文章详情
  220. show_article_detail(row) {
  221. console.log(row);
  222. this.article_detail.title = row.title
  223. this.article_detail.author = row.author
  224. this.article_detail.content = row.content
  225. this.article_detail.time = row.update_time
  226. this.article_detail.first_img = row.first_img
  227. this.dialog_show_article = true
  228. },
  229. // 置顶/取消置顶
  230. handle_top(id, param) {
  231. // console.log(id, param);
  232. var that = this
  233. var data = [id, param]
  234. topArticle(data).then((res) => {
  235. // console.log(res);
  236. if (res.code === 200) {
  237. // 更新列表
  238. that.get_table_data('list')
  239. that.$message.success(res.message)
  240. } else {
  241. that.$message.warning(res.message)
  242. }
  243. }).catch((err) => {
  244. that.$message.error(err.message)
  245. });
  246. },
  247. // 获取选择的文章ids
  248. handle_table_change(val) {
  249. // console.log(val);
  250. this.update_ids = []
  251. this.del_ids = []
  252. val.forEach(row => {
  253. this.update_ids.push(row.id)
  254. this.del_ids.push(row.id)
  255. });
  256. },
  257. // 删除文章
  258. handle_del_article() {
  259. var that = this
  260. delArticle(this.del_ids).then((res) => {
  261. // console.log(res);
  262. if (res.code === 200) {
  263. // 更新列表
  264. that.get_table_data('list')
  265. that.dialog_del_article = false
  266. that.$message.success(res.message)
  267. } else {
  268. that.dialog_del_article = false
  269. that.$message.warning(res.message)
  270. }
  271. }).catch((err) => {
  272. that.$message.error(err.message)
  273. });
  274. },
  275. // 更新文章
  276. handle_update_article() {
  277. var that = this
  278. updateArticle(this.update_ids).then((res) => {
  279. // console.log(res);
  280. if (res.code === 200) {
  281. // 更新列表
  282. that.get_table_data('list')
  283. that.dialog_update_article = false
  284. that.$message.success(res.message)
  285. } else {
  286. that.dialog_update_article = false
  287. that.$message.warning(res.message)
  288. }
  289. }).catch((err) => {
  290. that.$message.error(err.message)
  291. });
  292. },
  293. // 获取文章
  294. handle_get_article() {
  295. var that = this
  296. getArticle().then((res) => {
  297. // console.log(res);
  298. if (res.code === 200) {
  299. // 更新列表
  300. that.get_table_data('list')
  301. that.dialog_get_article = false
  302. that.$message.success(res.message)
  303. } else {
  304. that.dialog_get_article = false
  305. that.$message.warning(res.message)
  306. }
  307. }).catch((err) => {
  308. that.$message.error(err.message)
  309. });
  310. },
  311. // 移除文章内容中的html标签
  312. removeHtmlTags(str) {
  313. return str.replace(/<[^>]*>/g, '');
  314. },
  315. // 获取文章
  316. article_get() {
  317. this.dialog_get_article = true
  318. },
  319. // 更新文章
  320. article_update() {
  321. if (!isEmpty(this.update_ids)) {
  322. this.dialog_update_article = true
  323. } else {
  324. this.$message.warning('请选择要【更新】的文章!')
  325. }
  326. },
  327. // 删除文章
  328. article_del() {
  329. if (!isEmpty(this.del_ids)) {
  330. this.dialog_del_article = true
  331. } else {
  332. this.$message.warning('请选择要【删除】的文章!')
  333. }
  334. },
  335. /**
  336. * 获取消费记录,表格数据
  337. */
  338. get_table_data(param) {
  339. this.get_condtion();
  340. let data = this.cond_data;
  341. if (param == 'search') {
  342. data.page = 1
  343. this.pagination.currentPage = 1
  344. }
  345. var that = this
  346. // console.log(data);
  347. getTableData(data).then((res) => {
  348. // console.log(res);
  349. if (res.code === 200) {
  350. that.pagination.total = res.total
  351. that.tableData = res.rows
  352. } else {
  353. that.tableData = []
  354. that.$message.warning('没有符合条件的数据!')
  355. }
  356. }).catch((err) => {
  357. // console.log(err);
  358. that.$message.error(err.message)
  359. });
  360. },
  361. /**
  362. * 查询条件
  363. */
  364. get_condtion() {
  365. let data = {
  366. page: this.pagination.currentPage,
  367. rows: this.pagination.pageSize
  368. }
  369. if (this.formInline.search_datatime !== '') {
  370. data.search_datatime = this.formInline.search_datatime
  371. }
  372. if (this.formInline.keyword !== '') {
  373. data.keyword = this.formInline.keyword
  374. }
  375. if (this.formInline.is_top !== '') {
  376. data.is_top = this.formInline.is_top
  377. }
  378. this.cond_data = data;
  379. },
  380. /**
  381. * 搜索
  382. */
  383. btn_search() {
  384. this.get_table_data('search')
  385. },
  386. /**
  387. * currentPage 改变时会触发
  388. * @param {Object} val
  389. */
  390. currentPageChange(val) {
  391. this.pagination.currentPage = val
  392. this.get_table_data('pages')
  393. }
  394. }
  395. }
  396. </script>
  397. <style lang="scss" scoped>
  398. .app-container {
  399. background-color: #EFF2F7;
  400. padding: 10px;
  401. .el-row {
  402. .el-col {
  403. padding: 10px;
  404. .cell {
  405. padding: 30px;
  406. border-radius: 10px;
  407. background-color: #FFFFFF;
  408. box-shadow: 0px 3px 21px 0px rgba(60, 108, 254, 0.16);
  409. .cell-title {
  410. display: flex;
  411. justify-content: space-between;
  412. align-items: center;
  413. margin-bottom: 30px;
  414. padding-bottom: 30px;
  415. border-bottom: 1px solid #CCCCCC;
  416. .title-left {
  417. display: flex;
  418. align-items: center;
  419. .title {
  420. font-size: 22px;
  421. font-family: Microsoft YaHei-3970(82674968);
  422. font-weight: bold;
  423. color: #1A202B;
  424. }
  425. .title-detail {
  426. margin-left: 50px;
  427. font-size: 18px;
  428. font-family: Microsoft YaHei-3970(82674968);
  429. color: #1A202B;
  430. }
  431. }
  432. .title-right {
  433. display: flex;
  434. justify-content: space-between;
  435. align-items: center;
  436. .el-button {
  437. width: 110px;
  438. height: 46px;
  439. background: #2B4CFE;
  440. font-size: 18px;
  441. color: #FFFFFF;
  442. font-family: Microsoft YaHei-3970(82674968);
  443. border-radius: 5px;
  444. }
  445. .el-button--warning {
  446. background: #F88A64;
  447. }
  448. }
  449. }
  450. .cell-body {
  451. .controls {
  452. display: flex;
  453. justify-content: space-between;
  454. align-items: center;
  455. .demo-form-inline {
  456. display: inline-flex;
  457. flex-wrap: wrap;
  458. align-items: center;
  459. justify-content: flex-start;
  460. .el-form-item {
  461. margin-bottom: 16px;
  462. }
  463. .btn-search {
  464. background: rgba(9, 101, 98, 1);
  465. font-size: 14px;
  466. color: #FFFFFF;
  467. font-family: Microsoft YaHei-3970(82674968);
  468. border-radius: 5px;
  469. border: none;
  470. }
  471. }
  472. .btns {
  473. display: flex;
  474. align-items: center;
  475. margin-bottom: 16px;
  476. .btn-article-del {
  477. border-radius: 5px;
  478. background: rgba(212, 48, 48, 1);
  479. border: none;
  480. }
  481. .btn-update-get-article {
  482. background: rgba(9, 101, 98, 1);
  483. font-size: 14px;
  484. color: #FFFFFF;
  485. font-family: Microsoft YaHei-3970(82674968);
  486. border-radius: 5px;
  487. border: none;
  488. }
  489. }
  490. }
  491. .pagination-table {
  492. display: flex;
  493. justify-content: flex-end;
  494. align-items: center;
  495. height: 30px;
  496. margin-top: 20px;
  497. padding-right: 100px;
  498. ::v-deep .el-pagination {
  499. display: flex;
  500. justify-content: flex-end;
  501. align-items: center;
  502. }
  503. ::v-deep .el-pagination ul {
  504. display: flex;
  505. }
  506. ::v-deep .el-pagination button,
  507. ::v-deep .el-pagination li {
  508. display: flex;
  509. justify-content: center;
  510. align-items: center;
  511. width: 50px;
  512. height: 36px;
  513. border: 1px solid #626262;
  514. border-radius: 3px;
  515. font-size: 14px;
  516. margin: 0 5px;
  517. }
  518. ::v-deep .el-pagination span {
  519. margin-left: 10px;
  520. }
  521. ::v-deep .el-pagination .el-pagination__jump {
  522. font-size: 16px;
  523. }
  524. ::v-deep .el-pagination .el-pagination__editor {
  525. width: 50px;
  526. height: 36px;
  527. margin: 0 5px;
  528. }
  529. ::v-deep .el-pagination .el-input__inner {
  530. width: 50px;
  531. height: 36px;
  532. border: 1px solid #626262;
  533. margin: -4px 0 0 0;
  534. }
  535. }
  536. }
  537. }
  538. }
  539. }
  540. .dialog-qingzhang-body {
  541. display: flex;
  542. flex-direction: column;
  543. justify-content: center;
  544. align-items: center;
  545. height: 180px;
  546. img {
  547. width: 72px;
  548. }
  549. .dialog-qingzhang-body-txt {
  550. height: 38px;
  551. line-height: 38px;
  552. text-align: center;
  553. font-size: 18px;
  554. font-family: Microsoft YaHei-3970(82674968);
  555. color: #333333;
  556. margin-top: 20px;
  557. }
  558. }
  559. }
  560. </style>
  561. <style>
  562. .el-date-editor--daterange.el-input__inner {
  563. width: 280px !important;
  564. }
  565. .demo-table-expand {
  566. font-size: 0 !important;
  567. }
  568. .demo-table-expand label {
  569. width: 180px !important;
  570. color: #99a9bf !important;
  571. }
  572. .demo-table-expand .el-form-item {
  573. margin-right: 0 !important;
  574. margin-bottom: 0 !important;
  575. width: 33% !important;
  576. }
  577. .dialog-footer {
  578. display: flex !important;
  579. justify-content: flex-end !important;
  580. margin-top: -10px !important;
  581. }
  582. .dialog-qingzhang {
  583. height: 300px !important;
  584. width: 500px !important;
  585. margin-top: 330px !important;
  586. border-radius: 8px !important;
  587. }
  588. .dialog-qingzhang .el-dialog__header {
  589. display: none !important;
  590. }
  591. .add-user-cancel-btn {
  592. color: rgba(9, 101, 98, 1) !important;
  593. border: 1px solid rgba(9, 101, 98, 1) !important;
  594. }
  595. .add-user-confirm-btn {
  596. border: none !important;
  597. background: rgba(9, 101, 98, 1) !important;
  598. color: #fff !important;
  599. border-radius: 5px !important;
  600. margin-left: 28px !important;
  601. }
  602. </style>