code.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <view class="sub" :style="'padding-top:'+padtop+'px'">
  3. <navbar :back="false" title="扫码核销" :bgcolor="backgroundColor" color="#fff" fixed zIndex="1010" :center="true" :custom='true' @getTop="getTop" back="true"/>
  4. <!-- <div class="jhyyes">
  5. <img src="/static/images/sm.png" alt="" class="img">
  6. </div>
  7. <view class="naver" @click="smit">
  8. 扫码核销
  9. </view> -->
  10. </view>
  11. </template>
  12. <script>
  13. import url from "@/util/url";
  14. export default {
  15. data() {
  16. return {
  17. padtop:this.$http._GET.customBarH||0,
  18. backgroundColor: 'linear-gradient(90deg, #A00517, #E93030)',
  19. };
  20. },
  21. onLoad() {
  22. this.scanAction()
  23. },
  24. onShow() {
  25. // this.uehg = 1
  26. // this.scanAction()
  27. // console.log(34)
  28. },
  29. onHide() {
  30. // this.uehg = 2
  31. // console.log(344)
  32. },
  33. methods:{
  34. getTop(e){
  35. this.padtop=e
  36. },
  37. smit(){
  38. this.scanAction()
  39. },
  40. //扫码功能
  41. scanAction() {
  42. var that=this;
  43. uni.scanCode({
  44. onlyFromCamera: true,
  45. scanType: ['qrCode', 'barCode'],
  46. success: function (red) {
  47. // console.log(res,9)
  48. let result=red.result;
  49. if (typeof result == 'string') {
  50. try {
  51. var obj=JSON.parse(decodeURIComponent(result));
  52. if(typeof obj == 'object' && obj ){
  53. console.log(7)
  54. }else{
  55. console.log(9)
  56. uni.showToast({
  57. title:'扫码查询失败,请检查二维码是否正确',
  58. icon:"none"
  59. })
  60. uni.navigateBack({
  61. delta:1
  62. })
  63. return ;
  64. }
  65. } catch(e) {
  66. uni.navigateBack({
  67. delta:1
  68. })
  69. uni.showToast({
  70. title:'扫码查询失败,请检查二维码是否正确',
  71. icon:"none"
  72. })
  73. return
  74. }
  75. }
  76. var res=JSON.parse(decodeURIComponent(red.result))
  77. // console.log(res)
  78. // return
  79. if(!res.menuId|| !res.phone||!res.idCard){
  80. uni.navigateBack({
  81. delta:1
  82. })
  83. uni.showToast({
  84. title:'扫码查询失败,请检查二维码是否正确',
  85. icon:"none"
  86. })
  87. return
  88. }
  89. // var now=new Date().getTime()
  90. // var oldnow=res.time;
  91. // if(oldnow > now) {
  92. // console.log("二维码在有效期内");
  93. // } else {
  94. // uni.showToast({
  95. // title:'二维码已过期,请重新生成',
  96. // icon:"none"
  97. // })
  98. // return
  99. // }
  100. var businessId=uni.getStorageSync('businessId')
  101. var params={
  102. "businessId": businessId,
  103. "policyId": res.menuId,
  104. "creditPhone": res.phone,
  105. "idCard": res.idCard,
  106. }
  107. that.$http.post('system/record',params).then(red=>{
  108. if(red.code == 200 ) {
  109. uni.redirectTo({
  110. url:"/pages/index/success"
  111. })
  112. }else{
  113. uni.navigateBack({
  114. delta:1
  115. })
  116. uni.showToast({
  117. title: red.msg,
  118. duration: 1000,
  119. icon: 'none'
  120. });
  121. }
  122. })
  123. // console.log(res)
  124. // console.log('条码类型:' + res.scanType);
  125. // console.log('条码内容:' + res.result);
  126. },
  127. fail:function(e){
  128. console.log(e)
  129. if (e && e.errMsg && e.errMsg.indexOf('scanCode:fail cancel') != -1) {
  130. return;
  131. }
  132. uni.showToast({
  133. title:'扫码失败',
  134. icon:"none"
  135. })
  136. }
  137. });
  138. },
  139. }
  140. }
  141. </script>
  142. <style lang="scss">
  143. .sub{box-sizing: border-box;width: 100%;min-height: 100vh;}
  144. .jhyyes{
  145. display: flex;
  146. justify-content: center;
  147. margin-top: 200upx;
  148. }
  149. .img{
  150. width: 258upx;
  151. height: 251upx;
  152. // margin: auto;
  153. // margin-left: 50%;
  154. // transform: translateX(-50%);
  155. }
  156. .naver{
  157. width: 416rpx;height:84rpx;width: 208px;
  158. height: 42px;
  159. background: linear-gradient(90deg, #A00517, #E93030);
  160. border-radius: 21px;display: flex;align-items: center;justify-content: center;font-size: 30rpx;color: #ffffff;margin:150rpx auto 0;
  161. }
  162. </style>