index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. <template>
  2. <div class="app-container">
  3. <el-row ref="listQueryContainer" class="query-container" justify="space-between" type="flex">
  4. <el-col>
  5. <el-form ref="listQuery" :inline="true" :model="listQuery" style="flex-wrap: wrap" @submit.native.prevent @keyup.enter.native="onSubmit">
  6. <el-form-item label="楼栋" prop="buildingName">
  7. <el-input v-model.trim="listQuery.buildingName" clearable maxlength="16" placeholder="请输入楼栋名称" @clear="listQuery.buildingName=undefined" @keyup.enter.native="onFilterChange">
  8. <i slot="suffix" class="el-input__icon el-icon-search" @click="onFilterChange"></i>
  9. </el-input>
  10. </el-form-item>
  11. <el-form-item label="楼层" prop="floorName">
  12. <el-input v-model.trim="listQuery.floorName" clearable maxlength="16" placeholder="请输入楼层名称" @clear="listQuery.floorName=undefined" @keyup.enter.native="onFilterChange">
  13. <i slot="suffix" class="el-input__icon el-icon-search" @click="onFilterChange"></i>
  14. </el-input>
  15. </el-form-item>
  16. <el-form-item label="房间名称" prop="name">
  17. <el-input v-model.trim="listQuery.name" clearable maxlength="16" placeholder="请输入房间名称" @clear="listQuery.name=undefined" @keyup.enter.native="onFilterChange">
  18. <i slot="suffix" class="el-input__icon el-icon-search" @click="onFilterChange"></i>
  19. </el-input>
  20. </el-form-item>
  21. <el-form-item label-width="0">
  22. <el-button type="primary" @click="onFilterChange">查询</el-button>
  23. <el-button plain type="primary" @click="resetFields">重置</el-button>
  24. <el-button plain type="primary" @click="onExport">导出</el-button>
  25. </el-form-item>
  26. </el-form>
  27. </el-col>
  28. <form-clear :shrinkable="shrinkable" @change="onExpansion" @clear="resetFields"/>
  29. </el-row>
  30. <el-row>
  31. <el-button type="primary" @click="onAdd">添加</el-button>
  32. <el-button v-if="!editing" plain type="primary" @click="onBatchDelete">批量删除</el-button>
  33. <el-button v-if="editing" :disabled="!(selectIds&&selectIds.length)" type="danger" @click="onDeleteSelect">删除</el-button>
  34. <el-button v-if="editing" plain @click="onCancel">取消</el-button>
  35. </el-row>
  36. <el-table ref="table" :data="list" border class="mt10" highlight-current-row stripe @sort-change="onSortChange" @selection-change="onTableSelectionChange" @row-click="onRowClick">
  37. <el-table-column v-if="editing" fixed type="selection" width="55"></el-table-column>
  38. <el-table-column :index="indexCompute" align="center" fixed="left" label="序号" type="index" width="60px"/>
  39. <el-table-column align="center" fixed="left" label="房间名称" min-width="140px" prop="name" sortable="custom"/>
  40. <el-table-column align="center" label="房间编号" min-width="110px" prop="number" sortable="custom"/>
  41. <el-table-column align="center" label="所属楼栋" min-width="120px" prop="buildingName" sortable="custom"/>
  42. <el-table-column align="center" label="所属楼层" min-width="110px" prop="floorName" sortable="custom"/>
  43. <el-table-column align="center" label="设备数量" min-width="110px" prop="deviceTotal" sortable="custom">
  44. <template v-slot="scope">
  45. <router-link :to="{name:'DeviceDevice', params:{buildingId:scope.row.buildingId, floorId:scope.row.floorId, roomId:scope.row.id}}">
  46. <el-link type="primary">{{ scope.row.deviceTotal }}</el-link>
  47. </router-link>
  48. </template>
  49. </el-table-column>
  50. <el-table-column align="center" label="关联项目数" min-width="120px" prop="itemTotal" sortable="custom"/>
  51. <el-table-column align="center" label="操作人员" min-width="110px" prop="updateUsername" sortable="custom"/>
  52. <el-table-column align="center" label="更新时间" prop="updateTime" sortable="custom" width="160px">
  53. <template v-slot="scope">
  54. {{ scope.row.updateTime | dateFormat }}
  55. </template>
  56. </el-table-column>
  57. <el-table-column align="center" label="操作" width="230px">
  58. <template v-slot="scope">
  59. <el-link icon="el-icon-view" type="primary" @click="onQRCode(scope.row)">二维码</el-link>
  60. <el-link class="ml20" icon="el-icon-edit" type="primary" @click="onUpdate(scope.row)">编辑</el-link>
  61. <el-link class="ml20" icon="el-icon-delete" type="danger" @click="onDelete(scope.row)">删除</el-link>
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. <pagination :page.sync="listQuery.page" :size.sync="listQuery.size" :total="total" @change="onPageChange"/>
  66. <el-dialog :close-on-click-modal="false" :close-on-press-escape="false" :visible.sync="exportVisible" title="导出" width="600px">
  67. <el-progress :percentage="exportProgress" :stroke-width="24" :text-inside="true" status="success"></el-progress>
  68. <el-button slot="footer" @click="onCancelExport">取 消</el-button>
  69. </el-dialog>
  70. </div>
  71. </template>
  72. <script>
  73. import {dateFormat} from "@/utils/dateUtil"
  74. import {downloadImage} from "@/utils/httpUtil";
  75. import printJS from "print-js"
  76. export default {
  77. name: "DeviceRoom",
  78. data() {
  79. return {
  80. shrinkable: false, // 查询条件是否可以展开
  81. listQuery: { // 查询对象
  82. buildingId: undefined, // 楼栋id
  83. buildingName: undefined, // 楼栋名称
  84. floorId: undefined, // 楼层id
  85. floorName: undefined, // 楼层名称
  86. name: undefined, // 房间名称
  87. order: undefined,
  88. page: 1,
  89. size: 10
  90. },
  91. list: [], // 结果列表
  92. total: 0, // 总结果数量
  93. exportVisible: false, // 是否显示导出对话框
  94. exportData: [], // 导出数据
  95. exportPagination: { // 导出分页
  96. page: 1,
  97. size: 500,
  98. },
  99. exportProgress: 0, // 导出进度
  100. exportCancel: false, // 是否取消导出
  101. editing: false, // 表格编辑中
  102. selectIds: undefined, // 选中多条记录的id
  103. }
  104. },
  105. watch: {},
  106. // 页面创建
  107. created() {
  108. this.initData();
  109. this.initEvent();
  110. },
  111. // 页面挂载
  112. mounted() {
  113. this.initQuery();
  114. this.getList();
  115. this.initView();
  116. },
  117. // keep-alive 显示界面时调用
  118. activated() {
  119. this.$refs["table"].doLayout();
  120. let buildingId = this.$route.params.buildingId && Number(this.$route.params.buildingId)
  121. let floorId = this.$route.params.floorId && Number(this.$route.params.floorId)
  122. if (buildingId || floorId) {
  123. this.listQuery.buildingId = buildingId;
  124. this.listQuery.floorId = floorId;
  125. this.getList();
  126. }
  127. },
  128. // keep-alive 页面隐藏
  129. deactivated() {
  130. },
  131. methods: {
  132. // 初始化数据
  133. initData() {
  134. },
  135. // 初始化事件
  136. initEvent() {
  137. this.$eventBus.$on("DeviceRoomAdd", this.onAddComplete);
  138. this.$eventBus.$on("DeviceRoomUpdate", this.onUpdateComplete);
  139. },
  140. // 初始化查询条件
  141. initQuery() {
  142. if (this.$store.state.app.paramCache) {
  143. let query = this.$storage.getData(this.$options.name);
  144. if (Object.keys(query).length > 0) {
  145. this.listQuery = query;
  146. if (query.order) {
  147. this.$refs.table.sort(query.order.substring(1), query.order.substring(0, 1) === "+" ? "ascending" : "descending");
  148. } else {
  149. this.$refs.table.clearSort();
  150. }
  151. }
  152. }
  153. },
  154. // 初始化视图
  155. initView() {
  156. this.$nextTick(() => {
  157. this.shrinkable = this.$store.state.app.filterShrink && this.$refs['listQuery'].$el.offsetHeight > 51;
  158. })
  159. },
  160. // 展开/收起查询条件
  161. onExpansion(show) {
  162. this.$refs['listQueryContainer'].$el.style.height = show ? "auto" : "51px";
  163. },
  164. // 表格索引
  165. indexCompute(index) {
  166. return index + 1 + (this.listQuery.page - 1) * this.listQuery.size;
  167. },
  168. // 表单提交
  169. onSubmit() {
  170. this.onFilterChange();
  171. },
  172. // 表单清除
  173. resetFields() {
  174. this.$refs['listQuery'].resetFields();
  175. this.listQuery.buildingId = undefined;
  176. this.listQuery.floorId = undefined;
  177. this.listQuery.order = undefined;
  178. this.$refs.table.clearSort();
  179. this.onFilterChange();
  180. },
  181. // 添加
  182. onAdd() {
  183. this.onCancel();
  184. this.$router.push({path: '/device/room/add'});
  185. },
  186. // 编辑
  187. onBatchDelete() {
  188. this.editing = true;
  189. },
  190. // 删除选中
  191. onDeleteSelect() {
  192. this.$confirm('此操作将永久删除选中的记录, 是否继续?', '提示', {
  193. confirmButtonText: '确认',
  194. cancelButtonText: '取消',
  195. type: 'warning'
  196. }).then(async () => {
  197. this.$axios.delete('/v1/device/room/delete', {params: {ids: this.selectIds}}).then((data) => {
  198. if (this.list.length <= this.selectIds.length && this.listQuery.page > 1) {
  199. this.listQuery.page -= 1;
  200. }
  201. this.selectIds = undefined;
  202. if (data > 0) {
  203. this.$message.success("删除成功");
  204. } else {
  205. this.$message.warning("删除失败");
  206. }
  207. this.getList();
  208. });
  209. });
  210. },
  211. // 取消编辑
  212. onCancel() {
  213. this.$refs['table'].clearSelection();
  214. this.editing = false;
  215. },
  216. // 添加完成
  217. onAddComplete() {
  218. this.onFilterChange();
  219. },
  220. // 房间二维码
  221. onQRCode(row) {
  222. let url = encodeURIComponent(`https://xj.chuanghai-tech.com/exitwritoff/pages/onsitpection/selectplain/selectplain?id=${row.id}`)
  223. let qrUrl = `http://yun.huaxiyou.cc/internal.qcode.stream?dstUrl=${url}`;
  224. this.$alert(`<img id="qrcode" src="${qrUrl}" style="width:100%; height:100%">`, `【${row.name}】二维码`, {
  225. dangerouslyUseHTMLString: true,
  226. confirmButtonText: '下载',
  227. showCancelButton: true,
  228. cancelButtonText: '打印',
  229. distinguishCancelAndClose: true,
  230. callback: action => {
  231. if (action === 'confirm') {
  232. downloadImage(qrUrl, `【${row.name}】二维码`)
  233. } else if (action === 'cancel') {
  234. printJS({
  235. printable: "qrcode",
  236. type: 'html',
  237. header: null,
  238. targetStyles: ['*'],
  239. style: "@page {margin:0 auto}"
  240. })
  241. }
  242. }
  243. }
  244. )
  245. },
  246. // 更新
  247. onUpdate(item) {
  248. this.$router.push({path: '/device/room/edit', query: {id: item.id}});
  249. },
  250. // 更新完成
  251. onUpdateComplete() {
  252. this.onFilterChange();
  253. },
  254. // 删除
  255. onDelete(item) {
  256. this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
  257. confirmButtonText: '确认',
  258. cancelButtonText: '取消',
  259. type: 'warning'
  260. }).then(async () => {
  261. this.$axios.delete(`/v1/device/room/delete/${item.id}`).then((data) => {
  262. if (this.list.length === 1 && this.listQuery.page > 1) {
  263. this.listQuery.page -= 1;
  264. }
  265. if (data > 0) {
  266. this.$message.success("删除成功");
  267. } else {
  268. this.$message.warning("删除失败");
  269. }
  270. this.getList();
  271. });
  272. });
  273. },
  274. // 数据选择
  275. onTableSelectionChange(val) {
  276. this.selectIds = val.map(item => item.id);
  277. },
  278. // 排序改变
  279. onSortChange({prop, order}) {
  280. if (order === "ascending") {
  281. this.listQuery.order = "+" + prop;
  282. } else if (order === "descending") {
  283. this.listQuery.order = "-" + prop;
  284. } else {
  285. this.listQuery.order = undefined;
  286. }
  287. this.onFilterChange();
  288. },
  289. // 行点击
  290. onRowClick(row, column, event) {
  291. this.$refs["table"].setCurrentRow(row);
  292. if (this.editing) {
  293. this.$refs["table"].toggleRowSelection(row);
  294. }
  295. },
  296. // 条件改变
  297. onFilterChange() {
  298. this.listQuery.page = 1;
  299. this.$nextTick(this.getList);
  300. },
  301. // 页码改变
  302. onPageChange() {
  303. this.getList();
  304. },
  305. // 加载列表
  306. getList() {
  307. // 缓存参数
  308. if (this.$store.state.app.paramCache) {
  309. this.$storage.setData(this.$options.name, this.listQuery);
  310. }
  311. this.$axios.get('/v1/device/room/list', {params: this.listQuery}).then(data => {
  312. this.list = data.list;
  313. this.total = data.total;
  314. this.$refs["table"].doLayout();
  315. });
  316. },
  317. // 导出数据
  318. onExport() {
  319. if (this.total > 0) {
  320. this.exportPagination.page = 1;
  321. this.exportData = [];
  322. this.exportVisible = true;
  323. this.getExportData();
  324. }
  325. },
  326. // 取消导出
  327. onCancelExport() {
  328. this.exportVisible = false;
  329. this.exportCancel = true;
  330. },
  331. // 获取数据并导出
  332. getExportData() {
  333. if (!this.exportCancel) {
  334. this.$axios.get('/v1/device/room/list', {params: {...this.listQuery, ...this.exportPagination}}).then(data => {
  335. this.exportPagination.page++;
  336. this.exportData = this.exportData.concat(data.list);
  337. this.exportProgress = Math.round(this.exportData.length * 100 / this.total);
  338. if (this.exportData.length < this.total && data.list.length > 0) {
  339. this.getExportData();
  340. } else {
  341. this.exportVisible = false;
  342. let tHeader = ["序号",
  343. "房间名称",
  344. "房间编号",
  345. "楼栋名称",
  346. "楼层名称",
  347. "设备数量",
  348. "项目数量",
  349. "更新时间",
  350. "更新用户名",
  351. ];
  352. let filterVal = ["index",
  353. "name",
  354. "number",
  355. "buildingName",
  356. "floorName",
  357. "deviceTotal",
  358. "itemTotal",
  359. "updateTime",
  360. "updateUsername",
  361. ];
  362. let data = this.exportData.map((value, index) => filterVal.map((key) => {
  363. if (key === "index") {
  364. return index + 1;
  365. } else if (key === "updateTime") {
  366. return dateFormat("yyyy-MM-dd HH:mm:ss", value[key]);
  367. } else {
  368. return value[key];
  369. }
  370. }));
  371. import('@/utils/Export2Excel').then(excel => {
  372. excel.export_json_to_excel({
  373. header: tHeader, // 表头 必填
  374. data, // 具体数据 必填
  375. filename: '房间信息列表', // 非必填
  376. autoWidth: true, // 非必填
  377. bookType: 'xlsx' // 非必填
  378. })
  379. })
  380. }
  381. });
  382. }
  383. }
  384. }
  385. }
  386. </script>
  387. <style lang="scss" scoped>
  388. .app-container {
  389. }
  390. </style>