cell.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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="tab-box ddflex">
  12. <view class="fflex ddflex">
  13. <view :class="'tab-item fflex '+(queryType==''?'tab-item-active':'')" @click="queryTypeChange(-1)">
  14. <view>全部</view>
  15. <image class="tab-active-icon" src="../../static/images/tab_cur.png"></image>
  16. </view>
  17. <view :class="'tab-item fflex '+(queryType==2?'tab-item-active':'')" @click="queryTypeChange(2)">
  18. <view>未租</view>
  19. <image class="tab-active-icon" src="../../static/images/tab_cur.png"></image>
  20. </view>
  21. <view :class="'tab-item fflex '+(queryType==1?'tab-item-active':'')" @click="queryTypeChange(1)">
  22. <view>已租</view>
  23. <image class="tab-active-icon" src="../../static/images/tab_cur.png"></image>
  24. </view>
  25. </view>
  26. <view class="ddflex">
  27. <image class="saoma" src="../../static/pages/images/saoma.png" @click="saomaFn()"></image>
  28. <image class="sousuo" src="../../static/pages/images/search.png" @click="jumpUrl('/machineAndCell/cellSearch/cellSearch?storeId='+actMerchant.id+'&type='+queryType)"></image>
  29. </view>
  30. </view>
  31. </view>
  32. <block v-if="isLogin">
  33. <view :style="'height: '+ (systems.navigationHeight+systems.ktxStatusHeight+106) + 'rpx;'"></view>
  34. <view class="ddflex state-box">
  35. <view class="state-item">
  36. <view class="ddflex">
  37. <view class="icon"></view>
  38. <view class="state-label">租赁中</view>
  39. </view>
  40. <view class="ddflex state-data">
  41. <view>{{count.leaseCount?count.leaseCount:0}}</view>
  42. <view>{{getP(1)}}%</view>
  43. </view>
  44. </view>
  45. <view class="state-item">
  46. <view class="ddflex">
  47. <view class="icon" style="background: #0FCB27;"></view>
  48. <view class="state-label">空闲</view>
  49. </view>
  50. <view class="ddflex fflex state-data">
  51. <view>{{count.noLeaseCount?count.noLeaseCount:0}}</view>
  52. <view>{{getP(2)}}%</view>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 电池 -->
  57. <view>
  58. <view class="cell-box" v-for="item,index in groupList">
  59. <view class="ddflex">
  60. <view style="margin-right: 35rpx;">
  61. <cell :width="99" :height="197" :soc="item.leaseStatus==1?50:100" :showsoc="false"></cell>
  62. </view>
  63. <view class="cell-info fflex">
  64. <view class="ddflex">
  65. <view class="cell-title">{{item.model}}</view>
  66. <view class="cell-state" :style="item.leaseStatus==1?'':'background-color: #0FCB27;'">{{item.leaseStatus==1?'已租':'空闲'}}</view>
  67. </view>
  68. <view class="cell-info ddflex">
  69. <view>电池Id:</view>
  70. <view>{{item.batteryId?item.batteryId:'暂无电池'}}</view>
  71. </view>
  72. <view class="cell-info ddflex">
  73. <view>设备编号:</view>
  74. <view>{{item.number}}</view>
  75. </view>
  76. <view class="cell-info ddflex">
  77. <view>门店:</view>
  78. <view>{{item.storeName}}</view>
  79. </view>
  80. <view class="cell-info ddflex">
  81. <view>到期时间:</view>
  82. <view>{{item.blockDate}}</view>
  83. </view>
  84. </view>
  85. </view>
  86. <view class="cell-option ddflex">
  87. <view class="fflex" style="padding-top: 30rpx;" @click="!item.batteryId?noCell():jumpUrl('/machineAndCell/map/map?id='+item.batteryId)">定位</view>
  88. <view class="fflex" style="padding-top: 30rpx;" @click="!item.batteryId?noCell():jumpUrl('/machineAndCell/BMS/BMS?id='+item.batteryId)">BMS</view>
  89. <view class="fflex" style="padding-top: 30rpx;" @click="!item.batteryId?noCell():jumpUrl('/machineAndCell/cellDetail/cellDetail?id='+item.batteryId)">详情</view>
  90. </view>
  91. </view>
  92. </view>
  93. <view v-if="groupList.length==0">
  94. <view class="nodata">
  95. <image :src="picUrlss+'empty.png'" mode="aspectFit"></image>
  96. <text>暂无电池~</text>
  97. </view>
  98. </view>
  99. </block>
  100. <view v-else>
  101. <view :style="'height: '+ (systems.navigationHeight+systems.ktxStatusHeight) + 'rpx;'"></view>
  102. <view class="wei-login" v-if="!isLogin">
  103. <image :src="picUrlss + 'wei_login.png'"></image>
  104. <view>暂未登录</view>
  105. <navigator url="/pages/authorize/authorize" hover-class="none" class="cart-login">立即登录</navigator>
  106. </view>
  107. </view>
  108. <left-pop v-if="showPop" :showPop="showPop" :btnColor="'#11BB8B'" :showBtn='false' title="解除提醒" width="460rpx"
  109. @closePop="closePop()" @popSubmit="popSubmit()">
  110. <view class="" style="height: 100%;flex-direction: column;display: flex;">
  111. <view @click="closePop()" class="pop-title ddflex" :style="'height: '+ systems.navigationHeight + 'rpx;padding-top:' + systems.ktxStatusHeight + 'rpx;'+'line-height: '+ systems.navigationHeight + 'rpx;'">
  112. <view>切换门店</view>
  113. <image class="change-ssicon" src="../../static/pages/images/change.png"></image>
  114. </view>
  115. <scroll-view :scroll-y="true" @scrolltolower="loadLeftData" class="pop-content fflex">
  116. <view :class="'pop-content-item '+(actMerchant.id==item.id?'pop-content-active':'')" v-for="(item,index) in merchantList" @click="changePop(item)">
  117. <view class="pop-content-name tover">{{item.name}}</view>
  118. <image class="pop-content-icon" src=""></image>
  119. </view>
  120. </scroll-view>
  121. </view>
  122. </left-pop>
  123. <foot channel="cell" :isUpdate="isUpdate"></foot>
  124. </view>
  125. </template>
  126. <script>
  127. const app = getApp();
  128. const req = require("../../utils/request.js");
  129. import cell from "../../components/cell/index";
  130. import foot from "../../components/nav-bar/index";
  131. import leftPop from "../../components/left-pop/index";
  132. export default {
  133. components: {
  134. cell,
  135. foot,
  136. leftPop
  137. },
  138. props: {},
  139. data() {
  140. return {
  141. picUrlss: req.public.picUrls,
  142. systems: {},
  143. isTop:0,
  144. isLogin:false,
  145. userInfo:{},
  146. showPop: false,
  147. tempData: null,
  148. groupList: [],
  149. page: 1,
  150. limit: 10,
  151. searchValue:'',
  152. isQuerying:false,//正在查询数据
  153. queryType:'',
  154. merchantList: [],
  155. merchantPage: 1,
  156. merchantLimit: 10,
  157. actMerchant:null,//当前门店
  158. count:{}
  159. }
  160. },
  161. onLoad(options) {
  162. // 判断当前登录用户身份
  163. if(req.isLogins(false)){
  164. this.isLogin = true
  165. this.userInfo = req.getStorage('userInfo')
  166. if(!this.userInfo.storeId){
  167. this.getMerchantList()
  168. }else{
  169. this.actMerchant={
  170. id:this.userInfo.storeId
  171. }
  172. this.getMachineList()
  173. this.getTopNum()
  174. }
  175. }else{
  176. this.isLogin = false
  177. // this.getMachineList()
  178. }
  179. uni.$on('reSetLogin',(data)=>{
  180. this.isLogin = true
  181. console.log('reSetLogin')
  182. this.actMerchant = null
  183. // 判断当前登录用户身份
  184. if(req.isLogins(true)){
  185. this.userInfo = req.getStorage('userInfo')
  186. if(!this.userInfo.storeId){
  187. this.getMerchantList()
  188. }else{
  189. this.actMerchant={
  190. id:this.userInfo.storeId
  191. }
  192. this.getMachineList()
  193. }
  194. }else{
  195. this.isLogin = false
  196. // this.getMachineList()
  197. }
  198. })
  199. },
  200. onShow() {
  201. if(req.isLogins(false)){
  202. this.isLogin = true
  203. }else{
  204. this.isLogin = false
  205. this.actMerchant = null
  206. // this.getMachineList()
  207. }
  208. },
  209. onReachBottom() {
  210. this.getMachineList(true)
  211. },
  212. methods: {
  213. noCell(){
  214. req.msg("暂无电池")
  215. },
  216. getP(type){
  217. let p = 0
  218. console.log('111')
  219. if(type==1){
  220. if(this.count.leaseCount == 0 || this.count.leaseCount == undefined){}
  221. else{
  222. return (this.count.leaseCount/(this.count.leaseCount+(this.count.noLeaseCount?this.count.noLeaseCount:0))).toFixed(4)*100
  223. }
  224. }
  225. if(type==2){
  226. if(this.count.noLeaseCount == 0 || this.count.noLeaseCount == undefined){}
  227. else{
  228. return (this.count.noLeaseCount/(this.count.leaseCount+(this.count.noLeaseCount?this.count.noLeaseCount:0))).toFixed(4)*100
  229. }
  230. }
  231. return p*100
  232. },
  233. jumpUrl(url){
  234. if(req.isLogins(true)){
  235. uni.navigateTo({
  236. url:url
  237. })
  238. }
  239. },
  240. queryTypeChange(val) {
  241. if (this.queryType == val) return false
  242. this.queryType = val
  243. this.queryType = val==-1?'':val
  244. this.getMachineList()
  245. },
  246. // 弹窗弹出
  247. openPop(item) {
  248. this.tempData = JSON.parse(JSON.stringify(item))
  249. this.showPop = true
  250. },
  251. closePop(){
  252. this.showPop = false
  253. },
  254. changePop(item){
  255. this.actMerchant = item
  256. this.closePop()
  257. this.getMachineList()
  258. this.getTopNum()
  259. },
  260. // 电池数量
  261. getTopNum(){
  262. console.log('getTopNum')
  263. req.getRequest(
  264. '/admin/v2/battery/count',
  265. {storeId:this.actMerchant.id},
  266. data => {
  267. this.count = data
  268. }
  269. )
  270. },
  271. // 获取电池列表
  272. getMachineList(isPage){
  273. if(!this.actMerchant||!this.actMerchant.id) return
  274. if(this.isQuerying) return
  275. else this.isQuerying = true
  276. if (!isPage) {
  277. this.page = 1
  278. }
  279. let queryParams = {
  280. page: this.page,
  281. limit: this.limit,
  282. }
  283. if(this.searchValue){
  284. queryParams.number=this.searchValue
  285. }
  286. if(this.queryType){
  287. queryParams.type = this.queryType
  288. }
  289. queryParams.storeId = this.actMerchant.id
  290. req.getRequest(
  291. '/admin/v2/battery/page',
  292. queryParams,
  293. data => {
  294. if (data != null && data.list.length > 0) {
  295. if (!isPage) {
  296. this.groupList = data.list
  297. } else {
  298. this.groupList = this.groupList.concat(data.list)
  299. }
  300. this.page++
  301. } else {
  302. if (!isPage)
  303. this.groupList = data.list
  304. else {}
  305. }
  306. uni.hideLoading()
  307. this.isQuerying = false
  308. }
  309. )
  310. },
  311. loadLeftData(res){
  312. this.getMerchantList(true)
  313. },
  314. getMerchantList(isPage){
  315. if (!isPage) {
  316. this.merchantPage = 1
  317. }
  318. let queryParams = {
  319. page: this.merchantPage,
  320. limit: this.merchantLimit,
  321. }
  322. queryParams.merchantId = req.getStorage('userInfo').merchantId?req.getStorage('userInfo').merchantId:null
  323. req.getRequest(
  324. '/admin/v2/store/page',
  325. queryParams,
  326. data => {
  327. if (data != null && data.list.length > 0) {
  328. if (!isPage) {
  329. this.merchantList = data.list
  330. } else {
  331. this.merchantList = this.merchantList.concat(data.list)
  332. }
  333. this.merchantPage++
  334. } else {
  335. if (!isPage)
  336. this.merchantList = data.list
  337. else {}
  338. }
  339. if(!isPage){
  340. if(this.actMerchant){
  341. }else{
  342. this.actMerchant = this.merchantList[0]
  343. }
  344. this.getMachineList()
  345. this.getTopNum()
  346. }
  347. }
  348. )
  349. },
  350. saomaFn(){
  351. // 只允许通过相机扫码
  352. uni.scanCode({
  353. onlyFromCamera: false,
  354. success: (res) =>{
  355. console.log('条码类型:' + res.scanType);
  356. console.log('条码内容:' + res.result);
  357. // did设备id
  358. this.jumpUrl('/machineAndCell/cellSearch/cellSearch?storeId='+this.actMerchant.id+'&searchValue='+res.result+'&type='+this.queryType)
  359. }
  360. });
  361. }
  362. },
  363. mounted() {
  364. const systemInfo = uni.getSystemInfoSync();
  365. // px转换到rpx的比例
  366. let pxToRpxScale = 750 / systemInfo.windowWidth;
  367. let systems = {
  368. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  369. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  370. };
  371. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  372. this.systems = systems;
  373. },
  374. onPageScroll: function(e) {
  375. if (e.scrollTop > this.systems.barHeight) {
  376. this.isTop = 1;
  377. } else {
  378. this.isTop = 0;
  379. }
  380. }
  381. }
  382. </script>
  383. <style>
  384. @import "./cell.css";
  385. </style>