index.vue 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <div class="subPage">
  3. <div class="system-table-search">
  4. <div class="flex-h">
  5. <div class="flex-item flex-h">
  6. <el-button size="mini" type="success" @click='addNews'>新增资讯</el-button>
  7. </div>
  8. <ul>
  9. <li>
  10. <span>选择位置:</span>
  11. <el-select v-model="tableSearch.LocationId" placeholder="请选择">
  12. <el-option
  13. v-for="item in positionList"
  14. :key="item.LocationId"
  15. :label="item.LocationName"
  16. :value="item.LocationId">
  17. </el-option>
  18. </el-select>
  19. </li>
  20. </ul>
  21. <tableSearch @exportSearchKey="searchList" value="请输入标题"></tableSearch>
  22. </div>
  23. <div class="moreFilter"></div>
  24. </div>
  25. <div class="system-table-box">
  26. <el-table
  27. :data="tableData"
  28. stripe
  29. style="width: 100%">
  30. <el-table-column
  31. prop="img"
  32. label="图片">
  33. <template slot-scope="scope">
  34. <a class="tableImg">
  35. <img :src="scope.row.ImageUrl" class="centerLabel contain" alt="">
  36. </a>
  37. </template>
  38. </el-table-column>
  39. <el-table-column
  40. prop="Title"
  41. label="标题">
  42. </el-table-column>
  43. <el-table-column
  44. prop="LocationNames"
  45. label="位置">
  46. </el-table-column>
  47. <el-table-column
  48. prop="StatusShow"
  49. label="是否发布">
  50. </el-table-column>
  51. <el-table-column label="操作">
  52. <template slot-scope="scope">
  53. <el-button
  54. size="mini"
  55. type="warning"
  56. @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
  57. <el-button
  58. size="mini"
  59. type="danger"
  60. @click="handleDelete(scope.$index, scope.row)">删除</el-button>
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. </div>
  65. <el-pagination
  66. @current-change="handleCurrentChange"
  67. :current-page.sync="postData.currentPage"
  68. :page-size="postData.pageSize"
  69. layout="prev, pager, next, jumper"
  70. :total="postData.total">
  71. </el-pagination>
  72. </div>
  73. </template>
  74. <script>
  75. import tableSearch from '@/components/tableSearch/index'
  76. import { mapState, createNamespacedHelpers } from 'vuex'
  77. const { mapActions: mapCmsActions } = createNamespacedHelpers('cms')
  78. export default {
  79. name: '',
  80. data () {
  81. return {
  82. postData: {
  83. currentPage: 1, // 当前页码
  84. pageSize: 10,
  85. total: 0,
  86. },
  87. tableSearch: { // 表格搜索条件
  88. key: '', // 搜索关键字
  89. LocationId: '',
  90. },
  91. tableData: []
  92. }
  93. },
  94. computed: {
  95. ...mapState({
  96. positionList: x => x.cms.location,
  97. })
  98. },
  99. components: {
  100. tableSearch,
  101. },
  102. created () {
  103. this.updateLocationInfo().then(() => {
  104. this.getList()
  105. })
  106. },
  107. methods: {
  108. ...mapCmsActions(['updateLocationInfo']),
  109. handleCurrentChange (val) {
  110. console.log(`当前页: ${val}`)
  111. this.getList()
  112. },
  113. handleEdit (index, row) { // 编辑
  114. console.log(index, row)
  115. this.$router.push({ name: 'editNews', query: { id: row.NewsId } })
  116. },
  117. handleDelete (index, row) { // 删除
  118. console.log(index, row)
  119. this.$confirm('确认删除此资讯?', '提示', {
  120. confirmButtonText: '确定',
  121. cancelButtonText: '取消',
  122. type: 'warning'
  123. }).then(() => {
  124. this.deleteNews(row.NewsId)
  125. }).catch(() => {
  126. this.$message({
  127. type: 'info',
  128. message: '已取消删除'
  129. })
  130. })
  131. },
  132. searchList (key) { // 搜索列表
  133. this.tableSearch.key = key
  134. this.getList()
  135. },
  136. addNews () {
  137. this.$router.push({ name: 'addNews' })
  138. },
  139. getList () {
  140. this.tableData = []
  141. this.$ajax(this.$api.cms.news.url, {
  142. method: this.$api.cms.news.method,
  143. queryData: {
  144. page: this.postData.currentPage,
  145. pagesize: this.postData.pageSize,
  146. locationid: this.tableSearch.LocationId,
  147. title: this.tableSearch.key
  148. }
  149. }).then(res => {
  150. for (let i = 0; i < res.list.length; i++) {
  151. res.list[i].Status === 1 ? res.list[i].StatusShow = '是' : res.list[i].StatusShow = '否'
  152. }
  153. this.tableData = res.list
  154. this.postData.total = res.pagenum
  155. this.postData.currentPage = res.page
  156. }).catch(msg => {
  157. })
  158. },
  159. deleteNews (id) {
  160. this.$ajax(this.$api.cms.deleteNews.url, {
  161. method: this.$api.cms.deleteNews.method,
  162. urlData: {
  163. id: id
  164. }
  165. }).then(res => {
  166. this.$message({
  167. type: 'success',
  168. message: '删除成功!'
  169. })
  170. this.getList()
  171. }).catch(msg => {
  172. })
  173. }
  174. }
  175. }
  176. </script>
  177. <!-- Add "scoped" attribute to limit CSS to this component only -->
  178. <style lang="scss" scoped>
  179. </style>