index.vue 9.4 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="
  22. allowedPayment.includes(item.value) &&
  23. !(state.orderType === 'recharge' && item.value === 'money')
  24. "
  25. >
  26. <view class="ss-flex ss-col-center">
  27. <image
  28. class="pay-icon"
  29. v-if="item.disabled"
  30. :src="sheep.$url.static('/static/img/shop/pay/cod_disabled.png')"
  31. mode="aspectFit"
  32. ></image>
  33. <image
  34. class="pay-icon"
  35. v-else
  36. :src="sheep.$url.static(item.icon)"
  37. mode="aspectFit"
  38. ></image>
  39. <text class="pay-title">{{ item.title }}</text>
  40. </view>
  41. <view class="check-box ss-flex ss-col-center ss-p-l-10">
  42. <view class="userInfo-money ss-m-r-10" v-if="item.value == 'money'">
  43. 余额: {{ userInfo.money }}元
  44. </view>
  45. <view
  46. class="userInfo-money ss-m-r-10"
  47. v-if="item.value == 'offline' && item.disabled"
  48. >
  49. 部分商品不支持
  50. </view>
  51. <radio
  52. :value="item.value"
  53. color="var(--ui-BG-Main)"
  54. style="transform: scale(0.8)"
  55. :disabled="item.disabled"
  56. :checked="state.payment === item.value"
  57. />
  58. </view>
  59. </view>
  60. </label>
  61. </radio-group>
  62. </view>
  63. <!-- 工具 -->
  64. <view class="modal-footer ss-flex ss-row-center ss-col-center ss-m-t-80 ss-m-b-40">
  65. <button v-if="state.payStatus === 0" class="ss-reset-button past-due-btn">
  66. 检测支付环境中
  67. </button>
  68. <button v-else-if="state.payStatus === -1" class="ss-reset-button past-due-btn" disabled>
  69. 支付已过期
  70. </button>
  71. <button
  72. v-else
  73. class="ss-reset-button save-btn"
  74. @tap="onPay"
  75. :disabled="state.payStatus !== 1"
  76. :class="{ 'disabled-btn': state.payStatus !== 1 }"
  77. >
  78. 立即支付
  79. </button>
  80. </view>
  81. </view>
  82. </s-layout>
  83. </template>
  84. <script setup>
  85. import { computed, reactive } from 'vue';
  86. import { onLoad } from '@dcloudio/uni-app';
  87. import sheep from '@/sheep';
  88. import { useDurationTime } from '@/sheep/hooks/useGoods';
  89. const userInfo = computed(() => sheep.$store('user').userInfo);
  90. // 检测支付环境
  91. //
  92. const state = reactive({
  93. orderType: 'goods',
  94. payment: '',
  95. orderInfo: {},
  96. payStatus: 0, // 0=检测支付环境, -2=未查询到支付单信息, -1=支付已过期, 1=待支付,2=订单已支付
  97. payMethods: [],
  98. });
  99. const allowedPayment = computed(() => sheep.$store('app').platform.payment);
  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. payMethods.forEach((item, index, array) => {
  197. if (item.value === 'offline') {
  198. array.splice(index, 1);
  199. }
  200. });
  201. state.payMethods = payMethods;
  202. checkPayStatus();
  203. } else {
  204. state.payStatus = -2;
  205. }
  206. }
  207. async function setGoodsOrder(id) {
  208. const { data, error } = await sheep.$api.order.detail(id);
  209. if (error === 0) {
  210. state.orderInfo = data;
  211. if (state.orderInfo.ext.offline_status === 'none') {
  212. payMethods.forEach((item, index, array) => {
  213. if (item.value === 'offline') {
  214. array.splice(index, 1);
  215. }
  216. });
  217. } else if (state.orderInfo.ext.offline_status === 'disabled') {
  218. payMethods.forEach((item) => {
  219. if (item.value === 'offline') {
  220. item.disabled = true;
  221. }
  222. });
  223. }
  224. state.payMethods = payMethods;
  225. checkPayStatus();
  226. } else {
  227. state.payStatus = -2;
  228. }
  229. }
  230. onLoad((options) => {
  231. if (
  232. sheep.$platform.name === 'WechatOfficialAccount' &&
  233. sheep.$platform.os === 'ios' &&
  234. !sheep.$platform.landingPage.includes('pages/pay/index')
  235. ) {
  236. location.reload();
  237. return;
  238. }
  239. let id = '';
  240. if (options.orderSN) {
  241. id = options.orderSN;
  242. }
  243. if (options.id) {
  244. id = options.id;
  245. }
  246. if (options.type === 'recharge') {
  247. state.orderType = 'recharge';
  248. // 充值订单
  249. setRechargeOrder(id);
  250. } else {
  251. // 商品订单
  252. setGoodsOrder(id);
  253. }
  254. });
  255. </script>
  256. <style lang="scss" scoped>
  257. .pay-icon {
  258. width: 36rpx;
  259. height: 36rpx;
  260. margin-right: 26rpx;
  261. }
  262. .ss-modal-box {
  263. // max-height: 1000rpx;
  264. .modal-header {
  265. position: relative;
  266. padding: 60rpx 20rpx 40rpx;
  267. .modal-title {
  268. font-size: 32rpx;
  269. font-weight: 500;
  270. }
  271. .money-text {
  272. color: $red;
  273. font-size: 46rpx;
  274. font-weight: bold;
  275. font-family: OPPOSANS;
  276. &::before {
  277. content: '¥';
  278. font-size: 30rpx;
  279. }
  280. }
  281. .time-text {
  282. font-size: 26rpx;
  283. color: $gray-b;
  284. }
  285. .close-icon {
  286. position: absolute;
  287. top: 10rpx;
  288. right: 20rpx;
  289. font-size: 46rpx;
  290. opacity: 0.2;
  291. }
  292. }
  293. .modal-content {
  294. overflow-y: auto;
  295. .pay-title {
  296. font-size: 26rpx;
  297. font-weight: 500;
  298. color: #333333;
  299. }
  300. .pay-tip {
  301. font-size: 26rpx;
  302. color: #bbbbbb;
  303. }
  304. .pay-item {
  305. height: 86rpx;
  306. }
  307. .disabled-pay-item {
  308. .pay-title {
  309. color: #999999;
  310. }
  311. }
  312. .userInfo-money {
  313. font-size: 26rpx;
  314. color: #bbbbbb;
  315. line-height: normal;
  316. }
  317. }
  318. .save-btn {
  319. width: 710rpx;
  320. height: 80rpx;
  321. border-radius: 40rpx;
  322. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  323. color: $white;
  324. }
  325. .disabled-btn {
  326. background: #e5e5e5;
  327. color: #999999;
  328. }
  329. .past-due-btn {
  330. width: 710rpx;
  331. height: 80rpx;
  332. border-radius: 40rpx;
  333. background-color: #999;
  334. color: #fff;
  335. }
  336. }
  337. </style>