index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view class="container">
  3. <view class="header">
  4. <image mode="aspectFit" :src="`/static/order/writeOffBg.jpg`" @click="openQRCode" />
  5. </view>
  6. <view class="cells">
  7. <view class="cell">
  8. <view class="input">
  9. <input type="number" placeholder="请输入核销码" v-model="verify_code" />
  10. </view>
  11. </view>
  12. </view>
  13. <view class="verification-btn-container">
  14. <button class="verification-btn" @click="storeCancellation">
  15. <text>立即核销</text>
  16. </button>
  17. <button class="verification-btn" v-if="$deviceType !== 'weixin'" @click="openQRCode">
  18. <text>扫码核销</text>
  19. </button>
  20. </view>
  21. <tab-bar :active="1"></tab-bar>
  22. </view>
  23. </template>
  24. <script>
  25. import TabBar from '../../components/tab-bar';
  26. import { mapState } from 'vuex';
  27. export default {
  28. components: {
  29. TabBar
  30. },
  31. computed: {
  32. ...mapState(['token'])
  33. },
  34. data() {
  35. return {
  36. orderInfo: {},
  37. verify_code: '',
  38. id: undefined,
  39. };
  40. },
  41. methods: {
  42. storeCancellation() {
  43. let ref = /^[a-zA-Z0-9]{6}$/; // Changed to allow alphanumeric and 6 characters
  44. if (!this.verify_code) {
  45. uni.showToast({
  46. title: '请输入核销码',
  47. icon: 'none',
  48. duration: 2000,
  49. });
  50. return;
  51. }
  52. if (!ref.test(this.verify_code)) {
  53. uni.showToast({
  54. title: '请输入6位数字或字母的核销码',
  55. icon: 'none',
  56. duration: 2000,
  57. });
  58. return;
  59. }
  60. uni.showLoading({
  61. title: '查询中',
  62. });
  63. this.request('get', 'order/storeOrder/completePickup', this.token, {id: this.id,verifyCode:this.verify_code})
  64. .then(res => {
  65. uni.hideLoading();
  66. this.orderInfo = res.data;
  67. uni.showToast({
  68. title: res.msg,
  69. icon: 'success',
  70. duration: 5000,
  71. });
  72. })
  73. .catch(error => {
  74. uni.hideLoading();
  75. uni.showToast({
  76. title: error.msg || error.response.data.msg || error.response.data.message,
  77. icon: 'none',
  78. duration: 2000,
  79. });
  80. });
  81. },
  82. openQRCode() {
  83. let that = this;
  84. uni.scanCode({
  85. success: res => {
  86. var result = res.result;
  87. if (result) {
  88. // Split the result by underscore
  89. const parts = result.split('_');
  90. if (parts.length === 2) {
  91. // First part is order ID, second part is verification code
  92. that.id = parts[0];
  93. that.verify_code = parts[1];
  94. that.storeCancellation();
  95. } else {
  96. // Fallback for simple verification codes
  97. that.verify_code = result;
  98. that.storeCancellation();
  99. }
  100. } else {
  101. uni.showToast({
  102. title: '没有扫描到什么!',
  103. icon: 'none',
  104. duration: 2000,
  105. });
  106. }
  107. },
  108. });
  109. },
  110. },
  111. };
  112. </script>
  113. <style lang="scss" scoped>
  114. .container {
  115. line-height: 1.2;
  116. position: relative;
  117. min-height: 100vh;
  118. }
  119. .header {
  120. width: 100%;
  121. height: 300rpx;
  122. image {
  123. width: 100%;
  124. height: 300rpx;
  125. }
  126. }
  127. .cells {
  128. padding: 0 $uni-spacing-row-lg;
  129. margin-top: 20rpx;
  130. .cell {
  131. display: flex;
  132. align-items: center;
  133. height: 110rpx;
  134. font-size: $uni-font-size-base;
  135. padding: 0 $uni-spacing-row-lg;
  136. border-bottom: 1rpx solid $uni-border-color;
  137. background-color: $uni-bg-color;
  138. border-radius: 14rpx;
  139. }
  140. .input {
  141. width: 100%;
  142. input {
  143. width: 100%;
  144. text-align: center;
  145. font-size: $uni-font-size-lg;
  146. color: $font-color-black;
  147. }
  148. }
  149. }
  150. /* Verification Button Styles */
  151. .verification-btn-container {
  152. padding: 30rpx $uni-spacing-row-lg;
  153. display: flex;
  154. flex-direction: column;
  155. gap: 20rpx;
  156. .verification-btn {
  157. display: flex;
  158. align-items: center;
  159. justify-content: center;
  160. height: 90rpx;
  161. line-height: 90rpx;
  162. font-size: $uni-font-size-lg;
  163. color: #fff;
  164. background-color: $uni-color-primary;
  165. border-radius: 45rpx;
  166. border: none;
  167. width: 100%;
  168. &:last-child {
  169. background-color: $uni-color-warning;
  170. }
  171. }
  172. button::after {
  173. border: none;
  174. }
  175. }
  176. </style>