index.vue 9.4 KB

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