Riku
2025-09-20 32eedf2857255cf29985ffc0cc73e75eccda39bf
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
<template>
  <FYTable @search="onSearch" :pagination="false" ref="tableRef" size="small">
    <template #options>
      <!-- 区县 -->
      <FYOptionLocation
        :allOption="false"
        :level="3"
        :checkStrictly="false"
        v-model:value="formSearch.locations"
      ></FYOptionLocation>
      <!-- 场景类型 -->
      <FYOptionScene
        :allOption="false"
        :type="2"
        v-model:value="formSearch.scenetype"
      ></FYOptionScene>
      <FYOptionTime
        :initValue="false"
        type="month"
        v-model:value="formSearch.time"
      ></FYOptionTime>
    </template>
    <template #buttons> </template>
 
    <template #options-expand>
      <el-form :inline="true">
        <CompQuickSet @quick-set="setOptions"></CompQuickSet>
      </el-form>
    </template>
 
    <!-- <template #options-expand2>
      <CompDeviceMatchEdit :area="area"></CompDeviceMatchEdit>
    </template> -->
 
    <template #table-column>
      <el-table-column
        fixed="left"
        type="index"
        label="#"
        width="40"
        index="1"
      ></el-table-column>
      <el-table-column
        prop="deviceCode"
        :show-overflow-tooltip="true"
        label="监测设备编号"
        width="160"
      >
      </el-table-column>
      <el-table-column
        prop="deviceName"
        :show-overflow-tooltip="true"
        label="监测设备名称"
      >
      </el-table-column>
      <el-table-column
        prop="svUserName"
        :show-overflow-tooltip="true"
        label="监管用户名称"
      >
      </el-table-column>
      <el-table-column
        prop="tzUserName"
        :show-overflow-tooltip="true"
        label="守法自助用户名称"
      >
      </el-table-column>
      <el-table-column
        prop="createTime"
        :show-overflow-tooltip="true"
        label="创建时间"
        :formatter="timeFormat"
      >
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="150">
        <template #default="{ row }">
          <el-button
            v-show="row.deviceCode"
            type="primary"
            size="small"
            @click="itemEdit(row)"
            >编辑</el-button
          >
          <el-button type="success" size="small" @click="itemAdd(row)"
            >添加设备</el-button
          >
        </template>
      </el-table-column>
    </template>
  </FYTable>
  <el-drawer
    v-model="drawerShow"
    title="设备匹配记录编辑"
    direction="btt"
    size="80%"
    destroy-on-close
  >
    <CompDeviceMatchEdit
      :data="selectedItem"
      :area="area"
      @save="onSave"
    ></CompDeviceMatchEdit>
  </el-drawer>
</template>
<script setup>
/**
 * 监测设备和场景匹配记录管理
 */
import dayjs from 'dayjs';
import { ref, reactive, computed, getCurrentInstance } from 'vue';
import userMapApi from '@/api/fysp/userMapApi';
 
import CompDeviceMatchEdit from '@/views/fysp/config/device/CompDeviceMatchEdit.vue';
 
// fixme 2024.9.26 后续可以用vueuse中的时间格式化方法来代替
const { $fm } = getCurrentInstance().appContext.config.globalProperties;
 
/******** 匹配记录查询 ********/
const tableRef = ref();
const formSearch = reactive({
  locations: {},
  scenetype: {},
  time: dayjs().add(-1, 'M').date(1).toDate()
});
 
const area = computed(() => {
  return {
    provincecode: formSearch.locations.pCode,
    provincename: formSearch.locations.pName,
    citycode: formSearch.locations.cCode,
    cityname: formSearch.locations.cName,
    districtcode: formSearch.locations.dCode,
    districtname: formSearch.locations.dName,
    towncode: formSearch.locations.tCode,
    townname: formSearch.locations.tName,
    starttime: $fm.formatYMDH(formSearch.time),
    scensetypeid: formSearch.scenetype.value,
    online: true,
    // 此处数据来源固定为飞羽监管系统
    sourceType: 2
  };
});
 
function onSearch(page, func) {
  userMapApi.fetchDeviceMap(area.value).then((res) => {
    func({ data: res.data });
  });
}
 
function setOptions(param) {
  formSearch.locations = param.locations;
  formSearch.scenetype = param.scenetype;
  // formSearch.sourceType = param.sourceType;
  tableRef.value.onSearch();
}
 
function timeFormat(row) {
  const time = row.createTime;
  if (time) {
    return $fm.formatYMDH(time);
  } else {
    return '';
  }
}
 
/******** 匹配记录编辑 ********/
const drawerShow = ref(false);
const selectedItem = ref(null);
function itemEdit(row) {
  selectedItem.value = row;
  drawerShow.value = true;
}
 
/**
 * 向用户添加新设备
 * 不传递主键id和设备信息,以此表示需要添加新的设备
 * @param row 选中的行数据
 */
function itemAdd(row) {
  selectedItem.value = {
    svUserName: row.svUserName,
    tzUserName: row.tzUserName,
    svUserId: row.svUserId,
    tzUserId: row.tzUserId
  };
  drawerShow.value = true;
}
 
function onSave() {
  tableRef.value.onSearch();
  drawerShow.value = false;
}
</script>