index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <el-row :gutter="20">
  3. <el-col :span="4" :xs="24">
  4. <ContentWrap class="h-1/1">
  5. <DeptTree @node-click="handleDeptNodeClick" />
  6. </ContentWrap>
  7. </el-col>
  8. <el-col :span="20" :xs="24">
  9. <ContentWrap>
  10. <!-- 搜索工作栏 -->
  11. <el-form
  12. class="-mb-15px"
  13. :model="queryParams"
  14. ref="queryFormRef"
  15. :inline="true"
  16. label-width="68px"
  17. >
  18. <el-form-item label="设备类别" prop="deviceType">
  19. <el-tree-select
  20. v-model="formData.deviceType"
  21. :data="productClassifyList"
  22. :props="defaultProps"
  23. check-strictly
  24. node-key="id"
  25. placeholder="请选择设备类别"
  26. @change="assetclasschange"
  27. class="!w-240px"
  28. />
  29. </el-form-item>
  30. <el-form-item label="设备部件" prop="deviceComponent">
  31. <el-input
  32. v-model="queryParams.deviceComponent"
  33. placeholder="请输入设备部件"
  34. clearable
  35. @keyup.enter="handleQuery"
  36. class="!w-240px"
  37. />
  38. </el-form-item>
  39. <el-form-item label="创建人" prop="creName">
  40. <el-input
  41. v-model="queryParams.creName"
  42. placeholder="请输入创建人"
  43. clearable
  44. @keyup.enter="handleQuery"
  45. class="!w-240px"
  46. />
  47. </el-form-item>
  48. <el-form-item label="创建日期" prop="creDate">
  49. <el-date-picker
  50. v-model="queryParams.creDate"
  51. value-format="YYYY-MM-DD HH:mm:ss"
  52. type="date"
  53. start-placeholder="请选择"
  54. :default-time="[new Date('1 00:00:00')]"
  55. class="!w-240px"
  56. />
  57. </el-form-item>
  58. <el-form-item>
  59. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  60. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  61. <el-button
  62. type="primary"
  63. plain
  64. @click="openForm('create')"
  65. v-hasPermi="['rq:iot-operation-model:create']"
  66. >
  67. <Icon icon="ep:plus" class="mr-5px" /> 新增
  68. </el-button>
  69. <el-button
  70. type="success"
  71. plain
  72. @click="handleExport"
  73. :loading="exportLoading"
  74. v-hasPermi="['rq:iot-operation-model:export']"
  75. >
  76. <Icon icon="ep:download" class="mr-5px" /> 导出
  77. </el-button>
  78. </el-form-item>
  79. </el-form>
  80. </ContentWrap>
  81. <!-- 列表 -->
  82. <ContentWrap>
  83. <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
  84. <el-table-column label="所属组织" align="center" prop="orgName" />
  85. <el-table-column label="设备类别" align="center" prop="deviceType" />
  86. <el-table-column label="设备部件" align="center" prop="deviceComponent" />
  87. <el-table-column label="填写信息" align="center" prop="fillInfo" />
  88. <el-table-column label="创建人" align="center" prop="creName" />
  89. <el-table-column
  90. label="创建日期"
  91. align="center"
  92. prop="creDate"
  93. :formatter="dateFormatter2"
  94. width="180px"
  95. />
  96. <el-table-column label="操作" align="center" min-width="120px">
  97. <template #default="scope">
  98. <el-button
  99. link
  100. type="primary"
  101. @click="openForm('update', scope.row.id)"
  102. v-hasPermi="['rq:iot-operation-model:update']"
  103. >
  104. 编辑
  105. </el-button>
  106. <el-button
  107. link
  108. type="danger"
  109. @click="handleDelete(scope.row.id)"
  110. v-hasPermi="['rq:iot-operation-model:delete']"
  111. >
  112. 删除
  113. </el-button>
  114. </template>
  115. </el-table-column>
  116. </el-table>
  117. <!-- 分页 -->
  118. <Pagination
  119. :total="total"
  120. v-model:page="queryParams.pageNo"
  121. v-model:limit="queryParams.pageSize"
  122. @pagination="getList"
  123. />
  124. </ContentWrap>
  125. </el-col>
  126. <!-- 表单弹窗:添加/修改 -->
  127. <IotOpeationModelForm ref="formRef" @success="getList" :dept="deptInfo"/>
  128. </el-row>
  129. </template>
  130. <script setup lang="ts">
  131. import { dateFormatter2 } from '@/utils/formatTime'
  132. import DeptTree from "@/views/system/user/DeptTree.vue";
  133. import download from '@/utils/download'
  134. import {defaultProps,handleTree} from "@/utils/tree";
  135. import { IotOpeationModelApi, IotOpeationModelVO } from '@/api/pms/iotopeationmodel'
  136. import IotOpeationModelForm from './IotOpeationModelForm.vue'
  137. import * as DeptApi from "@/api/system/dept";
  138. import * as ProductClassifyApi from "@/api/pms/productclassify";
  139. import {IotDeviceApi} from "@/api/pms/device";
  140. import {DeviceAttrModelApi} from "@/api/pms/deviceattrmodel";
  141. /** 运行记录模板主 列表 */
  142. defineOptions({ name: 'IotOpeationModel' })
  143. const message = useMessage() // 消息弹窗
  144. const { t } = useI18n() // 国际化
  145. const loading = ref(true) // 列表的加载中
  146. const list = ref<IotOpeationModelVO[]>([]) // 列表的数据
  147. const total = ref(0) // 列表的总页数
  148. const { push } = useRouter() // 路由跳转
  149. const deptList = ref<Tree[]>([]) // 树形结构
  150. const productClassifyList = ref<Tree[]>([]) // 树形结构
  151. const { params, name } = useRoute() // 查询参数
  152. const id = params.id
  153. const brandLabel = ref('') // 表单的类型:create - 新增;update - 修改
  154. const zzLabel = ref('') // 表单的类型:create - 新增;update - 修改
  155. const supplierLabel = ref('') // 表单的类型:create - 新增;update - 修改
  156. const queryParams = reactive({
  157. pageNo: 1,
  158. pageSize: 10,
  159. deptId: undefined,
  160. orgName: undefined,
  161. deviceType: undefined,
  162. deviceComponent: undefined,
  163. fillInfo: undefined,
  164. creName: undefined,
  165. creDate: [],
  166. })
  167. let deptInfo = {deptId:'',orgName:''};
  168. const formData = ref({
  169. deviceType: undefined
  170. })
  171. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  172. const formType = ref('') // 表单的类型:create - 新增;update - 修改
  173. const queryFormRef = ref() // 搜索的表单
  174. const exportLoading = ref(false) // 导出的加载中
  175. /** 查询列表 */
  176. const getList = async () => {
  177. loading.value = true
  178. try {
  179. const data = await IotOpeationModelApi.getIotOpeationModelPage(queryParams)
  180. list.value = data.list
  181. total.value = data.total
  182. } finally {
  183. loading.value = false
  184. }
  185. }
  186. /** 搜索按钮操作 */
  187. const handleQuery = () => {
  188. queryParams.pageNo = 1
  189. getList()
  190. }
  191. /** 重置按钮操作 */
  192. const resetQuery = () => {
  193. queryFormRef.value.resetFields()
  194. handleQuery()
  195. }
  196. /** 添加/修改操作 */
  197. const formRef = ref()
  198. const openForm = (type: string, id?: number) => {
  199. //修改
  200. formRef.value.open(type, id)
  201. }
  202. /** 删除按钮操作 */
  203. const handleDelete = async (id: number) => {
  204. try {
  205. // 删除的二次确认
  206. await message.delConfirm()
  207. // 发起删除
  208. await IotOpeationModelApi.deleteIotOpeationModel(id)
  209. message.success(t('common.delSuccess'))
  210. // 刷新列表
  211. await getList()
  212. } catch {}
  213. }
  214. /** 导出按钮操作 */
  215. const handleExport = async () => {
  216. try {
  217. // 导出的二次确认
  218. await message.exportConfirm()
  219. // 发起导出
  220. exportLoading.value = true
  221. const data = await IotOpeationModelApi.exportIotOpeationModel(queryParams)
  222. download.excel(data, '运行记录模板主.xls')
  223. } catch {
  224. } finally {
  225. exportLoading.value = false
  226. }
  227. }
  228. const assetclasschange = () => {
  229. const assetClass = formData.value.deviceType
  230. DeviceAttrModelApi.getDeviceAttrModelListByDeviceCategoryId(assetClass).then(res => {
  231. if (res){
  232. res.forEach((item) => {
  233. if (item.requiredFlag) {
  234. const rule = {required: true, message: item.name+'不能为空', trigger: 'blur'}
  235. item.rules = []
  236. item.rules.push(rule)
  237. }
  238. })
  239. list.value = res
  240. debugger
  241. } else {
  242. list.value = []
  243. }
  244. })
  245. }
  246. onMounted(async () => {
  247. deptList.value = handleTree(await DeptApi.getSimpleDeptList())
  248. productClassifyList.value = handleTree(
  249. await ProductClassifyApi.IotProductClassifyApi.getSimpleProductClassifyList()
  250. )
  251. formData.value.assetProperty = 'zy'
  252. // 修改时,设置数据
  253. if (id) {
  254. formType.value = 'update';
  255. formLoading.value = true
  256. try {
  257. const iotDevice = await IotDeviceApi.getIotDevice(id);
  258. formData.value = iotDevice
  259. brandLabel.value = iotDevice.brandName;
  260. zzLabel.value = iotDevice.zzName;
  261. supplierLabel.value = iotDevice.supplierName;
  262. list.value = JSON.parse(iotDevice.templateJson);
  263. list.value.forEach((item) => {
  264. formData.value[item.identifier] = item.value;
  265. })
  266. } finally {
  267. formLoading.value = false
  268. }
  269. } else {
  270. formType.value = 'create';
  271. }
  272. })
  273. /** 处理部门被点击 */
  274. const handleDeptNodeClick = async (row) => {
  275. queryParams.deptId = row.id
  276. queryParams.orgName = row.name;
  277. deptInfo.orgName = queryParams.orgName;
  278. deptInfo.deptId = queryParams.deptId;
  279. await getList()
  280. }
  281. /** 初始化 **/
  282. onMounted(() => {
  283. getList()
  284. })
  285. </script>