list.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <a-card size="small" :bordered="false" class="noticeList-wrap">
  3. <!-- 搜索条件 -->
  4. <div ref="tableSearch" class="table-page-search-wrapper">
  5. <a-form layout="inline" @keyup.enter.native="handelSearch(1)">
  6. <a-row :gutter="15">
  7. <a-col :md="6" :sm="24">
  8. <a-form-item label="发布时间">
  9. <rangeDate ref="rangeDate" @change="dateChange" />
  10. </a-form-item>
  11. </a-col>
  12. <a-col :md="6" :sm="24">
  13. <a-form-item label="公告名称">
  14. <a-input id="noticeList-title" v-model.trim="queryParam.notice.title" allowClear placeholder="请输入公告名称"/>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :md="6" :sm="24">
  18. <a-button type="primary" @click="handelSearch(1)" :disabled="disabled" id="noticeList-refresh">查询</a-button>
  19. <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="noticeList-reset">重置</a-button>
  20. </a-col>
  21. </a-row>
  22. </a-form>
  23. </div>
  24. <!-- 列表 -->
  25. <a-table
  26. class="sTable fixPagination"
  27. ref="table"
  28. :style="{ height: tableHeight+84.5+'px' }"
  29. size="small"
  30. :rowKey="(record) => record.id"
  31. :columns="columns"
  32. :dataSource="loadData"
  33. :loading="listLoading"
  34. :pagination="false"
  35. bordered>
  36. <!-- 操作 -->
  37. <template slot="action" slot-scope="text, record">
  38. <a-badge :count="record.readFlag=='0'? 1 : 0" dot>
  39. <a-button size="small" type="primary" class="button-success" @click="handleDetail(record)" id="noticeList-detail-btn">详情</a-button>
  40. </a-badge>
  41. </template>
  42. </a-table>
  43. <!-- 分页 -->
  44. <tablePagination
  45. ref="tablePagination"
  46. :total="paginationProps.total"
  47. :current="paginationProps.current"
  48. :pageSize="paginationProps.pageSize"
  49. @changePageSize="changePageSize"
  50. @changePage="changePage" />
  51. <!-- 公告详情 -->
  52. <notice-detail-modal :openModal="openModal" :itemId="itemId" @close="closeModal" />
  53. </a-card>
  54. </template>
  55. <script>
  56. import { STable } from '@/components'
  57. import tablePagination from '@/views/common/tablePagination.vue'
  58. import rangeDate from '@/views/common/rangeDate.vue'
  59. import { mapActions } from 'vuex'
  60. import noticeDetailModal from './detailModal.vue'
  61. export default {
  62. components: { STable, noticeDetailModal, rangeDate, tablePagination },
  63. data () {
  64. return {
  65. tableHeight: 0,
  66. queryParam: { // 查询条件
  67. beginDate: '',
  68. endDate: '',
  69. notice: {
  70. title: ''
  71. }
  72. },
  73. disabled: false, // 查询、重置按钮是否可操作
  74. columns: [
  75. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  76. { title: '发布时间', dataIndex: 'createDate', align: 'center', customRender: function (text) { return text || '--' } },
  77. { title: '公告名称', dataIndex: 'notice.title', align: 'center', customRender: function (text) { return text || '--' } },
  78. { title: '操作', scopedSlots: { customRender: 'action' }, width: 200, align: 'center' }
  79. ],
  80. loadData: [],
  81. paginationProps: {
  82. total: 0, // 分页总条数
  83. current: 1,
  84. pageSize: 20
  85. },
  86. listLoading: false,
  87. openModal: false, // 查看客户详情 弹框
  88. itemId: '' // 当前id
  89. }
  90. },
  91. computed: {
  92. // 接受到ws消息
  93. wsMessage () {
  94. return this.$store.getters.wsMessageData()
  95. }
  96. },
  97. watch: {
  98. // 监听ws消息通知
  99. wsMessage (a, b) {
  100. if (a !== b && a) {
  101. // 新未读消息
  102. if (a.type == 'no_read_count') {
  103. this.resetData()
  104. this.handelSearch()
  105. }
  106. }
  107. }
  108. },
  109. methods: {
  110. ...mapActions([
  111. 'getMessageList', // 查询列表
  112. 'hasRead' // 设置已读
  113. ]),
  114. // 时间 change
  115. dateChange (date) {
  116. this.queryParam.beginDate = date[0] ? date[0] + ' 00:00:00' : ''
  117. this.queryParam.endDate = date[1] ? date[1] + ' 23:59:59' : ''
  118. },
  119. // 查询列表
  120. handelSearch (pageNo) {
  121. this.paginationProps.current = pageNo || this.paginationProps.current
  122. this.disabled = true
  123. const params = {
  124. pageNo: this.paginationProps.current,
  125. pageSize: this.paginationProps.pageSize,
  126. notice: {
  127. title: this.queryParam.notice.title
  128. },
  129. beginDate: this.queryParam.beginDate,
  130. endDate: this.queryParam.endDate
  131. }
  132. // 开始查询
  133. this.listLoading = true
  134. this.getMessageList(params).then((res) => {
  135. this.listLoading = false
  136. if (res.status == 200) {
  137. const data = res.data
  138. this.paginationProps.total = Number(res.data.count) || 0
  139. this.paginationProps.current = data.pageNo
  140. const no = (data.pageNo - 1) * data.pageSize
  141. for (var i = 0; i < data.list.length; i++) {
  142. data.list[i].no = no + i + 1
  143. }
  144. this.loadData = data.list
  145. this.disabled = false
  146. } else {
  147. this.paginationProps.total = 0
  148. this.paginationProps.current = 1
  149. this.paginationProps.pageSize = 20
  150. this.loadData = []
  151. }
  152. })
  153. },
  154. // 分页 一页多少条change
  155. changePageSize (current, pageSize) {
  156. this.paginationProps.current = current
  157. this.paginationProps.pageSize = pageSize
  158. this.handelSearch()
  159. },
  160. // 分页 页码change
  161. changePage (current) {
  162. this.paginationProps.current = current
  163. this.handelSearch()
  164. },
  165. // 重置
  166. resetSearchForm () {
  167. this.resetData()
  168. this.handelSearch(1)
  169. },
  170. resetData () {
  171. this.$refs.rangeDate.resetDate()
  172. this.queryParam.beginDate = ''
  173. this.queryParam.endDate = ''
  174. this.queryParam.notice.title = undefined
  175. this.paginationProps.total = 0
  176. this.paginationProps.current = 1
  177. this.paginationProps.pageSize = 20
  178. },
  179. // 详情
  180. handleDetail (row) {
  181. this.itemId = row.notice.id
  182. this.openModal = true
  183. // 设置已读
  184. if (row.readFlag == '0') {
  185. this.hasRead({ msg_id: row.id }).then(res => {
  186. // 刷新列表
  187. if (res.status == 200) {
  188. this.handelSearch()
  189. }
  190. })
  191. }
  192. },
  193. // 关闭弹框
  194. closeModal () {
  195. this.itemId = ''
  196. this.openModal = false
  197. },
  198. setTableH () {
  199. const tableSearchH = this.$refs.tableSearch.offsetHeight
  200. this.tableHeight = window.innerHeight - tableSearchH - 195
  201. }
  202. },
  203. mounted () {
  204. const _this = this
  205. this.$nextTick(() => { // 页面渲染完成后的回调
  206. _this.setTableH()
  207. })
  208. },
  209. beforeRouteEnter (to, from, next) {
  210. next(vm => {
  211. vm.openModal = false
  212. vm.handelSearch(1)
  213. })
  214. }
  215. }
  216. </script>
  217. <style lang="less">
  218. .noticeList-wrap{
  219. margin: -12px -12px 0px;
  220. }
  221. </style>