payMent.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <view class="container">
  3. <view class="content" v-if="showCon">
  4. <view class="parentBox">
  5. <view class="money_info_box">
  6. <view class="money_info">
  7. <text>{{orderDetail.PriceName}}</text>
  8. <text class="colorCustom">¥{{orderDetail.PayMoney/100}}</text>
  9. </view>
  10. <view class="count_down_box border_top">
  11. 订单已生成,请在<text class="colorCustom">{{endTimesDiy}}</text>内完成支付
  12. </view>
  13. </view>
  14. <view class="time_box">
  15. <view class="time_box_list">
  16. <text>就诊人</text>
  17. <text>{{orderDetail.MemberName}}</text>
  18. </view>
  19. <view class="time_box_list ellipsis" v-if="orderDetail.CardType">
  20. <text>{{orderDetail.CardType == '1'?'就诊卡号':orderDetail.CardType == '16'?'健康卡号':'住院号'}}</text>
  21. <text>{{orderDetail.CardNo}}</text>
  22. </view>
  23. <view class="time_box_list">
  24. <text>收款单位</text>
  25. <text class="bor_bottom border_bottom">{{hosName}}</text>
  26. </view>
  27. <view class="time_box_list">
  28. <text>订单号</text>
  29. <text>{{orderDetail.OrderNum}}</text>
  30. </view>
  31. <view class="time_box_list">
  32. <text>创建时间</text>
  33. <text>{{orderDetail.BeginDate}}</text>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 多个支付方式时显示 -->
  38. <view class="content_pay" v-if="pageConfig.payWay == '2'">
  39. <view class="info_list border_bottom" @click="confirmClick">
  40. <image class="list_circle" :src="iconUrl.treasure_pay"></image>
  41. <view class="list_name">支付宝支付</view>
  42. <image class="public_right_img" :src="iconUrl.icon_right"></image>
  43. </view>
  44. <view class="info_list border_bottom" @click="confirmClick">
  45. <image class="list_circle" :src="iconUrl.wechat_pay"></image>
  46. <view class="list_name">微信支付</view>
  47. <image class="public_right_img" :src="iconUrl.icon_right"></image>
  48. </view>
  49. <view class="info_list border_bottom" @click="confirmClick">
  50. <image class="list_circle" :src="iconUrl.unionpay_pay"></image>
  51. <view class="list_name">银联支付</view>
  52. <image class="public_right_img" :src="iconUrl.icon_right"></image>
  53. </view>
  54. <view class="info_list border_bottom" @click="confirmClick">
  55. <image class="list_circle" :src="iconUrl.cloudf_paylash"></image>
  56. <view class="list_name">云闪付支付</view>
  57. <image class="public_right_img" :src="iconUrl.icon_right"></image>
  58. </view>
  59. <view class="info_list border_bottom" @click="abcWapUnitePay">
  60. <image class="list_circle" :src="iconUrl.pay_abcPay"></image>
  61. <view class="list_name">农行支付</view>
  62. <image class="public_right_img" :src="iconUrl.icon_right"></image>
  63. </view>
  64. </view>
  65. <!-- 单个支付方式时显示 -->
  66. <view class="content_btn" v-if="pageConfig.payWay == '1'">
  67. <view class="btn cancel_btn" @click="cancelClick" v-if="orderDetail.PayState == 0">取消订单</view>
  68. <view class="btn confirm_btn backgroundCustom" :class="{'width100': orderDetail.PayState != 0}" @click="confirmClick">去支付</view>
  69. </view>
  70. </view>
  71. </view>
  72. </template>
  73. <script setup lang="ts">
  74. import { ref, onUnmounted } from 'vue';
  75. import { onLoad, onShow } from '@dcloudio/uni-app';
  76. import { common } from '@/utils';
  77. import icon from '@/utils/icon';
  78. import { pagesPatientFn, getState } from '@/utils';
  79. import { getConfigKey, getUnitePay, payCallBack } from '@/pagesPatient/service/pay/index';
  80. import { orderDetailLocal, orderCancel } from '@/pagesPatient/service/record/index';
  81. const app = getApp();
  82. const iconUrl = ref(icon);
  83. const orderId = ref('');
  84. const currentUser = ref<any>({});
  85. const showCon = ref(false);
  86. const orderDetail = ref<any>({});
  87. const endTimesDiy = ref('');
  88. const hosName = ref('');
  89. const pageConfig = ref<any>({});
  90. let countdown: any = null;
  91. onLoad((options) => {
  92. let config = common.deepCopy(app.globalData.config.pageConfiguration.payMent_config);
  93. hosName.value = app.globalData.hospitalInfo.HospitalAlias;
  94. orderId.value = options.orderId;
  95. currentUser.value = app.globalData.currentUser;
  96. pageConfig.value = config;
  97. main();
  98. });
  99. onUnmounted(() => {
  100. if (countdown) {
  101. clearInterval(countdown);
  102. }
  103. });
  104. const main = async () => {
  105. //获取订单详情
  106. let queryData = {
  107. OrderId: orderId.value
  108. };
  109. let resp = await orderDetailLocal(queryData);
  110. if (!common.isEmpty(resp)) {
  111. resp[0].OrderMemo = resp[0].OrderMemo ? JSON.parse(resp[0].OrderMemo) : {};
  112. orderDetail.value = resp[0];
  113. endTimesDiy.value = common.getexpirationTime(resp[0].EndDate);
  114. showCon.value = true;
  115. // 根据返回信息,修改页面标题
  116. uni.setNavigationBarTitle({
  117. title: resp[0].PriceName,
  118. });
  119. //倒计时
  120. countdown = setInterval(async () => {
  121. let currentTime = endTimesDiy.value;
  122. if (currentTime == '0' || currentTime == 0) {
  123. clearInterval(countdown);
  124. // 倒计时为0时查询订单转态 并取消订单
  125. let respCheck = await orderDetailLocal(queryData);
  126. // 判断不为空 且当前订单转态为待支付中
  127. if (!common.isEmpty(respCheck) && ((respCheck[0].PayState == 0 || respCheck[0].PayState == 1) && respCheck[0].BizState == 0 && respCheck[0].OverState == 0)) {
  128. let orderCancelData = {
  129. OperatorName: respCheck[0].OperatorName,
  130. OperatorId: respCheck[0].OperatorId,
  131. OrderId: respCheck[0].OrderId
  132. };
  133. await orderCancel(orderCancelData, respCheck[0].ServiceId);
  134. }
  135. common.showModal('订单支付超时', async () => {
  136. common.navigateBack(1);
  137. }, {
  138. title: '提示'
  139. });
  140. } else {
  141. endTimesDiy.value = common.getexpirationTime(resp[0].EndDate);
  142. }
  143. }, 1000);
  144. }
  145. };
  146. /**
  147. * 取消订单
  148. */
  149. const cancelClick = () => {
  150. let detail = orderDetail.value;
  151. pagesPatientFn.cancelOrder(detail, () => {
  152. common.navigateBack(1);
  153. });
  154. };
  155. /**
  156. * 去支付
  157. */
  158. const confirmClick = () => {
  159. let detail = orderDetail.value;
  160. common.throttle(async () => {
  161. //统一下单
  162. let configKeyResp = await getConfigKey(detail.OrderId, detail.ServiceId);
  163. if (!common.isEmpty(configKeyResp)) {
  164. // 获取支付配置
  165. let queryData = {
  166. token: uni.getStorageSync('token'),
  167. openId: uni.getStorageSync('openid'),
  168. orderId: detail.OrderId,
  169. priceName: detail.PriceName
  170. };
  171. let unitePayResp = await getUnitePay(queryData); // Note: Original code passed configKeyResp.WxPayConfigKey as second arg, but getUnitePay definition only takes one arg. Assuming definition is correct or handled inside.
  172. // However, looking at the definition in pay/index.ts: export const getUnitePay = async (queryData: any) => { ... }
  173. // It only accepts queryData. The original code passed a second argument which might be ignored or the definition I saw was incomplete.
  174. // Based on strict TS, I should follow the definition.
  175. // 调用JSAPI支付接口,拉起支付后,订单已失效,拦截本次支付
  176. if (!common.isEmpty(unitePayResp)) {
  177. let waunitePayData = await wxPayMent(unitePayResp);
  178. if (waunitePayData) {
  179. let callBackData = {
  180. token: uni.getStorageSync('token'),
  181. orderId: detail.OrderId,
  182. };
  183. // Same here for payCallBack
  184. await payCallBack(callBackData);
  185. common.goToUrl(`/pagesPatient/st1/business/pay/payStateQuery/payStateQuery?orderId=${detail.OrderId}`, {
  186. skipWay: "redirectTo"
  187. });
  188. }
  189. }
  190. }
  191. });
  192. };
  193. /**
  194. * 农行的wap下单
  195. */
  196. const abcWapUnitePay = () => {
  197. let detail = orderDetail.value;
  198. common.throttle(async () => {
  199. //统一下单
  200. let configKeyResp = await getConfigKey(detail.OrderId, detail.ServiceId);
  201. let token = uni.getStorageSync('token');
  202. if (!common.isEmpty(configKeyResp)) {
  203. common.goToUrl(`/pagesPatient/st1/business/pay/payMent/payMentH5?orderId=${detail.OrderId}&priceName=${detail.PriceName}&token=${token}&clientId=${detail.ChannelId}&configKey=${configKeyResp.AbcPayConfigKey}`);
  204. }
  205. });
  206. };
  207. /**
  208. * 调起微信支付
  209. */
  210. const wxPayMent = (data: any) => {
  211. return new Promise(resolve => {
  212. uni.requestPayment({
  213. 'timeStamp': data.timeStamp,
  214. 'nonceStr': data.nonceStr,
  215. 'package': data.package,
  216. 'signType': 'MD5',
  217. 'paySign': data.paySign,
  218. 'success': function (res) {
  219. resolve(res);
  220. },
  221. 'fail': function (res) {
  222. resolve(false);
  223. }
  224. });
  225. });
  226. };
  227. </script>
  228. <style lang="scss" scoped>
  229. .money_info_box {
  230. background: white;
  231. margin-top: 20upx;
  232. display: flex;
  233. flex-direction: column;
  234. justify-content: center;
  235. align-items: center;
  236. }
  237. .money_info {
  238. padding: 98upx 0 72upx 0;
  239. display: flex;
  240. flex-direction: column;
  241. justify-content: center;
  242. align-items: center;
  243. }
  244. .money_info text:nth-child(1) {
  245. font-size: 30upx;
  246. color: #333;
  247. margin-bottom: 20upx;
  248. }
  249. .money_info text:nth-child(2) {
  250. font-size: 56upx;
  251. }
  252. .count_down_box {
  253. width: 100%;
  254. text-align: left;
  255. padding: 40upx 30upx;
  256. box-sizing: border-box;
  257. font-size: 32upx;
  258. color: #333;
  259. }
  260. .count_down_box text {
  261. padding: 0 15upx;
  262. }
  263. .time_box {
  264. background: white;
  265. padding: 30upx 0 30upx 30upx;
  266. margin-top: 20upx;
  267. }
  268. .time_box_list {
  269. margin-bottom: 34upx;
  270. }
  271. .time_box_list:last-child {
  272. margin-top: 30upx;
  273. margin-bottom: 0;
  274. }
  275. .time_box_list text:nth-child(1) {
  276. width: 26%;
  277. display: inline-block;
  278. font-size: 32upx;
  279. color: #999;
  280. }
  281. .time_box_list text:nth-child(2) {
  282. width: 74%;
  283. font-size: 32upx;
  284. color: #333;
  285. }
  286. .bor_bottom {
  287. padding-bottom: 30upx;
  288. display: inline-block;
  289. }
  290. /* 支付方式 */
  291. .content_pay {
  292. padding: 1upx 33upx;
  293. }
  294. .info_list {
  295. position: relative;
  296. display: flex;
  297. align-items: center;
  298. padding: 33upx 0;
  299. }
  300. .content_pay .list_circle {
  301. width: 48upx;
  302. height: 48upx;
  303. }
  304. .content_pay .list_name {
  305. font-size: 32upx;
  306. font-family: Source Han Sans CN;
  307. font-weight: 400;
  308. color: rgba(0, 0, 0, 1);
  309. line-height: 60upx;
  310. margin-left: 31upx;
  311. }
  312. /* 底部按钮 */
  313. .content_btn {
  314. width: 100%;
  315. height: 98upx;
  316. font-size: 32upx;
  317. font-weight: 500;
  318. position: fixed;
  319. bottom: 0;
  320. left: 0;
  321. z-index: 1000;
  322. }
  323. .content_btn .btn {
  324. width: 50%;
  325. height: 98upx;
  326. line-height: 98upx;
  327. float: left;
  328. text-align: center;
  329. justify-items: center;
  330. }
  331. .content_btn .btn.width100 {
  332. width: 100%;
  333. }
  334. .confirm_btn {
  335. background: rgba(41, 207, 140, 1);
  336. color: #fff;
  337. }
  338. .cancel_btn {
  339. color: red;
  340. background-color: #fff;
  341. }
  342. .public_info_item.border_top {
  343. height: 1px;
  344. }
  345. .ellipsis {
  346. white-space: nowrap;
  347. /* 确保文本在一行内显示 */
  348. overflow: hidden;
  349. /* 隐藏溢出的内容 */
  350. text-overflow: ellipsis;
  351. /* 使用省略号表示溢出的文本 */
  352. }
  353. </style>