deviceManage.vue 17 KB

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