index.vue 9.3 KB

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