deviceManage.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <template>
  2. <view class="deviceRegistWrapper" ref="contentWrapper">
  3. <!-- 筛选框start -->
  4. <view>
  5. <view style="height:206rpx"></view>
  6. <view class="ding">
  7. <view class="cu-bar search bg-gray filter-section" style="with:50%;">
  8. <view class="search-form round bg-white selectBox">
  9. <select name="" id="" placeholder="" v-model="dwtype">
  10. <option value="0">请选择设备类型</option>
  11. <option value="1">用传</option>
  12. <option value="2">水表</option>
  13. <option value="3">烟感</option>
  14. <option value="4">消防栓</option>
  15. <option value="5">液位</option>
  16. <option value="6">RTU</option>
  17. <option value="7">电气火灾</option>
  18. <option value="16">视频监测</option>
  19. </select>
  20. <text class="icon iconfont margin-right margin-left">&#xe63d;</text>
  21. </view>
  22. </view>
  23. <view class="cu-bar search bg-gray filter-section">
  24. <view class="search-form round bg-white selectBox" style="margin-bottom:26rpx">
  25. <select name="" id="" placeholder="" v-model="transmission_mode">
  26. <option value="0">请选择传输方式</option>
  27. <option value="NB">NB</option>
  28. <option value="4G">4G</option>
  29. <option value="Lora">Lora</option>
  30. </select>
  31. <text class="icon iconfont margin-right margin-left">&#xe63d;</text>
  32. </view>
  33. <view class="action">
  34. <button class="cu-btn bg-blue round" @click="searchList">查询</button>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 筛选框end -->
  40. <!-- 设备注册列表start -->
  41. <block class="">
  42. <view class="processList deviceRegistList" style="height: calc(100vh - 470rpx);">
  43. <checkbox-group @change="changeCheckbox">
  44. <view class="cu-list menu-avatar ">
  45. <view class=" site-item text-center margin-top"
  46. v-if="!this.deviceManage.length&&this.deviceManageRes==1">暂无数据</view>
  47. <view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''"
  48. v-for="(item,index) in newDeviceManage" :key="index" :data-target="'move-box-' + index">
  49. <view class="cu-form-group margin-top">
  50. <checkbox :value="String(item.id)" :checked="checkedArr.includes(String(item.id))"
  51. :class="{'checked':checkedArr.includes(String(item.id))}"></checkbox>
  52. </view>
  53. <view class="cu-avatar round lg">
  54. <image class="image-bg" src="/static/device-icon.png" />
  55. </view>
  56. <view class="content" @longpress="showDetail(item)">
  57. <view class="pro-title">
  58. <view class="cut">{{item.owner_name}}</view>
  59. </view>
  60. <view class="pro-des ">
  61. <view class="text-cut">
  62. {{item.unitinfo}}
  63. </view>
  64. </view>
  65. <view class="pro-date ">{{item.install_time}}</view>
  66. <view class="showDetailEdit" v-if="item.isShow">
  67. <view @tap="goDeviceEdit(item)">修改设备</view>
  68. <!-- <view @tap="deleteItem2" data-target="DialogModal2" :data-id='item.id'
  69. :data-index='index'>删除设备</view> -->
  70. </view>
  71. </view>
  72. <view class="nav-right num">
  73. <view class="text-grey">
  74. <span class="online" v-if="item.device_state=='在线'">在线</span>
  75. <span class="offline" v-if="item.device_state==='离线'">离线</span>
  76. <span class="error" v-if="item.device_state==='故障'">故障</span>
  77. <text class="icon iconfont margin-right-xs margin-left-lg">&#xe629;</text>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </checkbox-group>
  83. </view>
  84. </block>
  85. <!-- 设备注册列表end -->
  86. <!-- 分享区域 start-->
  87. <view class="share grid col-3 ">
  88. <view class="share-item text-center">
  89. <view><text class="icon iconfont margin-xs" style="color:#19A402">&#xe66d;</text></view>
  90. <view @tap="goDeviceAdd">新增</view>
  91. </view>
  92. <view class="share-item text-center">
  93. <view><text class="icon iconfont margin-xs" style="color:#FF0303">&#xe66c;</text></view>
  94. <view @tap="deleteItem" data-target="DialogModal2">删除</view>
  95. </view>
  96. <view class="share-item text-center">
  97. <view><text class="icon iconfont margin-xs" style="color:#FF642E">&#xe66e;</text></view>
  98. <view @tap="showModal" data-target="DialogModal">
  99. 导出
  100. </view>
  101. </view>
  102. <view class="checkAll" style="display:inline-block">
  103. <checkbox-group @change="allChoose" v-if="deviceManage.length">
  104. <label>
  105. <checkbox value="all" :class="{'checked':allChecked}" :checked="allChecked?true:false">
  106. </checkbox> <text class="margin-left-xs">全选</text>
  107. </label>
  108. </checkbox-group>
  109. </view>
  110. </view>
  111. <!-- 分享区域 end-->
  112. <!-- 导出弹框 -->
  113. <export-modal :modalName='modalName' @f-SaveAsData="saveAsData()" @f-HideModel="hideModal()"></export-modal>
  114. <!-- 导出弹框 end -->
  115. <!-- 删除弹框 -->
  116. <view class="cu-modal export-modal" :class="modalName=='DialogModal2'?'show':''">
  117. <view class="cu-dialog">
  118. <view class="cu-bar bg-white justify-end">
  119. <view class="action" @tap="hideModal">
  120. <text class="cuIcon-close"></text>
  121. </view>
  122. </view>
  123. <view class="padding-sm bg-white">
  124. <image src="../../static/chart3-2.png" style="width:100rpx;height:100rpx"></image>
  125. <view style="margin:20rpx 0" v-if="checkedArr.length>1">确定删除这些设备吗?</view>
  126. <view style="margin:20rpx 0" v-else>确定删除该设备吗?</view>
  127. </view>
  128. <view class="cu-bar operate bg-white" style="min-height: 100rpx;">
  129. <view class="action margin-0 " @tap="hideModal">
  130. 取消</view>
  131. <view class="action margin-0 solid-left text-blue" @tap="openConfirmModal"
  132. data-target="DialogModal3">确定</view>
  133. </view>
  134. </view>
  135. </view>
  136. <!-- 删除弹框 end -->
  137. <!-- 再次确认删除弹框 -->
  138. <view class="cu-modal export-modal" :class="modalName=='DialogModal3'?'show':''">
  139. <view class="cu-dialog">
  140. <view class="cu-bar bg-white justify-end">
  141. <view class="action" @tap="hideModal">
  142. <text class="cuIcon-close"></text>
  143. </view>
  144. </view>
  145. <view class="padding-sm bg-white">
  146. <view style="margin:20rpx 0">请输入图片中的验证码</view>
  147. <valid-code :value.sync="validCode"></valid-code>
  148. </view>
  149. <view class="cu-bar operate bg-white" style="min-height: 100rpx;">
  150. <view class="action margin-0" @tap="hideModal">
  151. 取消</view>
  152. <view class="action margin-0 solid-left text-blue" @tap="confirmDelete">确定</view>
  153. </view>
  154. </view>
  155. </view>
  156. <!-- 再次确认删除弹框 end -->
  157. </view>
  158. </template>
  159. <script>
  160. import json from '../../data/json.js';
  161. import validCode from './component/validCode/validCode';
  162. // import searchArea from './component/searchArea.vue';
  163. import exportModal from './component/exportModal.vue';
  164. export default {
  165. components: {
  166. validCode,
  167. exportModal
  168. },
  169. data() {
  170. return {
  171. dwtype: 0,
  172. transmission_mode: 0,
  173. deviceManage: [],
  174. deviceManageRes: 0,
  175. type: '0',
  176. modalName: null,
  177. checkbox: [{
  178. value: 'A',
  179. checked: false
  180. }],
  181. isChecked: false,
  182. checkedArr: [], //复选框选中的值
  183. allChecked: false, //是否全选
  184. deleteIndex: '',
  185. deleteId: '',
  186. validCode: '',
  187. exportData: [],
  188. json_fields: {
  189. "单位编号": "company", //常规字段
  190. "状态": "device_state",
  191. "设备编号": "owner_code",
  192. "设备名称": "owner_name",
  193. "单元地址": "unitinfo",
  194. "创建时间": "install_time",
  195. },
  196. };
  197. },
  198. computed: {
  199. newDeviceManage() {
  200. return this.deviceManage.map(item => {
  201. this.$set(item, "isShow", false)
  202. return item
  203. })
  204. }
  205. },
  206. mounted() {
  207. //点击弹框外隐藏弹框
  208. document.addEventListener('click', (event) => {
  209. if (event.target.className != 'showDetailEdit') {
  210. this.deviceManage.forEach(item => {
  211. item.isShow = false;
  212. })
  213. }
  214. })
  215. },
  216. onLoad: function(option) {
  217. this.getDataList({
  218. 'company_code': uni.getStorageSync('selectedCode')
  219. })
  220. // document.querySelector('.uni-page-head-bd .uni-page-head__title').style.userSelect='none';
  221. },
  222. methods: {
  223. //筛选请求
  224. searchList() {
  225. this.getDataList({
  226. "transmission_mode": this.transmission_mode,
  227. "dwtype": this.dwtype,
  228. 'company_code': uni.getStorageSync('selectedCode')
  229. })
  230. },
  231. // 列表数据请求
  232. async getDataList(params = {}) {
  233. const res = await this.$myRequest({
  234. url: 'DeviceConfig/getDeviceList',
  235. data: params,
  236. showLoading: true
  237. })
  238. this.deviceManage = res.data.data;
  239. this.deviceManageRes = 1;
  240. },
  241. // 页面跳转
  242. goDeviceAdd() {
  243. uni.navigateTo({
  244. url: '/pages/deviceManage/deviceAdd/deviceAdd',
  245. });
  246. },
  247. goDeviceEdit(item) {
  248. uni.navigateTo({
  249. url: '/pages/deviceManage/deviceEdit/deviceEdit?type=' + item.id + '',
  250. });
  251. },
  252. // 长摁隐藏显示查看详情弹框
  253. showDetail(e) {
  254. // console.log(e)
  255. // 存储点击那一项的状态
  256. const nowStatu = e.isShow;
  257. //判断如果长摁弹框出来时,
  258. if (!nowStatu) {
  259. this.checkedArr = [];
  260. this.allChecked = false;
  261. }
  262. // 将每一项列表的isShow设置为false,让所有的列表都隐藏
  263. this.deviceManage.forEach(item => {
  264. item.isShow = false
  265. })
  266. // 用于再次点击该项的取反
  267. e.isShow = !nowStatu
  268. },
  269. //导出弹框
  270. showModal(e) {
  271. var ua = window.navigator.userAgent.toLowerCase();
  272. // if(ua.match(/MicroMessenger/i) == 'micromessenger'){
  273. // uni.showModal({
  274. // showCancel: false,
  275. // content: '点击右上角 ┇,选择默认浏览器进行导出操作'
  276. // });
  277. // }else{
  278. // if (this.checkedArr.length == 0) {
  279. // uni.showModal({
  280. // showCancel: false,
  281. // content: '请选择至少一条需要导出的数据'
  282. // });
  283. // } else {
  284. // this.modalName = e.currentTarget.dataset.target;
  285. // }
  286. // }
  287. if (this.checkedArr.length == 0) {
  288. uni.showModal({
  289. showCancel: false,
  290. content: '请选择至少一条需要导出的数据'
  291. });
  292. } else {
  293. this.modalName = e.currentTarget.dataset.target;
  294. }
  295. },
  296. //导出事件
  297. getDataExport() {
  298. const base64 = s => window.btoa(unescape(encodeURIComponent(s)));
  299. // let exportData = [];
  300. let newData = [];
  301. this.exportData = this.deviceManage.filter((item) => this.checkedArr.includes(item.id));
  302. this.exportData.forEach(function(item, index) {
  303. newData.push({
  304. company: item.company,
  305. device_state: item.device_state,
  306. owner_code: item.owner_code,
  307. unitinfo: item.unitinfo,
  308. owner_name: item.owner_name,
  309. install_time: item.install_time,
  310. })
  311. });
  312. let str =
  313. '<tr style="text-align:center"><th>单位编号</th><th>状态</th><th>设备编号</th><th>设备名称</th><th>单位地址</th><th>创建时间</th></tr>';
  314. // 循环遍历,每行加入tr标签,每个单元格加td标签
  315. for (let i = 0; i < newData.length; i++) {
  316. str += '<tr style="text-align:center">';
  317. for (const key in newData[i]) {
  318. // 增加\t为了不让表格显示科学计数法或者其他格式
  319. str += `<td x:str>${ newData[i][key] + '\t'}</td>`;
  320. }
  321. str += '</tr>';
  322. }
  323. // Worksheet名
  324. const worksheet = 'Sheet1'
  325. const uri = 'data:application/vnd.ms-excel;base64,';
  326. // 下载的表格模板数据
  327. let template = `<html xmlns:o="urn:schemas-microsoft-com:office:office"
  328. xmlns:x="urn:schemas-microsoft-com:office:excel"
  329. xmlns="http://www.w3.org/TR/REC-html40">
  330. <head><meta charset='UTF-8'><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet>
  331. <x:Name>${worksheet}</x:Name>
  332. <x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>
  333. </x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]-->
  334. </head><body><table>${str}</table></body></html>`;
  335. // 通过创建a标签实现
  336. const link = document.createElement("a");
  337. link.href = uri + base64(template);
  338. // 对下载的文件命名
  339. link.download = "设备注册管理数据表.xls";
  340. link.click();
  341. },
  342. //导出按钮另存为
  343. saveAsData(e) {
  344. this.modalName = null
  345. this.getDataExport();
  346. },
  347. //关闭弹框
  348. hideModal(e) {
  349. this.modalName = null
  350. },
  351. //删除弹出框操作
  352. deleteItem(e) {
  353. uni.showModal({
  354. showCancel: false,
  355. content: '暂不支持删除功能'
  356. });
  357. // if (this.checkedArr.length == 0) {
  358. // alert('请选择至少一条需要删除的数据')
  359. // } else {
  360. // this.modalName = e.currentTarget.dataset.target;
  361. // }
  362. },
  363. deleteItem2(e) {
  364. this.checkedArr.push(e.target.dataset.id);
  365. this.deleteIndex = e.target.dataset.index;
  366. console.log('this.checkedArr 单个点击删除按钮 存入要删除的索引')
  367. console.log(this.checkedArr)
  368. this.modalName = e.currentTarget.dataset.target;
  369. },
  370. confirmDelete() {
  371. this.deviceManage = this.deviceManage.filter((item) => !this.checkedArr.includes(item.id));
  372. console.log('this.deviceManage')
  373. console.log(this.deviceManage)
  374. this.modalName = null
  375. },
  376. //再次确认删除弹框
  377. openConfirmModal(e) {
  378. this.modalName = e.currentTarget.dataset.target;
  379. },
  380. // 多选复选框改变事件
  381. changeCheckbox(e) {
  382. this.checkedArr = e.detail.value;
  383. // 如果选择的数组中有值,并且长度等于列表的长度,就是全选
  384. if (this.checkedArr.length > 0 && this.checkedArr.length == this.newDeviceManage.length) {
  385. this.allChecked = true;
  386. } else {
  387. this.allChecked = false;
  388. }
  389. },
  390. // 全选事件
  391. allChoose(e) {
  392. let chooseItem = e.detail.value;
  393. // 全选
  394. if (chooseItem[0] == 'all') {
  395. this.allChecked = true;
  396. for (let item of this.newDeviceManage) {
  397. let itemVal = String(item.id);
  398. if (!this.checkedArr.includes(itemVal)) {
  399. this.checkedArr.push(itemVal);
  400. }
  401. }
  402. } else {
  403. // 取消全选
  404. this.allChecked = false;
  405. this.checkedArr = [];
  406. }
  407. },
  408. },
  409. }
  410. </script>
  411. <style>
  412. page {
  413. -moz-user-select: none;
  414. /*火狐*/
  415. -webkit-user-select: none;
  416. /*webkit浏览器*/
  417. -ms-user-select: none;
  418. /*IE10*/
  419. -khtml-user-select: none;
  420. /*早期浏览器*/
  421. user-select: none;
  422. }
  423. /* user-select有2个值(none表示不能选中文本,text表示可以选择文本) */
  424. * {
  425. -webkit-touch-callout: none;
  426. -webkit-user-select: none;
  427. -khtml-user-select: none;
  428. -moz-user-select: none;
  429. -ms-user-select: none;
  430. user-select: none;
  431. }
  432. input {
  433. -webkit-touch-callout: initial !important;
  434. -webkit-user-select: initial !important;
  435. -khtml-user-select: initial !important;
  436. -moz-user-select: initial !important;
  437. -ms-user-select: initial !important;
  438. user-select: initial !important;
  439. }
  440. .showDetailEdit {
  441. position: absolute;
  442. background: #fff;
  443. box-shadow: 0 1px 6px 0 rgb(32 33 36 / 28%);
  444. border-radius: 10rpx;
  445. top: 50rpx;
  446. right: 47%;
  447. z-index: 3000000;
  448. font-size: 28rpx;
  449. }
  450. .showDetailEdit view {
  451. padding: 0rpx 20rpx;
  452. }
  453. .showDetailEdit view:first-child {
  454. border-bottom: 1px solid #EDEDED;
  455. }
  456. </style>