searchDevice.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <view class="container">
  3. <view class="head-bar">
  4. <view class="search-container flex-row flex-between">
  5. <view class="search-btn flex-row" style="margin-right: 20rpx" @tap="scanCode">
  6. <image style="width: 40rpx; height: 40rpx" src="/static/resource/images/scan-i.png"></image>
  7. </view>
  8. <view class="search-control flex-row flex-between">
  9. <input
  10. type="text"
  11. class="input-search"
  12. :value="seach_value"
  13. confirm-type="搜索"
  14. placeholder="请输入"
  15. placeholder-style="font-size: 12px;"
  16. @input="bindInputSearch"
  17. />
  18. </view>
  19. <view class="search-btn flex-row">
  20. <view class="btn-search" @tap="bindHandleSearch">搜索</view>
  21. <image v-if="userInfo.type == 'group'" @tap="bindGroupSearch" style="width: 40rpx; height: 40rpx" src="/static/resource/images/youjiantou.png"></image>
  22. </view>
  23. </view>
  24. </view>
  25. <view style="height: 55px"></view>
  26. <view class="batterylist-container">
  27. <view class="battery-item" v-for="(item, index) in deviceList" :key="index">
  28. <!-- > bindlongpress="bindLongTapBattery" -->
  29. <view class="batter-info-group flex-row" @tap="bindSelect" :data-index="index">
  30. <view class="battery-icon">
  31. <image class="battery-icon-img" :src="iconList[item.icon].normal"></image>
  32. </view>
  33. <view style="width: calc(100% - 145rpx); padding-left: 23rpx">
  34. <view class="battery-text flex-row flex-between">
  35. <view>名称:{{ item.name }}</view>
  36. </view>
  37. <view class="battery-text">编号:{{ item.mac_id }}</view>
  38. <view class="battery-text">状态:{{ item.expire == 1 ? '到期' : item.online == 1 ? '在线' : '离线' }}</view>
  39. <view class="battery-text">时间:{{ tools.formatTime(item.gps_time) }}</view>
  40. <!--view class="battery-info flex-row flex-between">
  41. <view class="no-class battery-info-left" data-macid="{{item.mac_id}}">
  42. <view class="battery-macid">IMEI:{{item.mac_id}}</view>
  43. <view class="battery-macid">
  44. <view class="flex-row flex-between" style="margin-right: 10px;">
  45. <view class="flex-row" style="color: #0CC191">{{item.voltage}} V</view>
  46. <view class="flex-row" style="margin-left: 8px">里程: {{item.day_mil}} 公里</view>
  47. <view class="flex-row" style="margin-left: 8px">{{item.speed}}km/h</view>
  48. </view>
  49. </view>
  50. <view class="battery-macid">{{tools.formatTime(item.gps_time)}}</view>
  51. <view class="battery-com">
  52. </view>
  53. </view>
  54. <!--view class="no-class battery-info-right" style="text-align: right;">
  55. <view class="i-status shop-name">{{item.shop_name}}</view>
  56. <view wx:if="{{item.user_id!=0}}" class="surplus-days">
  57. <view wx:if="{{item.surplus_days>=0}}" class="b-day">剩余{{item.surplus_days}}天</view>
  58. <view wx:else class="b-day">已过期{{item.surplus_days*(-1)}}天</view>
  59. </view>
  60. </view>
  61. </view-->
  62. </view>
  63. </view>
  64. <view class="battery-text battery-info" style="color: #0ec193" @tap.stop.prevent="bindToInfo" :data-index="index">
  65. 详情
  66. <image class="battery-info-img" src="/static/resource/images/fanhui.png"></image>
  67. </view>
  68. <view class="battery-text battery-credit flex-row" @tap.stop.prevent="bindCredit" :data-index="index">续费</view>
  69. <view class="op-group flex-row flex-around">
  70. <!-- <picker mode="date" value="{{date}}" end="{{curDate}}" bindchange="bindDateChange" data-macid="{{item.macid}}">
  71. <view class="op-item flex-row flex-start">
  72. <view>
  73. <image class="op-icon" src="/resource/images/g-j.png"></image>
  74. </view>
  75. <view class="op-des">轨迹</view>
  76. </view>
  77. </picker> -->
  78. <view v-if="item.bms == 1" class="op-item" @tap.stop.prevent="bindToBMS" :data-index="index">
  79. <image class="op-icon" src="/static/resource/images/BMS.png"></image>
  80. <view class="op-des">BMS</view>
  81. </view>
  82. <view class="op-item" @tap.stop.prevent="bindLocal" :data-index="index">
  83. <image class="op-icon" src="/static/resource/images/dingwei2.png"></image>
  84. <view class="op-des">定位</view>
  85. </view>
  86. <view class="op-item" @tap.stop.prevent="bindAlarm" :data-index="index">
  87. <image class="op-icon" src="/static/resource/images/baojing.png"></image>
  88. <view class="op-des">报警</view>
  89. </view>
  90. <!-- view class="op-item" bindtap="bindToInfo" data-index="{{index}}" -->
  91. <view class="op-item" @tap.stop.prevent="bindToSet" :data-index="index">
  92. <image class="op-icon" src="/static/resource/images/set.png"></image>
  93. <view class="op-des">设置</view>
  94. </view>
  95. </view>
  96. <!--view wx:if="{{showSelectBtn}}" class="battery-select-container" bindtap="bindSelectBattery" data-index="{{index}}">
  97. <image src="/resource/images/check-{{item.selected?'yes':'no'}}.png" class="check-icon"></image>
  98. </view-->
  99. </view>
  100. </view>
  101. <!-- <view class="show-shop-btn" bindtap="handleShowShopContainer"> → </view> -->
  102. <!-- <no-more is-loading="{{isLoading}}" /> -->
  103. <i-load-more :tip="isLoading ? '正在加载 ...' : '没有更多信息啦'" :loading="isLoading" />
  104. </view>
  105. </template>
  106. <script module="tools" lang="wxs" src="@/pages/common/wxs/tools.wxs"></script>
  107. <script>
  108. import iLoadMore from '@/component/iview/load-more/index';
  109. // pages/searchDevice/searchDevice.js
  110. var config = require('../../common/config.js');
  111. var http = require('../../common/http.js');
  112. var common = require('../../common/common.js');
  113. var storage = require('../../common/storage.js');
  114. const LIMT_PAGE = 5;
  115. export default {
  116. components: {
  117. iLoadMore
  118. },
  119. data() {
  120. return {
  121. isLoading: false,
  122. iconList: [],
  123. deviceList: [],
  124. start_page: 1,
  125. limit_page: LIMT_PAGE,
  126. seach_value: '',
  127. search: '',
  128. userInfo: {
  129. type: ''
  130. },
  131. normal: ''
  132. };
  133. },
  134. /**
  135. * 生命周期函数--监听页面加载
  136. */
  137. onLoad: function (options) {
  138. if (options.search) {
  139. this.setData({
  140. seach_value: options.search
  141. });
  142. this.refreshLoadDeviceList();
  143. }
  144. this.loadIconList();
  145. },
  146. /**
  147. * 生命周期函数--监听页面显示
  148. */
  149. onShow: function () {
  150. const is_fresh = storage.getRefreshDeviceoPage();
  151. if (is_fresh) {
  152. this.refreshLoadDeviceList();
  153. storage.setRefreshDeviceoPage(false);
  154. }
  155. },
  156. /**
  157. * 用户点击右上角分享
  158. */
  159. onShareAppMessage: function () {},
  160. /**
  161. * 页面相关事件处理函数--监听用户下拉动作
  162. */
  163. onPullDownRefresh: function () {
  164. this.refreshLoadDeviceList();
  165. },
  166. /**
  167. * 页面上拉触底事件的处理函数
  168. */
  169. onReachBottom: function () {
  170. if (this.isLoading) {
  171. return;
  172. }
  173. this.setData({
  174. isLoading: true
  175. });
  176. this.start_page++;
  177. this.loadDeviceList();
  178. },
  179. methods: {
  180. loadIconList: function () {
  181. this.iconList = storage.getIconList();
  182. if (!this.iconList) {
  183. http.postApi(config.API_BATTERY_ICON_LIST, {}, (resp) => {
  184. if (resp.data.code === 200) {
  185. storage.setIconList(resp.data.data.list);
  186. this.setData({
  187. iconList: resp.data.data.list
  188. });
  189. } else {
  190. common.simpleToast(resp.data.msg);
  191. }
  192. });
  193. } else {
  194. this.setData({
  195. iconList: this.iconList
  196. });
  197. }
  198. },
  199. refreshLoadDeviceList: function () {
  200. if (this.isLoading) {
  201. return;
  202. }
  203. this.setData({
  204. deviceList: [],
  205. isLoading: true
  206. });
  207. common.loading();
  208. this.limit_page = LIMT_PAGE;
  209. this.start_page = 1;
  210. this.loadDeviceList();
  211. },
  212. loadDeviceList: function () {
  213. const that = this;
  214. const pData = {
  215. size: that.limit_page,
  216. page: that.start_page,
  217. search: that.search
  218. };
  219. http.postApi(config.API_BATTERY_SEARCH, pData, (resp) => {
  220. uni.hideLoading();
  221. uni.stopPullDownRefresh();
  222. if (resp.data.code === 200) {
  223. let deviceList = this.deviceList;
  224. deviceList.push.apply(deviceList, resp.data.data.list);
  225. this.setData({
  226. deviceList: deviceList,
  227. isLoading: false
  228. });
  229. } else {
  230. common.simpleToast(resp.data.msg);
  231. }
  232. });
  233. },
  234. bindInputSearch: function (e) {
  235. this.seach_value = e.detail.value;
  236. },
  237. bindHandleSearch: function () {
  238. this.search = this.seach_value;
  239. this.refreshLoadDeviceList();
  240. },
  241. bindLocal: function (e) {
  242. const index = e.currentTarget.dataset.index;
  243. const deviceInfo = this.deviceList[index];
  244. if (deviceInfo.expire == 1) {
  245. common.simpleToast('设备到期');
  246. return;
  247. }
  248. if (
  249. common.isEmpty(deviceInfo.longitude + '') ||
  250. deviceInfo.longitude == '-' ||
  251. common.isEmpty(deviceInfo.latitude + '') ||
  252. deviceInfo.latitude == '-' ||
  253. deviceInfo.longitude == 0 ||
  254. deviceInfo.latitude == 0
  255. ) {
  256. common.simpleToast('该设备暂无位置信息');
  257. return;
  258. }
  259. storage.setSelectedDeviceInfo(deviceInfo);
  260. uni.navigateTo({
  261. url: '/pages/deviceLocal/deviceLocal'
  262. });
  263. },
  264. bindToBMS: function (e) {
  265. const index = e.currentTarget.dataset.index;
  266. const deviceInfo = this.deviceList[index];
  267. if (deviceInfo.expire == 1) {
  268. common.simpleToast('设备到期');
  269. return;
  270. }
  271. if (deviceInfo.bms == 1) {
  272. uni.navigateTo({
  273. url:
  274. '/pages/bms/bms?macid=' +
  275. deviceInfo.mac_id +
  276. '&deviceType=' +
  277. deviceInfo.device_type +
  278. '&bt_type=' +
  279. deviceInfo.bt_type +
  280. '&bms=' +
  281. deviceInfo.bms +
  282. '&btid=' +
  283. deviceInfo.btid +
  284. '&btkey=' +
  285. deviceInfo.btkey,
  286. success: function (res) {},
  287. fail: function (res) {},
  288. complete: function (res) {}
  289. });
  290. } else {
  291. common.alert('该设备暂未配置BMS数据');
  292. return;
  293. }
  294. },
  295. bindToInfo: function (e) {
  296. const index = e.currentTarget.dataset.index;
  297. const deviceInfo = this.deviceList[index];
  298. if (deviceInfo.expire == 1) {
  299. common.simpleToast('设备到期');
  300. return;
  301. }
  302. storage.setSelectedDeviceInfo(deviceInfo);
  303. const _deviceInfo = encodeURIComponent(JSON.stringify(deviceInfo));
  304. uni.navigateTo({
  305. url: '/pages/deviceInfo/deviceInfo?deviceInfo=' + _deviceInfo
  306. });
  307. },
  308. bindSelect: function (e) {
  309. const index = e.currentTarget.dataset.index;
  310. const deviceInfo = this.deviceList[index];
  311. if (deviceInfo.expire == 1) {
  312. common.simpleToast('设备到期');
  313. return;
  314. }
  315. storage.setSelectedDeviceInfo(deviceInfo);
  316. uni.reLaunch({
  317. url: '/pages/home/home'
  318. });
  319. },
  320. bindAlarm: function (e) {
  321. const index = e.currentTarget.dataset.index;
  322. const deviceInfo = this.deviceList[index];
  323. if (deviceInfo.expire == 1) {
  324. common.simpleToast('设备到期');
  325. return;
  326. }
  327. uni.navigateTo({
  328. url: '/pages/warnList/warnList?macid=' + deviceInfo.mac_id
  329. });
  330. },
  331. bindToSet: function (e) {
  332. const index = e.currentTarget.dataset.index;
  333. const deviceInfo = this.deviceList[index];
  334. if (deviceInfo.expire == 1) {
  335. common.simpleToast('设备到期');
  336. return;
  337. }
  338. uni.navigateTo({
  339. url: '/pages/deviceCommand/deviceCommand?macid=' + deviceInfo.mac_id + '&type=' + deviceInfo.device_type + '&bt_type=' + deviceInfo.bt_type
  340. });
  341. },
  342. bindCredit: function (e) {
  343. const index = e.currentTarget.dataset.index;
  344. const deviceInfo = this.deviceList[index];
  345. uni.navigateTo({
  346. url: '/pages/credit/credit?macid=' + deviceInfo.mac_id,
  347. success: function (res) {},
  348. fail: function (res) {},
  349. complete: function (res) {}
  350. });
  351. },
  352. scanCode: function (e) {
  353. uni.scanCode({
  354. onlyFromCamera: true,
  355. scanType: [],
  356. success: (res) => {
  357. console.log(res);
  358. if (res.result) {
  359. this.setData({
  360. search: res.result,
  361. seach_value: res.result
  362. });
  363. this.refreshLoadDeviceList();
  364. }
  365. },
  366. fail: function (res) {},
  367. complete: function (res) {}
  368. });
  369. },
  370. bindGroupSearch() {
  371. console.log('占位:函数 bindGroupSearch 未声明');
  372. }
  373. }
  374. };
  375. </script>
  376. <style>
  377. @import './searchDevice.css';
  378. </style>