messageList.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <div class="right" :style="{ height: height, width: width }">
  3. <div class="up">
  4. <div>
  5. <div class="up-title"><i class="el-icon-search"></i>筛选搜索</div>
  6. <div class="btn">
  7. <el-button plain @click="reset">重置</el-button>
  8. <el-button type="primary" @click="searchJingMessage" plain>查询列表</el-button>
  9. </div>
  10. </div>
  11. <div class="left-up">
  12. <div class="up-input-title">
  13. 消息标题:<el-input v-model="input" class="up-input" placeholder="请输入内容"></el-input>
  14. </div>
  15. <div class="up-input-title-right">
  16. <span class="demonstration" >发布时间:</span>
  17. <el-date-picker v-model="value2" type="datetimerange" class="up-input-right" :picker-options="pickerOptions"
  18. range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" align="right">
  19. </el-date-picker>
  20. </div>
  21. </div>
  22. </div>
  23. <div class="down">
  24. <div class="down-add">
  25. <el-row :gutter="24">
  26. <el-col :span="22" class="down-title"> <i class="el-icon-tickets">消息列表</i> </el-col>
  27. <el-col :span="2"> <el-button id="addBtn" size="small" @click="addNoticce">添加</el-button> </el-col>
  28. </el-row>
  29. </div>
  30. <div class="down-table">
  31. <el-table :data="tableData" order style="width: 100%" class="messagetable">
  32. <el-table-column prop="newsId" label="ID">
  33. </el-table-column>
  34. <el-table-column :formatter="stateFormat" prop="newsTitle" label="消息标题">
  35. </el-table-column>
  36. <el-table-column prop="userPhone" label="手机号">
  37. </el-table-column>
  38. <el-table-column prop="createTime" label="发布时间">
  39. </el-table-column>
  40. <el-table-column prop="operate" label="操作">
  41. <template slot-scope="scope">
  42. <el-button size="mini" type="text" @click="viewDetails(scope)" v-bind:row_ = "row_">查看详情</el-button>
  43. <el-popconfirm title="你确定删除本条消息吗?" @confirm="deleteMessage(scope)">
  44. <el-button class="btn-delete" size="mini" type="text" icon="el-icon-delete"
  45. slot="reference">删除</el-button>
  46. </el-popconfirm>
  47. </template>
  48. </el-table-column>
  49. </el-table>
  50. </div>
  51. </div>
  52. <div class="bottom">
  53. <div class="bottom-page">
  54. <el-pagination layout="prev, pager, next" :total="tableData.length" @size-change="handleSizeChange"
  55. @current-change="handleCurrentChange">
  56. </el-pagination>
  57. </div>
  58. <span class="bottom-number">共{{ tableData.length }}条 </span>
  59. </div>
  60. </div>
  61. </template>
  62. <script>
  63. import { getMessage, deleteMessage, searchJMessage } from '../../api/message/message.js'
  64. import mitt from '@/utils/mitt.js';
  65. export default {
  66. props: {
  67. },
  68. data() {
  69. return {
  70. tableData: [],
  71. input: "",
  72. value2: "",
  73. mock: "",
  74. mockMessageList: [],
  75. currentPage: 1,
  76. pagesize: 10,
  77. row_ : "1",
  78. }
  79. },
  80. mounted() {
  81. this.getMockMessageList();
  82. },
  83. beforeDestroy() {
  84. },
  85. methods: {
  86. getMockMessageList() {
  87. getMessage().then((res) => {
  88. this.tableData = res.rows
  89. console.log(res.rows);
  90. })
  91. },
  92. //分页功能
  93. getPageData() {
  94. console.log(this.mockMessageList);
  95. let start = (this.currentPage - 1) * this.pagesize;
  96. let end = start + this.pagesize;
  97. this.tableData = this.mockMessageList.slice(start, end);
  98. },
  99. handleSizeChange(val) {
  100. this.pagesize = val;
  101. this.getPageData();
  102. },
  103. handleCurrentChange(val) {
  104. this.currentPage = val;
  105. this.getPageData();
  106. },
  107. stateFormat(row, column, cellValue) {
  108. if (!cellValue) return ''
  109. if (cellValue.length > 15) { //最长固定显示10个字符
  110. return cellValue.slice(0, 15) + '...'
  111. }
  112. return cellValue
  113. },
  114. //删除列表
  115. deleteMessage(row) {
  116. console.log(row);
  117. row = row.row.newsId
  118. console.log(row);
  119. deleteMessage(row).then((res) => {
  120. console.log(res);
  121. this.$message({
  122. message: '恭喜你,删除成功!',
  123. type: 'success'
  124. });
  125. this.$router.go(0)
  126. })
  127. },
  128. //查看详情
  129. viewDetails(row) {
  130. row = row.row.newsId
  131. mitt.emit('searchMore', row)
  132. this.row_ = row
  133. console.log(this.row_);
  134. this.$router.push({path:"/messageList/messageDetails",query:{row_: this.row_}})
  135. // this.$router.push("/messageList/messageDetails");
  136. },
  137. //添加跳转
  138. addNoticce() {
  139. this.$router.push("/messageList/addMessage");
  140. },
  141. //搜索
  142. searchJingMessage() {
  143. // console.log(this.input );
  144. searchJMessage(
  145. this.input
  146. ).then((res) => {
  147. console.log(res);
  148. this.tableData = res.rows
  149. })
  150. this.reset();
  151. },
  152. //重置
  153. reset() {
  154. this.input = ""
  155. this.value2 = ""
  156. }
  157. }
  158. }
  159. </script>
  160. <style scoped>
  161. .up {
  162. width: 96%;
  163. height: 170px;
  164. margin-top: 20px;
  165. margin-left: 2%;
  166. border: 1px solid #ccc;
  167. border-radius: 4px;
  168. }
  169. .up-title {
  170. font-size: 20px;
  171. width: 20%;
  172. margin-left: 20px;
  173. margin-top: 20px;
  174. float: left;
  175. }
  176. .btn {
  177. float: right;
  178. padding-right: 3%;
  179. margin-top: 2.5%;
  180. }
  181. .up-input {
  182. width: 250px;
  183. margin-left: 15px;
  184. }
  185. .up-input-title {
  186. margin-left: 40px;
  187. float: left;
  188. }
  189. .up-input-right {
  190. margin-left: 15px;
  191. width: 500px;
  192. }
  193. .up-input-title-right {
  194. width: 800px;
  195. margin-left: 450px;
  196. }
  197. .left-up {
  198. width: 80%;
  199. float: left;
  200. height: 37px;
  201. margin-top: 50px;
  202. }
  203. .right-up {
  204. width: 16%;
  205. margin-top: 2%;
  206. float: right;
  207. }
  208. .anniu {
  209. padding-right: 5%;
  210. }
  211. .down {
  212. margin-top: 40px;
  213. }
  214. .down-add {
  215. padding: 10px;
  216. margin: 0 27px;
  217. border: 1px solid #ccc;
  218. border-radius: 2px
  219. }
  220. .down-title {
  221. padding-top: 10px;
  222. color: #303133;
  223. }
  224. .down-table {
  225. margin-top: 15px;
  226. text-align: center;
  227. margin: 35px 27px;
  228. }
  229. .el-table .el-table__header-wrapper th,
  230. .el-table .el-table__fixed-header-wrapper th {
  231. word-break: break-word;
  232. /* background-color: #f8f8f9; */
  233. color: #515a6e;
  234. height: 40px;
  235. font-size: 13px;
  236. text-align: center;
  237. }
  238. .bottom-number {
  239. padding-top: 5px;
  240. color: #303133;
  241. float: right;
  242. }
  243. .bottom-page {
  244. float: right;
  245. }
  246. .el-icon-search {
  247. padding-right: 10px;
  248. }
  249. .btn-delete {
  250. margin-left: 20px;
  251. }
  252. /**
  253. 自适应
  254. */
  255. /* .demonstration{
  256. width: 50%;
  257. } */
  258. .right {
  259. float: none;
  260. width: 100%;
  261. height: 100%;
  262. /* background-color: #9dc3e6; */
  263. }
  264. </style>