bookticket.vue 35 KB

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