code.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. // 最好?id=1&name=测试
  48. // console.log(res,9)
  49. console.log(red,999)
  50. return
  51. let result=red.result;
  52. if (typeof result == 'string') {
  53. try {
  54. var obj=JSON.parse(decodeURIComponent(result));
  55. if(typeof obj == 'object' && obj ){
  56. console.log(7)
  57. }else{
  58. console.log(9)
  59. uni.showToast({
  60. title:'扫码查询失败,请检查二维码是否正确',
  61. icon:"none"
  62. })
  63. uni.navigateBack({
  64. delta:1
  65. })
  66. return ;
  67. }
  68. } catch(e) {
  69. uni.navigateBack({
  70. delta:1
  71. })
  72. uni.showToast({
  73. title:'扫码查询失败,请检查二维码是否正确',
  74. icon:"none"
  75. })
  76. return
  77. }
  78. }
  79. var res=JSON.parse(decodeURIComponent(red.result))
  80. // console.log(res)
  81. // return
  82. if(!res.menuId|| !res.phone||!res.idCard){
  83. uni.navigateBack({
  84. delta:1
  85. })
  86. uni.showToast({
  87. title:'扫码查询失败,请检查二维码是否正确',
  88. icon:"none"
  89. })
  90. return
  91. }
  92. // var now=new Date().getTime()
  93. // var oldnow=res.time;
  94. // if(oldnow > now) {
  95. // console.log("二维码在有效期内");
  96. // } else {
  97. // uni.showToast({
  98. // title:'二维码已过期,请重新生成',
  99. // icon:"none"
  100. // })
  101. // return
  102. // }
  103. var businessId=uni.getStorageSync('businessId')
  104. var params={
  105. "businessId": businessId,
  106. "policyId": res.menuId,
  107. "creditPhone": res.phone,
  108. "idCard": res.idCard,
  109. }
  110. that.$http.post('system/record',params).then(red=>{
  111. if(red.code == 200 ) {
  112. uni.redirectTo({
  113. url:"/pages/index/success"
  114. })
  115. }else{
  116. uni.navigateBack({
  117. delta:1
  118. })
  119. uni.showToast({
  120. title: red.msg,
  121. duration: 1000,
  122. icon: 'none'
  123. });
  124. }
  125. })
  126. // console.log(res)
  127. // console.log('条码类型:' + res.scanType);
  128. // console.log('条码内容:' + res.result);
  129. },
  130. fail:function(e){
  131. console.log(e)
  132. if (e && e.errMsg && e.errMsg.indexOf('scanCode:fail cancel') != -1) {
  133. return;
  134. }
  135. uni.showToast({
  136. title:'扫码失败',
  137. icon:"none"
  138. })
  139. }
  140. });
  141. },
  142. }
  143. }
  144. </script>
  145. <style lang="scss">
  146. .sub{box-sizing: border-box;width: 100%;min-height: 100vh;}
  147. .jhyyes{
  148. display: flex;
  149. justify-content: center;
  150. margin-top: 200upx;
  151. }
  152. .img{
  153. width: 258upx;
  154. height: 251upx;
  155. // margin: auto;
  156. // margin-left: 50%;
  157. // transform: translateX(-50%);
  158. }
  159. .naver{
  160. width: 416rpx;height:84rpx;width: 208px;
  161. height: 42px;
  162. background: linear-gradient(90deg, #A00517, #E93030);
  163. border-radius: 21px;display: flex;align-items: center;justify-content: center;font-size: 30rpx;color: #ffffff;margin:150rpx auto 0;
  164. }
  165. </style>