bookticket.vue 34 KB

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