list.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 { commonMixin } from '@/utils/mixin'
  57. import { STable } from '@/components'
  58. import tablePagination from '@/views/common/tablePagination.vue'
  59. import rangeDate from '@/views/common/rangeDate.vue'
  60. import { mapActions } from 'vuex'
  61. import noticeDetailModal from './detailModal.vue'
  62. export default {
  63. name: 'NoticeList',
  64. components: { STable, noticeDetailModal, rangeDate, tablePagination },
  65. mixins: [commonMixin],
  66. data () {
  67. return {
  68. queryParam: { // 查询条件
  69. beginDate: '',
  70. endDate: '',
  71. notice: {
  72. title: ''
  73. }
  74. },
  75. tableHeight: 0,
  76. disabled: false, // 查询、重置按钮是否可操作
  77. columns: [
  78. { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
  79. { title: '发布时间', dataIndex: 'createDate', align: 'center', customRender: function (text) { return text || '--' } },
  80. { title: '公告名称', dataIndex: 'notice.title', align: 'center', customRender: function (text) { return text || '--' } },
  81. { title: '操作', scopedSlots: { customRender: 'action' }, width: 200, align: 'center' }
  82. ],
  83. loadData: [],
  84. paginationProps: {
  85. total: 0, // 分页总条数
  86. current: 1,
  87. pageSize: 20
  88. },
  89. listLoading: false,
  90. openModal: false, // 查看客户详情 弹框
  91. itemId: '' // 当前id
  92. }
  93. },
  94. computed: {
  95. // 接受到ws消息
  96. wsMessage () {
  97. return this.$store.getters.wsMessageData()
  98. }
  99. },
  100. methods: {
  101. ...mapActions([
  102. 'getMessageList', // 查询列表
  103. 'hasRead' // 设置已读
  104. ]),
  105. // 时间 change
  106. dateChange (date) {
  107. this.queryParam.beginDate = date[0] ? date[0]: ''
  108. this.queryParam.endDate = date[1] ? date[1]: ''
  109. },
  110. // 查询列表
  111. handelSearch (pageNo) {
  112. this.paginationProps.current = pageNo || this.paginationProps.current
  113. this.disabled = true
  114. const params = {
  115. pageNo: this.paginationProps.current,
  116. pageSize: this.paginationProps.pageSize,
  117. notice: {
  118. title: this.queryParam.notice.title
  119. },
  120. beginDate: this.queryParam.beginDate,
  121. endDate: this.queryParam.endDate
  122. }
  123. // 开始查询
  124. this.listLoading = true
  125. this.getMessageList(params).then((res) => {
  126. this.listLoading = false
  127. if (res.status == 200) {
  128. const data = res.data
  129. this.paginationProps.total = Number(res.data.count) || 0
  130. this.paginationProps.current = data.pageNo
  131. const no = (data.pageNo - 1) * data.pageSize
  132. for (var i = 0; i < data.list.length; i++) {
  133. data.list[i].no = no + i + 1
  134. }
  135. this.loadData = data.list
  136. this.disabled = false
  137. } else {
  138. this.paginationProps.total = 0
  139. this.paginationProps.current = 1
  140. this.paginationProps.pageSize = 20
  141. this.loadData = []
  142. }
  143. })
  144. },
  145. // 分页 一页多少条change
  146. changePageSize (current, pageSize) {
  147. this.paginationProps.current = current
  148. this.paginationProps.pageSize = pageSize
  149. this.handelSearch()
  150. },
  151. // 分页 页码change
  152. changePage (current) {
  153. this.paginationProps.current = current
  154. this.handelSearch()
  155. },
  156. // 重置
  157. resetSearchForm () {
  158. this.resetData()
  159. this.handelSearch(1)
  160. },
  161. resetData () {
  162. this.$refs.rangeDate.resetDate()
  163. this.queryParam.beginDate = ''
  164. this.queryParam.endDate = ''
  165. this.queryParam.notice.title = undefined
  166. this.paginationProps.total = 0
  167. this.paginationProps.current = 1
  168. this.paginationProps.pageSize = 20
  169. },
  170. // 详情
  171. handleDetail (row) {
  172. this.itemId = row.notice.id
  173. this.openModal = true
  174. // 设置已读
  175. if (row.readFlag == '0') {
  176. this.hasRead({ msg_id: row.id }).then(res => {
  177. // 刷新列表
  178. if (res.status == 200) {
  179. this.handelSearch()
  180. }
  181. })
  182. }
  183. },
  184. // 关闭弹框
  185. closeModal () {
  186. this.itemId = ''
  187. this.openModal = false
  188. },
  189. pageInit () {
  190. const _this = this
  191. this.$nextTick(() => { // 页面渲染完成后的回调
  192. _this.setTableH()
  193. })
  194. this.openModal = false
  195. },
  196. setTableH () {
  197. const tableSearchH = this.$refs.tableSearch.offsetHeight
  198. this.tableHeight = window.innerHeight - tableSearchH - 210
  199. }
  200. },
  201. watch: {
  202. // 监听ws消息通知
  203. wsMessage (a, b) {
  204. if (a !== b && a) {
  205. // 新未读消息
  206. if (a.type == 'no_read_count') {
  207. this.resetData()
  208. this.handelSearch()
  209. }
  210. }
  211. },
  212. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  213. this.setTableH()
  214. }
  215. },
  216. mounted () {
  217. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  218. this.pageInit()
  219. this.resetSearchForm()
  220. }
  221. },
  222. activated () {
  223. // 如果是新页签打开,则重置当前页面
  224. if (this.$store.state.app.isNewTab) {
  225. this.pageInit()
  226. this.resetSearchForm()
  227. }
  228. },
  229. beforeRouteEnter (to, from, next) {
  230. next(vm => {})
  231. }
  232. }
  233. </script>