马宇豪
2024-01-26 c694cffc8541d921e5256d33e14e3237454de950
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<template>
    <div class="home-container">
        <div style="height: 100%">
          <div class="homeCard">
            <div class="main-card">
            <el-row class="cardTop">
              <el-col :span="12" class="mainCardBtn">
                <el-button type="primary" icon="Plus" size="default" @click="openDialog('add',{})">新增</el-button>
              </el-col>
            </el-row>
            <el-table :data="reportData" style="width: 100%" height="calc(100% - 48px)" :header-cell-style="{ background: '#fafafa' }">
              <el-table-column prop="id" label="id" show-overflow-tooltip></el-table-column>
              <el-table-column prop="createTime" label="上报时间" show-overflow-tooltip></el-table-column>
              <el-table-column prop="cardNo" label="卡号" show-overflow-tooltip></el-table-column>
              <el-table-column prop="realName" label="报警人员名称" show-overflow-tooltip></el-table-column>
              <el-table-column prop="alarmStatus" label="报警状态" show-overflow-tooltip>
                <template #default="scope">
                  {{scope.row.alarmStatus == '1'?'报警':scope.row.alarmStatus == '2'?'报警已处理':'--'}}
                </template>
              </el-table-column>
              <el-table-column prop="alarmTime" label="报警时间" show-overflow-tooltip></el-table-column>
              <el-table-column prop="alarmInfo" label="报警信息" show-overflow-tooltip></el-table-column>
              <el-table-column prop="alarmType" label="报警类型" show-overflow-tooltip>
                <template #default="scope">
                  {{getAlarmType(scope.row.alarmType)}}
                </template>
              </el-table-column>
              <el-table-column prop="alarmLocation" label="报警位置" show-overflow-tooltip></el-table-column>
              <el-table-column prop="longitude" label="经度" show-overflow-tooltip></el-table-column>
              <el-table-column prop="latitude" label="纬度" show-overflow-tooltip></el-table-column>
              <el-table-column prop="floorNo" label="楼层号" show-overflow-tooltip></el-table-column>
              <el-table-column prop="handleTime" label="销警时间" show-overflow-tooltip></el-table-column>
              <el-table-column prop="handleInfo" label="处理信息" show-overflow-tooltip></el-table-column>
              <el-table-column label="操作" width="140">
                  <template #default="scope">
                    <el-button size="small" text type="primary" @click="openDialog('update',scope.row)">重新上报</el-button>
                    <el-button style="color: red" size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>
                  </template>
              </el-table-column>
            </el-table>
            <div class="pageBtn">
              <el-pagination @size-change="onHandleSizeChange" small="false" @current-change="onHandleCurrentChange" class="page-position" :pager-count="5" :page-sizes="[10, 20, 30]" v-model:current-page="listQuery.pageIndex" background v-model:page-size="listQuery.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
            </div>
            </div>
          </div>
        </div>
        <add-report ref="reportRef" @refresh="getData"></add-report>
    </div>
</template>
 
<script lang="ts">
import { toRefs, reactive, onMounted, ref, defineComponent } from 'vue'
import { ElMessageBox, ElMessage } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
import addReport from "./components/addReport.vue"
import {judgeReportApi} from "/@/api/dataUpload/saftyBaseInfo/judgeReport";
interface TableDataState {
  reportData: [],
  listQuery: {
    searchParams: {}
    pageIndex: number
    pageSize: number
  }
  total: null | number
  alarmTypeList: Array<alarmType>
}
interface alarmType {
  value: string
  name: string
}
export default defineComponent({
    name: 'contractorInfo',
    components: {addReport },
    setup() {
      const reportRef= ref();
      const state = reactive<TableDataState>({
        reportData: [],
        listQuery: {
          searchParams: {},
          pageIndex: 1,
          pageSize: 10
        },
        total: null,
        alarmTypeList: [
          {value: '01', name: '一键求救报警'},
          {value: '02', name: '滞留预警'},
          {value: '03', name: '越界报警'},
          {value: '04', name: '超员预警'},
          {value: '05', name: '缺员预警'},
          {value: '06', name: '静止预警'},
          {value: '07', name: '作业人员离开报警'},
          {value: '08', name: '非作业人员闯入报警'}
        ]
      });
 
      // 页面加载时
      onMounted(() => {
        getData()
      });
 
      const getData = async ()=>{
        const res = await judgeReportApi().getPositionList(state.listQuery)
        if(res.data.code == 200){
          state.reportData = res.data.data
          state.total = res.data.total
        }else{
          ElMessage({
            type: 'warning',
            message: res.data.msg
          })
        }
      }
 
      const openDialog=(type:string,data:object)=>{
        reportRef.value.open(type,data)
      }
 
      // 删除用户
      const onRowDel = (row: Object) => {
          ElMessageBox.confirm(`此操作将永久删除该条数据,是否继续?`, '提示', {
              confirmButtonText: '确认',
              cancelButtonText: '取消',
              type: 'warning'
          })
              .then(async () => {
                const res = await judgeReportApi().delPosition({ids: [row.id]})
                if(res.data.code == 200){
                  ElMessage({
                    type: 'success',
                    message: '删除成功'
                  })
                  await getData()
                }else{
                  ElMessage({
                    type: 'warning',
                    message: res.data.msg
                  })
                }
              })
              .catch(() => {});
      };
      // 分页改变
      const onHandleSizeChange = (val: number) => {
          state.listQuery.pageSize = val;
          getData()
      };
      // 分页改变
      const onHandleCurrentChange = (val: number) => {
          state.listQuery.pageIndex = val;
          getData()
      };
 
      const getAlarmType = (type: string)=>{
        return state.alarmTypeList.find(i=>i.value == type)?.name
      }
      return {
        reportRef,
        getAlarmType,
        openDialog,
        getData,
        onRowDel,
        onHandleSizeChange,
        onHandleCurrentChange,
        ...toRefs(state)
      };
    }
});
</script>
<style lang="scss" scoped>
.home-container {
  height: calc(100vh - 144px);
  box-sizing: border-box;
  overflow: hidden;
  .demo-tabs {
    width: 100%;
    height: 100%;
 
    &::v-deep(.el-tabs__content) {
      height: calc(100% - 60px);
    }
 
    .el-tab-pane {
      height: 100%;
    }
  }
  .homeCard {
    width: 100%;
    padding: 20px;
    box-sizing: border-box;
    background: #fff;
    border-radius: 4px;
 
    .main-card {
      width: 100%;
      height: 100%;
      .cardTop {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 20px;
        .mainCardBtn {
          margin: 0;
        }
      }
      .pageBtn {
        height: 60px;
        display: flex;
        align-items: center;
        justify-content: right;
 
        .demo-pagination-block + .demo-pagination-block {
          margin-top: 10px;
        }
        .demo-pagination-block .demonstration {
          margin-bottom: 16px;
        }
      }
    }
    &:last-of-type {
      height: calc(100% - 100px);
    }
  }
  .el-row {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
    .grid-content {
      align-items: center;
      min-height: 36px;
    }
 
    .topInfo {
      display: flex;
      align-items: center;
      font-size: 16px;
      font-weight: bold;
 
      & > div {
        white-space: nowrap;
        margin-right: 20px;
      }
    }
  }
  .el-card {
    border: 0;
  }
}
</style>