cell.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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'"></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.getMachineList()
  206. }
  207. },
  208. onReachBottom() {
  209. this.getMachineList(true)
  210. },
  211. methods: {
  212. noCell(){
  213. req.msg("暂无电池")
  214. },
  215. getP(type){
  216. let p = 0
  217. console.log('111')
  218. if(type==1){
  219. if(this.count.leaseCount == 0 || this.count.leaseCount == undefined){}
  220. else{
  221. return (this.count.leaseCount/(this.count.leaseCount+(this.count.noLeaseCount?this.count.noLeaseCount:0))).toFixed(4)*100
  222. }
  223. }
  224. if(type==2){
  225. if(this.count.noLeaseCount == 0 || this.count.noLeaseCount == undefined){}
  226. else{
  227. return (this.count.noLeaseCount/(this.count.leaseCount+(this.count.noLeaseCount?this.count.noLeaseCount:0))).toFixed(4)*100
  228. }
  229. }
  230. return p*100
  231. },
  232. jumpUrl(url){
  233. if(req.isLogins(true)){
  234. uni.navigateTo({
  235. url:url
  236. })
  237. }
  238. },
  239. queryTypeChange(val) {
  240. if (this.queryType == val) return false
  241. this.queryType = val
  242. this.queryType = val==-1?'':val
  243. this.getMachineList()
  244. },
  245. // 弹窗弹出
  246. openPop(item) {
  247. this.tempData = JSON.parse(JSON.stringify(item))
  248. this.showPop = true
  249. },
  250. closePop(){
  251. this.showPop = false
  252. },
  253. changePop(item){
  254. this.actMerchant = item
  255. this.closePop()
  256. this.getMachineList()
  257. this.getTopNum()
  258. },
  259. // 电池数量
  260. getTopNum(){
  261. console.log('getTopNum')
  262. req.getRequest(
  263. '/admin/v2/battery/count',
  264. {storeId:this.actMerchant.id},
  265. data => {
  266. this.count = data
  267. }
  268. )
  269. },
  270. // 获取电池列表
  271. getMachineList(isPage){
  272. if(!this.actMerchant||!this.actMerchant.id) return
  273. if(this.isQuerying) return
  274. else this.isQuerying = true
  275. if (!isPage) {
  276. this.page = 1
  277. }
  278. let queryParams = {
  279. page: this.page,
  280. limit: this.limit,
  281. }
  282. if(this.searchValue){
  283. queryParams.number=this.searchValue
  284. }
  285. if(this.queryType){
  286. queryParams.type = this.queryType
  287. }
  288. queryParams.storeId = this.actMerchant.id
  289. req.getRequest(
  290. '/admin/v2/battery/page',
  291. queryParams,
  292. data => {
  293. if (data != null && data.list.length > 0) {
  294. if (!isPage) {
  295. this.groupList = data.list
  296. } else {
  297. this.groupList = this.groupList.concat(data.list)
  298. }
  299. this.page++
  300. } else {
  301. if (!isPage)
  302. this.groupList = data.list
  303. else {}
  304. }
  305. uni.hideLoading()
  306. this.isQuerying = false
  307. }
  308. )
  309. },
  310. loadLeftData(res){
  311. this.getMerchantList(true)
  312. },
  313. getMerchantList(isPage){
  314. if (!isPage) {
  315. this.merchantPage = 1
  316. }
  317. let queryParams = {
  318. page: this.merchantPage,
  319. limit: this.merchantLimit,
  320. }
  321. queryParams.merchantId = req.getStorage('userInfo').merchantId?req.getStorage('userInfo').merchantId:null
  322. req.getRequest(
  323. '/admin/v2/store/page',
  324. queryParams,
  325. data => {
  326. if (data != null && data.list.length > 0) {
  327. if (!isPage) {
  328. this.merchantList = data.list
  329. } else {
  330. this.merchantList = this.merchantList.concat(data.list)
  331. }
  332. this.merchantPage++
  333. } else {
  334. if (!isPage)
  335. this.merchantList = data.list
  336. else {}
  337. }
  338. if(!isPage){
  339. if(this.actMerchant){
  340. }else{
  341. this.actMerchant = this.merchantList[0]
  342. }
  343. this.getMachineList()
  344. this.getTopNum()
  345. }
  346. }
  347. )
  348. },
  349. saomaFn(){
  350. // 只允许通过相机扫码
  351. uni.scanCode({
  352. onlyFromCamera: false,
  353. success: (res) =>{
  354. console.log('条码类型:' + res.scanType);
  355. console.log('条码内容:' + res.result);
  356. // did设备id
  357. this.jumpUrl('/machineAndCell/cellSearch/cellSearch?storeId='+this.actMerchant.id+'&searchValue='+res.result+'&type='+this.queryType)
  358. }
  359. });
  360. }
  361. },
  362. mounted() {
  363. const systemInfo = uni.getSystemInfoSync();
  364. // px转换到rpx的比例
  365. let pxToRpxScale = 750 / systemInfo.windowWidth;
  366. let systems = {
  367. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  368. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  369. };
  370. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  371. this.systems = systems;
  372. },
  373. onPageScroll: function(e) {
  374. if (e.scrollTop > this.systems.barHeight) {
  375. this.isTop = 1;
  376. } else {
  377. this.isTop = 0;
  378. }
  379. }
  380. }
  381. </script>
  382. <style>
  383. @import "./cell.css";
  384. </style>