bindLock.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. <template>
  2. <view class="jpmain ">
  3. <!-- <view class="body">
  4. <u-steps :list="numList" mode="number" :current="current" un-active-color="#999999"></u-steps >
  5. </view>-->
  6. <view class="list" >
  7. <view class="item" @click="gotoscan">
  8. <view class="name">
  9. <span>*</span>地锁编号
  10. </view>
  11. <view class="value">
  12. <view :style="bindInfo.lockNo?'':'color:rgb(187, 187, 187)'">{{bindInfo.lockNo?bindInfo.lockNo:'请扫码识别地锁'}}</view>
  13. <view v-if="!id" ><img class="img" src="@/assets/img/mylock/item3.svg" alt=""></view>
  14. </view>
  15. </view>
  16. <view class="item">
  17. <view class="name">
  18. <span>*</span>管理者
  19. </view>
  20. <view class="value">
  21. <input v-model="bindInfo.name" placeholder="请填写用户真实姓名" />
  22. </view>
  23. </view>
  24. <view class="item">
  25. <view class="name">
  26. <span>*</span>联系电话
  27. </view>
  28. <view class="value">
  29. <input v-model="bindInfo.phone" placeholder="请填写手机号码" />
  30. </view>
  31. </view>
  32. </view>
  33. <u-select v-model="bindInfotypeshow" :default-value="bindInfotypeshowdefaultvalue"
  34. value-name="id" label-name="name" @confirm="bindInfotypeconfirm"
  35. :list="bindInfotypelist"></u-select>
  36. <view class="list">
  37. <view class="item" >
  38. <view class="name">
  39. <span>*</span>地锁类型
  40. </view>
  41. <view class="value" @click="gotobindInfotypeshow">
  42. <view v-if="0">
  43. <u-radio-group v-model="bindInfo.type" >
  44. <u-radio
  45. v-for="(item, index) in bindInfotypelist" :key="index"
  46. :name="item.id"
  47. >
  48. {{item.name}}
  49. </u-radio>
  50. </u-radio-group>
  51. </view>
  52. <view :style="bindInfo.type?'':'color:#BBB'"
  53. >{{bindInfo.type?bindInfo.typeN:'请选择地锁类型'}}</view>
  54. <u-icon name="arrow-right" size="24" color="#BBBBBB"></u-icon>
  55. <!-- <u-icon name="arrow-right" size="24" color="#BBBBBB"></u-icon> -->
  56. </view>
  57. </view>
  58. <view class=" item tips" v-if="bindInfo.type==3">专属停车位只能选择运营停车场</view>
  59. <view class="item" >
  60. <view class="name">
  61. <span>*</span>所属停车场
  62. </view>
  63. <view class="value" @click="gotoSelectParking()">
  64. <view style="display: flex;" :style="bindInfo.parkingIdN?'':'color:#BBB'"
  65. >
  66. <template v-if="bindInfo.parkingIdN">
  67. <span class="buildMode buildMode1" v-if="bindInfo.buildMode==1">
  68. 用户自建
  69. </span>
  70. <span class="buildMode buildMode2" v-if="bindInfo.buildMode==2">
  71. 平台运营
  72. </span>
  73. </template>
  74. {{bindInfo.parkingIdN?bindInfo.parkingIdN:'请选择所属停车场'}}</view>
  75. <u-icon name="arrow-right" size="24" color="#BBBBBB"></u-icon>
  76. </view>
  77. </view>
  78. <view class="item">
  79. <view class="name">
  80. <span>*</span>地锁名称
  81. </view>
  82. <view class="value">
  83. <input placeholder="如智泊地锁" v-model="bindInfo.lockName" />
  84. </view>
  85. </view>
  86. <view class="item">
  87. <view class="name">
  88. <span>*</span>地锁定位
  89. </view>
  90. <view class="value" @click="getUserLocation" >
  91. <view :style="bindInfo.address?'':'color:#BBB'"
  92. >{{bindInfo.address?bindInfo.address:'点击获取地锁定位信息'}}</view>
  93. <view><img class="img" src="@/assets/img/mylock/item5.svg" alt=""></view>
  94. </view>
  95. </view>
  96. <view class="floating-button">
  97. <view class="button" @click="submit" >
  98. {{id?'保存':'立即绑定'}}
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. </template>
  104. <script>
  105. import * as API from '@/apis/pagejs/mylock.js'
  106. export default {
  107. components: {
  108. // //'u-radio-group': () => import('@/uni_modules/uview-ui/components/u-radio-group/u-radio-group'),
  109. // //'u-radio': () => import('@/uni_modules/uview-ui/components/u-radio/u-radio'),
  110. //'u-picker': () => import('@/uni_modules/uview-ui/components/u-picker/u-picker'),
  111. },
  112. options:{styleIsolation: 'shared'},
  113. data() {
  114. return {
  115. id:"",
  116. current: 0,
  117. nowscan:{},
  118. columnsindex:[0],
  119. bindInfo:{
  120. name:"",
  121. lockName:"",
  122. phone:"",
  123. lockNo:"",
  124. type:"",
  125. remark:"",
  126. describe:"",
  127. parkingNumber:"",
  128. address:"",
  129. },
  130. bindInfotypeshow:false,
  131. bindInfotypelist:[
  132. {id:"1",name:"公共地锁"},
  133. {id:"2",name:"私人地锁"},
  134. {id:"3",name:"专属地锁"}
  135. ],
  136. bindInfotypeshowdefaultvalue:[0],
  137. isswitchshow:false,
  138. allList:[],
  139. numList: [{
  140. name: '绑定地锁'
  141. }, {
  142. name: '等待审核'
  143. }, {
  144. name: '完成绑定'
  145. }],
  146. };
  147. },
  148. onLoad(op) {
  149. this.userInfo = this.jphelp.getPersonInfo()
  150. this.bindInfo.phone=this.userInfo.phone
  151. if(op.id){
  152. this.id=op.id
  153. uni.setNavigationBarTitle({
  154. title: "修改地锁"
  155. })
  156. this.getFloorlockDetails()
  157. }
  158. },
  159. computed:{
  160. columns(){
  161. var sz=[]
  162. for(var i in this.allList){
  163. var obj=this.allList[i]
  164. sz.push({
  165. value:obj.id,
  166. label:obj.name
  167. })
  168. }
  169. return sz
  170. }
  171. },
  172. methods:{
  173. bindInfotypeconfirm(e){
  174. console.log(e)
  175. this.bindInfo.typeN=e[0].label
  176. this.bindInfo.type=e[0].value
  177. },
  178. gotobindInfotypeshow(){
  179. if(this.bindInfo.type){
  180. this.bindInfotypeshowdefaultvalue=[parseInt(this.bindInfo.type)-1]
  181. }
  182. this.bindInfotypeshow=true;
  183. },
  184. getFloorlockDetails() {
  185. uni.showLoading({
  186. title: "加载中",
  187. mask: true,
  188. })
  189. var obj = {
  190. id: this.id
  191. }
  192. API.floorlockDetails(obj).then((res) => {
  193. this.bindInfo.id = res.data.floorlockInfo.id
  194. this.bindInfo.lockNo = res.data.floorlockInfo.lockNo
  195. this.bindInfo.name = res.data.floorlockInfo.contacts
  196. this.bindInfo.phone = res.data.floorlockInfo.contactPhone
  197. this.bindInfo.lockName = res.data.floorlockInfo.name
  198. if(res.data.parkingInfo&&res.data.parkingInfo.id){
  199. this.bindInfo.parkingId=res.data.parkingInfo.id
  200. this.bindInfo.parkingIdN=res.data.parkingInfo.name
  201. this.bindInfo.parkingName=res.data.parkingInfo.name
  202. this.bindInfo.buildMode=res.data.parkingInfo.buildMode
  203. }
  204. this.bindInfo.type = res.data.floorlockInfo.type
  205. this.bindInfotypelist.forEach(item=>{
  206. if(item.id==this.bindInfo.type){
  207. this.bindInfo.typeN=item.name
  208. }
  209. })
  210. if(this.bindInfo.buildMode==2){
  211. this.bindInfo.latitude = res.data.parkingInfo.latitude
  212. this.bindInfo.longitude = res.data.parkingInfo.longitude
  213. this.bindInfo.address = res.data.parkingInfo.address
  214. }else{
  215. this.bindInfo.latitude = res.data.floorlockInfo.latitude
  216. this.bindInfo.longitude = res.data.floorlockInfo.longitude
  217. this.bindInfo.address = res.data.floorlockInfo.locationAddress
  218. }
  219. uni.hideLoading();
  220. }).catch(error => {
  221. uni.hideLoading();
  222. uni.showToast({
  223. title: error,
  224. icon: "none"
  225. })
  226. })
  227. },
  228. gotoSelectParking(){
  229. uni.navigateTo({
  230. url: '/pages/mylock/selectParking?type='+this.bindInfo.type,
  231. events: {
  232. // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据
  233. acceptDataFromOpenerPage: (item)=>{
  234. console.log(item)
  235. this.bindInfo.parkingIdN=item.data
  236. this.bindInfo.parkingId=item.dataid
  237. this.bindInfo.parkingName=item.data
  238. this.bindInfo.buildMode=item.datatype
  239. if(item.datatype==2){
  240. this.bindInfo.latitude = item.item.latitude
  241. this.bindInfo.longitude = item.item.longitude
  242. this.bindInfo.address = item.item.address
  243. }
  244. this.$forceUpdate()
  245. },
  246. }
  247. // ,
  248. // success: function(res) {
  249. // // 通过eventChannel向被打开页面传送数据
  250. //
  251. // }
  252. })
  253. },
  254. chooseLocationsuccess(res){
  255. console.log('位置名称:' + res.name);
  256. console.log('详细地址:' + res.address);
  257. console.log('纬度:' + res.latitude);
  258. console.log('经度:' + res.longitude);
  259. this.bindInfo.address=res.address
  260. this.bindInfo.latitude=res.latitude
  261. this.bindInfo.longitude=res.longitude
  262. },
  263. getUserLocation(){
  264. if(this.bindInfo.buildMode==2){
  265. uni.showToast({
  266. title: "平台运营停车场不能修改定位",
  267. icon: "none"
  268. })
  269. return
  270. }
  271. var _this=this;
  272. // #ifdef H5
  273. this.bindInfo.address='湖北省荆州市'
  274. this.bindInfo.latitude='30.31098'
  275. this.bindInfo.longitude='112.25494'
  276. // #endif
  277. // #ifdef MP-WEIXIN
  278. uni.authorize({
  279. scope: 'scope.userLocation',
  280. success() {
  281. uni.chooseLocation({
  282. success: function (res) {
  283. _this.chooseLocationsuccess(res)
  284. }
  285. });
  286. }
  287. })
  288. // #endif
  289. },
  290. switchBtn(e){
  291. this.columnsindex=[e[0]]
  292. var obj=this.columns[e[0]]
  293. this.bindInfo.parkingId=obj.value
  294. this.bindInfo.parkingIdN=obj.label
  295. },
  296. isswitchshowBtn(){
  297. if(this.allList.length){
  298. this.isswitchshow=true
  299. }else{
  300. this.getParkingList()
  301. }
  302. },
  303. getParkingList() {
  304. uni.showLoading({
  305. title: "加载中",
  306. mask: true,
  307. })
  308. var obj = {
  309. pageIndex: 1,
  310. pageSize: 900,
  311. type:"bindLock"
  312. }
  313. API.parkingList(obj).then((res) => {
  314. this.allList = res.data.data
  315. this.isswitchshow=true
  316. uni.hideLoading();
  317. }).catch(error => {
  318. uni.hideLoading();
  319. uni.showToast({
  320. title: error,
  321. icon: "none"
  322. })
  323. })
  324. },
  325. submit(){
  326. if(!this.bindInfo.lockNo){
  327. uni.showToast({
  328. title: "请扫码识别地锁",
  329. icon: "none"
  330. })
  331. return
  332. }
  333. if(!this.bindInfo.name){
  334. uni.showToast({
  335. title: "请填写用户真实姓名",
  336. icon: "none"
  337. })
  338. return
  339. }
  340. if(!this.bindInfo.phone){
  341. uni.showToast({
  342. title: "请填写手机号码",
  343. icon: "none"
  344. })
  345. return
  346. }
  347. if(!this.bindInfo.type){
  348. uni.showToast({
  349. title: "请选择地锁类型",
  350. icon: "none"
  351. })
  352. return
  353. }
  354. if(!this.bindInfo.parkingIdN){
  355. uni.showToast({
  356. title: "请选择所属停车场",
  357. icon: "none"
  358. })
  359. return
  360. }
  361. if(!this.bindInfo.lockName){
  362. uni.showToast({
  363. title: "请填写地锁名称",
  364. icon: "none"
  365. })
  366. return
  367. }
  368. if(!this.bindInfo.address){
  369. uni.showToast({
  370. title: "点击获取地锁定位信息",
  371. icon: "none"
  372. })
  373. return
  374. }
  375. if(this.bindInfo.type==3&&this.bindInfo.buildMode!=2){
  376. uni.showToast({
  377. title: "专属停车位只能选择运营停车场",
  378. icon: "none"
  379. })
  380. return
  381. }
  382. uni.showLoading({
  383. title: "加载中",
  384. mask: true,
  385. })
  386. if(this.bindInfo.id){
  387. API.updateLock( this.bindInfo ).then((res) => {
  388. uni.navigateBack()
  389. }).catch(error => {
  390. uni.showToast({
  391. title: error,
  392. icon: "none"
  393. })
  394. })
  395. }else{
  396. API.add( this.bindInfo ).then((res) => {
  397. uni.redirectTo({
  398. url:"/pages/mylock/bindLockStatus?id="+this.nowscan.id
  399. })
  400. uni.hideLoading();
  401. }).catch(error => {
  402. uni.showToast({
  403. title: error,
  404. icon: "none"
  405. })
  406. })
  407. }
  408. },
  409. gotoscanMP(){
  410. // 允许从相机和相册扫码
  411. var _this=this
  412. uni.scanCode({
  413. success: function (res) {
  414. console.log('条码类型:' + res.scanType);
  415. console.log('条码内容:' + res.result);
  416. _this.getscan(res.result)
  417. }
  418. });
  419. },
  420. gotoscan() {
  421. if(this.id){
  422. return
  423. }
  424. // #ifdef H5
  425. this.gotoscanH5()
  426. // #endif
  427. // #ifdef MP-WEIXIN
  428. this.gotoscanMP()
  429. // #endif
  430. },
  431. getscan(val) {
  432. uni.showLoading({
  433. title: "加载中",
  434. mask: true,
  435. })
  436. API.bindStatusByNo({
  437. lockNo: val,
  438. }).then((res) => {
  439. uni.hideLoading();
  440. if (res.data.openBind) {
  441. var nowscan=res.data.floorlockInfoList;
  442. if(nowscan&&nowscan.length){
  443. this.nowscan=nowscan[0];
  444. this.bindInfo.lockNo=nowscan[0].lockNo
  445. this.bindInfo.type=nowscan[0].type
  446. this.bindInfo.lockName="智泊地锁"
  447. }
  448. uni.showToast({
  449. title: "扫码成功",
  450. icon: "none"
  451. })
  452. } else {
  453. uni.showToast({
  454. title: "当前地锁不可绑定",
  455. icon: "none"
  456. })
  457. }
  458. }).catch(error => {
  459. uni.showToast({
  460. title: error,
  461. icon: "none"
  462. })
  463. })
  464. },
  465. gotoscanH5() {
  466. console.log('111')
  467. var _this = this;
  468. uni.showModal({
  469. title: '提示',
  470. editable: true,
  471. //content: '这是一个模态弹窗',
  472. success: function(res) {
  473. if (res.confirm) {
  474. _this.getscan(res.content)
  475. } else if (res.cancel) {
  476. console.log('用户点击取消');
  477. }
  478. }
  479. });
  480. },
  481. }
  482. }
  483. </script>
  484. <style>
  485. page {
  486. background-color: rgba(242, 244, 246, 1);
  487. }
  488. </style>
  489. <style lang="scss" scoped>
  490. .body {
  491. padding: 32rpx;
  492. }
  493. .list{
  494. background-color: rgba(255,255,255,1);
  495. margin: 20rpx 0;
  496. .item:not(:last-child) {
  497. border-bottom:1px solid rgba(232,232,232,1);
  498. }
  499. .item{
  500. padding: 32rpx;
  501. display: flex;
  502. justify-content: space-between;
  503. .name{
  504. width: 40%;
  505. font-size: 32rpx;
  506. color: #777777;
  507. span{
  508. color:red
  509. }
  510. white-space: pre;
  511. }
  512. .value{
  513. font-size: 32rpx;
  514. width: 60%;
  515. display: flex;
  516. justify-content: space-between;
  517. input::placeholder{
  518. color:#AAAAAA;
  519. }
  520. .img{
  521. width: 40rpx;
  522. height: 40rpx;
  523. }
  524. }
  525. }
  526. .tips{
  527. color: rgb(187, 187, 187);
  528. text-align: end;
  529. margin-right: 32rpx;
  530. padding:0;
  531. justify-content: flex-end;
  532. }
  533. }
  534. .uni-input-placeholder{
  535. color:#AAAAAA;
  536. }
  537. .floating-button {
  538. position: fixed;
  539. bottom: 0; /* 距离底部 20px */
  540. width: 100%;
  541. display: flex;
  542. height: 120rpx;
  543. justify-content: center;
  544. background-color: rgba(255,255,255,1);
  545. .button{
  546. margin-top: 24rpx;
  547. border-radius: 50px;
  548. height: 80rpx;
  549. width: 80%;
  550. display: flex;
  551. align-items: center;
  552. justify-content: center;
  553. padding:12rpx;
  554. background-color: rgba(22,119,255,1);
  555. color: rgba(255,255,255,1);
  556. font-size: 36rpx;
  557. }
  558. }
  559. .buildMode{
  560. font-size: 24rpx;
  561. border: 1px solid #bbbbbb;
  562. border-radius: 4px;
  563. color: #1677ff;
  564. padding: 2rpx 8rpx;
  565. margin:0 8rpx;
  566. }
  567. .buildMode1{
  568. color: #1677ff;
  569. border: 1px solid #1677ff;
  570. }
  571. .buildMode2{
  572. color:#4CAF50;
  573. border: 1px solid #4CAF50;
  574. }
  575. </style>