packagePayment.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template>
  2. <view>
  3. <view class="inner-box" v-if="order!=null">
  4. <!-- 时间、价格 -->
  5. <view class="time-price">
  6. <text class="time">订单金额</text>
  7. <view class="price-box">
  8. <text class="unit">¥</text>
  9. <text class="num" >{{order.payMoney.toFixed(2)}}</text>
  10. </view>
  11. </view>
  12. <!-- 订单详情查看 -->
  13. <view class="order-info">
  14. <view class="title">订单信息</view>
  15. <view class="item">
  16. <text class="label">订单编号</text>
  17. <view class="sn-box">
  18. <text class="text">{{order.orderSn}}</text>
  19. <view class="copy-btn" @click="copyTest(order.orderSn)">复制</view>
  20. </view>
  21. </view>
  22. <view class="item">
  23. <text class="label">下单时间</text>
  24. <text class="text">{{order.createTime}}</text>
  25. </view>
  26. </view>
  27. <view class="order-info" v-if="isShow==0&&splitOrderTypes&&splitOrderTypes.length>0">
  28. <view class="label">配送方式</view>
  29. <radio-group @change="splitOrderTypeChange">
  30. <view class="item" v-for="(it, i) in splitOrderTypes" :key="i">
  31. <view class="left" >
  32. <text class="title">{{it.dictLabel}}</text>
  33. </view>
  34. <label>
  35. <radio :value="it.dictValue" :checked="splitOrderType==it.dictValue" />
  36. </label>
  37. </view>
  38. </radio-group>
  39. </view>
  40. <view class="tips" v-if="isShow==0&&(splitOrderType==2||splitOrderType==3)">
  41. <checkbox :checked="isAgreement" @click="handleAgreement()" />
  42. <view @click="handleAgreement()">同意</view>
  43. <view class="btn" @click.stop="openContent('splitOrderAgreement')">《互联网药品委托保存协议》</view>
  44. </view>
  45. </view>
  46. <!-- 底部按钮 -->
  47. <view class="btn-box">
  48. <view class="btn" v-if="order!=null" @click="payOrder()">立即支付</view>
  49. <!-- <view class="btn1" v-if="order!=null" >
  50. 亲友代付
  51. <button class='share-btn' data-name="shareBtn" open-type="share">
  52. </button>
  53. </view> -->
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import {getDictByKey} from '@/api/common'
  59. import {getPackageOrderById,payment} from '@/api/packageOrder'
  60. export default {
  61. data() {
  62. return {
  63. payMethod:null,
  64. orderId:null,
  65. order:null,
  66. splitOrderType: 1,
  67. splitOrderTypes: [],
  68. isShow: 1,
  69. isAgreement:true
  70. }
  71. },
  72. onLoad(option) {
  73. if(option.scene) {
  74. const scene = decodeURIComponent(option.scene);
  75. this.orderId= scene.split("orderId=")[1];
  76. } else {
  77. this.orderId=option.orderId;
  78. }
  79. this.payMethod=option.payMethod;
  80. },
  81. onShow() {
  82. this.getPackageOrderById();
  83. },
  84. methods: {
  85. openContent(type) {
  86. uni.navigateTo({
  87. url: "/pages_user/agreement?type=" + type
  88. })
  89. },
  90. handleAgreement() {
  91. this.isAgreement = !this.isAgreement;
  92. },
  93. getDictByKey(splitOrderType){
  94. var that=this;
  95. var data={key:"sys_package_split_order_type"}
  96. getDictByKey(data).then(
  97. res => {
  98. if(res.code==200&&res.data.length > 0){
  99. const targetValues = splitOrderType.map(String);
  100. const result = res.data.filter(item => targetValues.includes(item.dictValue));
  101. this.splitOrderTypes=result
  102. this.splitOrderType = this.splitOrderTypes[0].dictValue
  103. this.isAgreement = true
  104. } else {
  105. this.splitOrderTypes = []
  106. this.splitOrderType = 1
  107. this.isAgreement = true
  108. }
  109. },
  110. rej => {}
  111. );
  112. },
  113. copyTest(text) {
  114. // 复制方法
  115. uni.setClipboardData({
  116. data:text,
  117. success:()=>{
  118. uni.showToast({
  119. title:'内容已成功复制到剪切板',
  120. icon:'none'
  121. })
  122. }
  123. });
  124. },
  125. getPackageOrderById(){
  126. var data={orderId:this.orderId};
  127. console.log(data)
  128. uni.hideLoading();
  129. getPackageOrderById(data).then(
  130. res => {
  131. if(res.code==200){
  132. this.order=res.order
  133. this.isShow = res.package ? res.package.isShow : 1;
  134. const splitOrderType = res.package ?res.package.splitOrderType.split(','):[];
  135. if(splitOrderType&&splitOrderType.length > 0) {
  136. this.getDictByKey(splitOrderType);
  137. }
  138. // 让用户自主点击支付
  139. // if(this.payMethod!=null&&this.payMethod=='app'){
  140. // this.payOrder();
  141. // }
  142. }else{
  143. uni.showToast({
  144. title: res.msg,
  145. icon: 'none'
  146. })
  147. }
  148. },
  149. rej => {}
  150. );
  151. },
  152. payOrder(){
  153. let data = {orderId:this.orderId,appId:getApp().globalData.appId};
  154. if(this.isShow ==0&&this.splitOrderTypes&&this.splitOrderTypes.length > 0) {
  155. if((this.splitOrderType == 2 || this.splitOrderType==3)&&!this.isAgreement) {
  156. uni.showToast({
  157. icon:'none',
  158. title: "请先同意协议",
  159. });
  160. return
  161. }
  162. data = {
  163. orderId:this.orderId,
  164. splitOrderType: this.splitOrderType,
  165. appId:getApp().globalData.appId
  166. }
  167. }
  168. var that=this;
  169. uni.showLoading();
  170. payment(data).then(
  171. res => {
  172. if(res.code==200){
  173. if(res.isPay==0){
  174. if(res.type=="tz"){
  175. uni.setStorageSync("ztPayUrl",res.data.body.url)
  176. uni.navigateTo({
  177. url:"/pages_order/tzPay"
  178. })
  179. }
  180. if(res.type=="yb"){
  181. var payData=JSON.parse(res.data.pay_info)
  182. console.log(payData)
  183. uni.requestPayment({
  184. provider: 'wxpay',
  185. timeStamp: payData.timeStamp,
  186. nonceStr: payData.nonceStr,
  187. package: payData.package,
  188. signType: payData.signType,
  189. paySign: payData.paySign,
  190. success: function(res) {
  191. console.log(that.order.orderId)
  192. uni.hideLoading();
  193. uni.redirectTo({
  194. url:"./packageOrderPaySuccess?orderId="+that.order.orderId
  195. })
  196. },
  197. fail: function(err) {
  198. uni.showToast({
  199. icon:'none',
  200. title:'fail:' + JSON.stringify(err),
  201. });
  202. uni.hideLoading();
  203. }
  204. });
  205. }
  206. else if(res.type=="hf"){
  207. var payData=JSON.parse(res.data.pay_info)
  208. console.log(payData)
  209. uni.requestPayment({
  210. provider: 'wxpay',
  211. timeStamp: payData.timeStamp,
  212. nonceStr: payData.nonceStr,
  213. package: payData.package,
  214. signType: payData.signType,
  215. paySign: payData.paySign,
  216. success: function(res) {
  217. console.log(that.order.orderId)
  218. uni.hideLoading();
  219. uni.redirectTo({
  220. url:"./packageOrderPaySuccess?orderId="+that.order.orderId
  221. })
  222. },
  223. fail: function(err) {
  224. uni.showToast({
  225. icon:'none',
  226. title:'fail:' + JSON.stringify(err),
  227. });
  228. uni.hideLoading();
  229. }
  230. });
  231. }
  232. else if(res.type=="wx"){
  233. uni.requestPayment({
  234. provider: 'wxpay',
  235. timeStamp: res.data.timeStamp,
  236. nonceStr: res.data.nonceStr,
  237. package: res.data.packageValue,
  238. signType: res.data.signType,
  239. paySign: res.data.paySign,
  240. success: function(res) {
  241. console.log(that.order.orderId)
  242. uni.hideLoading();
  243. uni.redirectTo({
  244. url:"./packageOrderPaySuccess?orderId="+that.order.orderId
  245. })
  246. },
  247. fail: function(err) {
  248. uni.showToast({
  249. icon:'none',
  250. title:'fail:' + JSON.stringify(err),
  251. });
  252. uni.hideLoading();
  253. }
  254. });
  255. }
  256. }
  257. else{
  258. uni.hideLoading();
  259. uni.redirectTo({
  260. url:"./packageOrderPaySuccess?orderId="+that.order.orderId
  261. })
  262. }
  263. }else{
  264. uni.showToast({
  265. icon:'none',
  266. title: res.msg,
  267. });
  268. this.$reLoginCheck(res.msg)
  269. }
  270. },
  271. rej => {}
  272. );
  273. },
  274. splitOrderTypeChange(e){
  275. this.splitOrderType=e.detail.value;
  276. this.isAgreement = this.splitOrderType == 2 || this.splitOrderType==3 ? true : false
  277. },
  278. }
  279. }
  280. </script>
  281. <style lang="scss">
  282. .tips {
  283. margin-top: 15rpx;
  284. padding: 0rpx 30rpx;
  285. display: flex;
  286. justify-content: flex-start;
  287. align-items: center;
  288. font-size: 28rpx;
  289. color: #000;
  290. checkbox {}
  291. .btn {
  292. color: #078C9D;
  293. }
  294. }
  295. .inner-box{
  296. padding: 20upx 20upx 300upx;
  297. .time-price{
  298. box-sizing: border-box;
  299. padding: 50upx 0upx;
  300. background: #FFFFFF;
  301. border-radius: 16upx;
  302. display: flex;
  303. flex-direction: column;
  304. align-items: center;
  305. .time{
  306. font-size: 32upx;
  307. font-family: PingFang SC;
  308. font-weight: 500;
  309. color: #222222;
  310. line-height: 1;
  311. text-align: center;
  312. }
  313. .desc{
  314. margin: 30upx 0upx 15upx;
  315. font-size: 26upx;
  316. font-family: PingFang SC;
  317. color: #999999;
  318. line-height: 1;
  319. text-align: center;
  320. }
  321. .price-box{
  322. display: flex;
  323. align-items: flex-end;
  324. margin-top: 28upx;
  325. .unit{
  326. font-size: 32upx;
  327. font-family: PingFang SC;
  328. font-weight: bold;
  329. color: #FF6633;
  330. line-height: 1.3;
  331. margin-right: 10upx;
  332. }
  333. .num{
  334. font-size: 56upx;
  335. font-family: PingFang SC;
  336. font-weight: bold;
  337. color: #FF6633;
  338. line-height: 1;
  339. }
  340. }
  341. }
  342. .order-info{
  343. margin-top: 20upx;
  344. background: #FFFFFF;
  345. border-radius: 16upx;
  346. padding: 40upx 30upx;
  347. .title{
  348. font-size: 30upx;
  349. font-family: PingFang SC;
  350. font-weight: bold;
  351. color: #222222;
  352. line-height: 1;
  353. }
  354. .text{
  355. font-size: 26upx;
  356. font-family: PingFang SC;
  357. font-weight: 500;
  358. color: #222222;
  359. line-height: 32upx;
  360. }
  361. .label{
  362. font-size: 26upx;
  363. font-family: PingFang SC;
  364. font-weight: 500;
  365. color: #666666;
  366. line-height: 1;
  367. }
  368. .item{
  369. margin-top: 40upx;
  370. display: flex;
  371. align-items: center;
  372. justify-content: space-between;
  373. .cont-text{
  374. font-size: 26upx;
  375. font-family: PingFang SC;
  376. font-weight: 500;
  377. color: #666666;
  378. .bold{
  379. color: #111111;
  380. }
  381. }
  382. .sn-box{
  383. display: flex;
  384. align-items: center;
  385. .copy-btn{
  386. width: 58upx;
  387. height: 32upx;
  388. line-height: 32upx;
  389. text-align: center;
  390. font-size: 22upx;
  391. font-family: PingFang SC;
  392. font-weight: 500;
  393. color: #222222;
  394. background: #F5F5F5;
  395. border-radius: 4upx;
  396. margin-left: 24upx;
  397. }
  398. }
  399. }
  400. .line{
  401. width: 100%;
  402. height: 1px;
  403. background: #F0F0F0;
  404. margin-top: 30upx;
  405. }
  406. }
  407. }
  408. .btn-box{
  409. z-index: 9999;
  410. width: 100%;
  411. padding: 30rpx 30upx 0rpx;
  412. position: fixed;
  413. bottom: 0;
  414. left: 0;
  415. box-sizing: border-box;
  416. background-color: #ffffff;
  417. display: flex;
  418. flex-direction: column;
  419. align-items: center;
  420. justify-content: center;
  421. .btn{
  422. margin-bottom: 20rpx;
  423. width: 100%;
  424. height: 88upx;
  425. line-height: 88upx;
  426. text-align: center;
  427. font-size: 34upx;
  428. font-family: PingFang SC;
  429. font-weight: 400;
  430. color: #FFFFFF;
  431. background: #078C9D;
  432. border-radius: 10upx;
  433. position: relative;
  434. }
  435. .btn1{
  436. margin-bottom: 20rpx;
  437. width: 100%;
  438. height: 88upx;
  439. line-height: 88upx;
  440. text-align: center;
  441. font-size: 34upx;
  442. font-family: PingFang SC;
  443. font-weight: 400;
  444. color: #078C9D;
  445. border: 1rpx solid #078C9D;
  446. border-radius: 10upx;
  447. position: relative;
  448. .share-btn {
  449. top:0rpx;
  450. left:0rpx;
  451. position: absolute;
  452. width: 100%;
  453. height: 88upx;
  454. display: flex;
  455. opacity: 0;
  456. }
  457. }
  458. }
  459. </style>