deviceManage.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <template>
  2. <view class="deviceRegistWrapper" ref="contentWrapper">
  3. <!-- 筛选框start -->
  4. <search-area></search-area>
  5. <!-- 筛选框end -->
  6. <!-- 设备注册列表start -->
  7. <block class="">
  8. <view class="processList deviceRegistList" style="height: calc(100vh - 241px);">
  9. <checkbox-group @change="changeCheckbox">
  10. <view class="cu-list menu-avatar ">
  11. <view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''"
  12. v-for="(item,index) in getData" :key="index" :data-target="'move-box-' + index">
  13. <view class="cu-form-group margin-top">
  14. <checkbox :value="String(item.id)" :checked="checkedArr.includes(String(item.id))"
  15. :class="{'checked':checkedArr.includes(String(item.id))}"></checkbox>
  16. </view>
  17. <view class="cu-avatar round lg" style="background-image:url(../../static/device-icon.png)">
  18. </view>
  19. <view class="content" @longpress="showDetail(item)">
  20. <view class="pro-title">
  21. <view class="cut">{{item.owner_name}}</view>
  22. </view>
  23. <view class="pro-des ">
  24. <view class="text-cut">
  25. {{item.unitinfo}}
  26. </view>
  27. </view>
  28. <view class="pro-date ">{{item.install_time}}</view>
  29. <view class="showDetail" v-if="item.isShow">
  30. <view @tap="goDeviceEdit(item)">修改设备</view>
  31. <view @tap="deleteItem2" data-target="DialogModal2" :data-id='item.id' :data-index='index'>删除设备</view>
  32. </view>
  33. </view>
  34. <view class="nav-right num">
  35. <view class="text-grey">
  36. <span class="online" v-if="item.device_state=='在线'">在线</span>
  37. <span class="offline" v-if="item.device_state==='离线'">离线</span>
  38. <span class="error" v-if="item.device_state==='故障'">故障</span>
  39. <text class="icon iconfont margin-right-xs margin-left-lg">&#xe629;</text>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </checkbox-group>
  45. </view>
  46. </block>
  47. <!-- 设备注册列表end -->
  48. <!-- 分享区域 start-->
  49. <view class="share grid col-3 ">
  50. <view class="share-item text-center">
  51. <view><text class="icon iconfont margin-xs" style="color:#19A402">&#xe66d;</text></view>
  52. <view @tap="goDeviceAdd">新增</view>
  53. </view>
  54. <view class="share-item text-center">
  55. <view><text class="icon iconfont margin-xs" style="color:#FF0303">&#xe66c;</text></view>
  56. <view @tap="deleteItem" data-target="DialogModal2">删除</view>
  57. </view>
  58. <view class="share-item text-center">
  59. <view><text class="icon iconfont margin-xs" style="color:#FF642E">&#xe66e;</text></view>
  60. <view @tap="showModal" data-target="DialogModal">导出</view>
  61. </view>
  62. <view class="checkAll" style="display:inline-block">
  63. <checkbox-group @change="allChoose">
  64. <label>
  65. <checkbox value="all" :class="{'checked':allChecked}" :checked="allChecked?true:false">
  66. </checkbox> <text class="margin-left-xs">全选</text>
  67. </label>
  68. </checkbox-group>
  69. </view>
  70. </view>
  71. <!-- 分享区域 end-->
  72. <!-- 导出弹框 -->
  73. <export-modal :modalName='modalName' @fatherHideModal="hideModal()"></export-modal>
  74. <!-- 导出弹框 end -->
  75. <!-- 删除弹框 -->
  76. <view class="cu-modal export-modal" :class="modalName=='DialogModal2'?'show':''">
  77. <view class="cu-dialog">
  78. <view class="cu-bar bg-white justify-end">
  79. <view class="action" @tap="hideModal">
  80. <text class="cuIcon-close"></text>
  81. </view>
  82. </view>
  83. <view class="padding-sm bg-white">
  84. <image src="../../static/chart3-2.png" style="width:100rpx;height:100rpx"></image>
  85. <view style="margin:20rpx 0" v-if="checkedArr.length>1">确定删除这些设备吗?</view>
  86. <view style="margin:20rpx 0" v-else>确定删除该设备吗?</view>
  87. </view>
  88. <view class="cu-bar operate bg-white" style="min-height: 100rpx;">
  89. <view class="action margin-0 " @tap="hideModal">
  90. 取消</view>
  91. <view class="action margin-0 solid-left text-blue" @tap="openConfirmModal"
  92. data-target="DialogModal3">确定</view>
  93. </view>
  94. </view>
  95. </view>
  96. <!-- 删除弹框 end -->
  97. <!-- 再次确认删除弹框 -->
  98. <view class="cu-modal export-modal" :class="modalName=='DialogModal3'?'show':''">
  99. <view class="cu-dialog">
  100. <view class="cu-bar bg-white justify-end">
  101. <view class="action" @tap="hideModal">
  102. <text class="cuIcon-close"></text>
  103. </view>
  104. </view>
  105. <view class="padding-sm bg-white">
  106. <view style="margin:20rpx 0">请输入图片中的验证码</view>
  107. <valid-code :value.sync="validCode"></valid-code>
  108. </view>
  109. <view class="cu-bar operate bg-white" style="min-height: 100rpx;">
  110. <view class="action margin-0 " @tap="hideModal">
  111. 取消</view>
  112. <view class="action margin-0 solid-left text-blue" @tap="confirmDelete">确定</view>
  113. </view>
  114. </view>
  115. </view>
  116. <!-- 再次确认删除弹框 end -->
  117. </view>
  118. </template>
  119. <script>
  120. import json from '../../data/json.js';
  121. import validCode from './component/validCode/validCode';
  122. import searchArea from './component/searchArea.vue';
  123. import exportModal from './component/exportModal.vue';
  124. export default {
  125. components: {
  126. validCode,
  127. searchArea,
  128. exportModal
  129. },
  130. data() {
  131. return {
  132. getData:[],
  133. validCode: '',
  134. checkbox: [{
  135. value: 'A',
  136. checked: false
  137. }],
  138. deviceManage: json.deviceManage,
  139. siteListRes: 0,
  140. type: '0',
  141. siteListData: [],
  142. modalName: null,
  143. listTouchStart: 0,
  144. listTouchDirection: null,
  145. CustomBar: this.CustomBar,
  146. deleteIndex:'',
  147. deleteId:'',
  148. // checkAllFlag:false,
  149. isChecked: false,
  150. checkedArr: [], //复选框选中的值
  151. allChecked: false //是否全选
  152. };
  153. },
  154. onPullDownRefresh() {
  155. console.log('refresh');
  156. setTimeout(function() {
  157. uni.stopPullDownRefresh();
  158. }, 1000);
  159. },
  160. computed: {
  161. newDeviceManage() {
  162. return this.deviceManage.map(item => {
  163. this.$set(item, "isShow", false)
  164. return item
  165. })
  166. }
  167. },
  168. mounted() {
  169. document.addEventListener('click', (e) => {
  170. if (e.target.className != 'showDetail') {
  171. this.deviceManage.forEach(item => {
  172. item.isShow = false
  173. })
  174. }
  175. })
  176. },
  177. onLoad:function(option){
  178. this.getDataList({'company_code':uni.getStorageSync('selectedCode')})
  179. },
  180. methods: {
  181. // 列表数据请求
  182. async getDataList(params = {}) {
  183. const res = await this.$myRequest({
  184. url: 'DeviceConfig/getDeviceList',
  185. data:params,
  186. showLoading: true
  187. })
  188. this.getData=res.data.data;
  189. // console.log(res.data.data.length)
  190. console.log(this.getData);
  191. },
  192. // 页面跳转
  193. goDeviceAdd() {
  194. uni.navigateTo({
  195. url: '/pages/deviceManage/deviceAdd/deviceAdd',
  196. });
  197. },
  198. goDeviceEdit(item) {
  199. uni.navigateTo({
  200. url: '/pages/deviceManage/deviceEdit/deviceEdit?type=' + item.id + '',
  201. });
  202. },
  203. //导出弹框
  204. showModal(e) {
  205. // alert(1)
  206. if (this.checkedArr.length == 0) {
  207. alert('请选择至少一条需要导出的数据')
  208. } else {
  209. this.modalName = e.currentTarget.dataset.target
  210. }
  211. },
  212. //关闭弹框
  213. hideModal(e) {
  214. this.modalName = null
  215. },
  216. //删除弹出框操作
  217. deleteItem(e) {
  218. if (this.checkedArr.length == 0) {
  219. alert('请选择至少一条需要删除的数据')
  220. } else {
  221. this.modalName = e.currentTarget.dataset.target;
  222. }
  223. },
  224. deleteItem2(e) {
  225. this.checkedArr.push(e.target.dataset.id);
  226. this.deleteIndex=e.target.dataset.index;
  227. console.log('this.checkedArr 单个点击删除按钮 存入要删除的索引')
  228. console.log(this.checkedArr)
  229. this.modalName = e.currentTarget.dataset.target;
  230. },
  231. confirmDelete() {
  232. // alert(this.deleteIndex)
  233. // this.deviceManage.splice(this.deleteIndex,1);
  234. this.deviceManage = this.deviceManage.filter((item) => !this.checkedArr.includes(item.id));
  235. console.log('this.deviceManage')
  236. console.log(this.deviceManage)
  237. this.modalName = null
  238. },
  239. //再次确认弹框
  240. openConfirmModal(e) {
  241. this.modalName = e.currentTarget.dataset.target;
  242. },
  243. // 隐藏显示
  244. showDetail(e) {
  245. // console.log('e')
  246. // console.log(e)
  247. // 存储点击那一项的状态
  248. const nowStatu = e.isShow;
  249. //判断如果长摁弹框出来时,情况选中状态 ???
  250. if(!nowStatu){
  251. this.checkedArr=[];
  252. this.allChecked = false;
  253. }
  254. // 将每一项列表的isShow设置为false,让所有的列表都隐藏
  255. this.deviceManage.forEach(item => {
  256. item.isShow = false
  257. })
  258. // 用于再次点击该项的取反
  259. e.isShow = !nowStatu
  260. },
  261. // 多选复选框改变事件
  262. changeCheckbox(e) {
  263. this.checkedArr = e.detail.value;
  264. // 如果选择的数组中有值,并且长度等于列表的长度,就是全选
  265. if (this.checkedArr.length > 0 && this.checkedArr.length == this.newDeviceManage.length) {
  266. this.allChecked = true;
  267. } else {
  268. this.allChecked = false;
  269. }
  270. },
  271. // 全选事件
  272. allChoose(e) {
  273. let chooseItem = e.detail.value;
  274. // 全选
  275. if (chooseItem[0] == 'all') {
  276. this.allChecked = true;
  277. for (let item of this.newDeviceManage) {
  278. let itemVal = String(item.id);
  279. if (!this.checkedArr.includes(itemVal)) {
  280. this.checkedArr.push(itemVal);
  281. }
  282. }
  283. } else {
  284. // 取消全选
  285. this.allChecked = false;
  286. this.checkedArr = [];
  287. }
  288. }
  289. },
  290. }
  291. </script>
  292. <style>
  293. .showDetail {
  294. position: absolute;
  295. background: #fff;
  296. box-shadow: 0 1px 6px 0 rgb(32 33 36 / 28%);
  297. border-radius: 10rpx;
  298. top: 50rpx;
  299. right: 47%;
  300. z-index: 3000000;
  301. font-size: 28rpx;
  302. }
  303. .showDetail view {
  304. padding: 0rpx 20rpx;
  305. }
  306. .showDetail view:first-child {
  307. border-bottom: 1px solid #EDEDED;
  308. }
  309. </style>