list.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div>
  3. <a-card size="small" :bordered="false" class="noticeManagementList-wrap searchBoxNormal">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" class="table-page-search-wrapper">
  6. <a-form layout="inline" @keyup.enter.native="$refs.table.refresh(true)">
  7. <a-row :gutter="15">
  8. <a-col :md="6" :sm="24">
  9. <a-form-item label="标题">
  10. <a-input id="noticeManagementList-title" v-model.trim="queryParam.title" allowClear placeholder="请输入标题"/>
  11. </a-form-item>
  12. </a-col>
  13. <a-col :md="6" :sm="24">
  14. <a-form-item label="类别">
  15. <v-select code="NOTITY_BIZ_TYPE" id="noticeManagementList-type" v-model="queryParam.type" allowClear placeholder="请选择类别"></v-select>
  16. </a-form-item>
  17. </a-col>
  18. <a-col :md="6" :sm="24">
  19. <a-form-item label="发布状态">
  20. <v-select code="NOTITY_SEND_STATUS" id="noticeManagementList-sendStatus" v-model="queryParam.sendStatus" allowClear placeholder="请选择发布状态"></v-select>
  21. </a-form-item>
  22. </a-col>
  23. <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
  24. <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="noticeManagementList-refresh">查询</a-button>
  25. <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="noticeManagementList-reset">重置</a-button>
  26. </a-col>
  27. </a-row>
  28. </a-form>
  29. </div>
  30. </a-card>
  31. <a-card size="small" :bordered="false">
  32. <a-spin :spinning="spinning" tip="Loading...">
  33. <!-- 操作按钮 -->
  34. <div class="table-operator">
  35. <a-button id="noticeManagementList-add" type="primary" class="button-error" @click="handleAdd">新增</a-button>
  36. </div>
  37. <!-- 总计 -->
  38. <!-- <a-alert type="info" style="margin-bottom:10px">
  39. <div slot="message">合计:<strong>{{ total || 0 }}</strong>条</div>
  40. </a-alert> -->
  41. <!-- 列表 -->
  42. <s-table
  43. class="sTable fixPagination"
  44. ref="table"
  45. :style="{ height: tableHeight+84.5+'px' }"
  46. size="small"
  47. :rowKey="(record) => record.id"
  48. :columns="columns"
  49. :data="loadData"
  50. :scroll="{ y: tableHeight }"
  51. :defaultLoadData="false"
  52. bordered>
  53. <!-- 操作 -->
  54. <template slot="action" slot-scope="text, record">
  55. <a-button
  56. size="small"
  57. type="link"
  58. class="button-info"
  59. v-if="record.sendStatus=='0'"
  60. @click="handleEdit(record)"
  61. id="noticeManagementList-edit-btn">编辑</a-button>
  62. <a-button
  63. size="small"
  64. type="link"
  65. class="button-success"
  66. v-if="record.sendStatus=='1'"
  67. @click="handleDetail(record)"
  68. id="noticeManagementList-detail-btn">详情</a-button>
  69. <a-button
  70. size="small"
  71. type="link"
  72. class="button-error"
  73. v-if="record.sendStatus=='0'"
  74. @click="handleDel(record)"
  75. id="noticeManagementList-del-btn">删除</a-button>
  76. </template>
  77. </s-table>
  78. </a-spin>
  79. <!-- 编辑 -->
  80. <notice-edit-modal :openModal="openModal" :itemId="itemId" @close="closeModal" @ok="$refs.table.refresh()" />
  81. <!-- 详情 -->
  82. <notice-detail-modal :openModal="openDetailModal" :itemId="itemId" @close="closeDetailModal" />
  83. </a-card>
  84. </div>
  85. </template>
  86. <script>
  87. import { commonMixin } from '@/utils/mixin'
  88. import { STable, VSelect } from '@/components'
  89. import noticeEditModal from './editModal.vue'
  90. import noticeDetailModal from './detailModal.vue'
  91. import { noticeList, noticeDel } from '@/api/notice'
  92. export default {
  93. name: 'NoticeManagementList',
  94. mixins: [commonMixin],
  95. components: { STable, VSelect, noticeEditModal, noticeDetailModal },
  96. data () {
  97. return {
  98. spinning: false,
  99. tableHeight: 0,
  100. queryParam: { // 查询条件
  101. title: '',
  102. type: undefined,
  103. sendStatus: undefined
  104. },
  105. disabled: false, // 查询、重置按钮是否可操作
  106. columns: [
  107. { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
  108. { title: '创建时间', dataIndex: 'createDate', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
  109. { title: '类别', dataIndex: 'typeDictValue', width: '11%', align: 'center', customRender: function (text) { return text || '--' } },
  110. { title: '标题', dataIndex: 'title', align: 'center', width: '25%', customRender: function (text) { return text || '--' }, ellipsis: true },
  111. { title: '可见性', dataIndex: 'toAppNameDictValue', width: '9%', align: 'center', customRender: function (text) { return text || '--' } },
  112. { title: '发布时间', dataIndex: 'releaseDate', width: '13%', align: 'center', customRender: function (text) { return text || '--' } },
  113. { title: '发布状态', dataIndex: 'sendStatusDictValue', width: '10%', align: 'center', customRender: function (text) { return text || '--' } },
  114. { title: '操作', scopedSlots: { customRender: 'action' }, width: '15%', align: 'center' }
  115. ],
  116. // 加载数据方法 必须为 Promise 对象
  117. loadData: parameter => {
  118. this.disabled = true
  119. this.spinning = true
  120. return noticeList(Object.assign(parameter, this.queryParam)).then(res => {
  121. let data
  122. if (res.status == 200) {
  123. data = res.data
  124. const no = (data.pageNo - 1) * data.pageSize
  125. for (var i = 0; i < data.list.length; i++) {
  126. data.list[i].no = no + i + 1
  127. data.list[i].typeDictValue = data.list[i].type == 'notity' ? '公告' : data.list[i].type == 'news_company' ? '企业新闻' : data.list[i].type == 'news_trade' ? '行业咨询' : '--'
  128. data.list[i].sendStatusDictValue = data.list[i].sendStatus == 1 ? '已发布' : data.list[i].sendStatus == 0 ? '未发布' : '--'
  129. data.list[i].toAppNameDictValue = data.list[i].toAppName == '1,2' ? '所有' : data.list[i].toAppName == '2' ? '经销商' : data.list[i].toAppName == '1' ? '总部' : '--'
  130. }
  131. this.total = data.count || 0
  132. this.disabled = false
  133. }
  134. this.spinning = false
  135. return data
  136. })
  137. },
  138. total: 0, // 合计
  139. openModal: false, // 编辑 弹框
  140. openDetailModal: false, // 详情 弹框
  141. itemId: '' // 当前产品id
  142. }
  143. },
  144. methods: {
  145. // 重置
  146. resetSearchForm () {
  147. this.queryParam.title = ''
  148. this.queryParam.type = undefined
  149. this.queryParam.sendStatus = undefined
  150. this.$refs.table.refresh(true)
  151. },
  152. // 详情
  153. handleDetail (row) {
  154. this.itemId = row.id
  155. this.openDetailModal = true
  156. },
  157. // 新增
  158. handleAdd () {
  159. this.itemId = ''
  160. this.openModal = true
  161. },
  162. // 编辑
  163. handleEdit (row) {
  164. this.itemId = row.id
  165. this.openModal = true
  166. },
  167. // 关闭弹框
  168. closeModal () {
  169. this.itemId = ''
  170. this.openModal = false
  171. },
  172. // 关闭详情弹框
  173. closeDetailModal () {
  174. this.itemId = ''
  175. this.openDetailModal = false
  176. },
  177. // 删除
  178. handleDel (row) {
  179. const _this = this
  180. this.$confirm({
  181. title: '提示',
  182. content: '确认要删除吗?',
  183. centered: true,
  184. onOk () {
  185. _this.spinning = true
  186. noticeDel({ id: row.id }).then(res => {
  187. if (res.status == 200) {
  188. _this.$message.success(res.message)
  189. _this.$refs.table.refresh()
  190. _this.spinning = false
  191. } else {
  192. _this.spinning = false
  193. }
  194. })
  195. }
  196. })
  197. },
  198. pageInit () {
  199. const _this = this
  200. this.$nextTick(() => { // 页面渲染完成后的回调
  201. _this.setTableH()
  202. })
  203. },
  204. setTableH () {
  205. const tableSearchH = this.$refs.tableSearch.offsetHeight
  206. this.tableHeight = window.innerHeight - tableSearchH - 254
  207. }
  208. },
  209. watch: {
  210. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  211. this.setTableH()
  212. }
  213. },
  214. mounted () {
  215. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  216. this.pageInit()
  217. this.resetSearchForm()
  218. }
  219. },
  220. activated () {
  221. // 如果是新页签打开,则重置当前页面
  222. if (this.$store.state.app.isNewTab) {
  223. this.pageInit()
  224. this.resetSearchForm()
  225. }
  226. // 仅刷新列表,不重置页面
  227. if (this.$store.state.app.updateList) {
  228. this.pageInit()
  229. this.$refs.table.refresh()
  230. }
  231. }
  232. }
  233. </script>