index.vue 9.3 KB

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