1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<template>
  <a-modal :title="modalTitle" :width="modalWidth" :visible="modalVisible" :footer="null" @cancel="$emit('closeModal')">
    <a-table bordered :columns="modalTableColumns" :dataSource="dataSource" :pagination="ipagination" :loading="loading"
             @change="handleTableChange" rowKey="id"/>
  </a-modal>
</template>
 
<script>
  import { putAction, getAction } from '@/api/manage'
 
  export default {
    name: 'SignageModal',
    components: {},
    props: {
      modalWidth: {
        type: Number,
        default: 1048
      },
      modalTitle: {
        type: String
      },
      modalDataApiUrl: {
        type: String
      },
      modalVisible: {
        type: Boolean
      },
      modalDataApiParams: {
        type: Object,
        default: () => {
        }
      }
    },
    watch: {
      modalVisible: {
        handler(newVal) {
          // 打开弹窗时数据回到第一页且每页显示最大条数恢复为最小值
          if (newVal) {
            this.searchReset()
            this.ipagination.pageSize = +this.ipagination.pageSizeOptions[0]
          }
        }
      }
    },
    data() {
      return {
        loading: false,
        /* 分页参数 */
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        dataSource: [],
        modalTableColumns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: function(t, r, index) {
              return parseInt(index) + 1
            }
          },
          {
            width: 150,
            align: 'center',
            title: '设备编号',
            dataIndex: 'equipmentCode',
            key: 'equipmentCode'
          },
          {
            align: 'center',
            title: '设备名称',
            dataIndex: 'equipmentName',
            key: 'equipmentName'
          },
          {
            align: 'center',
            title: '设备型号',
            dataIndex: 'equipmentModel',
            key: 'equipmentModel'
          },
          {
            align: 'center',
            title: '使用部门',
            key: 'zxfactoryOrgCode_dictText',
            dataIndex: 'zxfactoryOrgCode_dictText'
          },
          {
            width: 100,
            align: 'center',
            title: '技术状态',
            key: 'technologyStatus_dictText',
            dataIndex: 'technologyStatus_dictText'
          }
        ]
      }
    },
    methods: {
      loadData(arg) {
        if (!this.modalDataApiUrl) {
          this.$message.error('请设置接口地址!')
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) this.ipagination.current = 1
        const params = Object.assign({}, this.modalDataApiParams)
        params.pageNo = this.ipagination.current
        params.pageSize = this.ipagination.pageSize
        if (!params) return false
        this.loading = true
        getAction(this.modalDataApiUrl, params)
          .then((res) => {
            if (res.success) {
              this.dataSource = res.result.records || res.result
              if (res.result.total) this.ipagination.total = res.result.total
              else this.ipagination.total = 0
            } else {
              this.$message.warning(res.message)
            }
          })
          .finally(() => {
            this.loading = false
          })
      },
 
      searchReset() {
        this.dataSource = []
        this.loadData(1)
      },
 
      /**
       * 分页变化时触发
       * @param pagination 分页参数
       */
      handleTableChange(pagination) {
        this.ipagination = pagination
        this.loadData()
      }
    }
  }
</script>