control1.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <template>
  2. <view class="box">
  3. <view class="tab">
  4. <view @click="tap" :data-index="0" :class="index==0?'active':''">
  5. <text>立即绑定</text>
  6. </view>
  7. <view @click="tap" :data-index="1" :class="index==1?'active':''">
  8. <text>解除绑定</text>
  9. </view>
  10. </view>
  11. <block v-if="index==0">
  12. <view class='ma'>
  13. <view class="view">
  14. <input placeholder="请输入车辆编码" placeholder-style="color:#B6B6B6;" @input='input1' :value='erweima'></input>
  15. <view class="btn" @click="erwei"><text>扫描</text></view>
  16. </view>
  17. <view class="view">
  18. <input @input='input2' :value='value' placeholder="中控设备号" placeholder-style="color:#B6B6B6;"></input>
  19. <view class="btn" @click="tiaoxing"><text>扫描</text></view>
  20. </view>
  21. </view>
  22. <view class='btm' @click="qued">
  23. <text>立即绑定</text>
  24. </view>
  25. </block>
  26. <!-- 解除绑定 -->
  27. <block v-if="index==1">
  28. <view class='ma'>
  29. <view class="view">
  30. <input :value='value' @input='input2' placeholder="中控设备号" placeholder-style="color:#B6B6B6;"></input>
  31. <view class="btn" @click="tiaoxing"><text>扫描</text></view>
  32. </view>
  33. </view>
  34. <view class='btm' @click='relieve'>
  35. <text>解除绑定 </text>
  36. </view>
  37. </block>
  38. <!-- <view class="scanCode" bindtap="scanCode">
  39. <text>扫一扫</text>
  40. </view> -->
  41. <!-- <view class="logo">
  42. <image src="http://resource.weilaibike.com/yunwei/logo.png" style="width:70rpx;height:70rpx;border-radius:50%;"></image>
  43. <text style="padding-top:16rpx;">闪现出行方便大学生出行</text>
  44. </view> -->
  45. </view>
  46. </template>
  47. <script>
  48. var barcode = null;
  49. export default {
  50. data() {
  51. return {
  52. erweima: '',
  53. value: '',
  54. index: 0
  55. }
  56. },
  57. methods: {
  58. input1: function(e) {
  59. this.erweima = e.detail.value
  60. console.log(e.detail.value, '这是input中的数据')
  61. },
  62. input2: function(e) {
  63. this.value = e.detail.value
  64. console.log(e.detail.value, '这是input中的数据')
  65. },
  66. //立即绑定
  67. qued: function() {
  68. if (this.erweima == '' || this.value == '') {
  69. uni.showModal({
  70. title: '提示',
  71. content: '请完善设备码或车辆编号',
  72. showCancel: false
  73. })
  74. } else {
  75. uni.showLoading({
  76. title: '绑定中...',
  77. })
  78. let data = {
  79. bike_no: that.data.erweima,
  80. box_no: that.data.value
  81. }
  82. app.request('control/addBike', data, 'POST').then(res => {
  83. uni.hideLoading();
  84. if (res.statusCode == 200) {
  85. uni.showToast({
  86. title: '绑定成功',
  87. icon: 'none'
  88. })
  89. }
  90. })
  91. }
  92. },
  93. //解除绑定
  94. relieve: function() {
  95. //解除绑定
  96. if (this.value == '') {
  97. uni.showModal({
  98. title: '提示',
  99. content: '请完善中控设备号',
  100. showCancel: false
  101. })
  102. } else {
  103. uni.showLoading({
  104. title: '解绑中...',
  105. })
  106. let data = {
  107. box_no: that.data.value
  108. }
  109. app.request('control/unbindingBike', data, 'POST').then(res => {
  110. uni.hideLoading();
  111. if (res.statusCode == 200) {
  112. uni.showToast({
  113. title: '解除成功',
  114. icon: 'none'
  115. })
  116. }
  117. })
  118. }
  119. },
  120. //条形码
  121. tiaoxing: function() {
  122. //点击扫描条形码
  123. var that = this
  124. // this.value=99999
  125. uni.scanCode({
  126. success: function(res) {
  127. console.log(res, "99999")
  128. console.log(typeof(res.result))
  129. var arr = res.result.split('\n')
  130. var zk = arr[0]
  131. console.log(zk, "77777")
  132. var zk1 = zk.split(':')
  133. var IMEI = zk1[1]
  134. console.log(IMEI, "666666")
  135. console.log(that.value)
  136. if (typeof(IMEI) == 'string') {
  137. console.log(IMEI)
  138. if (IMEI.length == 9 || IMEI.length == 15) {
  139. that.value = zk1[1]
  140. } else {
  141. uni.showToast({
  142. title: '扫错了~',
  143. icon: 'none'
  144. })
  145. }
  146. }
  147. },
  148. fail: function(err) {
  149. console.log(err, "88888")
  150. uni.showToast({
  151. title: '扫码失败',
  152. icon: 'none'
  153. })
  154. }
  155. })
  156. },
  157. erwei: function() {
  158. //点击扫描二维码
  159. var that = this
  160. uni.scanCode({
  161. success: function(res) {
  162. console.log(res, "uuuuuuu")
  163. var code = decodeURIComponent(res.result);
  164. var code1 = code.lastIndexOf("=");
  165. var source = code.substring(code1 + 1, code.length);
  166. console.log(source, "99999")
  167. that.erweima = source
  168. },
  169. fail: function() {
  170. uni.showToast({
  171. title: '扫码失败',
  172. icon: 'none'
  173. })
  174. }
  175. })
  176. },
  177. tap: function(e) { //绑定解绑标签切换
  178. this.index = e.currentTarget.dataset.index,
  179. console.log(e, '这是绑定id')
  180. }
  181. }
  182. }
  183. </script>
  184. <style>
  185. .box {
  186. width: 100%;
  187. height: 100%;
  188. display: flex;
  189. flex-direction: column;
  190. align-items: center;
  191. }
  192. .tab {
  193. width: 85%;
  194. display: flex;
  195. justify-content: space-between;
  196. height: 75rpx;
  197. margin-top: 20rpx;
  198. border-radius: 30rpx;
  199. overflow: hidden;
  200. }
  201. .tab view {
  202. width: 49.9%;
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. background: #ccc;
  207. color: white;
  208. font-size: 28rpx;
  209. }
  210. .box .tab .active {
  211. background: #18D5B9;
  212. color: #FFFFFF !important;
  213. }
  214. .box .ma {
  215. width: 90%;
  216. display: flex;
  217. flex-direction: column;
  218. margin: 0 auto;
  219. padding-top: 80rpx;
  220. }
  221. .box .ma .view {
  222. width: 690rpx;
  223. height: 90rpx;
  224. background: rgba(255, 255, 255, 1);
  225. box-shadow: 0px 0px 4rpx 0px rgba(222, 222, 222, 1);
  226. border-radius: 10rpx;
  227. display: flex;
  228. align-items: center;
  229. justify-content: space-around;
  230. margin-top: 35rpx;
  231. }
  232. .box .ma .view .btn {
  233. width: 90rpx;
  234. height: 47rpx;
  235. background: rgba(229, 229, 229, 1);
  236. border-radius: 10rpx;
  237. font-size: 24rpx;
  238. font-family: PingFang SC;
  239. color: rgba(136, 136, 136, 1);
  240. display: flex;
  241. align-items: center;
  242. justify-content: center;
  243. }
  244. .box .ma input {
  245. width: 70%;
  246. border-bottom: 1rpx solid gray;
  247. height: 60rpx;
  248. line-height: 60rpx;
  249. font-size: 26rpx;
  250. }
  251. .btm {
  252. width: 420rpx;
  253. height: 88rpx;
  254. background: rgba(24, 213, 185, 1);
  255. box-shadow: 0px 8rpx 13rpx 0px rgba(100, 239, 218, 1);
  256. border-radius: 44rpx;
  257. display: flex;
  258. align-items: center;
  259. justify-content: center;
  260. font-size: 30rpx;
  261. color: white;
  262. margin-top: 200rpx;
  263. }
  264. .logo {
  265. width: 100%;
  266. display: flex;
  267. flex-direction: column;
  268. align-items: center;
  269. position: fixed;
  270. font-size: 22rpx;
  271. bottom: 30rpx;
  272. color: #999;
  273. }
  274. .scanCode {
  275. width: 420rpx;
  276. height: 88rpx;
  277. background: linear-gradient(163deg, rgba(255, 139, 102, 1) 0%, rgba(254, 87, 34, 1) 100%);
  278. border-radius: 44rpx;
  279. display: flex;
  280. align-items: center;
  281. justify-content: center;
  282. font-size: 30rpx;
  283. color: white;
  284. margin-top: 150rpx;
  285. }
  286. </style>