bookticket.vue 35 KB

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