index.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <!-- 收银台 -->
  2. <template>
  3. <s-layout title="收银台">
  4. <view class="bg-white ss-modal-box ss-flex-col">
  5. <view class="modal-header ss-flex-col ss-col-center ss-row-center">
  6. <text class="modal-title ss-m-b-30">收银台</text>
  7. <view class="money-box ss-m-b-20">
  8. <text class="money-text">{{ state.orderInfo.pay_fee }}</text>
  9. </view>
  10. <view class="time-text">
  11. <text>{{ payDescText }}</text>
  12. </view>
  13. </view>
  14. <view class="modal-content ss-flex-1">
  15. <view class="pay-title ss-p-l-30 ss-m-y-30">选择支付方式</view>
  16. <view class="pay-type-item border-bottom" v-for="item in payMethods" :key="item.title">
  17. <view
  18. class="pay-item ss-flex ss-col-center ss-row-between ss-p-x-30"
  19. v-if="
  20. allowedPayment.includes(item.value) &&
  21. !(state.orderType === 'recharge' && item.value === 'money')
  22. "
  23. @tap="state.payment = item.value"
  24. >
  25. <view class="ss-flex ss-col-center">
  26. <image class="pay-icon" :src="sheep.$url.static(item.icon)" mode="aspectFit"></image>
  27. <text class="pay-title">{{ item.title }}</text>
  28. </view>
  29. <view class="check-box ss-flex ss-col-center ss-p-l-10">
  30. <view class="userInfo-money ss-m-r-10" v-if="item.value == 'money'">
  31. 余额: {{ userInfo.money }}元
  32. </view>
  33. <radio
  34. :value="item.value"
  35. color="var(--ui-BG-Main)"
  36. style="transform: scale(0.8)"
  37. :checked="state.payment === item.value"
  38. />
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- 工具 -->
  44. <view class="modal-footer ss-flex ss-row-center ss-col-center ss-m-t-80 ss-m-b-40">
  45. <button v-if="state.payStatus === 0" class="ss-reset-button past-due-btn">
  46. 检测支付环境中
  47. </button>
  48. <button v-else-if="state.payStatus === -1" class="ss-reset-button past-due-btn" disabled>
  49. 支付已过期
  50. </button>
  51. <button
  52. v-else
  53. class="ss-reset-button save-btn"
  54. @tap="onPay"
  55. :disabled="state.payStatus !== 1"
  56. :class="{ 'disabled-btn': state.payStatus !== 1 }"
  57. >
  58. 立即支付
  59. </button>
  60. </view>
  61. </view>
  62. </s-layout>
  63. </template>
  64. <script setup>
  65. import { computed, reactive } from 'vue';
  66. import { onLoad } from '@dcloudio/uni-app';
  67. import sheep from '@/sheep';
  68. import { useDurationTime } from '@/sheep/hooks/useGoods';
  69. const userInfo = computed(() => sheep.$store('user').userInfo);
  70. // 检测支付环境
  71. //
  72. const state = reactive({
  73. orderType: 'goods',
  74. payment: '',
  75. orderInfo: {},
  76. payStatus: 0, // 0=检测支付环境, -2=未查询到支付单信息, -1=支付已过期, 1=待支付,2=订单已支付
  77. });
  78. const allowedPayment = computed(() => sheep.$store('app').platform.payment);
  79. const payMethods = [
  80. {
  81. icon: '/static/img/shop/wechat_pay.png',
  82. title: '微信支付',
  83. value: 'wechat',
  84. },
  85. {
  86. icon: '/static/img/shop/ali_pay.png',
  87. title: '支付宝支付',
  88. value: 'alipay',
  89. },
  90. {
  91. icon: '/static/img/shop/wallet_pay.png',
  92. title: '余额支付',
  93. value: 'money',
  94. },
  95. {
  96. icon: '/static/img/shop/apple_pay.png',
  97. title: 'Apple Pay',
  98. value: 'apple',
  99. },
  100. ];
  101. const onPay = () => {
  102. if (state.payment === '') {
  103. sheep.$helper.toast('请选择支付方式');
  104. return;
  105. }
  106. if (state.payment === 'money') {
  107. uni.showModal({
  108. title: '提示',
  109. content: '确定要支付吗?',
  110. success: function (res) {
  111. if (res.confirm) {
  112. sheep.$platform.pay(state.payment, state.orderType, state.orderInfo.order_sn);
  113. }
  114. },
  115. });
  116. } else {
  117. sheep.$platform.pay(state.payment, state.orderType, state.orderInfo.order_sn);
  118. }
  119. };
  120. const payDescText = computed(() => {
  121. if (state.payStatus === 2) {
  122. return '该订单已支付';
  123. }
  124. if (state.payStatus === 1 && state.orderInfo.ext.expired_time !== 0) {
  125. const time = useDurationTime(state.orderInfo.ext.expired_time);
  126. if (time.ms <= 0) {
  127. state.payStatus = -1;
  128. return '';
  129. }
  130. return `剩余支付时间 ${time.h}:${time.m}:${time.s} `;
  131. }
  132. if (state.payStatus === -2) {
  133. return '未查询到支付单信息';
  134. }
  135. return '';
  136. });
  137. function checkPayStatus() {
  138. if (state.orderInfo.status === 'unpaid') {
  139. state.payStatus = 1;
  140. return;
  141. }
  142. if (state.orderInfo.status === 'closed') {
  143. state.payStatus = -1;
  144. return;
  145. }
  146. state.payStatus = 2;
  147. }
  148. async function setRechargeOrder(id) {
  149. const { data, error } = await sheep.$api.trade.order(id);
  150. if (error === 0) {
  151. state.orderInfo = data;
  152. checkPayStatus();
  153. } else {
  154. state.payStatus = -2;
  155. }
  156. }
  157. async function setGoodsOrder(id) {
  158. const { data, error } = await sheep.$api.order.detail(id);
  159. if (error === 0) {
  160. state.orderInfo = data;
  161. checkPayStatus();
  162. } else {
  163. state.payStatus = -2;
  164. }
  165. }
  166. onLoad((options) => {
  167. if (
  168. sheep.$platform.name === 'WechatOfficialAccount' &&
  169. sheep.$platform.os === 'ios' &&
  170. !sheep.$platform.landingPage.includes('pages/pay/index')
  171. ) {
  172. location.reload();
  173. return;
  174. }
  175. let id = '';
  176. if (options.orderSN) {
  177. id = options.orderSN;
  178. }
  179. if (options.id) {
  180. id = options.id;
  181. }
  182. if (options.type === 'recharge') {
  183. state.orderType = 'recharge';
  184. // 充值订单
  185. setRechargeOrder(id);
  186. } else {
  187. // 商品订单
  188. setGoodsOrder(id);
  189. }
  190. });
  191. </script>
  192. <style lang="scss" scoped>
  193. .pay-icon {
  194. width: 36rpx;
  195. height: 36rpx;
  196. margin-right: 26rpx;
  197. }
  198. .ss-modal-box {
  199. // max-height: 1000rpx;
  200. .modal-header {
  201. position: relative;
  202. padding: 60rpx 20rpx 40rpx;
  203. .modal-title {
  204. font-size: 32rpx;
  205. font-weight: 500;
  206. }
  207. .money-text {
  208. color: $red;
  209. font-size: 46rpx;
  210. font-weight: bold;
  211. font-family: OPPOSANS;
  212. &::before {
  213. content: '¥';
  214. font-size: 30rpx;
  215. }
  216. }
  217. .time-text {
  218. font-size: 26rpx;
  219. color: $gray-b;
  220. }
  221. .close-icon {
  222. position: absolute;
  223. top: 10rpx;
  224. right: 20rpx;
  225. font-size: 46rpx;
  226. opacity: 0.2;
  227. }
  228. }
  229. .modal-content {
  230. overflow-y: auto;
  231. .pay-title {
  232. font-size: 26rpx;
  233. font-weight: 500;
  234. color: #333333;
  235. }
  236. .pay-tip {
  237. font-size: 26rpx;
  238. color: #bbbbbb;
  239. }
  240. .pay-item {
  241. height: 86rpx;
  242. }
  243. .userInfo-money {
  244. font-size: 26rpx;
  245. color: #bbbbbb;
  246. line-height: normal;
  247. }
  248. }
  249. .save-btn {
  250. width: 710rpx;
  251. height: 80rpx;
  252. border-radius: 40rpx;
  253. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  254. color: $white;
  255. }
  256. .disabled-btn {
  257. background: #e5e5e5;
  258. color: #999999;
  259. }
  260. .past-due-btn {
  261. width: 710rpx;
  262. height: 80rpx;
  263. border-radius: 40rpx;
  264. background-color: #999;
  265. color: #fff;
  266. }
  267. }
  268. </style>