index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="verify iphone-safe-area">
  3. <!-- #ifdef MP-WEIXIN -->
  4. <view class="scan">
  5. <!-- <view class="recode color-base-text" @click="$util.redirectTo('/pages/verify/records')">核销记录</view> -->
  6. <image :src="$util.img('/upload/uniapp/shop_uniapp/verify/verify.png')" mode="aspectFit" @click="scanCode()"></image>
  7. <view class="tip color-tip">点击此区域扫描核销码</view>
  8. </view>
  9. <!-- #endif -->
  10. <view class="menu_item">
  11. <view class="menu_title">
  12. <view class="">
  13. <text class="line color-base-bg margin-right"></text>
  14. <text>输入核销码</text>
  15. </view>
  16. <view class="recode color-base-text" @click="$util.redirectTo('/pages/verify/records')">核销记录</view>
  17. </view>
  18. <view class="menu_content">
  19. <input placeholder="请输入核销码" v-model="verify_code" class="uni-input" @confirm="search()" />
  20. <button type="primary" :disabled="verify_code == ''" @click="search">提交核销码</button>
  21. </view>
  22. </view>
  23. <view v-if="search_info">
  24. <view class="list">
  25. <view class="goods" v-for="(item_c, index) in item_array" :key="index">
  26. <image class="img" :src="$util.img(item_c.img)" mode="aspectFit" @error="imgError(index)"></image>
  27. <view class="info">
  28. <view class="goods_name">{{ item_c.name }}</view>
  29. <view class="flex">
  30. <view class="flex_left">x{{ item_c.num }}</view>
  31. <view class="flex_right">
  32. <text class="font-size-tag">¥</text>
  33. {{ item_c.price }}
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="other_info" v-for="(item_r, index_r) in remark_array" :key="index_r">{{ item_r.title }}:{{ item_r.value }}</view>
  39. </view>
  40. <button type="primary" @click="verify">验证使用</button>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import Weixin from '@/common/js/wx-jssdk.js';
  46. export default {
  47. data() {
  48. return {
  49. verify_code: '',
  50. search_info: '',
  51. item_array: [],
  52. remark_array: []
  53. };
  54. },
  55. onShow() {
  56. if (!this.$util.checkToken('/pages/verify/index')) return;
  57. },
  58. methods: {
  59. search() {
  60. this.$api.sendRequest({
  61. url: '/shopapi/verify/verifyCard',
  62. data: {
  63. verify_code: this.verify_code
  64. },
  65. success: res => {
  66. if (res.code >= 0 && res.data) {
  67. this.search_info = res.data;
  68. this.item_array = res.data.data.item_array;
  69. this.remark_array = res.data.data.remark_array;
  70. } else {
  71. this.remark_array = [];
  72. this.item_array = [];
  73. this.$util.showToast({
  74. title: res.message
  75. });
  76. }
  77. }
  78. });
  79. },
  80. verify() {
  81. this.$api.sendRequest({
  82. url: '/shopapi/verify/verify',
  83. data: {
  84. verify_code: this.verify_code
  85. },
  86. success: res => {
  87. var that = this;
  88. this.$util.showToast({
  89. title: res.message
  90. });
  91. if (res.code >= 0) {
  92. setTimeout(() => {
  93. that.$util.redirectTo('/pages/verify/records');
  94. }, 1000);
  95. }
  96. }
  97. });
  98. },
  99. scanCode() {
  100. // #ifdef H5
  101. if (!this.$util.isWeiXin()) {
  102. this.$util.showToast({
  103. title: 'H5端不支持扫码核销'
  104. });
  105. return;
  106. }
  107. // #endif
  108. // #ifdef MP
  109. uni.scanCode({
  110. onlyFromCamera: true,
  111. success: res => {
  112. if (res.scanType == 'WX_CODE' && res.errMsg == 'scanCode:ok') {
  113. try {
  114. var code = this.getQueryVariable(res.path,'code');
  115. this.verify_code = code;
  116. this.search();
  117. } catch (e) {
  118. this.$util.showToast({
  119. title: e.message
  120. });
  121. }
  122. }else if(res.scanType == 'QR_CODE' && res.errMsg == 'scanCode:ok'){
  123. var code = this.getQueryVariable(res.result,'code');
  124. this.verify_code = code;
  125. this.search();
  126. } else {
  127. this.$util.showToast({
  128. title: res.errorMsg?res.errorMsg:'请扫描小程序二维码'
  129. });
  130. }
  131. }
  132. });
  133. // #endif
  134. // #ifdef H5
  135. if (this.$util.isWeiXin()) {
  136. if (uni.getSystemInfoSync().platform == 'ios') {
  137. var url = uni.getStorageSync('initUrl');
  138. } else {
  139. var url = location.href;
  140. }
  141. this.$api.sendRequest({
  142. url: '/wechat/api/wechat/jssdkconfig',
  143. data: {
  144. url: url
  145. },
  146. success: jssdkRes => {
  147. if (jssdkRes.code == 0) {
  148. var wxJS = new Weixin();
  149. wxJS.init(jssdkRes.data);
  150. wxJS.scanQRCode(res => {
  151. if (res.resultStr) {
  152. location.href = res.resultStr;
  153. }
  154. });
  155. } else {
  156. this.$util.showToast({
  157. title: jssdkRes.message
  158. });
  159. }
  160. }
  161. });
  162. }
  163. // #endif
  164. },
  165. getQueryVariable(url_val,name)
  166. {
  167.     var url = url_val;
  168.     var arrObj = url.split("?");
  169.     if (arrObj.length > 1) {
  170.       var arrPara = arrObj[1].split("&");
  171.       var arr;
  172.       for (var i = 0; i < arrPara.length; i++) {
  173.         arr = arrPara[i].split("=");
  174.         if (arr != null && arr[0] == name) {
  175.           return arr[1];
  176.         }
  177.       }
  178.       return "";
  179.     }
  180.     else {
  181.       return "";
  182.     }
  183. },
  184. imgError(index) {
  185. this.item_array[index].img = this.$util.getDefaultImage().default_goods_img;
  186. this.$forceUpdate();
  187. }
  188. }
  189. };
  190. </script>
  191. <style lang="scss">
  192. .verify {
  193. padding: 1px 0;
  194. }
  195. .scan {
  196. text-align: center;
  197. padding: 30rpx;
  198. margin: 30rpx $margin-both;
  199. background-color: #fff;
  200. border-radius: $border-radius;
  201. image {
  202. width: 300rpx;
  203. height: 300rpx;
  204. }
  205. .recode {
  206. text-align: right;
  207. margin-bottom: 30rpx;
  208. }
  209. .tip {
  210. margin-top: 20rpx;
  211. }
  212. }
  213. .menu_item {
  214. margin: 30rpx $margin-both 0;
  215. padding-top: 25rpx;
  216. padding-bottom: 30rpx;
  217. .menu_title {
  218. display: flex;
  219. flex-direction: row;
  220. justify-content: space-between;
  221. align-items: center;
  222. font-size: $font-size-toolbar;
  223. font-weight: bold;
  224. margin-bottom: 10rpx;
  225. .line {
  226. display: inline-block;
  227. height: 28rpx;
  228. width: 4rpx;
  229. border-radius: 4rpx;
  230. }
  231. }
  232. .menu_content {
  233. display: flex;
  234. align-items: center;
  235. margin-top: 20rpx;
  236. background-color: #fff;
  237. border-radius: $border-radius;
  238. .uni-input {
  239. flex: 1;
  240. padding: 0 30rpx;
  241. }
  242. button {
  243. border-radius: $border-radius;
  244. border-top-left-radius: 0;
  245. border-bottom-left-radius: 0;
  246. margin: 0;
  247. }
  248. }
  249. }
  250. .list {
  251. background-color: #fff;
  252. margin: 0 $margin-both $margin-both;
  253. padding: 0 30rpx 20rpx;
  254. border-radius: $border-radius;
  255. .title {
  256. display: flex;
  257. align-items: center;
  258. padding: 20rpx 0;
  259. font-size: $font-size-tag;
  260. border-bottom: 1px solid $color-line;
  261. .time {
  262. flex: 1;
  263. color: $color-tip;
  264. }
  265. .status {
  266. margin-left: 30rpx;
  267. }
  268. }
  269. .goods {
  270. display: flex;
  271. padding: 30rpx 0;
  272. .img {
  273. height: 140rpx;
  274. width: 140rpx;
  275. min-width: 140rpx;
  276. }
  277. .info {
  278. flex: 1;
  279. margin-left: 30rpx;
  280. display: flex;
  281. flex-direction: column;
  282. justify-content: space-between;
  283. .goods_name {
  284. overflow: hidden;
  285. text-overflow: ellipsis;
  286. display: -webkit-box; //作为弹性伸缩盒子模型显示。
  287. -webkit-box-orient: vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
  288. -webkit-line-clamp: 2; //
  289. line-height: 1.5;
  290. }
  291. .flex {
  292. margin-top: 10rpx;
  293. display: flex;
  294. justify-content: space-between;
  295. align-items: baseline;
  296. .flex_left {
  297. font-size: $font-size-tag;
  298. color: $color-tip;
  299. }
  300. }
  301. }
  302. }
  303. .other_info {
  304. color: $color-tip;
  305. font-size: $font-size-tag;
  306. }
  307. }
  308. </style>