index.vue 9.1 KB

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