searchDevice.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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="https://qiniu.bms16.com/Fn5mP9lHn-yq1rTxEOzf40sv7pd1"></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="$t('搜索')"
  14. :placeholder="$t('请输入')"
  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">{{$t('搜索')}}</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>{{$t('名称') +':' + item.name }}</view>
  36. </view>
  37. <view class="battery-text">{{ $t('编号') +':' + item.mac_id }}</view>
  38. <view class="battery-text">{{ $t('状态') +':' + item.expire == 1 ? $t('到期') : item.online == 1 ? $t('在线') : $t('离线') }}</view>
  39. <view class="battery-text">{{ $t('时间') +':' + 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. {{$t('详情')}}
  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">{{$t('续费')}}</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="https://qiniu.bms16.com/Fi_JnvnBjpW1Hmv_7zsEcc0Ut7qO"></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">{{$t('定位')}}</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">{{$t('报警')}}</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">{{$t('设置')}}</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 ? $t('正在加载...') : $t('没有更多信息啦~')" :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. uni.setNavigationBarTitle({
  139. title: this.$t('全局搜索')
  140. });
  141. if (options.search) {
  142. this.setData({
  143. seach_value: options.search
  144. });
  145. this.refreshLoadDeviceList();
  146. }
  147. this.loadIconList();
  148. },
  149. /**
  150. * 生命周期函数--监听页面显示
  151. */
  152. onShow: function () {
  153. const is_fresh = storage.getRefreshDeviceoPage();
  154. if (is_fresh) {
  155. this.refreshLoadDeviceList();
  156. storage.setRefreshDeviceoPage(false);
  157. }
  158. },
  159. /**
  160. * 用户点击右上角分享
  161. */
  162. onShareAppMessage: function () {},
  163. /**
  164. * 页面相关事件处理函数--监听用户下拉动作
  165. */
  166. onPullDownRefresh: function () {
  167. this.refreshLoadDeviceList();
  168. },
  169. /**
  170. * 页面上拉触底事件的处理函数
  171. */
  172. onReachBottom: function () {
  173. if (this.isLoading) {
  174. return;
  175. }
  176. this.setData({
  177. isLoading: true
  178. });
  179. this.start_page++;
  180. this.loadDeviceList();
  181. },
  182. methods: {
  183. loadIconList: function () {
  184. this.iconList = storage.getIconList();
  185. if (!this.iconList) {
  186. http.postApi(config.API_BATTERY_ICON_LIST, {}, (resp) => {
  187. if (resp.data.code === 200) {
  188. storage.setIconList(resp.data.data.list);
  189. this.setData({
  190. iconList: resp.data.data.list
  191. });
  192. } else {
  193. common.simpleToast(this,resp.data.msg);
  194. }
  195. });
  196. } else {
  197. this.setData({
  198. iconList: this.iconList
  199. });
  200. }
  201. },
  202. refreshLoadDeviceList: function () {
  203. if (this.isLoading) {
  204. return;
  205. }
  206. this.setData({
  207. deviceList: [],
  208. isLoading: true
  209. });
  210. common.loading(this);
  211. this.limit_page = LIMT_PAGE;
  212. this.start_page = 1;
  213. this.loadDeviceList();
  214. },
  215. loadDeviceList: function () {
  216. const that = this;
  217. const pData = {
  218. size: that.limit_page,
  219. page: that.start_page,
  220. search: that.search
  221. };
  222. http.postApi(config.API_BATTERY_SEARCH, pData, (resp) => {
  223. uni.hideLoading();
  224. uni.stopPullDownRefresh();
  225. if (resp.data.code === 200) {
  226. let deviceList = this.deviceList;
  227. deviceList.push.apply(deviceList, resp.data.data.list);
  228. this.setData({
  229. deviceList: deviceList,
  230. isLoading: false
  231. });
  232. } else {
  233. common.simpleToast(this,resp.data.msg);
  234. }
  235. });
  236. },
  237. bindInputSearch: function (e) {
  238. this.seach_value = e.detail.value;
  239. },
  240. bindHandleSearch: function () {
  241. this.search = this.seach_value;
  242. this.refreshLoadDeviceList();
  243. },
  244. bindLocal: function (e) {
  245. const index = e.currentTarget.dataset.index;
  246. const deviceInfo = this.deviceList[index];
  247. if (deviceInfo.expire == 1) {
  248. common.simpleToast(this,this.$t('设备到期'));
  249. return;
  250. }
  251. if (
  252. common.isEmpty(deviceInfo.longitude + '') ||
  253. deviceInfo.longitude == '-' ||
  254. common.isEmpty(deviceInfo.latitude + '') ||
  255. deviceInfo.latitude == '-' ||
  256. deviceInfo.longitude == 0 ||
  257. deviceInfo.latitude == 0
  258. ) {
  259. common.simpleToast(this,this.$t('该设备暂无位置信息'));
  260. return;
  261. }
  262. storage.setSelectedDeviceInfo(deviceInfo);
  263. uni.navigateTo({
  264. url: '/pages/deviceLocal/deviceLocal'
  265. });
  266. },
  267. bindToBMS: function (e) {
  268. const index = e.currentTarget.dataset.index;
  269. const deviceInfo = this.deviceList[index];
  270. if (deviceInfo.expire == 1) {
  271. common.simpleToast(this,this.$t('设备到期'));
  272. return;
  273. }
  274. if (deviceInfo.bms == 1) {
  275. uni.navigateTo({
  276. url:
  277. '/pages/bms/bms?macid=' +
  278. deviceInfo.mac_id +
  279. '&deviceType=' +
  280. deviceInfo.device_type +
  281. '&bt_type=' +
  282. deviceInfo.bt_type +
  283. '&bms=' +
  284. deviceInfo.bms +
  285. '&btid=' +
  286. deviceInfo.btid +
  287. '&btkey=' +
  288. deviceInfo.btkey,
  289. success: function (res) {},
  290. fail: function (res) {},
  291. complete: function (res) {}
  292. });
  293. } else {
  294. common.alert(this.$t('该设备暂未配置BMS数据'));
  295. return;
  296. }
  297. },
  298. bindToInfo: function (e) {
  299. const index = e.currentTarget.dataset.index;
  300. const deviceInfo = this.deviceList[index];
  301. if (deviceInfo.expire == 1) {
  302. common.simpleToast(this,this.$t('设备到期'));
  303. return;
  304. }
  305. storage.setSelectedDeviceInfo(deviceInfo);
  306. const _deviceInfo = encodeURIComponent(JSON.stringify(deviceInfo));
  307. uni.navigateTo({
  308. url: '/myPages/pages/deviceInfo/deviceInfo?deviceInfo=' + _deviceInfo
  309. });
  310. },
  311. bindSelect: function (e) {
  312. const index = e.currentTarget.dataset.index;
  313. const deviceInfo = this.deviceList[index];
  314. if (deviceInfo.expire == 1) {
  315. common.simpleToast(this,this.$t('设备到期'));
  316. return;
  317. }
  318. storage.setSelectedDeviceInfo(deviceInfo);
  319. uni.reLaunch({
  320. url: '/pages/home/home'
  321. });
  322. },
  323. bindAlarm: function (e) {
  324. const index = e.currentTarget.dataset.index;
  325. const deviceInfo = this.deviceList[index];
  326. if (deviceInfo.expire == 1) {
  327. common.simpleToast(this,this.$t('设备到期'));
  328. return;
  329. }
  330. uni.navigateTo({
  331. url: '/pages/warnList/warnList?macid=' + deviceInfo.mac_id
  332. });
  333. },
  334. bindToSet: function (e) {
  335. const index = e.currentTarget.dataset.index;
  336. const deviceInfo = this.deviceList[index];
  337. if (deviceInfo.expire == 1) {
  338. common.simpleToast(this,this.$t('设备到期'));
  339. return;
  340. }
  341. uni.navigateTo({
  342. url: '/myPages/pages/deviceCommand/deviceCommand?macid=' + deviceInfo.mac_id + '&type=' + deviceInfo.device_type + '&bt_type=' + deviceInfo.bt_type
  343. });
  344. },
  345. bindCredit: function (e) {
  346. const index = e.currentTarget.dataset.index;
  347. const deviceInfo = this.deviceList[index];
  348. uni.navigateTo({
  349. url: '/pages/credit/credit?macid=' + deviceInfo.mac_id,
  350. success: function (res) {},
  351. fail: function (res) {},
  352. complete: function (res) {}
  353. });
  354. },
  355. scanCode: function (e) {
  356. uni.scanCode({
  357. onlyFromCamera: true,
  358. scanType: [],
  359. success: (res) => {
  360. console.log(res);
  361. if (res.result) {
  362. this.setData({
  363. search: res.result,
  364. seach_value: res.result
  365. });
  366. this.refreshLoadDeviceList();
  367. }
  368. },
  369. fail: function (res) {},
  370. complete: function (res) {}
  371. });
  372. },
  373. bindGroupSearch() {
  374. console.log('占位:函数 bindGroupSearch 未声明');
  375. }
  376. }
  377. };
  378. </script>
  379. <style>
  380. @import './searchDevice.css';
  381. </style>