deviceManage.vue 14 KB

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