userAuth.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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>{{stationName}}</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.customerMobile" 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 rubbishtype" :key="item.id" @click="selRubbishType(item)" :class="formData.rubbishType==item.rubbishType?'active':''">
  21. <view class="imgs">
  22. <u-image :src="`/static/${item.rubbishType}.png`" width="70rpx" height="70rpx"></u-image>
  23. </view>
  24. <view class="info">
  25. <view>{{item.rubbishTypeDictValue}}</view>
  26. <view class="texts">{{item.rubbishWeight}}g/{{item.goleNum}}乐豆</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>{{formData.customerMobile}}</view>
  36. </view>
  37. <view class="form-row form-flex">
  38. <view>用户乐豆余额</view>
  39. <view class="flex-row"><text>{{currentGold}}</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. {{curRubbishType.rubbishTypeDictValue}}
  45. <text class="des">({{curRubbishType.rubbishWeight}}g/{{curRubbishType.goleNum}}乐豆)</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">{{goldNum}}</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" :loading="loading" :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. import {findBySrcDeviceNo, saveDelivery} from '@/api/delivery.js'
  81. import {queryldByMobile} from '@/api/officialPartnerGoldLog.js'
  82. export default {
  83. data() {
  84. return {
  85. showOk: false,
  86. modelContent:'',
  87. customStyle: {
  88. background: '#00aaff'
  89. },
  90. current: 0,
  91. numList: [{
  92. name: '用户认证'
  93. }, {
  94. name: '称重'
  95. }],
  96. stationName: '', // 网点名称
  97. formData:{
  98. customerMobile: '', // 客户电话
  99. rubbishType: '', // 投递类型
  100. rubbishWeight:0, // 投递重量
  101. srcDeviceCode: '',
  102. },
  103. currentGold: 0, // 用户乐豆余额
  104. blueConnect: true,
  105. deviceId: null,
  106. rubbishtype: [],
  107. curRubbishType: null,
  108. loading: false
  109. }
  110. },
  111. computed: {
  112. // 计算可兑换乐豆
  113. goldNum(){
  114. let ret = 0
  115. if(this.curRubbishType){
  116. ret = this.balanceData / this.curRubbishType.rubbishWeight / this.curRubbishType.goleNum
  117. }
  118. return Math.floor(ret)
  119. },
  120. // 称重结果
  121. balanceData() {
  122. this.cancel()
  123. let _this = this
  124. let data = _this.$store.state.vuex_balanceData
  125. console.log(data)
  126. // 解析结果
  127. let weight = data.split(',')[2]
  128. let uit = '' // 单位
  129. let fh = '' // 正负符号
  130. // 去掉换行符
  131. weight = weight.replace('\n','')
  132. // 符号位
  133. if(weight.indexOf('+')>=0){
  134. fh = '+'
  135. }
  136. if(weight.indexOf('-')>=0){
  137. fh = '-'
  138. }
  139. // 解析数字
  140. if(weight.indexOf('kg')>0){
  141. weight = weight.replace(/\+|-|[kg]/g,'')
  142. console.log(weight,'kg-weight')
  143. weight = Number(weight) * 1000
  144. uit = 'kg'
  145. }else if(weight.indexOf('lb')>0){
  146. weight = weight.replace(/\+|-|[lb]/g,'')
  147. console.log(weight,'lb-weight')
  148. weight = Math.floor(Number(weight) * 453.59237)
  149. uit = 'lb'
  150. }else{
  151. weight = weight.replace(/\+|-|g/g,'')
  152. console.log(weight,'g-weight')
  153. weight = Number(weight)
  154. uit = 'g'
  155. }
  156. // console.log(weight,uit,fh,'weight end')
  157. _this.formData.rubbishWeight = weight
  158. return fh + weight
  159. }
  160. },
  161. onLoad(options) {
  162. let _this = this
  163. // 设备id,去掉冒号并转小写
  164. this.deviceId = options.deviceId.toLowerCase()
  165. this.deviceId = this.deviceId.replace(/:/g,'')
  166. // 连接中断
  167. uni.$on('blueConnectClose',function(){
  168. _this.reConnect(1)
  169. })
  170. // 连接成功
  171. uni.$on('blueConnectCallback',function(type){
  172. if(type&&!this.blueConnect){
  173. _this.blueConnect = true
  174. uni.showModal({
  175. title: '提示',
  176. content: '重连成功,请重新称重',
  177. showCancel: false,
  178. })
  179. }else{
  180. _this.reConnect(0)
  181. }
  182. })
  183. // 通过设备id查询网点信息
  184. this.findBySrcDeviceNo()
  185. },
  186. onUnload() {
  187. uni.$off('blueConnectClose')
  188. uni.$off('blueConnectCallback')
  189. },
  190. methods: {
  191. // 获取网点信息
  192. findBySrcDeviceNo(){
  193. findBySrcDeviceNo({srcDeviceCode:this.deviceId}).then(res=>{
  194. console.log(res,'====')
  195. if(res.status == 200){
  196. this.rubbishtype = res.data.list
  197. this.stationName = res.data.stationEntity.name
  198. this.formData.srcDeviceCode = this.deviceId
  199. }
  200. })
  201. },
  202. // 选择投递类型
  203. selRubbishType(item){
  204. this.formData.rubbishType = item.rubbishType
  205. this.curRubbishType = item
  206. },
  207. // 重连蓝牙设备
  208. reConnect(type){
  209. this.blueConnect = false
  210. uni.showModal({
  211. title: '提示',
  212. content: type ? '蓝牙连接设备已断开,请重新绑定连接' : '请检测电子秤或手机蓝牙是否开启,确认后请重新连接',
  213. showCancel: false,
  214. confirmText: '重新连接',
  215. complete(e){
  216. if(e.confirm){
  217. uni.$emit('blueReConnect')
  218. }
  219. }
  220. })
  221. },
  222. next(){
  223. if(this.formData.customerMobile == ''){
  224. uni.showToast({
  225. icon: 'none',
  226. title: '请输入手机号码'
  227. })
  228. return
  229. }
  230. if(this.formData.customerMobile.length!=11){
  231. uni.showToast({
  232. icon: 'none',
  233. title: '请输入正确的手机号码'
  234. })
  235. return
  236. }
  237. if(this.formData.rubbishType == ''){
  238. uni.showToast({
  239. icon: 'none',
  240. title: '请选择投递类型'
  241. })
  242. return
  243. }
  244. this.loading = true
  245. // 查询用户乐豆余额
  246. queryldByMobile({mobile: this.formData.customerMobile}).then(res => {
  247. if(res.status == 200){
  248. this.current = this.current + 1
  249. this.currentGold = res.data.currentGold
  250. }
  251. this.loading = false
  252. })
  253. },
  254. // 上一步
  255. prev(){
  256. this.current = this.current - 1
  257. },
  258. // 提交保存结果
  259. submit(){
  260. let that = this
  261. console.log(this.formData.rubbishWeight,'this.formData.rubbishWeight')
  262. if(this.formData.rubbishWeight<=0){
  263. uni.showToast({
  264. icon: 'none',
  265. title: '请投放物品!'
  266. })
  267. return
  268. }
  269. // 判断设备蓝牙是否仍然连接中
  270. uni.getBluetoothDevices({
  271. success(res) {
  272. let has = res.devices.find(item => {
  273. let deviceId = item.deviceId.toLowerCase()
  274. return deviceId.replace(/:/g,'') == that.deviceId
  275. })
  276. // console.log(has,'判断设备仍然连接中')
  277. if(that.blueConnect && has){
  278. that.showOk = true
  279. that.modelContent = `
  280. <div>
  281. <div style="font-weight:bold;padding:10px 0;">投递重量:<span style="color:red">${that.balanceData}</span> g</div>
  282. <div>提交后将为此用户计入本次投递数据,确认提交吗?</div>
  283. </div>
  284. `
  285. }else{
  286. that.reConnect(1)
  287. }
  288. }
  289. })
  290. },
  291. // 取消提交
  292. cancel(){
  293. this.showOk = false
  294. this.modelContent = ''
  295. },
  296. // 确认提交
  297. confirm(){
  298. console.log(this.formData,'formData')
  299. saveDelivery(this.formData).then(res => {
  300. if(res.status == 200){
  301. setTimeout(()=>{
  302. uni.navigateBack()
  303. },500)
  304. }
  305. uni.showToast({
  306. icon: 'none',
  307. title: res.message
  308. })
  309. })
  310. }
  311. }
  312. }
  313. </script>
  314. <style lang="less">
  315. .content{
  316. width: 100%;
  317. padding: 20rpx;
  318. background-color: #FFFFFF;
  319. .steps{
  320. padding: 40rpx 0;
  321. border-bottom: 1px solid #f8f8f8;
  322. }
  323. .flex-row{
  324. display: flex;
  325. align-items: center;
  326. justify-content: flex-end;
  327. }
  328. .form-flex{
  329. display: flex;
  330. align-items: center;
  331. > view{
  332. &:first-child{
  333. width: 30%;
  334. }
  335. &:last-child{
  336. width: 70%;
  337. text-align: right;
  338. color: #666;
  339. }
  340. }
  341. }
  342. .form-row{
  343. border-bottom: 1px solid #f8f8f8;
  344. padding: 20rpx 15rpx;
  345. position: relative;
  346. .red{
  347. color: red;
  348. margin-right: 6rpx;
  349. }
  350. .des{
  351. color: #666;
  352. margin-left: 5rpx;
  353. font-size: 24rpx;
  354. }
  355. .nums{
  356. color: red;
  357. margin-right: 5rpx;
  358. }
  359. }
  360. .form-grid{
  361. display: flex;
  362. align-items: center;
  363. flex-wrap: wrap;
  364. > view{
  365. width: 46%;
  366. border: 1px solid #eee;
  367. margin: 10rpx;
  368. padding: 10rpx 20rpx;
  369. border-radius: 8rpx;
  370. display: flex;
  371. align-items: center;
  372. background-color: #f8f8f8;
  373. .texts{
  374. font-size: 24rpx;
  375. color: #999;
  376. padding: 2rpx 0;
  377. }
  378. .imgs{
  379. width: 90rpx;
  380. }
  381. .info{
  382. flex-grow: 1;
  383. }
  384. }
  385. .active{
  386. border-color: #e69900;
  387. background-color: #ffaa00;
  388. color: #FFFFFF;
  389. .texts{
  390. color: #FFFFFF;
  391. }
  392. }
  393. }
  394. .buttons{
  395. padding: 50rpx 5%;
  396. display: flex;
  397. align-items: center;
  398. justify-content: center;
  399. >view{
  400. width: 50%;
  401. padding: 0 5%;
  402. }
  403. }
  404. .notes{
  405. margin-top: 50rpx;
  406. border-radius: 10rpx;
  407. color: #999;
  408. > view{
  409. &:first-child{
  410. padding: 10rpx 20rpx;
  411. }
  412. &:last-child{
  413. padding: 0 40rpx;
  414. > view{
  415. padding: 6rpx 20rpx;
  416. }
  417. }
  418. }
  419. }
  420. .slot-content{
  421. padding: 25rpx 50rpx 50rpx;
  422. }
  423. }
  424. </style>