index.vue 8.8 KB

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