userAuth.vue 11 KB

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