code.vue 4.0 KB

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