machine.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <view>
  3. <view class="top-box">
  4. <view class="top-title" :style="'height: '+ systems.navigationHeight + 'rpx;padding-top:' + systems.ktxStatusHeight + 'rpx;'+'line-height: '+ systems.navigationHeight + 'rpx;'">
  5. <view v-if="!userInfo.storeId&&actMerchant" @click="showPop=true" class="ddflex">
  6. <view class="tover" style="max-width: 400rpx;">{{actMerchant.name}}</view>
  7. <image class="dow-ssicon" src="../../static/pages/images/dow-ssicon.png"></image>
  8. </view>
  9. <view v-else>机柜</view>
  10. </view>
  11. <view class="search-box ddflex">
  12. <image class="search-saoma" src="../../static/pages/images/saoma.png" @click="saomaFn()"></image>
  13. <view class="search-input ddflex fflex">
  14. <image class="search-input-icon" src="../../static/pages/images/search.png"></image>
  15. <input class="fflex" v-model="searchValue" confirm-type="search" @confirm="searchFn" placeholder="请输入编号查询"/>
  16. <view class="search-btn" @click="searchFn">搜索</view>
  17. </view>
  18. </view>
  19. </view>
  20. <block v-if="isLogin">
  21. <view :style="'height: '+ (systems.navigationHeight+systems.ktxStatusHeight+134) + 'rpx;'"></view>
  22. <!-- 机柜 -->
  23. <view class="machine-item" v-for="item,index in groupList" @click="jumpUrl('/machineAndCell/machineInfo/machineInfo?id='+item.devId)">
  24. <view class="ddflex" style="justify-content: space-between;">
  25. <view class="machine-title fflex tover">{{item.devName}}</view>
  26. <view class="state" v-if="item.online==1">在线</view>
  27. <view class="state" style="border-color: #999;color: #999;" v-if="item.online==0">离线</view>
  28. <view class="state" style="border-color: #999;color: #999;" v-if="item.online==2">设备未激活</view>
  29. <view class="state" style="border-color: #999;color: #999;" v-if="item.online==3">设备禁用</view>
  30. </view>
  31. <view class="machine-number">机柜编号:{{item.devId}}</view>
  32. <view class="machine-info ddflex">
  33. <view class="ddflex">
  34. <view class="margin-r40">温度:{{item.cabTemp?item.cabTemp:0}}℃</view>
  35. <view class="margin-r40">仓门数:{{item.doorCount?item.doorCount:0}}</view>
  36. <view class="margin-r40">电池数:{{item.batNum?item.batNum:0}}</view>
  37. </view>
  38. <view class="fflex tover" style="color: #2A82E4;text-align: right;">
  39. {{item.storeName?item.storeName:''}}
  40. </view>
  41. </view>
  42. <view class="address-box ddflex">
  43. <image class="address-icon" src="../../static/pages/images/address-icon.png"></image>
  44. <view class="fflex tover">{{item.address}}</view>
  45. <image @click.stop="toLocation(item)" class="daohang" src="../../static/pages/images/daohang.png"></image>
  46. </view>
  47. </view>
  48. <view v-if="groupList.length==0">
  49. <view class="nodata">
  50. <image :src="picUrlss+'empty.png'" mode="aspectFit"></image>
  51. <text>暂无设备~</text>
  52. </view>
  53. </view>
  54. </block>
  55. <view v-else>
  56. <view :style="'height: '+ (systems.navigationHeight+systems.ktxStatusHeight) + 'rpx;'"></view>
  57. <view class="wei-login" v-if="!isLogin">
  58. <image :src="picUrlss + 'wei_login.png'"></image>
  59. <view>暂未登录</view>
  60. <navigator url="/pages/authorize/authorize" hover-class="none" class="cart-login">立即登录</navigator>
  61. </view>
  62. </view>
  63. <left-pop v-if="showPop" :showPop="showPop" :btnColor="'#11BB8B'" :showBtn='false' title="解除提醒" width="460rpx"
  64. @closePop="closePop()" @popSubmit="popSubmit()">
  65. <view class="" style="height: 100%;flex-direction: column;display: flex;">
  66. <view @click="closePop()" class="pop-title ddflex" :style="'height: '+ systems.navigationHeight + 'rpx;padding-top:' + systems.ktxStatusHeight + 'rpx;'+'line-height: '+ systems.navigationHeight + 'rpx;'">
  67. <view>切换门店</view>
  68. <image class="change-ssicon" src="../../static/pages/images/change.png"></image>
  69. </view>
  70. <scroll-view :scroll-y="true" @scrolltolower="loadLeftData" class="pop-content fflex">
  71. <view :class="'pop-content-item '+(actMerchant.id==item.id?'pop-content-active':'')" v-for="(item,index) in merchantList" @click="changePop(item)">
  72. <view class="pop-content-name tover">{{item.name}}</view>
  73. <image class="pop-content-icon" src=""></image>
  74. </view>
  75. </scroll-view>
  76. </view>
  77. </left-pop>
  78. <foot channel="machine" :isUpdate="isUpdate"></foot>
  79. </view>
  80. </template>
  81. <script>
  82. const app = getApp();
  83. const req = require("../../utils/request.js");
  84. import foot from "../../components/nav-bar/index";
  85. import leftPop from "../../components/left-pop/index";
  86. export default {
  87. components: {
  88. foot,
  89. leftPop
  90. },
  91. props: {},
  92. data() {
  93. return {
  94. picUrlss: req.public.picUrls,
  95. systems: {},
  96. isTop:0,
  97. isUpdate: false,
  98. isLogin:false,
  99. userInfo:{},
  100. showPop: false,
  101. tempData: null,
  102. groupList: [],
  103. page: 1,
  104. limit: 10,
  105. searchValue:'',
  106. isQuerying:false,//正在查询数据
  107. merchantList: [],
  108. merchantPage: 1,
  109. merchantLimit: 10,
  110. actMerchant:null,//当前门店
  111. }
  112. },
  113. onLoad(options) {
  114. // 判断当前登录用户身份
  115. if(req.isLogins(false)){
  116. this.isLogin = true
  117. this.userInfo = req.getStorage('userInfo')
  118. if(!this.userInfo.storeId){
  119. this.getMerchantList()
  120. }else{
  121. this.actMerchant={
  122. id:this.userInfo.storeId
  123. }
  124. this.getMachineList()
  125. }
  126. }else{
  127. this.isLogin = false
  128. // this.getMachineList()
  129. }
  130. uni.$on('reSetLogin',(data)=>{
  131. this.isLogin = true
  132. console.log('reSetLogin')
  133. this.actMerchant = null
  134. // 判断当前登录用户身份
  135. if(req.isLogins(true)){
  136. this.userInfo = req.getStorage('userInfo')
  137. if(!this.userInfo.storeId){
  138. this.getMerchantList()
  139. }else{
  140. this.actMerchant={
  141. id:this.userInfo.storeId
  142. }
  143. this.getMachineList()
  144. }
  145. }else{
  146. this.isLogin = false
  147. // this.getMachineList()
  148. }
  149. })
  150. },
  151. onShow() {
  152. this.setData({
  153. isUpdate: !this.isUpdate
  154. });
  155. if(req.isLogins(false)){
  156. this.isLogin = true
  157. }else{
  158. this.isLogin = false
  159. this.actMerchant = null
  160. // this.getMachineList()
  161. }
  162. },
  163. onReachBottom() {
  164. this.getMachineList(true)
  165. },
  166. methods: {
  167. jumpUrl(url){
  168. if(req.isLogins(true)){
  169. uni.navigateTo({
  170. url:url
  171. })
  172. }
  173. },
  174. // 弹窗弹出
  175. openPop(item) {
  176. this.tempData = JSON.parse(JSON.stringify(item))
  177. this.showPop = true
  178. },
  179. closePop(){
  180. this.showPop = false
  181. },
  182. changePop(item){
  183. this.actMerchant = item
  184. this.closePop()
  185. this.getMachineList()
  186. },
  187. // 获取机柜列表
  188. getMachineList(isPage){
  189. if(!this.actMerchant||!this.actMerchant.id) return
  190. if(this.isQuerying) return
  191. else this.isQuerying = true
  192. if (!isPage) {
  193. this.page = 1
  194. }
  195. let queryParams = {
  196. page: this.page,
  197. limit: this.limit,
  198. }
  199. if(this.searchValue){
  200. queryParams.devId=this.searchValue
  201. }
  202. queryParams.storeId = this.actMerchant.id
  203. req.getRequest(
  204. '/admin/v2/cab/page',
  205. queryParams,
  206. data => {
  207. if (data != null && data.list.length > 0) {
  208. if (!isPage) {
  209. this.groupList = data.list
  210. } else {
  211. this.groupList = this.groupList.concat(data.list)
  212. }
  213. this.page++
  214. } else {
  215. if (!isPage)
  216. this.groupList = data.list
  217. else {}
  218. }
  219. uni.hideLoading()
  220. this.isQuerying = false
  221. }
  222. )
  223. },
  224. loadLeftData(res){
  225. this.getMerchantList(true)
  226. },
  227. getMerchantList(isPage){
  228. if (!isPage) {
  229. this.merchantPage = 1
  230. }
  231. let queryParams = {
  232. page: this.merchantPage,
  233. limit: this.merchantLimit,
  234. }
  235. queryParams.merchantId = req.getStorage('userInfo').merchantId?req.getStorage('userInfo').merchantId:null
  236. req.getRequest(
  237. '/admin/v2/store/page',
  238. queryParams,
  239. data => {
  240. if (data != null && data.list.length > 0) {
  241. if (!isPage) {
  242. this.merchantList = data.list
  243. } else {
  244. this.merchantList = this.merchantList.concat(data.list)
  245. }
  246. this.merchantPage++
  247. } else {
  248. if (!isPage)
  249. this.merchantList = data.list
  250. else {}
  251. }
  252. if(!isPage){
  253. if(this.actMerchant){
  254. }else{
  255. this.actMerchant = this.merchantList[0]
  256. }
  257. this.getMachineList()
  258. }
  259. }
  260. )
  261. },
  262. toLocation(item) {
  263. let plugin = requirePlugin('routePlan');
  264. let key = req.public.mapLBSKEY; //使用在腾讯位置服务申请的key
  265. let referer = '皮小店商家端'; //调用插件的app的名称
  266. // console.log("名称====" + referer);
  267. let endPoint = JSON.stringify({
  268. //终点
  269. 'name': item.devName,
  270. 'latitude': item.latitude,
  271. 'longitude':item.longitude
  272. });
  273. uni.navigateTo({
  274. url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint
  275. });
  276. },
  277. searchFn(){
  278. this.getMachineList()
  279. },
  280. saomaFn(){
  281. // 只允许通过相机扫码
  282. uni.scanCode({
  283. onlyFromCamera: false,
  284. success: (res) =>{
  285. console.log('条码类型:' + res.scanType);
  286. console.log('条码内容:' + res.result);
  287. // did设备id
  288. this.searchValue = res.result
  289. this.searchFn()
  290. }
  291. });
  292. }
  293. },
  294. mounted() {
  295. const systemInfo = uni.getSystemInfoSync();
  296. // px转换到rpx的比例
  297. let pxToRpxScale = 750 / systemInfo.windowWidth;
  298. let systems = {
  299. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  300. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  301. };
  302. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  303. this.systems = systems;
  304. },
  305. onPageScroll: function(e) {
  306. if (e.scrollTop > this.systems.barHeight) {
  307. this.isTop = 1;
  308. } else {
  309. this.isTop = 0;
  310. }
  311. }
  312. }
  313. </script>
  314. <style>
  315. @import "./machine.css";
  316. </style>