list.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <a-card size="small" :bordered="false" class="customerTypeList-wrap">
  3. <a-spin :spinning="spinning" tip="Loading...">
  4. <!-- 搜索条件 -->
  5. <div ref="tableSearch" class="table-page-search-wrapper"></div>
  6. <!-- 列表 -->
  7. <a-table
  8. class="sTable fixPagination"
  9. ref="table"
  10. :style="{ height: tableHeight+84.5+'px' }"
  11. size="small"
  12. :rowKey="(record) => record.id"
  13. :columns="columns"
  14. :data-source="loadData"
  15. :scroll="{ y: tableHeight }"
  16. bordered>
  17. <!-- 操作 -->
  18. <template slot="action1" slot-scope="text, record, index">
  19. <a-checkbox :id="'ac1-'+record.id" :checked="text==1" @change="onChange(0,record)"></a-checkbox>
  20. </template>
  21. <template slot="action2" slot-scope="text, record, index">
  22. <a-checkbox :id="'ac2-'+record.id" :checked="text==1" @change="onChange(1,record)"></a-checkbox>
  23. </template>
  24. <template slot="action3" slot-scope="text, record, index">
  25. <a-checkbox :id="'ac3-'+record.id" :checked="text==1" @change="onChange(2,record)"></a-checkbox>
  26. </template>
  27. <template slot="action4" slot-scope="text, record, index">
  28. <a-checkbox :id="'ac4-'+record.id" :checked="text==1" @change="onChange(3,record)"></a-checkbox>
  29. </template>
  30. <template slot="action5" slot-scope="text, record, index">
  31. <a-checkbox :id="'ac5-'+record.id" :checked="text==1" @change="onChange(4,record)"></a-checkbox>
  32. </template>
  33. </a-table>
  34. </a-spin>
  35. </a-card>
  36. </template>
  37. <script>
  38. import { commonMixin } from '@/utils/mixin'
  39. import { noticeUserBizQuery, noticeUserBizSave } from '@/api/noticeUser'
  40. import { STable, VSelect } from '@/components'
  41. export default {
  42. name: 'NotificationManageList',
  43. components: { STable, VSelect },
  44. mixins: [commonMixin],
  45. data () {
  46. return {
  47. spinning: false,
  48. tableHeight: 0,
  49. disabled: false, // 查询、重置按钮是否可操作
  50. columns: [
  51. { title: '序号', dataIndex: 'no', width: '5%', align: 'center' },
  52. { title: '用户名称', dataIndex: 'userName', width: '45%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
  53. { title: '急送提醒', dataIndex: 'tempOrderFlag', scopedSlots: { customRender: 'action1' }, width: '10%', align: 'center' },
  54. { title: '补货提醒', dataIndex: 'shelfReplenishFlag', scopedSlots: { customRender: 'action2' }, width: '10%', align: 'center' },
  55. { title: '订单提醒', dataIndex: 'shelfOrderFlag', scopedSlots: { customRender: 'action3' }, width: '10%', align: 'center' },
  56. { title: '货架异常提醒', dataIndex: 'shelfWarnFlag', scopedSlots: { customRender: 'action4' }, width: '10%', align: 'center' },
  57. { title: '全选', dataIndex: 'allFlag', scopedSlots: { customRender: 'action5' }, width: '10%', align: 'center' }
  58. ],
  59. loadData: [], // 列表数据
  60. openModal: false, // 新增编辑客户类型 弹框
  61. itemId: '', // 当前id
  62. nowData: null // 当前记录数据
  63. }
  64. },
  65. methods: {
  66. // 选择
  67. onChange (index, record) {
  68. const key = ['tempOrderFlag', 'shelfReplenishFlag', 'shelfOrderFlag', 'shelfWarnFlag', 'allFlag']
  69. record[key[index]] = record[key[index]] ? 0 : 1
  70. // 全选
  71. if (index == 4) {
  72. const flag = record[key[index]]
  73. key.map(item => {
  74. record[item] = flag ? 1 : 0
  75. })
  76. } else {
  77. const ret = []
  78. key.map(item => {
  79. if (item != 'allFlag') {
  80. ret.push(record[item])
  81. }
  82. })
  83. record['allFlag'] = ret.filter(item => item == 1).length == 4 ? 1 : 0
  84. }
  85. // 保存数据
  86. const noticeTypeList = []
  87. const keys = ['temp_order', 'shelf_replenish', 'shelf_order', 'shelf_warn']
  88. key.map((item, i) => {
  89. if (item != 'allFlag' && record[item] == 1) {
  90. noticeTypeList.push(keys[i])
  91. }
  92. })
  93. this.spinning = true
  94. noticeUserBizSave({
  95. userSn: record.userSn,
  96. noticeTypeList: noticeTypeList
  97. }).then(res => {
  98. if (res.status == 200) {
  99. this.$message.success(res.message)
  100. }
  101. this.spinning = false
  102. this.getData()
  103. })
  104. },
  105. // 获取列表数据
  106. getData () {
  107. this.spinning = true
  108. noticeUserBizQuery().then(res => {
  109. const data = res.data
  110. if (res.status == 200) {
  111. const no = 0
  112. for (var i = 0; i < data.length; i++) {
  113. data[i].no = no + i + 1
  114. const key = ['tempOrderFlag', 'shelfReplenishFlag', 'shelfOrderFlag', 'shelfWarnFlag', 'allFlag']
  115. const ret = []
  116. key.map(item => {
  117. if (data[i][item] == 1) {
  118. ret.push(1)
  119. }
  120. })
  121. data[i].allFlag = ret.length == 4 ? 1 : 0
  122. }
  123. }
  124. this.loadData = data
  125. this.spinning = false
  126. })
  127. },
  128. pageInit () {
  129. const _this = this
  130. this.$nextTick(() => { // 页面渲染完成后的回调
  131. _this.setTableH()
  132. })
  133. this.getData()
  134. },
  135. setTableH () {
  136. const tableSearchH = this.$refs.tableSearch.offsetHeight
  137. this.tableHeight = window.innerHeight - tableSearchH - 200
  138. }
  139. },
  140. watch: {
  141. '$store.state.app.winHeight' (newValue, oldValue) { // 窗口变更时,需同时更改表格高度
  142. this.setTableH()
  143. }
  144. },
  145. mounted () {
  146. if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
  147. this.pageInit()
  148. }
  149. },
  150. activated () {
  151. // 如果是新页签打开,则重置当前页面
  152. if (this.$store.state.app.isNewTab) {
  153. this.pageInit()
  154. }
  155. }
  156. }
  157. </script>