list.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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="4" :sm="24">
  13. <a-form-item label="标题">
  14. <a-input v-model.trim="queryParam.notice.title" allowClear placeholder="请输入标题"/>
  15. </a-form-item>
  16. </a-col>
  17. <a-col :md="4" :sm="24">
  18. <a-form-item label="类别">
  19. <a-select v-model.trim="queryParam.notice.type" allowClear placeholder="请选择类别">
  20. <a-select-option v-for="item in typeList" :key="item.val" :value="item.val">
  21. {{ item.text }}
  22. </a-select-option>
  23. </a-select>
  24. </a-form-item>
  25. </a-col>
  26. <a-col :md="4" :sm="24">
  27. <a-form-item label="状态">
  28. <a-select v-model.trim="queryParam.readFlag" allowClear placeholder="请选择状态">
  29. <a-select-option value="0">
  30. 未读
  31. </a-select-option>
  32. <a-select-option value="1">
  33. 已读
  34. </a-select-option>
  35. </a-select>
  36. </a-form-item>
  37. </a-col>
  38. <a-col :md="6" :sm="24">
  39. <a-button type="primary" @click="handelSearch(1)" :disabled="disabled" id="noticeList-refresh">查询</a-button>
  40. <a-button style="margin-left: 8px" @click="resetSearchForm" :disabled="disabled" id="noticeList-reset">重置</a-button>
  41. </a-col>
  42. </a-row>
  43. </a-form>
  44. <!-- 操作按钮 -->
  45. <div class="table-operator">
  46. <a-button type="primary" class="button-error" @click="handleSetRead">设置全部已读</a-button>
  47. </div>
  48. </div>
  49. <!-- 列表 -->
  50. <a-table
  51. class="sTable fixPagination"
  52. ref="table"
  53. :style="{ height: tableHeight+84.5+'px' }"
  54. :scroll="{ y:tableHeight+40 }"
  55. size="small"
  56. :rowKey="(record) => record.id"
  57. :columns="columns"
  58. :dataSource="loadData"
  59. :loading="listLoading"
  60. :pagination="false"
  61. bordered>
  62. <!-- 操作 -->
  63. <template slot="action" slot-scope="text, record">
  64. <a-badge :count="record.readFlag=='0'? 1 : 0" dot>
  65. <a-button size="small" type="link" class="button-success" @click="handleDetail(record)">详情</a-button>
  66. </a-badge>
  67. </template>
  68. <!-- type-->
  69. <template slot="type" slot-scope="text, record">
  70. {{ text?typeList.find(item => item.val == text).text:'--' }}
  71. </template>
  72. <!-- 内容 content-->
  73. <template slot="content" slot-scope="text, record">
  74. {{ text?text.slice(0,30)+(text.length>30?'...':''):'--' }}
  75. <a-button v-if="record.notice&&record.notice.type=='tx'" @click="toAction(record)" size="small" type="link" class="button-info">
  76. {{ record.notice.extInfo.bizType == 'SHELF_REPLENISH' ? '立即处理':'点击查看' }}
  77. </a-button>
  78. </template>
  79. </a-table>
  80. <!-- 分页 -->
  81. <tablePagination
  82. ref="tablePagination"
  83. :total="paginationProps.total"
  84. :current="paginationProps.current"
  85. :pageSize="paginationProps.pageSize"
  86. @changePageSize="changePageSize"
  87. @changePage="changePage" />
  88. <!-- 公告详情 -->
  89. <notice-detail-modal :openModal="openModal" :itemId="itemId" @close="closeModal" />
  90. </a-card>
  91. </template>
  92. <script>
  93. import { commonMixin } from '@/utils/mixin'
  94. import { STable } from '@/components'
  95. import tablePagination from '@/views/common/tablePagination.vue'
  96. import rangeDate from '@/views/common/rangeDate.vue'
  97. import { mapActions } from 'vuex'
  98. import noticeDetailModal from './detailModal.vue'
  99. export default {
  100. name: 'NoticeList',
  101. components: { STable, noticeDetailModal, rangeDate, tablePagination },
  102. mixins: [commonMixin],
  103. data () {
  104. return {
  105. queryParam: { // 查询条件
  106. beginDate: '',
  107. endDate: '',
  108. readFlag: undefined,
  109. notice: {
  110. title: '',
  111. type: undefined
  112. }
  113. },
  114. tableHeight: 0,
  115. disabled: false, // 查询、重置按钮是否可操作
  116. columns: [
  117. { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
  118. { title: '发布时间', dataIndex: 'createDate', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  119. { title: '类别', dataIndex: 'notice.type', scopedSlots: { customRender: 'type' }, width: '15%', align: 'center' },
  120. { title: '标题', dataIndex: 'notice.title', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  121. { title: '内容', dataIndex: 'notice.plainContent', scopedSlots: { customRender: 'content' }, width: '35%', align: 'center' },
  122. { title: '操作', scopedSlots: { customRender: 'action' }, width: '15%', align: 'center' }
  123. ],
  124. loadData: [],
  125. paginationProps: {
  126. total: 0, // 分页总条数
  127. current: 1,
  128. pageSize: 20
  129. },
  130. listLoading: false,
  131. openModal: false, // 查看客户详情 弹框
  132. itemId: '', // 当前id
  133. typeList: [
  134. {
  135. text: '公告',
  136. val: 'notity'
  137. },
  138. {
  139. text: '企业新闻',
  140. val: 'news_company'
  141. },
  142. {
  143. text: '行业咨询',
  144. val: 'news_trade'
  145. },
  146. {
  147. text: '提醒',
  148. val: 'tx'
  149. }
  150. ]
  151. }
  152. },
  153. computed: {
  154. // 接受到ws消息
  155. wsMessage () {
  156. return this.$store.getters.wsMessageData()
  157. }
  158. },
  159. methods: {
  160. ...mapActions([
  161. 'getMessageList', // 查询列表
  162. 'setAllNoticeRead',
  163. 'hasRead' // 设置已读
  164. ]),
  165. // 时间 change
  166. dateChange (date) {
  167. this.queryParam.beginDate = date[0] ? date[0] : ''
  168. this.queryParam.endDate = date[1] ? date[1] : ''
  169. },
  170. handleSetRead () {
  171. const _this = this
  172. this.$confirm({
  173. title: '提示',
  174. content: '确认将所有未读消息标记为已读?',
  175. centered: true,
  176. closable: true,
  177. onOk () {
  178. _this.setAllNoticeRead().then(res => {
  179. if (res.status == 200) {
  180. _this.$message.info(res.message)
  181. _this.resetSearchForm()
  182. }
  183. })
  184. }
  185. })
  186. },
  187. toAction (data) {
  188. // 急送订单
  189. if (data.notice.extInfo.bizType == 'TEMP_ORDER') {
  190. this.$router.push({ name: 'salesDetail', params: { sn: data.notice.extInfo.bizSn } })
  191. }
  192. // 补货订单
  193. if (data.notice.extInfo.bizType == 'SHELF_REPLENISH') {
  194. this.$router.push({ name: 'replenishmentManagement', query: { bizType: 'WAIT_CONFIRM' } })
  195. }
  196. // 货架订单
  197. if (data.notice.extInfo.bizType == 'SHELF_ORDER') {
  198. this.$router.push({ name: 'shelfOrderDetail', params: { sn: data.notice.extInfo.bizSn } })
  199. }
  200. // 货架异常
  201. if (data.notice.extInfo.bizType == 'SHELF_WARN') {
  202. this.$router.push({ name: 'shelfOrderList', query: { bizType: 'SHELF_WARN', shelfSn: data.notice.extInfo.bizSn } })
  203. }
  204. this.hasRead({ msg_id: data.id }).then(res => {
  205. // 刷新列表
  206. if (res.status == 200) {
  207. this.handelSearch()
  208. }
  209. })
  210. },
  211. // 查询列表
  212. handelSearch (pageNo) {
  213. this.paginationProps.current = pageNo || this.paginationProps.current
  214. this.disabled = true
  215. const params = {
  216. pageNo: this.paginationProps.current,
  217. pageSize: this.paginationProps.pageSize,
  218. readFlag: this.queryParam.readFlag,
  219. notice: {
  220. title: this.queryParam.notice.title,
  221. type: this.queryParam.notice.type
  222. },
  223. beginDate: this.queryParam.beginDate,
  224. endDate: this.queryParam.endDate
  225. }
  226. // 开始查询
  227. this.listLoading = true
  228. this.getMessageList(params).then((res) => {
  229. this.listLoading = false
  230. if (res.status == 200) {
  231. const data = res.data
  232. this.paginationProps.total = Number(res.data.count) || 0
  233. this.paginationProps.current = data.pageNo
  234. const no = (data.pageNo - 1) * data.pageSize
  235. for (var i = 0; i < data.list.length; i++) {
  236. data.list[i].no = no + i + 1
  237. if (data.list[i].notice && data.list[i].notice.extInfo) {
  238. data.list[i].notice.extInfo = JSON.parse(data.list[i].notice.extInfo)
  239. }
  240. }
  241. this.loadData = data.list
  242. console.log(this.loadData)
  243. this.disabled = false
  244. } else {
  245. this.paginationProps.total = 0
  246. this.paginationProps.current = 1
  247. this.paginationProps.pageSize = 20
  248. this.loadData = []
  249. }
  250. })
  251. },
  252. // 分页 一页多少条change
  253. changePageSize (current, pageSize) {
  254. this.paginationProps.current = current
  255. this.paginationProps.pageSize = pageSize
  256. this.handelSearch()
  257. },
  258. // 分页 页码change
  259. changePage (current) {
  260. this.paginationProps.current = current
  261. this.handelSearch()
  262. },
  263. // 重置
  264. resetSearchForm () {
  265. this.resetData()
  266. this.handelSearch(1)
  267. },
  268. resetData () {
  269. this.$refs.rangeDate.resetDate()
  270. this.queryParam.beginDate = ''
  271. this.queryParam.endDate = ''
  272. this.queryParam.readFlag = undefined
  273. this.queryParam.notice.title = undefined
  274. this.queryParam.notice.type = undefined
  275. this.paginationProps.total = 0
  276. this.paginationProps.current = 1
  277. this.paginationProps.pageSize = 20
  278. },
  279. // 详情
  280. handleDetail (row) {
  281. this.itemId = row.noticeId
  282. this.openModal = true
  283. // 设置已读
  284. if (row.readFlag == '0') {
  285. this.hasRead({ msg_id: row.id }).then(res => {
  286. // 刷新列表
  287. if (res.status == 200) {
  288. this.handelSearch()
  289. }
  290. })
  291. }
  292. },
  293. // 关闭弹框
  294. closeModal () {
  295. this.itemId = ''
  296. this.openModal = false
  297. },
  298. pageInit () {
  299. const _this = this
  300. this.$nextTick(() => { // 页面渲染完成后的回调
  301. _this.setTableH()
  302. })
  303. this.openModal = false
  304. },
  305. setTableH () {
  306. const tableSearchH = this.$refs.tableSearch.offsetHeight
  307. this.tableHeight = window.innerHeight - tableSearchH - 240
  308. }
  309. },
  310. watch: {
  311. // 监听ws消息通知
  312. wsMessage (a, b) {
  313. if (a !== b && a) {
  314. // 新未读消息
  315. if (a.type == 'no_read_count') {
  316. this.resetData()
  317. this.handelSearch()
  318. }
  319. }
  320. },
  321. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  322. this.setTableH()
  323. }
  324. },
  325. mounted () {
  326. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  327. this.pageInit()
  328. this.resetSearchForm()
  329. }
  330. },
  331. activated () {
  332. // 如果是新页签打开,则重置当前页面
  333. if (this.$store.state.app.isNewTab) {
  334. this.pageInit()
  335. this.resetSearchForm()
  336. }
  337. },
  338. beforeRouteEnter (to, from, next) {
  339. next(vm => {})
  340. }
  341. }
  342. </script>