bindLock.vue 12 KB

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