eight
2024-12-03 a0d89e1a39de18baccd2cee18b5785ce476363ed
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
<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
        class="-mb-15px"
        :model="queryParams"
        ref="queryFormRef"
        :inline="true"
        label-width="68px"
    >
      <el-form-item label="分类名" prop="category">
        <el-select
            v-model="queryParams.category"
            placeholder="请选择分类名"
            clearable
            class="!w-240px"
            @change="categoryChanged"
        >
          <el-option
              v-for="dict in categoryOptions"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="品牌" prop="brand">
        <el-select
            v-model="queryParams.brand"
            placeholder="请选择品牌"
            clearable
            class="!w-240px"
            @change="brandChanged"
        >
          <el-option
              v-for="dict in brandOptions"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="型号" prop="model">
        <el-select
            v-model="queryParams.model"
            placeholder="请选择型号"
            clearable
            class="!w-240px"
        >
          <el-option
              v-for="dict in modelOptions"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>
 
  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <!--      <el-table-column label="id" align="center" prop="id" />-->
      <el-table-column label="分类名" align="center" prop="category">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.ECG_DEV_CATEGORY" :value="scope.row.category" />
        </template>
      </el-table-column>
<!--
      <el-table-column label="品牌" align="center" prop="brand" width="100px">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.ECG_DEV_BRAND" :value="scope.row.brand" />
        </template>
      </el-table-column>
      <el-table-column label="型号" align="center" prop="model" />
-->
      <el-table-column label="使用状态" align="center" prop="lost" >
        <template #default="scope">
          <span>{{tranlateDevState(scope.row.state)}}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="采购日期" align="center" prop="purchaseDate" :formatter="dateFormatter2" width="120px"/>-->
      <el-table-column label="数量" align="center" prop="devCount" />
    </el-table>
  </ContentWrap>
</template>
 
<script setup lang="ts">
import {getStrDictOptions, DICT_TYPE, DictDataType} from '@/utils/dict'
import {dateFormatter, dateFormatter2} from '@/utils/formatTime'
import download from '@/utils/download'
import {DeviceApi, DeviceStatisticVO, DeviceVO, DevModelApi, OptionsVO} from '@/api/ecg/devmanage'
import DeviceForm from './DeviceForm.vue'
 
/** 设备 列表 */
defineOptions({ name: 'DeviceStatistic' })
 
const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化
 
const loading = ref(true) // 列表的加载中
const list = ref<DeviceStatisticVO[]>([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  purchaseDate: [],
  createTime: [],
  devId: undefined,
  category: undefined,
  brand: undefined,
  model: undefined
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中
 
const categoryOptions = ref<DictDataType[]>([])
const brandOptions = ref<OptionsVO[]>([])
const modelOptions = ref<OptionsVO[]>([])
 
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await DeviceApi.deviceStatistic(queryParams)
    console.info( data )
    list.value = data
  } finally {
    loading.value = false
  }
}
 
/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}
 
/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}
 
/** 添加/修改操作 */
const formRef = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}
 
/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await DeviceApi.deleteDevice(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}
 
/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await DeviceApi.exportDevice(queryParams)
    download.excel(data, '设备.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}
 
const tranlateDevState = (state) => {
  if (state === 0) return "空闲";
  else if (state=== 5) return "已领用";
  else if (state=== 10) return "已装机";
  else if (state=== 20) return "已遗失";
  else if (state=== 30) return "维修中";
  else if (state=== 40) return "已报废";
}
 
const categoryChanged = async () => {
  const data = await DevModelApi.getBrandOption(queryParams.category!)
  brandOptions.value = data
 
  queryParams.brand = ''
  queryParams.model = ''
 
  //queryParams.brand = brandOptions.value.length === 0 ? "" : brandOptions.value[0].value
  //brandChanged()
}
 
const brandChanged = async () => {
  const data = await DevModelApi.getModelOption(queryParams.category!, queryParams.brand!)
  modelOptions.value = data
 
  queryParams.model = ''
 
  //queryParams.model = modelOptions.value.length === 0 ? "" : modelOptions.value[0].value
}
 
/** 初始化 **/
onMounted( async () => {
  const data = await getStrDictOptions(DICT_TYPE.ECG_DEV_CATEGORY)
  categoryOptions.value = data
 
  getList()
})
</script>