userAuth.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <view class="content">
  3. <view class="steps">
  4. <u-steps :list="numList" active-color="#00aaff" :current="current"></u-steps>
  5. </view>
  6. <view class="step1" v-if="current==0">
  7. <view class="form-row form-flex">
  8. <view><text class="red">*</text>网点名称</view>
  9. <view>啊撒旦解放拉风小区</view>
  10. </view>
  11. <view class="form-row form-flex">
  12. <view><text class="red">*</text>投递手机号</view>
  13. <view>
  14. <u-input v-model="formData.phone" type="number" input-align="right" :custom-style="{color: '#666'}" :maxlength="11" placeholder="请输入手机号码"></u-input>
  15. </view>
  16. </view>
  17. <view class="form-row">
  18. <view><text class="red">*</text>投递类型</view>
  19. <view class="form-grid">
  20. <view v-for="(item,index) in 8" :key="item" :class="index==0?'active':''">
  21. <view class="imgs">
  22. <u-image src="/static/RECYCLING.png" width="70rpx" height="70rpx"></u-image>
  23. </view>
  24. <view class="info">
  25. <view>废旧纸张</view>
  26. <view class="texts">200g/1乐豆</view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="step2" v-if="current==1">
  33. <view class="form-row form-flex">
  34. <view>投递手机号</view>
  35. <view>13709146191</view>
  36. </view>
  37. <view class="form-row form-flex">
  38. <view>用户乐豆余额</view>
  39. <view class="flex-row"><text>560</text><u-image width="30rpx" height="30rpx" src="/static/ledou.png"></u-image></view>
  40. </view>
  41. <view class="form-row form-flex">
  42. <view>投递类型</view>
  43. <view>
  44. 废旧衣服
  45. <text class="des">(200g/1乐豆)</text>
  46. </view>
  47. </view>
  48. <view class="form-row form-flex">
  49. <view>投递重量</view>
  50. <view><text class="nums">{{balanceData}}g</text></view>
  51. </view>
  52. <view class="form-row form-flex">
  53. <view>可兑换乐豆数</view>
  54. <view class="flex-row"><text class="nums">10</text><u-image width="30rpx" height="30rpx" src="/static/ledou.png"></u-image></view>
  55. </view>
  56. </view>
  57. <view class="buttons">
  58. <view v-if="current==0" ><u-button shape="circle" :custom-style="customStyle" @click="next()" type="primary">下一步</u-button></view>
  59. <view v-if="current==1"><u-button shape="circle" @click="prev()">上一步</u-button></view>
  60. <view v-if="current==1"><u-button shape="circle" @click="submit()" :custom-style="customStyle" type="primary">提交</u-button></view>
  61. </view>
  62. <!-- 注意事项 -->
  63. <view class="notes">
  64. <view>注意事项:</view>
  65. <view>
  66. <view>1.请等待电子秤数据稳定后,再点击提交按钮</view>
  67. <view>2.提交数据时,请仔细检查投递重量是否正确</view>
  68. <view>3.下次称重时,记得将上次称重的物品取下,避免重复称重</view>
  69. </view>
  70. </view>
  71. <!-- 提交确认弹框 -->
  72. <u-modal v-model="showOk" :duration="50" show-cancel-button @confirm="confirm" @cancel="cancel">
  73. <view class="slot-content">
  74. <rich-text :nodes="modelContent"></rich-text>
  75. </view>
  76. </u-modal>
  77. </view>
  78. </template>
  79. <script>
  80. export default {
  81. data() {
  82. return {
  83. showOk: false,
  84. modelContent:'',
  85. customStyle: {
  86. background: '#00aaff'
  87. },
  88. current: 0,
  89. numList: [{
  90. name: '用户认证'
  91. }, {
  92. name: '称重'
  93. }],
  94. formData:{
  95. address: '',
  96. phone: '',
  97. washType: '0',
  98. washWeight:0
  99. },
  100. blueConnect: true,
  101. deviceId: null
  102. }
  103. },
  104. computed: {
  105. balanceData() {
  106. this.cancel()
  107. let data = this.$store.state.vuex_balanceData
  108. console.log(data)
  109. let weight = data.split(',')[2]
  110. let uit = ''
  111. let fh = ''
  112. weight = weight.replace('\n','')
  113. // 符号位
  114. if(weight.indexOf('+')>=0){
  115. fh = '+'
  116. }
  117. if(weight.indexOf('-')>=0){
  118. fh = '-'
  119. }
  120. // 解析数字
  121. if(weight.indexOf('kg')>0){
  122. weight = weight.replace(/\+|-|[kg]/g,'')
  123. console.log(weight,'kg-weight')
  124. weight = Number(weight) * 1000
  125. uit = 'kg'
  126. }else if(weight.indexOf('lb')>0){
  127. weight = weight.replace(/\+|-|[lb]/g,'')
  128. console.log(weight,'lb-weight')
  129. weight = Math.floor(Number(weight) * 453.59237)
  130. uit = 'lb'
  131. }else{
  132. weight = weight.replace(/\+|-|g/g,'')
  133. console.log(weight,'g-weight')
  134. weight = Number(weight)
  135. uit = 'g'
  136. }
  137. console.log(weight,uit,fh,'weight end')
  138. this.washWeight = weight
  139. return fh + weight
  140. }
  141. },
  142. onLoad(options) {
  143. let _this = this
  144. this.deviceId = options.deviceId
  145. // 连接中断
  146. uni.$on('blueConnectClose',function(){
  147. _this.reConnect(1)
  148. })
  149. // 连接成功
  150. uni.$on('blueConnectCallback',function(type){
  151. if(type&&!this.blueConnect){
  152. _this.blueConnect = true
  153. uni.showModal({
  154. title: '提示',
  155. content: '重连成功,请重新称重',
  156. showCancel: false,
  157. })
  158. }else{
  159. _this.reConnect(0)
  160. }
  161. })
  162. },
  163. onUnload() {
  164. uni.$off('blueConnectClose')
  165. uni.$off('blueConnectCallback')
  166. },
  167. methods: {
  168. reConnect(type){
  169. this.blueConnect = false
  170. uni.showModal({
  171. title: '提示',
  172. content: type ? '蓝牙连接设备已断开,请重新绑定连接' : '请检测电子秤或手机蓝牙是否开启,确认后请重新连接',
  173. showCancel: false,
  174. confirmText: '重新连接',
  175. complete(e){
  176. if(e.confirm){
  177. uni.$emit('blueReConnect')
  178. }
  179. }
  180. })
  181. },
  182. next(){
  183. if(this.formData.phone == ''){
  184. uni.showToast({
  185. icon: 'none',
  186. title: '请输入手机号码'
  187. })
  188. return
  189. }
  190. if(this.formData.washType == ''){
  191. uni.showToast({
  192. icon: 'none',
  193. title: '请选择投递类型'
  194. })
  195. return
  196. }
  197. this.current = this.current + 1
  198. },
  199. prev(){
  200. this.current = this.current - 1
  201. },
  202. submit(){
  203. let that = this
  204. console.log(this.washWeight,'this.washWeight')
  205. if(this.washWeight<=0){
  206. uni.showToast({
  207. icon: 'none',
  208. title: '请投放物品!'
  209. })
  210. return
  211. }
  212. // 判断设备仍然连接中
  213. uni.getBluetoothDevices({
  214. success(res) {
  215. console.log(res.devices,that.deviceId)
  216. let has = res.devices.find(item => item.deviceId == that.deviceId)
  217. if(that.blueConnect && has){
  218. that.showOk = true
  219. that.modelContent = `
  220. <div>
  221. <div style="font-weight:bold;padding:10px 0;">投递重量:<span style="color:red">${that.balanceData}</span> g</div>
  222. <div>提交后将为此用户计入本次投递数据,确认提交吗?</div>
  223. </div>
  224. `
  225. }else{
  226. that.reConnect(1)
  227. }
  228. }
  229. })
  230. },
  231. // 取消提交
  232. cancel(){
  233. this.showOk = false
  234. this.modelContent = ''
  235. },
  236. // 确认提交
  237. confirm(){
  238. }
  239. }
  240. }
  241. </script>
  242. <style lang="less">
  243. .content{
  244. width: 100%;
  245. padding: 20rpx;
  246. background-color: #FFFFFF;
  247. .steps{
  248. padding: 40rpx 0;
  249. border-bottom: 1px solid #f8f8f8;
  250. }
  251. .flex-row{
  252. display: flex;
  253. align-items: center;
  254. justify-content: flex-end;
  255. }
  256. .form-flex{
  257. display: flex;
  258. align-items: center;
  259. > view{
  260. &:first-child{
  261. width: 30%;
  262. }
  263. &:last-child{
  264. width: 70%;
  265. text-align: right;
  266. color: #666;
  267. }
  268. }
  269. }
  270. .form-row{
  271. border-bottom: 1px solid #f8f8f8;
  272. padding: 20rpx 15rpx;
  273. position: relative;
  274. .red{
  275. color: red;
  276. margin-right: 6rpx;
  277. }
  278. .des{
  279. color: #666;
  280. margin-left: 5rpx;
  281. font-size: 24rpx;
  282. }
  283. .nums{
  284. color: red;
  285. margin-right: 5rpx;
  286. }
  287. }
  288. .form-grid{
  289. display: flex;
  290. align-items: center;
  291. flex-wrap: wrap;
  292. justify-content: space-around;
  293. > view{
  294. width: 46%;
  295. border: 1px solid #eee;
  296. margin: 10rpx 0;
  297. padding: 10rpx 20rpx;
  298. border-radius: 8rpx;
  299. display: flex;
  300. align-items: center;
  301. background-color: #f8f8f8;
  302. .texts{
  303. font-size: 24rpx;
  304. color: #999;
  305. padding: 2rpx 0;
  306. }
  307. .imgs{
  308. width: 90rpx;
  309. }
  310. .info{
  311. flex-grow: 1;
  312. }
  313. }
  314. .active{
  315. border-color: #4792d8;
  316. background-color: #55aaff;
  317. color: #FFFFFF;
  318. .texts{
  319. color: #FFFFFF;
  320. }
  321. }
  322. }
  323. .buttons{
  324. padding: 50rpx 5%;
  325. display: flex;
  326. align-items: center;
  327. justify-content: center;
  328. >view{
  329. width: 50%;
  330. padding: 0 5%;
  331. }
  332. }
  333. .notes{
  334. margin-top: 50rpx;
  335. border-radius: 10rpx;
  336. color: #999;
  337. > view{
  338. &:first-child{
  339. padding: 10rpx 20rpx;
  340. }
  341. &:last-child{
  342. padding: 0 40rpx;
  343. > view{
  344. padding: 6rpx 20rpx;
  345. }
  346. }
  347. }
  348. }
  349. .slot-content{
  350. padding: 25rpx 50rpx 50rpx;
  351. }
  352. }
  353. </style>