order.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. <template>
  2. <!-- 禁止滚动穿透 -->
  3. <page-meta :page-style="'overflow:'+(show?'hidden':'visible')"></page-meta>
  4. <view class="main">
  5. <view class="info">
  6. <scroll-view scroll-y="true" class="scroll-view">
  7. <view class="list-scroll-view">
  8. <view class="one">
  9. <view class="one_1">
  10. <text class="name textOver">{{info.name||'暂无'}}</text>
  11. <text @tap='toInfo(info)'>购买须知<text class="iconfont icon-dayuhao"></text></text>
  12. </view>
  13. <view class="one_2">
  14. <view class="time time_1" v-if="date">{{date}}</view>
  15. <view class="time_2" v-else>请选择时间!</view>
  16. <button type="button" @click="open">选择日期</button>
  17. </view>
  18. <view class="one_3">
  19. <view class="left">选择数量</view>
  20. <view class="right">
  21. <uni-number-box :min="1" :max="99" v-model="num" @change="changeNum" />
  22. </view>
  23. </view>
  24. <view class="one_4" v-if="couponList.length>0">
  25. <view class="left">优惠券</view>
  26. <view class="right" @tap="toCoupon">
  27. <text v-if="discountInfo.name">{{discountInfo.name}}</text>
  28. <text class="iconfont icon-dayuhao"></text>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="two">
  33. <view class="two_1">
  34. <text class="text_1">游客信息</text>
  35. <text class="text_2">需填<text class="num">{{num}}</text>位,用于入园身份验证</text>
  36. </view>
  37. <view class="two_2" v-for="(item, index) in identityList" :key="index">
  38. <view class="list_1">
  39. <text>游客{{index+1}}</text>
  40. <text v-if="item.name||item.card||item.phone" @tap="toDel(item,index)"
  41. class="iconfont icon-shanchu"></text>
  42. </view>
  43. <view class="list_2">
  44. <view v-if="item.name||item.card||item.phone" class="form_1">
  45. <view class="form_1_1">
  46. <text v-if="item.name">{{item.name}}</text>
  47. <text style="color: red;" v-else>缺少姓名信息 请填写补充!</text>
  48. </view>
  49. <view class="form_1_1">
  50. <text v-if="item.card">{{item.card}}</text>
  51. <text style="color: red;" v-else>缺少证件号信息 请填写补充!</text>
  52. </view>
  53. <view class="form_1_1">
  54. <text v-if="item.phone">{{item.phone}}</text>
  55. <text style="color: red;" v-else>缺少手机号信息 请填写补充!</text>
  56. </view>
  57. </view>
  58. <view v-else class="form_2" @tap="toWrite(item,index)">点击填写游客信息</view>
  59. </view>
  60. <view class="list_3" @tap="toWrite(item,index)">编辑</view>
  61. </view>
  62. </view>
  63. </view>
  64. </scroll-view>
  65. </view>
  66. <view class="foot">
  67. <view class="money">
  68. <text>¥{{info.original_price||'暂无'}}</text>
  69. <text>¥{{info.money||'暂无'}}起</text>
  70. </view>
  71. <view class="button">
  72. <button type="warn" @tap.stop="toOrder()">提交订单</button>
  73. </view>
  74. </view>
  75. <uni-calendar ref="calendar" :clear-date="true" :date="date" :insert="false" :lunar="true"
  76. :startDate="startDate" :endDate="endDate" :range="false" @confirm="confirm" />
  77. <uni-popup ref="popup" background-color="#fff" type="bottom" :is-mask-click="false" @change="change">
  78. <view class="popup">
  79. <view class="close">
  80. <text>新增游客信息</text>
  81. <text @click="toClose" class="iconfont icon-shanchu"></text>
  82. </view>
  83. <view class="info_1">
  84. <uni-forms ref="form" :rules="rules" :modelValue="form" :label-width="80">
  85. <uni-forms-item label="证件类型">
  86. <uni-easyinput disabled v-model="type" />
  87. </uni-forms-item>
  88. <uni-forms-item label="姓名" required name="name">
  89. <uni-easyinput v-model="form.name" placeholder="必填,请输入证件上的姓名" />
  90. </uni-forms-item>
  91. <uni-forms-item label="证件号" required name="card">
  92. <uni-easyinput v-model="form.card" maxlength="18" placeholder="必填,请输入证件号" />
  93. </uni-forms-item>
  94. <uni-forms-item label="手机号" required name="phone">
  95. <uni-easyinput v-model="form.phone" maxlength="11" placeholder="必填,请输入联系人手机号" />
  96. </uni-forms-item>
  97. </uni-forms>
  98. <button class="button" type="primary" @click="submit('form')">保存</button>
  99. </view>
  100. </view>
  101. </uni-popup>
  102. <!-- 领取优惠卷 -->
  103. <uni-popup ref="coupon" background-color="#fff" type="bottom" :is-mask-click="false" @change="change">
  104. <view class="popup">
  105. <view class="close">
  106. <text>抵用券</text>
  107. <text @click="toCouponClose" class="iconfont icon-shanchu"></text>
  108. </view>
  109. <view class="info_1">
  110. <scroll-view scroll-y="true" class="scroll-view">
  111. <view class="list-scroll-view">
  112. <view class="list" v-for="(item, index) in couponList" :key="index">
  113. <view class="list_1">
  114. <view class="left">
  115. <view class="left_1">
  116. ¥<text>{{item.discount_config.min}}</text>
  117. </view>
  118. <view class="left_2">
  119. <text v-if="item.discount_config.limit=='0'">无门槛</text>
  120. <text
  121. v-else>满{{item.discount_config.limit}}减{{item.discount_config.min}}</text>
  122. </view>
  123. </view>
  124. <view class="center">
  125. <view class="name textOver">{{item.name}}</view>
  126. <view class="content">有效日期:({{item.expire_type_label}}) {{item.expire_time}}
  127. </view>
  128. </view>
  129. <view class="right">
  130. <button class="button_1" type="primary" @tap="toUser(item)">使用</button>
  131. </view>
  132. </view>
  133. <view class="list_2">
  134. <uni-collapse>
  135. <uni-collapse-item title="使用规则补充说明" :open="false">
  136. <view class="content">{{item.brief}}</view>
  137. </uni-collapse-item>
  138. </uni-collapse>
  139. </view>
  140. </view>
  141. </view>
  142. </scroll-view>
  143. </view>
  144. </view>
  145. </uni-popup>
  146. </view>
  147. </template>
  148. <script>
  149. import moment from 'moment';
  150. export default {
  151. data() {
  152. return {
  153. id: '',
  154. user: {},
  155. info: {
  156. file: []
  157. },
  158. // 身份信息
  159. identityList: [{
  160. id: 0,
  161. }],
  162. // 优惠券
  163. couponList: [],
  164. discountInfo: '',
  165. // 数量
  166. num: 1,
  167. // 日期
  168. date: '',
  169. startDate: '',
  170. endDate: '',
  171. // 游客信息
  172. form: {},
  173. type: '身份证',
  174. // 禁止滚动穿透
  175. show: false,
  176. // 校验规则
  177. rules: {
  178. name: {
  179. rules: [{
  180. required: true,
  181. errorMessage: '请填写姓名'
  182. }]
  183. },
  184. phone: {
  185. rules: [{
  186. required: true,
  187. errorMessage: '请填写手机号码',
  188. }, {
  189. validateFunction: function(rule, value, data, callback) {
  190. let iphoneReg = (
  191. /^(13[0-9]|14[1579]|15[0-3,5-9]|16[6]|17[0123456789]|18[0-9]|19[89])\d{8}$/
  192. ); //手机号码
  193. if (!iphoneReg.test(value)) {
  194. callback('手机号码格式不正确,请重新填写')
  195. }
  196. }
  197. }]
  198. },
  199. card: {
  200. rules: [{
  201. required: true,
  202. errorMessage: '请填写证件号',
  203. },
  204. {
  205. validateFunction: function(rule, value, data, callback) {
  206. let iphoneReg =
  207. /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9]||[Xx]$/
  208. if (!iphoneReg.test(value)) {
  209. callback('身份证号格式不正确,请重新填写')
  210. }
  211. return true
  212. }
  213. }
  214. ]
  215. },
  216. },
  217. }
  218. },
  219. onLoad: async function(e) {
  220. const that = this;
  221. that.$set(that, `id`, e && e.id || '');
  222. that.searchToken();
  223. that.search();
  224. },
  225. methods: {
  226. // 禁止滚动穿透
  227. change(e) {
  228. const that = this;
  229. that.show = e.show
  230. },
  231. async searchToken() {
  232. const that = this;
  233. try {
  234. const res = uni.getStorageSync('token');
  235. if (res) {
  236. that.$set(that, `user`, res);
  237. const arr = await that.$api(`/userCoupon/specialQuery`, 'GET', {
  238. user: res._id || res.id,
  239. is_use: "0"
  240. })
  241. if (arr.errcode == '0') that.$set(that, `couponList`, arr.data)
  242. }
  243. } catch (e) {
  244. uni.showToast({
  245. title: err.errmsg,
  246. icon: 'error',
  247. duration: 2000
  248. });
  249. }
  250. },
  251. async search() {
  252. const that = this;
  253. if (that.id) {
  254. const res = await that.$api(`/ticket/${that.id}`, 'GET', {})
  255. if (res.errcode == '0') {
  256. if (res.data.date) {
  257. that.$set(that, `startDate`, res.data.date[0])
  258. that.$set(that, `endDate`, res.data.date[1])
  259. }
  260. that.$set(that, `info`, res.data)
  261. } else {
  262. uni.showToast({
  263. title: res.errmsg,
  264. });
  265. }
  266. }
  267. },
  268. // 详情
  269. toInfo(e) {
  270. uni.navigateTo({
  271. url: `/pagesHome/ticket/info?id=${e.id||e._id}`
  272. })
  273. },
  274. //日期弹窗
  275. open() {
  276. const that = this;
  277. that.$refs.calendar.open()
  278. },
  279. // 选择日期
  280. confirm(e) {
  281. const that = this;
  282. that.$set(that, `date`, e.fulldate)
  283. },
  284. // 数字选择器
  285. changeNum(value) {
  286. const that = this;
  287. that.$set(that, `num`, value)
  288. const data = []
  289. const identity = []
  290. identity.length = value;
  291. // 处理数量+1 游客信息+1
  292. for (let [index, val] of identity.entries()) {
  293. data.push({
  294. id: index
  295. })
  296. }
  297. that.$set(that, `identityList`, data)
  298. },
  299. // 删除游客信息
  300. toDel(item, index) {
  301. const that = this;
  302. const data = []
  303. for (let val of that.identityList) {
  304. if (val.id == item.id) data.push({
  305. id: index
  306. })
  307. else data.push(val)
  308. }
  309. that.$set(that, `identityList`, data)
  310. },
  311. // 编辑游客信息
  312. toWrite(item, index) {
  313. const that = this;
  314. that.$set(that, `form`, item)
  315. that.$refs.popup.open()
  316. },
  317. // 登录
  318. submit(ref) {
  319. const that = this;
  320. that.$refs[ref].validate().then(async form => {
  321. // 根据id 寻找添加的游客信息
  322. for (let val of that.identityList) {
  323. if (val.id == that.form.id) {
  324. form.id = that.form.id
  325. val = form
  326. }
  327. }
  328. that.toClose()
  329. })
  330. },
  331. // 领卷
  332. toCoupon() {
  333. const that = this;
  334. that.$refs.coupon.open()
  335. },
  336. // 关闭弹框
  337. toCouponClose() {
  338. const that = this;
  339. that.$refs.coupon.close();
  340. },
  341. // 去使用
  342. toUser(item) {
  343. const that = this;
  344. if (item.type == '0') {
  345. uni.showToast({
  346. title: '该优惠券不符合使用类型!',
  347. icon: 'none',
  348. duration: 2000
  349. });
  350. } else that.$set(that, `discountInfo`, item);
  351. that.toCouponClose();
  352. },
  353. // 关闭弹框
  354. toClose() {
  355. const that = this;
  356. that.$set(that, `form`, {});
  357. that.$refs.popup.close();
  358. },
  359. // 提交订单
  360. async toOrder() {
  361. const that = this;
  362. if (!that.date) {
  363. uni.showToast({
  364. title: '请选择日期!',
  365. icon: 'none',
  366. duration: 2000
  367. });
  368. return
  369. }
  370. // 判断每个游客信息是否都填写
  371. const name = that.identityList.every(function(item) {
  372. return item.name;
  373. })
  374. if (name) {
  375. const data = {
  376. user: that.user._id || that.user.id,
  377. source: that.info,
  378. source_name: that.info.name,
  379. type: '1',
  380. money: that.$multiply(that.info.money, that.num),
  381. date: that.date,
  382. num: that.num,
  383. identity: that.identityList,
  384. discount: that.discountInfo._id || that.discountInfo.id,
  385. buy_time: moment().format('YYYY-MM-DD HH:mm:ss'),
  386. pay_time: '',
  387. pay: [],
  388. status: '1'
  389. }
  390. const res = await that.$api(`/order`, 'POST', data);
  391. if (res.errcode == '0') {
  392. uni.redirectTo({
  393. url: `/pagesIndex/order/index?status=${'1'}`
  394. })
  395. } else {
  396. uni.showToast({
  397. title: res.errmsg,
  398. icon: 'none'
  399. })
  400. }
  401. } else {
  402. uni.showToast({
  403. title: '未填写游客信息!',
  404. icon: 'none',
  405. duration: 2000
  406. });
  407. return
  408. }
  409. }
  410. }
  411. }
  412. </script>
  413. <style lang="scss" scoped>
  414. .main {
  415. display: flex;
  416. flex-direction: column;
  417. width: 100vw;
  418. height: 100vh;
  419. .info {
  420. position: relative;
  421. flex-grow: 1;
  422. background-image: linear-gradient(to top, rgba(241, 241, 241, 1), rgba(241, 241, 241, 1), rgba(0, 122, 255, 1));
  423. border-bottom: 1px solid var(--f9Color);
  424. .one {
  425. margin: 2vw;
  426. padding: 2vw;
  427. border-radius: 10px;
  428. background-color: var(--mainColor);
  429. .one_1 {
  430. display: flex;
  431. justify-content: space-between;
  432. align-items: center;
  433. padding: 2vw;
  434. border-bottom: 1px solid var(--f9Color);
  435. .name {
  436. width: 85vw;
  437. font-size: var(--font18Size);
  438. font-weight: bold;
  439. }
  440. text:last-child {
  441. width: 20vw;
  442. text-align: right;
  443. font-weight: bold;
  444. font-size: var(--font12Size);
  445. color: var(--f3CColor);
  446. }
  447. }
  448. .one_2 {
  449. padding: 2vw;
  450. border-bottom: 1px solid var(--f9Color);
  451. .time {
  452. text-align: center;
  453. padding: 2vw;
  454. margin: 2vw;
  455. border-radius: 10px;
  456. border: 1px solid;
  457. }
  458. .time_1 {
  459. color: var(--f3CColor);
  460. }
  461. .time_2 {
  462. padding: 2vw;
  463. font-size: var(--font12Size);
  464. color: var(--fF0Color);
  465. }
  466. }
  467. .one_3 {
  468. display: flex;
  469. justify-content: space-between;
  470. padding: 4vw 2vw;
  471. border-bottom: 1px solid var(--f9Color);
  472. .left {
  473. font-size: var(--font18Size);
  474. font-weight: bold;
  475. }
  476. }
  477. .one_4 {
  478. display: flex;
  479. justify-content: space-between;
  480. font-size: var(--font18Size);
  481. font-weight: bold;
  482. padding: 2vw;
  483. border-bottom: 1px solid var(--f9Color);
  484. }
  485. }
  486. .two {
  487. margin: 0 2vw;
  488. padding: 2vw;
  489. border-radius: 10px;
  490. background-color: var(--mainColor);
  491. .two_1 {
  492. padding: 2vw;
  493. border-bottom: 1px solid var(--f9Color);
  494. .text_1 {
  495. font-size: var(--font18Size);
  496. }
  497. .text_2 {
  498. font-size: var(--font14Size);
  499. color: var(--f85Color);
  500. padding: 0 2vw;
  501. .num {
  502. padding: 0 2px;
  503. color: var(--fF0Color);
  504. }
  505. }
  506. }
  507. .two_2 {
  508. display: flex;
  509. justify-content: space-between;
  510. align-items: center;
  511. padding: 2vw;
  512. border-bottom: 1px solid var(--f9Color);
  513. .list_1 {
  514. display: flex;
  515. flex-direction: column;
  516. align-items: center;
  517. font-size: var(--font14Size);
  518. color: var(--f85Color);
  519. text {
  520. padding: 2px 0;
  521. }
  522. }
  523. .list_2 {
  524. .form_1 {
  525. width: 55vw;
  526. padding: 0 2px;
  527. .form_1_1 {
  528. padding: 3px 0;
  529. font-size: var(--font12Size);
  530. }
  531. }
  532. .form_2 {
  533. color: var(--f3CColor);
  534. font-size: var(--font14Size);
  535. }
  536. }
  537. .list_3 {
  538. font-size: var(--font12Size);
  539. }
  540. }
  541. }
  542. }
  543. .foot {
  544. display: flex;
  545. justify-content: space-between;
  546. align-items: center;
  547. padding: 2vw;
  548. background-color: var(--mainColor);
  549. .money {
  550. text-align: right;
  551. color: var(--fF0Color);
  552. font-size: var(--font16Size);
  553. font-weight: bold;
  554. text:first-child {
  555. text-decoration: line-through;
  556. color: var(--f69Color);
  557. font-size: var(--font12Size);
  558. font-weight: 400;
  559. }
  560. }
  561. .button {
  562. button {
  563. width: 30vw;
  564. font-size: var(--font14Size);
  565. border-radius: 40px;
  566. background: linear-gradient(to right, #00BFFF, #007AFF);
  567. }
  568. }
  569. }
  570. }
  571. .uni-popup {
  572. z-index: 9999 !important;
  573. }
  574. .popup {
  575. display: flex;
  576. flex-direction: column;
  577. width: 100vw;
  578. height: 60vh;
  579. .close {
  580. display: flex;
  581. justify-content: space-between;
  582. padding: 2vw;
  583. text:first-child {
  584. font-size: var(--font16Size);
  585. font-weight: bold;
  586. }
  587. }
  588. .info_1 {
  589. position: relative;
  590. display: flex;
  591. flex-direction: column;
  592. height: 54vh;
  593. padding: 2vw;
  594. .list {
  595. background-color: var(--mainColor);
  596. border: 1px solid var(--f5Color);
  597. padding: 2vw;
  598. margin: 2vw 2vw 0 2vw;
  599. border-radius: 5px;
  600. .list_1 {
  601. display: flex;
  602. justify-content: space-between;
  603. align-items: center;
  604. .left {
  605. width: 20vw;
  606. display: flex;
  607. flex-direction: column;
  608. justify-content: center;
  609. align-items: center;
  610. padding: 3vw;
  611. color: var(--fF0Color);
  612. font-size: var(--font14Size);
  613. .left_1 {
  614. text {
  615. font-weight: bold;
  616. font-size: 25px;
  617. }
  618. }
  619. .left_2 {
  620. font-size: var(--font12Size);
  621. }
  622. }
  623. .center {
  624. width: 40vw;
  625. .name {
  626. font-size: var(--font14Size);
  627. font-weight: bold;
  628. margin: 0 0 1vw 0;
  629. }
  630. .content {
  631. color: var(--f85Color);
  632. font-size: var(--font12Size);
  633. }
  634. }
  635. .right {
  636. .button {
  637. font-size: 12px;
  638. border-radius: 20px;
  639. background: linear-gradient(to right, #FFA500, #FF0000);
  640. }
  641. .button_1 {
  642. font-size: 12px;
  643. border-radius: 20px;
  644. border: 1px solid var(--fF0Color);
  645. color: var(--fF0Color);
  646. background: var(--mainColor);
  647. }
  648. }
  649. }
  650. .list_2 {
  651. font-size: var(--font12Size);
  652. /deep/.uni-collapse-item__title-box {
  653. padding: 0 !important;
  654. font-size: 12px !important;
  655. }
  656. /deep/.uni-collapse-item__title-text {
  657. font-size: 12px !important;
  658. }
  659. .content {
  660. padding: 2vw;
  661. }
  662. }
  663. }
  664. button {
  665. font-size: var(--font14Size);
  666. background: linear-gradient(to right, #00BFFF, #007AFF);
  667. }
  668. }
  669. }
  670. .scroll-view {
  671. position: absolute;
  672. top: 0;
  673. left: 0;
  674. right: 0;
  675. bottom: 0;
  676. .list-scroll-view {
  677. display: flex;
  678. flex-direction: column;
  679. }
  680. }
  681. </style>