machine.vue 9.4 KB

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