index.vue 7.3 KB

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