order.vue 19 KB

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