bookticket.vue 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178
  1. <template>
  2. <view class="pages">
  3. <view class="" :style="{height: navHeight+'px' }"></view>
  4. <view class="navbar-box">
  5. <u-navbar title="订单详情" :safeAreaInsetTop="true" @leftClick="leftClick" :titleStyle="{color:'#fff'}"
  6. leftIconColor="#fff" bgColor="transparent"></u-navbar>
  7. </view>
  8. <view class="page-wrap">
  9. <view class="base-info">
  10. <view class="up u-flex">
  11. <image class="img" :src="pageContent.performImg" mode="aspectFill" alt="">
  12. <view class="text">
  13. <view class="name text-item">{{pageContent.performName}}-{{pageContent.goodsName}}</view>
  14. <view class="time text-item">日期 {{pageContent.timeDate}}({{pageContent.timeWeek}})</view>
  15. <view class="time text-item">场次 {{pageContent.performTimeStart}} -
  16. {{pageContent.performTimeEnd}}</view>
  17. <view class="num text-item">{{pageContent.goodsName}} / {{pageContent.seatTypeName}}</view>
  18. <view class=" text-item">{{pageContent.auditoriumName}}</view>
  19. <!-- <view class="position text-item">{{performInfo.name}}</view> -->
  20. <!-- <view class="addr u-flex u-row-between">
  21. <view class="u-line-1">地址:遵义市《伟大转折》演艺中心</view>
  22. <u-icon name="arrow-right" color="#2D2D2D" size="36rpx"></u-icon>
  23. </view> -->
  24. </view>
  25. </view>
  26. <view class="down">
  27. <view class="num-wrap u-flex u-row-between">
  28. <view class="title">选购数量</view>
  29. <view class="num">{{totalVisitor}}</view>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="block-wrap purchaser">
  34. <view class="block-title u-flex">
  35. <view class="name">购票人信息</view>
  36. <!-- <text>用于入园身份验证</text> -->
  37. </view>
  38. <view class="" v-if="vuex_member_info.isAuth">
  39. <view class="item">姓名:{{pageContent.purchaser.name}}</view>
  40. <view class="item">手机号:{{pageContent.purchaser.mobile|hidePhoneNumber}}</view>
  41. <view class="item">身份证:{{pageContent.purchaser.idcard|maskID}}</view>
  42. </view>
  43. <view class="un-auth" v-else @click="$u.route('center/factorauth',{from:'bookticket'})">
  44. 请先<text style="color: #ED0000;">实名认证</text>
  45. </view>
  46. </view>
  47. <view class="block-wrap visitors">
  48. <view class="block-title u-flex">
  49. <view class="name">观影人信息</view>
  50. <text v-if="needIdcardNumber">需要{{needIdcardNumber}}张身份证</text>
  51. <!-- <text>用于入园身份验证</text> -->
  52. </view>
  53. <view class="people-list u-flex u-flex-wrap">
  54. <view class="people btn" v-if="visitors.length>0" v-for="(visitor,index) in visitors" :key="index">
  55. {{visitor.name}}
  56. </view>
  57. <view class="btn u-flex u-row-center"
  58. @click="visitorShow = true">
  59. <u-icon name="plus-circle" color="#2D2D2D" size="32rpx"></u-icon>
  60. <text class="text">新增/更换</text>
  61. </view>
  62. </view>
  63. <!-- <view class="no-people u-flex" v-if="!visitors.length>0">
  64. <text>游客</text>
  65. <text class="right" @click="visitorShow = true">点击选择游客</text>
  66. </view> -->
  67. <view class="peoples" v-if="visitors.length>0">
  68. <view class="peoples-item u-flex u-row-between" v-for="(visitor,index) in visitors" :key="index">
  69. <view class="left u-flex">
  70. <u-icon @click="delVisitor(visitor)" name="close-circle" color="#2D2D2D"
  71. size="32rpx"></u-icon>
  72. <text style="margin-left: 8rpx;">观影人{{ index + 1 }}</text>
  73. <text class="name">{{visitor.name}}</text>
  74. <!-- <text class="people-id">{{ visitor.idcard | maskID }}</text> -->
  75. </view>
  76. <view class="right" @click="editVisitor(visitor)">编辑</view>
  77. </view>
  78. </view>
  79. </view>
  80. <view class="coupon u-flex u-row-between block-wrap" @click="selectCoupon">
  81. <view class="left">优惠券</view>
  82. <view class="right u-flex">
  83. <text v-if="couponList.length<1||Number(this.totalPrice)<=0">暂无可用</text>
  84. <text v-if="coupon.quota" style="color: #EF2929;">已选1张优惠券</text>
  85. <text v-if="couponList.length>0&&!coupon.quota&&Number(this.totalPrice)>0">未选择优惠券</text>
  86. <u-icon name="arrow-right" color="#7F7F7F" size="24rpx"></u-icon>
  87. </view>
  88. </view>
  89. <view class="notice">
  90. <view class="title u-flex u-row-between u-border-bottom">
  91. <text>购票须知</text>
  92. </view>
  93. <view class="notice-item parse-content">
  94. <u-parse :content="pageContent.ticketNotice"></u-parse>
  95. </view>
  96. <!-- <view class="notice-item">
  97. 1.由于设备故障等不可抗力因素,存在少量场次取消的情况,会
  98. 进行退票退款
  99. </view>
  100. <view class="notice-item">
  101. 2.由于影院系统不稳定等因素,存在出票失败的情况,会进行退款
  102. </view>
  103. <view class="notice-item">
  104. 3.取票码可以在“我的-订单页”中查看
  105. </view> -->
  106. </view>
  107. </view>
  108. <u-popup :show="visitorShow">
  109. <view class="people-show-content">
  110. <view class="title">
  111. <view class="cancel" @click="visitorShow=false">取消</view>
  112. 选择观影人
  113. </view>
  114. <view class="add-btn u-flex u-row-center" @click="addVisitor">
  115. <!-- <image class="img" :src="staticUrl+'/img/car.png'" ></image> -->
  116. 添加观影人信息
  117. </view>
  118. <view class="list">
  119. <u-checkbox-group v-model="selectedVisitor" iconPlacement="left">
  120. <view class="people u-flex u-row-between" v-for="(item,index) in visitorList" :key="index">
  121. <u-checkbox activeColor="#ED0303" :label="item.name" :name="item.idcard"></u-checkbox>
  122. <u-icon name="edit-pen-fill" color="#7F7F7F" size="32rpx"
  123. @click="editVisitor(item)"></u-icon>
  124. </view>
  125. </u-checkbox-group>
  126. </view>
  127. <view class="full-btn" @click="confirmVisitor">确定</view>
  128. </view>
  129. </u-popup>
  130. <view class="page-bottom">
  131. <view class="inner u-flex u-row-between">
  132. <view class="left u-flex u-col-top">
  133. <text>实付金额:</text>
  134. <view class="total-price">
  135. ¥{{finalPrice}}
  136. <view class="bottom-coupon" v-if="coupon.quota">
  137. 优惠券共减¥{{couponAmount}}
  138. </view>
  139. </view>
  140. </view>
  141. <view class="right">
  142. <view class="btn active" v-if="totalPrice>=0&&cansubmit&&vuex_member_info.isAuth"
  143. @click="setTemplate">立即支付</view>
  144. <!-- <u-button @click="setTemplate" class="btn active" v-if="totalPrice>0&&cansubmit&&vuex_member_info.isAuth">立即支付</u-button> -->
  145. <view class="btn" v-else>立即支付</view>
  146. </view>
  147. </view>
  148. </view>
  149. <u-modal
  150. :show="umodal.show"
  151. :title="umodal.title"
  152. :content='umodal.content'
  153. confirmColor="#ED0303"
  154. @confirm="modalConfirm"
  155. ></u-modal>
  156. </view>
  157. </template>
  158. <script>
  159. import { locale } from "moment/moment";
  160. import {
  161. systemInfo
  162. } from "@/mixin.js";
  163. // #ifdef H5
  164. import wxH5 from "weixin-jsapi";
  165. // #endif
  166. export default {
  167. mixins: [systemInfo],
  168. data() {
  169. return {
  170. performId: '',
  171. performInfo: {},
  172. pageData: {}, //上个页面传过来的数据
  173. pageContent: {
  174. performName: '',
  175. goodsName: '',
  176. timeDate: '',
  177. timeWeek: '',
  178. seatTypeName: '',
  179. auditoriumName: '',
  180. performTimeEnd: '',
  181. performTimeStart: '',
  182. purchaser: {
  183. mobile: '',
  184. idcard: ''
  185. },
  186. ticketNotice: '',
  187. viewerList: [],
  188. }, //页面信息
  189. ticketNotice: '',
  190. cansubmit: true,
  191. staticUrl: this.$commonConfig.staticUrl,
  192. visitors: [], //确认的游客
  193. visitorShow: false, //游客弹层
  194. visitorList: [], //游客列表
  195. selectedVisitor: [], //选中的游客(id)
  196. params: {}, //要提交的数据
  197. orderId: '', //订单提交获取
  198. payResult: {}, //gotoPay结果
  199. paysuccess: false, //支付结果
  200. templateIdList: [], //微信小程序订阅消息
  201. umodal:{
  202. show:false,
  203. title:'温馨提示',
  204. content:''
  205. },
  206. scene:null,
  207. retailId:null,//分销码
  208. label:null,//scene解析出来的
  209. retailId:null,
  210. couponList:[],
  211. latitude:null,
  212. longitude:null
  213. }
  214. },
  215. watch: {
  216. visitors: {
  217. handler: function(newValue, oldValue) {
  218. this.findOrderCoupons();
  219. console.log(`The value changed to ${newValue.length}`);
  220. },
  221. immediate: false
  222. }
  223. },
  224. computed: {
  225. finalPrice(){
  226. let discount = 0;
  227. let price = this.totalPrice||0;
  228. if(this.coupon.type==1){
  229. discount = this.coupon.quota || 0; // 如果没有优惠券,默认为0
  230. price = Math.max(this.totalPrice - discount,0);
  231. }else if(this.coupon.type==2){
  232. price = this.totalPrice*(this.coupon.quota/100);
  233. }
  234. // console.log('price',price);
  235. // console.log('price',typeof price);
  236. if(typeof price=='string'){
  237. price = Number(price)
  238. }
  239. return price.toFixed(2)
  240. },
  241. totalPrice() {
  242. let that = this;
  243. return this.visitors.reduce((total, item) => {
  244. let price = Number(that.pageData.salePrice);
  245. if(this.pageContent.personnelNum!==0){
  246. total = price
  247. }else{
  248. total += price;
  249. }
  250. return total;
  251. }, 0).toFixed(2);
  252. },
  253. totalVisitor() {
  254. let that = this;
  255. return this.visitors.reduce((total, item) => {
  256. total += 1;
  257. return total;
  258. }, 0);
  259. },
  260. needIdcardNumber(){
  261. if(this.pageContent.oneMany===1&&this.pageContent.personnelNum!==0){
  262. return this.pageContent.personnelNum
  263. }else if(this.pageContent.oneMany===1&&this.pageContent.personnelNum===0){
  264. return null
  265. }else if(this.pageContent.oneMany===2){
  266. return 1
  267. }
  268. },
  269. couponAmount() {
  270. let amount = 0;
  271. if (this.coupon.type == 1) {
  272. amount = this.coupon.quota || 0; // 如果没有优惠券,默认为0
  273. } else if (this.coupon.type == 2) {
  274. // 将总价和折扣转化为整数
  275. const totalPrice = Math.round(this.totalPrice * 100); // 以分为单位
  276. const discountRate = this.coupon.quota; // 折扣百分比
  277. const discountAmount = totalPrice * (discountRate / 100);
  278. const finalAmount = totalPrice - discountAmount;
  279. amount = finalAmount / 100; // 结果转换回以元为单位
  280. // console.log('this.totalPrice',this.totalPrice);
  281. // console.log('this.coupon.quota',this.coupon.quota);
  282. // console.log('amount',amount);
  283. }
  284. return amount.toFixed(2);
  285. },
  286. },
  287. onShow() {
  288. this.getSettlement();
  289. if(this.totalPrice>0){
  290. this.findOrderCoupons()
  291. }
  292. },
  293. onLoad(page) {
  294. console.log('page', page);
  295. this.pageData = page;
  296. this.performId = page.performId;
  297. this.pageData.performTimeId = page.performTimeId;
  298. this.pageData.seatTypeId = page.seatTypeId
  299. this.getSystemInfo();
  300. this.getSettlement();
  301. this.getTemplateIdList(); //获取模板列表
  302. },
  303. onUnload() {
  304. this.$u.vuex('coupon', {});
  305. },
  306. methods: {
  307. leftClick(e) {
  308. let pages = getCurrentPages();
  309. if (pages.length == 1) {
  310. uni.$u.route('/pages/index/index')
  311. } else {
  312. uni.navigateBack()
  313. };
  314. },
  315. getSettlement() {
  316. this.$u.api.getSettlement(this.pageData).then(res => {
  317. // console.log('getSettlement',res.data);
  318. this.pageContent = res.data;
  319. this.getMemberAll();
  320. }).catch(err => {
  321. console.log('getSettlement', err);
  322. })
  323. },
  324. getMemberAll() {
  325. let that = this;
  326. // const userId = this.vuex_member_info.id;
  327. const userId = this.pageContent.viewerList[0]?.id;
  328. this.$u.api.selectMemberAll({
  329. userid: userId
  330. }).then(res => {
  331. // console.log('getMemberAll',res.data);
  332. this.visitorList = res.data.list;
  333. // this.visitors = this.visitorList.filter(obj => obj.memberId==userId);
  334. this.selectedVisitor = [];
  335. this.visitorList.forEach(visitor => {
  336. if (this.visitors.find(item => item.idcard === visitor.idcard)) {
  337. this.selectedVisitor.push(visitor.idcard);
  338. }
  339. });
  340. this.visitors = this.visitorList.filter(obj => that.selectedVisitor.includes(obj.idcard));
  341. console.log('this.visitorList',this.visitorList);
  342. console.log('this.selectedVisitor',this.selectedVisitor);
  343. console.log('this.visitors',this.visitors);
  344. }).catch(err => {
  345. console.log('getMemberAll', err);
  346. })
  347. },
  348. confirmVisitor() {
  349. let that = this;
  350. if(this.needIdcardNumber&&this.needIdcardNumber!==this.selectedVisitor.length){
  351. uni.showToast({
  352. title:`身份证数量应该为${this.needIdcardNumber}张`,
  353. icon:'none'
  354. })
  355. return false
  356. }
  357. // console.log('selectedVisitor',this.selectedVisitor);
  358. this.visitorShow = false;
  359. this.visitors = this.visitorList.filter(obj => that.selectedVisitor.includes(obj.idcard)).map(item => {
  360. return {
  361. name: item.name,
  362. mobile: item.mobile,
  363. idcard: item.idcard
  364. }
  365. });
  366. // console.log('this.visitors',this.visitors);
  367. },
  368. delVisitor(visitor) {
  369. // console.log('delVisitor',visitor);
  370. // console.log('this.visitors',this.visitors);
  371. this.visitors = this.visitors.filter(obj => obj.idcard != visitor.idcard);
  372. this.selectedVisitor = this.selectedVisitor.filter(item => item != visitor.idcard);
  373. // console.log('this.visitors',this.visitors);
  374. // console.log('this.selectedVisitor',this.selectedVisitor);
  375. },
  376. addVisitor() {
  377. uni.$u.route('/center/people', {
  378. type: 'addVisitor',
  379. fromPage: 'bookticket'
  380. });
  381. },
  382. editVisitor(item) {
  383. uni.$u.route('/center/people', {
  384. type: 'editVisitor',
  385. fromPage: 'bookticket',
  386. id: item.id,
  387. name: item.name,
  388. mobile: item.mobile,
  389. idcard: item.idcard,
  390. });
  391. },
  392. getTemplateIdList() {
  393. this.$u.api.templateIdList({
  394. templateLabel: 'order_pay'
  395. }).then(res => {
  396. // console.log('getTemplateIdList', res.data);
  397. this.templateIdList = res.data.list.map(item => {
  398. return item.templateId
  399. });
  400. // if(this.templateIdList.length>0){
  401. // this.templateEven();
  402. // }
  403. }).catch(err => {
  404. console.log('getTemplateIdList', err);
  405. })
  406. },
  407. async submitorder() {
  408. let _this = this;
  409. let retailId = null;
  410. try {
  411. retailId = await new Promise((resolve, reject) => {
  412. uni.getStorage({
  413. key: 'retailId',
  414. success: function (res) {
  415. console.log('getPositionData retailId====', res.data);
  416. resolve(res.data);
  417. },
  418. fail: function (error) {
  419. reject(error);
  420. }
  421. });
  422. });
  423. console.log('getPositionData retailId', retailId);
  424. } catch (error) {
  425. console.error('获取retailId失败', error);
  426. // 在这里可以添加处理失败的逻辑
  427. }
  428. this.retailId = retailId;
  429. console.log('submitorder retailId',this.retailId);
  430. if(this.pageContent.oneMany === 2 && this.pageContent.personnelNum!==0){//一证多票,补齐观影人信息
  431. let dontNeedCardsNumber = this.pageContent.personnelNum - this.visitors.length;
  432. if(dontNeedCardsNumber>0){//
  433. for (let i = 0;i<dontNeedCardsNumber;i++) {
  434. console.log('dontNeedCardsNumber',dontNeedCardsNumber);
  435. this.visitors.push({
  436. name: this.visitors[0].name,
  437. idcard: this.visitors[0].idcard,
  438. mobile: this.visitors[0].mobile,
  439. });
  440. }
  441. }
  442. }
  443. let params = {
  444. performId: this.pageContent.performId,
  445. goodsList: [{
  446. goodsId: this.pageContent.goodsId,
  447. salePeice: this.pageContent.salePrice,
  448. saleNum: 1
  449. }],
  450. auditoriumId: this.pageContent.auditoriumId,
  451. performTimeId: this.pageContent.performTimeId,
  452. seatTypeId: this.pageContent.seatTypeId,
  453. purchaser: {
  454. name: this.pageContent.purchaser.name,
  455. mobile: this.pageContent.purchaser.mobile,
  456. idcard: this.pageContent.purchaser.idcard
  457. },
  458. viewerList: this.visitors,
  459. label:this.label,
  460. retailId:this.retailId,
  461. coupon:{
  462. memberCouponId:null
  463. },
  464. longitude:this.longitude,
  465. latitude:this.latitude,
  466. }
  467. if(this.coupon.quota){
  468. // console.log('this.coupon',this.coupon);
  469. params.coupon.memberCouponId = this.coupon.id;
  470. // return
  471. }
  472. console.log('submitorder params',params);
  473. // return
  474. // #ifdef MP
  475. params['source'] = 1
  476. // #endif
  477. // #ifdef H5
  478. params['source'] = 4
  479. // #endif
  480. this.cansubmit = false;
  481. // console.log('pageData',this.pageData);
  482. // console.log('visitors',this.visitors);
  483. // console.log('params',params);
  484. this.$u.api.submitOrder(params,{custom:{toast:false}}).then(res => {
  485. // console.log('submitOrder',res.data);
  486. this.orderId = res.data.orderId;
  487. // this.templateEven()
  488. this.gotoPay();
  489. }).catch(err => {
  490. this.cansubmit = true;
  491. uni.hideLoading();
  492. // uni.$u.toast(err.msg);
  493. // if (err.msg.includes('限购')) {
  494. this.umodal.title = '';
  495. this.umodal.content = err.msg;
  496. this.umodal.show = true;
  497. // setTimeout(() => {
  498. // uni.$u.route('/center/order', {
  499. // status: 0
  500. // });
  501. // }, 2000)
  502. // }
  503. console.log('submitOrder', err);
  504. })
  505. },
  506. modalConfirm(){
  507. this.umodal.show = false;
  508. },
  509. // 订阅消息
  510. templateEven() {
  511. let that = this
  512. wx.showModal({
  513. title: '温馨提示',
  514. content: '为更好的促进与您的交流,服务号需要实时向您发送消息',
  515. confirmText: "同意",
  516. cancelText: "拒绝",
  517. success: function(res) {
  518. if (res.confirm) {
  519. //调用订阅消息
  520. // console.log('用户点击确定');
  521. //调用订阅
  522. that.setTemplate();
  523. } else if (res.cancel) {
  524. // console.log('用户点击取消');
  525. ///显示第二个弹说明一下
  526. wx.showModal({
  527. title: '温馨提示',
  528. content: '拒绝后您将无法获取实时的消息',
  529. confirmText: "知道了",
  530. showCancel: false,
  531. success: function(res) {
  532. that.gotoPay();
  533. ///点击知道了的后续操作
  534. ///如跳转首页面
  535. }
  536. });
  537. }
  538. }
  539. });
  540. },
  541. showOpenLocationSettings() {
  542. uni.showModal({
  543. title: '提示',
  544. content: '需要获取您的地理位置,请前往设置中开启',
  545. confirmText: '去设置',
  546. success: (res) => {
  547. if (res.confirm) {
  548. uni.openSetting({
  549. success: (res) => {
  550. if (res.authSetting['scope.userLocation']) {
  551. this.setTemplate();
  552. }
  553. }
  554. });
  555. }
  556. }
  557. });
  558. },
  559. getUserLocation() {
  560. return new Promise((resolve, reject) => {
  561. uni.getLocation({
  562. type: 'gcj02',
  563. success: (res) => {
  564. resolve(res);
  565. },
  566. fail: (err) => {
  567. reject(err);
  568. }
  569. });
  570. });
  571. },
  572. // 设置小程序订阅消息
  573. async setTemplate() {
  574. if(this.needIdcardNumber&&this.needIdcardNumber!==this.visitors.length){
  575. uni.showToast({
  576. title:'观影人信息不正确',
  577. icon:'none'
  578. })
  579. return false
  580. }
  581. try {
  582. const location = await this.getUserLocation();
  583. this.longitude = location.longitude;
  584. this.latitude = location.latitude;
  585. if (!this.longitude || !this.latitude) {
  586. uni.showToast({
  587. title: '无法获取地理位置',
  588. icon: 'none'
  589. });
  590. return;
  591. }
  592. console.log('location', location);
  593. } catch (err) {
  594. if (err.errMsg === 'getLocation:fail auth deny') {
  595. // 用户拒绝授权,提示用户打开位置权限
  596. this.showOpenLocationSettings();
  597. } else {
  598. uni.showToast({
  599. title: '获取地理位置失败',
  600. icon: 'none'
  601. });
  602. }
  603. return
  604. }
  605. let that = this;
  606. // console.log('templateIdList', this.templateIdList);
  607. // #ifdef MP
  608. uni.requestSubscribeMessage({
  609. tmplIds: that.templateIdList,
  610. success(res) {
  611. // that.gotoPay();
  612. console.log("设置小程序订阅消息 success:", res);
  613. },
  614. fail(res) {
  615. console.log("设置小程序订阅消息 fail:", res);
  616. },
  617. complete(res) {
  618. // that.gotoPay();
  619. that.submitorder();
  620. console.log("设置小程序订阅消息 complete:", res);
  621. }
  622. })
  623. // #endif
  624. // #ifdef H5
  625. that.gotoPay()
  626. // #endif
  627. },
  628. gotoPay() {
  629. this.$u.api.gotoPay({
  630. orderId: this.orderId,
  631. openid: ''
  632. }).then(res => {
  633. // this.payResult = res.data.payInfo;
  634. // this.payResult.package = res.data.payInfo.packageValue;
  635. // ygh
  636. if(!res.data.needPay){
  637. //this.payQuery();
  638. uni.$u.route('/center/orderdetails', {
  639. type:'redirectTo',
  640. id: this.orderId
  641. });
  642. }else {
  643. this.payResult = res.data.payInfo;
  644. this.payResult.package = res.data.payInfo.packageValue;
  645. // #ifdef H5
  646. this.initConfig(this.payResult)
  647. // #endif
  648. // #ifdef MP
  649. this.wxPay()
  650. // #endif
  651. }
  652. // if(this.params.paymentMode==1||this.params.paymentMode==4){
  653. // this.wxPay()
  654. // }else{
  655. // uni.$u.route('/shopping/paysuccess');
  656. // }
  657. // console.log('gotoPayres', res.data);
  658. }).catch(err => {
  659. this.cansubmit = true;
  660. // this.paypass = '';
  661. // this.checkPassShow = false;
  662. console.log('gotoPay', err);
  663. })
  664. },
  665. wxPay() {
  666. let that = this;
  667. uni.requestPayment({
  668. ...this.payResult,
  669. "provider": "wxpay",
  670. "orderInfo": {
  671. // "appid": "wx499********7c70e", // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
  672. // "noncestr": "c5sEwbaNPiXAF3iv", // 随机字符串
  673. // "package": "Sign=WXPay", // 固定值
  674. // "partnerid": "148*****52", // 微信支付商户号
  675. // "prepayid": "wx202254********************fbe90000", // 统一下单订单号
  676. // "timestamp": 1597935292, // 时间戳(单位:秒)
  677. // "sign": "A842B45937F6EFF60DEC7A2EAA52D5A0" // 签名,这里用的 MD5/RSA 签名
  678. },
  679. success(res) {
  680. that.payQuery();
  681. },
  682. fail(e) {
  683. uni.$u.route('/center/order', {
  684. status: 0
  685. });
  686. console.log('wxPayfail', e);
  687. },
  688. complete() {
  689. this.cansubmit = true;
  690. }
  691. })
  692. },
  693. payQuery() {
  694. let that = this;
  695. let retryCount = 0;
  696. let maxRetryCount = 5; // 设置最大重试次数
  697. let interval = 2000; // 设置间隔时间为2秒
  698. let timeout = 10000; // 设置超时时间为10秒
  699. let timer;
  700. uni.showLoading({
  701. title: '支付结果查询中'
  702. })
  703. timer = setInterval(() => {
  704. retryCount++;
  705. if (retryCount > maxRetryCount || retryCount * interval > timeout) {
  706. clearInterval(timer);
  707. uni.hideLoading();
  708. console.log("支付查询超时或达到最大重试次数");
  709. // 在这里添加超时或达到最大重试次数的处理逻辑
  710. uni.$u.route('/center/order');
  711. } else {
  712. console.log("第" + retryCount + "次查询");
  713. // 调用查询支付状态的方法
  714. // 如果支付状态为成功,则清除定时器并处理成功的逻辑
  715. // 如果支付状态为失败,则清除定时器并处理失败的逻辑
  716. this.$u.api.payQuery({
  717. orderId: this.orderId
  718. }).then(res => {
  719. // 0-未支付 1-已支付 2-支付中 3-支付失败 4-支付退款
  720. let payStatus = res.data.payStatus;
  721. if (payStatus === 1) {
  722. uni.$u.route('/center/orderdetails', {
  723. type:'redirectTo',
  724. id: res.data.orderId
  725. });
  726. // uni.$u.route('/center/order', {
  727. // status: 3
  728. // });
  729. // uni.$u.route('/center/paysuccess');
  730. } else if (payStatus === 0 || payStatus === 2) {
  731. this.payQuery()
  732. } else if (payStatus === 3) {
  733. uni.toast('支付失败')
  734. }
  735. clearInterval(timer);
  736. }).catch(err => {
  737. console.log('payQuery', err);
  738. }).finally(() => {
  739. uni.hideLoading()
  740. this.cansubmit = true;
  741. })
  742. }
  743. }, interval);
  744. },
  745. /**
  746. * 公众号微信支付
  747. */
  748. initConfig() {
  749. // #ifdef H5
  750. let that = this
  751. wxH5.config({
  752. debug: false, // 这里一般在测试阶段先用ture,等打包给后台的时候就改回false,
  753. appId: that.payResult.appId, // 必填,公众号的唯一标识
  754. timestamp: that.payResult.timeStamp, // 必填,生成签名的时间戳
  755. nonceStr: that.payResult.nonceStr, // 必填,生成签名的随机串
  756. signature: that.payResult.paySign, // 必填,签名
  757. jsApiList: ['chooseWXPay', 'checkJsApi'] // 必填,需要使用的JS接口列表
  758. })
  759. wxH5.ready(() => {
  760. wxH5.chooseWXPay({
  761. timestamp: that.payResult.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
  762. nonceStr: that.payResult.nonceStr, // 支付签名随机串,不长于 32 位
  763. package: that.payResult.packageValue, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
  764. signType: 'SHA1', // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
  765. paySign: that.payResult.paySign, // 支付签名
  766. success: () => {
  767. that.payQuery();
  768. },
  769. fail: (e) => {
  770. uni.$u.route('/center/order', {
  771. status: 0
  772. });
  773. console.log('wxPayfail', e);
  774. },
  775. cancel: () => {
  776. uni.$u.route('/center/order', {
  777. status: 0
  778. });
  779. that.cansubmit = true;
  780. }
  781. })
  782. })
  783. // #endif
  784. },
  785. selectCoupon(){
  786. if(Number(this.totalPrice)<=0){
  787. return
  788. }
  789. this.$u.route('/center/couponselect',{
  790. salePrice:this.totalPrice,
  791. performId:this.performId,
  792. goodsId: this.pageContent.goodsId
  793. })
  794. },
  795. findOrderCoupons() {
  796. let param = {
  797. salePrice: this.totalPrice,
  798. performId: this.performId,
  799. goodsId: this.pageContent.goodsId
  800. };
  801. this.$u.api.findOrderCoupons(param)
  802. .then(res => {
  803. this.couponList = res.data.list || [];
  804. console.log('this.couponList',this.couponList);
  805. console.log('this.coupon.id',this.coupon.id);
  806. if (this.couponList.length < 1 || !this.couponList.some(obj => obj.id === this.coupon.id)) {
  807. this.$u.vuex('coupon', {});
  808. }
  809. })
  810. .catch(err => {
  811. // console.log('findOrderCoupons',err.data);
  812. });
  813. },
  814. }
  815. }
  816. </script>
  817. <style>
  818. page {
  819. background: linear-gradient(180deg, #ED0000 0%, #F9FBFD 50%, #fff 100%);
  820. background-repeat: no-repeat;
  821. }
  822. </style>
  823. <style lang="scss" scoped>
  824. .base-info {
  825. border-radius: 30rpx;
  826. overflow: hidden;
  827. background: radial-gradient(circle at -26rpx 294rpx, transparent 8%, #fff 4%) left, radial-gradient(circle at calc(100% + 26rpx) 294rpx, transparent 8%, #fff 4%) right;
  828. background-size: 50% 100%;
  829. background-repeat: no-repeat;
  830. padding: 34rpx 36rpx;
  831. box-sizing: border-box;
  832. margin: 30rpx 0 40rpx;
  833. .up {
  834. margin-bottom: 36rpx;
  835. .img {
  836. display: block;
  837. width: 172rpx;
  838. height: 230rpx;
  839. border-radius: 20rpx;
  840. margin-right: 32rpx;
  841. }
  842. .text {
  843. flex: 1;
  844. font-size: 22rpx;
  845. font-weight: 400;
  846. color: #606060;
  847. line-height: 1;
  848. }
  849. .text-item {
  850. margin-bottom: 18rpx;
  851. }
  852. .name {
  853. font-size: 32rpx;
  854. line-height: 1.5;
  855. font-weight: bold;
  856. color: #2D2D2D;
  857. }
  858. .addr {
  859. font-size: 24rpx;
  860. font-weight: 500;
  861. color: #2D2D2D;
  862. }
  863. }
  864. .down {
  865. position: relative;
  866. &:before {
  867. content: '';
  868. width: calc(100% + 26rpx);
  869. height: 1px;
  870. position: absolute;
  871. left: -13rpx;
  872. top: -2rpx;
  873. border-top: 4rpx dashed #F39FA0;
  874. }
  875. .num-wrap {
  876. padding-top: 36rpx;
  877. .title {
  878. font-size: 14px;
  879. color: #4E4E4E;
  880. }
  881. }
  882. }
  883. }
  884. .block-wrap {
  885. background: #FFFFFF;
  886. box-shadow: 0rpx 0rpx 20rpx 2rpx rgba(221, 221, 221, 0.5);
  887. border-radius: 20rpx;
  888. margin-bottom: 28rpx;
  889. padding: 32rpx 30rpx 34rpx;
  890. .block-title {
  891. // padding-left: 16rpx;
  892. position: relative;
  893. margin-bottom: 22rpx;
  894. font-size: 24rpx;
  895. font-weight: 500;
  896. color: #CACACA;
  897. // &:before{
  898. // content: '';
  899. // width: 6rpx;
  900. // height: 32rpx;
  901. // background: #1677FF;
  902. // border-radius: 4rpx;
  903. // position: absolute;
  904. // left: 0;
  905. // top: 50%;
  906. // margin-top: -16rpx;
  907. // }
  908. .name {
  909. font-size: 32rpx;
  910. font-weight: bold;
  911. color: #2D2D2D;
  912. margin-right: 20rpx;
  913. }
  914. }
  915. .no-people {
  916. font-size: 28rpx;
  917. font-weight: 400;
  918. color: #7F7F7F;
  919. .right {
  920. margin-left: 20rpx;
  921. color: #1677FF;
  922. }
  923. }
  924. .peoples {
  925. font-size: 28rpx;
  926. font-weight: 400;
  927. color: #7F7F7F;
  928. margin-bottom: 24rpx;
  929. .peoples-item {
  930. margin-bottom: 10rpx;
  931. }
  932. .name {
  933. margin-left: 20rpx;
  934. margin-right: 28rpx;
  935. font-size: 28rpx;
  936. font-weight: bold;
  937. color: #363636;
  938. }
  939. .people-id {
  940. font-size: 20rpx;
  941. font-weight: 400;
  942. color: #606060;
  943. }
  944. .right {
  945. font-size: 28rpx;
  946. font-weight: 400;
  947. color: #ED0303;
  948. }
  949. }
  950. }
  951. .people-list {
  952. margin-bottom: 20rpx;
  953. .btn {
  954. width: 185rpx;
  955. height: 60rpx;
  956. line-height: 60rpx;
  957. font-size: 24rpx;
  958. font-weight: 500;
  959. color: #2D2D2D;
  960. background-color: #F1F1F1;
  961. border: 1px solid #F1F1F1;
  962. border-radius: 8rpx;
  963. margin-bottom: 12rpx;
  964. .text {
  965. margin-left: 16rpx;
  966. }
  967. &.people {
  968. margin-right: 16rpx;
  969. text-align: center;
  970. background-color: #FFF2F2;
  971. border-color: #ED0303;
  972. }
  973. }
  974. }
  975. .visitors {
  976. margin-bottom: 20rpx;
  977. }
  978. .people-show-content {
  979. background: #FFFFFF;
  980. border-radius: 40rpx 40rpx 0rpx 0rpx;
  981. padding: 30rpx 40rpx;
  982. .title {
  983. position: relative;
  984. font-size: 32rpx;
  985. font-weight: 500;
  986. color: #606060;
  987. margin-bottom: 46rpx;
  988. text-align: center;
  989. .cancel {
  990. position: absolute;
  991. left: 0;
  992. top: 0;
  993. }
  994. }
  995. .add-btn {
  996. margin-bottom: 28rpx;
  997. background: #ffdee1;
  998. border-radius: 44rpx;
  999. padding: 26rpx;
  1000. font-size: 24rpx;
  1001. font-weight: 400;
  1002. color: #ff1616;
  1003. .img {
  1004. width: 28rpx;
  1005. height: 36rpx;
  1006. margin-right: 36rpx;
  1007. }
  1008. }
  1009. .list {
  1010. /deep/ .u-radio-group {
  1011. flex-wrap: wrap;
  1012. }
  1013. /deep/ .u-checkbox-group {
  1014. flex-wrap: wrap;
  1015. }
  1016. overflow-y: auto;
  1017. height: 40vh;
  1018. .people {
  1019. width: 100%;
  1020. margin-bottom: 24rpx;
  1021. }
  1022. }
  1023. .btn {}
  1024. }
  1025. .coupon {
  1026. .left{
  1027. font-weight: bold;
  1028. font-size: 28rpx;
  1029. color: #2D2D2D;
  1030. }
  1031. .right{
  1032. font-weight: 400;
  1033. font-size: 24rpx;
  1034. color: #606060;
  1035. }
  1036. /deep/ .u-icon{
  1037. top: 1px;
  1038. margin-left: 5px;
  1039. position: relative;
  1040. }
  1041. }
  1042. .notice {
  1043. background: #FFFFFF;
  1044. box-shadow: 0rpx 0rpx 16rpx 2rpx rgba(232, 232, 232, 0.5);
  1045. border-radius: 16rpx;
  1046. padding: 44rpx 36rpx;
  1047. margin-bottom: 24rpx;
  1048. .title {
  1049. font-size: 28rpx;
  1050. font-weight: bold;
  1051. color: #2D2D2D;
  1052. padding-bottom: 20rpx;
  1053. margin-bottom: 26rpx;
  1054. border-bottom-style: dashed;
  1055. }
  1056. .notice-item {
  1057. font-size: 24rpx;
  1058. font-weight: 400;
  1059. color: #7F7F7F;
  1060. line-height: 36rpx;
  1061. margin-bottom: 8rpx;
  1062. }
  1063. }
  1064. .page-bottom {
  1065. position: relative;
  1066. z-index: 1001;
  1067. height: 98rpx;
  1068. padding: 24rpx 20rpx 50rpx;
  1069. .inner {
  1070. position: fixed;
  1071. background-color: #fff;
  1072. height: 98rpx;
  1073. left: 0;
  1074. right: 0;
  1075. bottom: 0;
  1076. padding: 24rpx 20rpx 50rpx;
  1077. box-shadow: 0rpx -4rpx 12rpx 0rpx rgba(215, 215, 215, 0.5);
  1078. .total-price {
  1079. font-size: 40rpx;
  1080. font-weight: bold;
  1081. color: #ED0000;
  1082. .bottom-coupon{
  1083. font-size: 24rpx;
  1084. }
  1085. }
  1086. .btn {
  1087. font-size: 28rpx;
  1088. height: 80rpx;
  1089. line-height: 80rpx;
  1090. border-radius: 50rpx;
  1091. padding: 0 50rpx;
  1092. background-color: #eee;
  1093. color: #333;
  1094. text-align: center;
  1095. &.active {
  1096. background: linear-gradient(90deg, #FF7979 0%, #ED0000 100%);
  1097. color: #fff;
  1098. }
  1099. }
  1100. }
  1101. }
  1102. .purchaser {
  1103. .item {
  1104. margin-bottom: 10rpx;
  1105. font-size: 26rpx;
  1106. color: #333;
  1107. }
  1108. .un-auth {
  1109. padding: 26rpx;
  1110. background-color: #eee;
  1111. color: #333;
  1112. text-align: center;
  1113. border-radius: 8rpx;
  1114. }
  1115. }
  1116. </style>