userAuth.vue 7.1 KB

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