index-copy.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. 余额: {{ fen2yuan(userWallet.balance) }}元
  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 userWallet = computed(() => sheep.$store('user').userWallet);
  84. // 检测支付环境
  85. const state = reactive({
  86. orderType: 'goods', // 订单类型; goods - 商品订单, recharge - 充值订单
  87. orderInfo: {}, // 支付单信息
  88. payStatus: 0, // 0=检测支付环境, -2=未查询到支付单信息, -1=支付已过期, 1=待支付,2=订单已支付
  89. payMethods: [], // 可选的支付方式
  90. payment: '', // 选中的支付方式
  91. });
  92. const onPay = () => {
  93. if (state.payment === '') {
  94. sheep.$helper.toast('请选择支付方式');
  95. return;
  96. }
  97. if (state.payment === 'wallet') {
  98. uni.showModal({
  99. title: '提示',
  100. content: '确定要支付吗?',
  101. success: function (res) {
  102. if (res.confirm) {
  103. sheep.$platform.pay(state.payment, state.orderType, state.orderInfo.id);
  104. }
  105. },
  106. });
  107. } else {
  108. sheep.$platform.pay(state.payment, state.orderType, state.orderInfo.id);
  109. }
  110. };
  111. // 支付文案提示
  112. const payDescText = computed(() => {
  113. if (state.payStatus === 2) {
  114. return '该订单已支付';
  115. }
  116. if (state.payStatus === 1) {
  117. const time = useDurationTime(state.orderInfo.expireTime);
  118. if (time.ms <= 0) {
  119. state.payStatus = -1;
  120. return '';
  121. }
  122. return `剩余支付时间 ${time.h}:${time.m}:${time.s} `;
  123. }
  124. if (state.payStatus === -2) {
  125. return '未查询到支付单信息';
  126. }
  127. return '';
  128. });
  129. // 状态转换:payOrder.status => payStatus
  130. function checkPayStatus() {
  131. if (state.orderInfo.status === 10
  132. || state.orderInfo.status === 20 ) { // 支付成功
  133. state.payStatus = 2;
  134. return;
  135. }
  136. if (state.orderInfo.status === 30) { // 支付关闭
  137. state.payStatus = -1;
  138. return;
  139. }
  140. state.payStatus = 1; // 待支付
  141. }
  142. // 切换支付方式
  143. function onTapPay(e) {
  144. state.payment = e.detail.value;
  145. }
  146. // 设置支付订单信息
  147. async function setOrder(id) {
  148. // 获得支付订单信息
  149. const { data, code } = await PayOrderApi.getOrder(id);
  150. if (code !== 0 || !data) {
  151. state.payStatus = -2;
  152. return;
  153. }
  154. state.orderInfo = data;
  155. // 获得支付方式
  156. await setPayMethods();
  157. // 设置支付状态
  158. checkPayStatus();
  159. }
  160. // 设置支付订单信息
  161. async function setPayOrder(id) {
  162. // 获得支付订单信息
  163. const { data, code } = await PayOrderApi.getPayOrder(id);
  164. if (code !== 0 || !data) {
  165. state.payStatus = -2;
  166. return;
  167. }
  168. state.orderInfo = data;
  169. // 获得支付方式
  170. await setPayMethods();
  171. // 设置支付状态
  172. checkPayStatus();
  173. }
  174. // 获得支付方式
  175. async function setPayMethods() {
  176. const { data, code } = await PayChannelApi.getEnableChannelCodeList(state.orderInfo.appId)
  177. if (code !== 0) {
  178. return
  179. }
  180. state.payMethods = getPayMethods(data)
  181. }
  182. onLoad((options) => {
  183. if (sheep.$platform.name === 'WechatOfficialAccount'
  184. && sheep.$platform.os === 'ios'
  185. && !sheep.$platform.landingPage.includes('pages/pay/index')) {
  186. location.reload();
  187. return;
  188. }
  189. // 获得支付订单信息
  190. // console.log(options)
  191. let id = options.id;
  192. if (options.orderType) {
  193. state.orderType = options.orderType;
  194. }
  195. if(options.openType == 2){
  196. setPayOrder(id)
  197. }else{
  198. // console.log(123)
  199. setOrder(id);
  200. }
  201. // 刷新钱包的缓存
  202. sheep.$store('user').getWallet();
  203. });
  204. </script>
  205. <style lang="scss" scoped>
  206. .pay-icon {
  207. width: 36rpx;
  208. height: 36rpx;
  209. margin-right: 26rpx;
  210. }
  211. .ss-modal-box {
  212. // max-height: 1000rpx;
  213. .modal-header {
  214. position: relative;
  215. padding: 60rpx 20rpx 40rpx;
  216. .money-text {
  217. color: $red;
  218. font-size: 46rpx;
  219. font-weight: bold;
  220. font-family: OPPOSANS;
  221. &::before {
  222. content: '¥';
  223. font-size: 30rpx;
  224. }
  225. }
  226. .time-text {
  227. font-size: 26rpx;
  228. color: $gray-b;
  229. }
  230. .close-icon {
  231. position: absolute;
  232. top: 10rpx;
  233. right: 20rpx;
  234. font-size: 46rpx;
  235. opacity: 0.2;
  236. }
  237. }
  238. .modal-content {
  239. overflow-y: auto;
  240. .pay-title {
  241. font-size: 26rpx;
  242. font-weight: 500;
  243. color: #333333;
  244. }
  245. .pay-tip {
  246. font-size: 26rpx;
  247. color: #bbbbbb;
  248. }
  249. .pay-item {
  250. height: 86rpx;
  251. }
  252. .disabled-pay-item {
  253. .pay-title {
  254. color: #999999;
  255. }
  256. }
  257. .userInfo-money {
  258. font-size: 26rpx;
  259. color: #bbbbbb;
  260. line-height: normal;
  261. }
  262. }
  263. .save-btn {
  264. width: 710rpx;
  265. height: 80rpx;
  266. border-radius: 40rpx;
  267. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  268. color: $white;
  269. }
  270. .disabled-btn {
  271. background: #e5e5e5;
  272. color: #999999;
  273. }
  274. .past-due-btn {
  275. width: 710rpx;
  276. height: 80rpx;
  277. border-radius: 40rpx;
  278. background-color: #999;
  279. color: #fff;
  280. }
  281. }
  282. </style>