order.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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>{{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>
  27. </view>
  28. <view class="two">
  29. <view class="two_1">
  30. <text class="text_1">游客信息</text>
  31. <text class="text_2">需填<text class="num">{{num}}</text>位,用于入园身份验证</text>
  32. </view>
  33. <view class="two_2" v-for="(item, index) in identityList" :key="index">
  34. <view class="list_1">
  35. <text>游客{{index+1}}</text>
  36. <text v-if="item.name||item.card||item.phone" @tap="toDel(item,index)"
  37. class="iconfont icon-shanchu"></text>
  38. </view>
  39. <view class="list_2">
  40. <view v-if="item.name||item.card||item.phone" class="form_1">
  41. <view class="form_1_1">
  42. <text v-if="item.name">{{item.name}}</text>
  43. <text style="color: red;" v-else>缺少姓名信息 请填写补充!</text>
  44. </view>
  45. <view class="form_1_1">
  46. <text v-if="item.card">{{item.card}}</text>
  47. <text style="color: red;" v-else>缺少证件号信息 请填写补充!</text>
  48. </view>
  49. <view class="form_1_1">
  50. <text v-if="item.phone">{{item.phone}}</text>
  51. <text style="color: red;" v-else>缺少手机号信息 请填写补充!</text>
  52. </view>
  53. </view>
  54. <view v-else class="form_2" @tap="toWrite(item,index)">点击填写游客信息</view>
  55. </view>
  56. <view class="list_3" @tap="toWrite(item,index)">编辑</view>
  57. </view>
  58. </view>
  59. </view>
  60. </scroll-view>
  61. </view>
  62. <view class="foot">
  63. <view class="money">
  64. <text>¥{{info.original_price||'暂无'}}</text>
  65. <text>¥{{info.money||'暂无'}}起</text>
  66. </view>
  67. <view class="button">
  68. <button type="warn" @tap.stop="toOrder()">提交订单</button>
  69. </view>
  70. </view>
  71. <uni-calendar ref="calendar" :clear-date="true" :date="date" :insert="false" :lunar="true"
  72. :startDate="startDate" :endDate="endDate" :range="false" @confirm="confirm" />
  73. <uni-popup ref="popup" background-color="#fff" type="bottom" :is-mask-click="false" @change="change">
  74. <view class="popup">
  75. <view class="close">
  76. <text>新增游客信息</text>
  77. <text @click="toClose" class="iconfont icon-shanchu"></text>
  78. </view>
  79. <view class="info_1">
  80. <uni-forms ref="form" :rules="rules" :modelValue="form" :label-width="80">
  81. <uni-forms-item label="证件类型">
  82. <uni-easyinput disabled v-model="type" />
  83. </uni-forms-item>
  84. <uni-forms-item label="姓名" required name="name">
  85. <uni-easyinput v-model="form.name" placeholder="必填,请输入证件上的姓名" />
  86. </uni-forms-item>
  87. <uni-forms-item label="证件号" required name="card">
  88. <uni-easyinput v-model="form.card" maxlength="18" placeholder="必填,请输入证件号" />
  89. </uni-forms-item>
  90. <uni-forms-item label="手机号" required name="phone">
  91. <uni-easyinput v-model="form.phone" maxlength="11" placeholder="必填,请输入联系人手机号" />
  92. </uni-forms-item>
  93. </uni-forms>
  94. <button class="button" type="primary" @click="submit('form')">登录</button>
  95. </view>
  96. </view>
  97. </uni-popup>
  98. </view>
  99. </template>
  100. <script>
  101. export default {
  102. data() {
  103. return {
  104. id: '',
  105. user: {},
  106. info: {
  107. file: []
  108. },
  109. // 身份信息
  110. identityList: [{
  111. id: 0,
  112. }],
  113. // 优惠卷
  114. couponList: [],
  115. // 数量
  116. num: 1,
  117. // 日期
  118. date: '',
  119. startDate: '',
  120. endDate: '',
  121. // 游客信息
  122. form: {},
  123. type: '身份证',
  124. // 禁止滚动穿透
  125. show: false,
  126. // 校验规则
  127. rules: {
  128. name: {
  129. rules: [{
  130. required: true,
  131. errorMessage: '请填写姓名'
  132. }]
  133. },
  134. phone: {
  135. rules: [{
  136. required: true,
  137. errorMessage: '请填写手机号码',
  138. }, {
  139. validateFunction: function(rule, value, data, callback) {
  140. let iphoneReg = (
  141. /^(13[0-9]|14[1579]|15[0-3,5-9]|16[6]|17[0123456789]|18[0-9]|19[89])\d{8}$/
  142. ); //手机号码
  143. if (!iphoneReg.test(value)) {
  144. callback('手机号码格式不正确,请重新填写')
  145. }
  146. }
  147. }]
  148. },
  149. card: {
  150. rules: [{
  151. required: true,
  152. errorMessage: '请填写证件号',
  153. },
  154. {
  155. validateFunction: function(rule, value, data, callback) {
  156. let iphoneReg =
  157. /^[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]$/
  158. if (!iphoneReg.test(value)) {
  159. callback('身份证号格式不正确,请重新填写')
  160. }
  161. return true
  162. }
  163. }
  164. ]
  165. },
  166. },
  167. }
  168. },
  169. onLoad: async function(e) {
  170. const that = this;
  171. that.$set(that, `id`, e && e.id || '');
  172. that.searchToken();
  173. that.search();
  174. },
  175. methods: {
  176. // 禁止滚动穿透
  177. change(e) {
  178. const that = this;
  179. that.show = e.show
  180. },
  181. searchToken() {
  182. const that = this;
  183. try {
  184. const res = uni.getStorageSync('token');
  185. if (res) {
  186. that.$set(that, `user`, res);
  187. }
  188. } catch (e) {
  189. uni.showToast({
  190. title: err.errmsg,
  191. icon: 'error',
  192. duration: 2000
  193. });
  194. }
  195. },
  196. async search() {
  197. const that = this;
  198. if (that.id) {
  199. const res = await that.$api(`/ticket/${that.id}`, 'GET', {})
  200. if (res.errcode == '0') {
  201. if (res.data.date) {
  202. that.$set(that, `startDate`, res.data.date[0])
  203. that.$set(that, `endDate`, res.data.date[1])
  204. }
  205. that.$set(that, `info`, res.data)
  206. } else {
  207. uni.showToast({
  208. title: res.errmsg,
  209. });
  210. }
  211. }
  212. },
  213. // 详情
  214. toInfo(e) {
  215. uni.navigateTo({
  216. url: `/pagesHome/ticket/info?id=${e.id||e._id}`
  217. })
  218. },
  219. //日期弹窗
  220. open() {
  221. const that = this;
  222. that.$refs.calendar.open()
  223. },
  224. // 选择日期
  225. confirm(e) {
  226. const that = this;
  227. that.$set(that, `date`, e.fulldate)
  228. },
  229. // 数字选择器
  230. changeNum(value) {
  231. const that = this;
  232. that.$set(that, `num`, value)
  233. const data = []
  234. const identity = []
  235. identity.length = value;
  236. // 处理数量+1 游客信息+1
  237. for (let [index, val] of identity.entries()) {
  238. data.push({
  239. id: index
  240. })
  241. }
  242. that.$set(that, `identityList`, data)
  243. },
  244. // 删除游客信息
  245. toDel(item, index) {
  246. const that = this;
  247. const data = []
  248. for (let val of that.identityList) {
  249. if (val.id == item.id) data.push({
  250. id: index
  251. })
  252. else data.push(val)
  253. }
  254. that.$set(that, `identityList`, data)
  255. },
  256. // 编辑游客信息
  257. toWrite(item, index) {
  258. const that = this;
  259. that.$set(that, `form`, item)
  260. that.$refs.popup.open()
  261. },
  262. // 登录
  263. submit(ref) {
  264. const that = this;
  265. that.$refs[ref].validate().then(async form => {
  266. // 根据id 寻找添加的游客信息
  267. for (let val of that.identityList) {
  268. if (val.id == that.form.id) {
  269. form.id = that.form.id
  270. val = form
  271. }
  272. }
  273. that.toClose()
  274. })
  275. },
  276. // 关闭弹框
  277. toClose() {
  278. const that = this;
  279. that.$set(that, `form`, {});
  280. that.$refs.popup.close();
  281. },
  282. // 提交订单
  283. async toOrder() {
  284. const that = this;
  285. if (!that.date) {
  286. uni.showToast({
  287. title: '请选择日期!',
  288. icon: 'none',
  289. duration: 2000
  290. });
  291. return
  292. }
  293. // 判断每个游客信息是否都填写
  294. const name = that.identityList.every(function(item) {
  295. return item.name;
  296. })
  297. if (name) {
  298. console.log('提交订单');
  299. } else {
  300. uni.showToast({
  301. title: '未填写游客信息!',
  302. icon: 'none',
  303. duration: 2000
  304. });
  305. return
  306. }
  307. }
  308. }
  309. }
  310. </script>
  311. <style lang="scss" scoped>
  312. .main {
  313. display: flex;
  314. flex-direction: column;
  315. width: 100vw;
  316. height: 100vh;
  317. .info {
  318. position: relative;
  319. flex-grow: 1;
  320. background-image: linear-gradient(to top, rgba(249, 249, 249, 0), rgba(249, 249, 249, 0), rgba(0, 0, 255, 1));
  321. border-bottom: 1px solid var(--f9Color);
  322. .one {
  323. margin: 2vw;
  324. padding: 2vw;
  325. border-radius: 10px;
  326. background-color: var(--mainColor);
  327. .one_1 {
  328. display: flex;
  329. justify-content: space-between;
  330. align-items: center;
  331. padding: 2vw;
  332. border-bottom: 1px solid var(--f9Color);
  333. text {
  334. font-size: var(--font18Size);
  335. font-weight: bold;
  336. }
  337. text:last-child {
  338. font-size: var(--font12Size);
  339. color: var(--f3CColor);
  340. }
  341. }
  342. .one_2 {
  343. padding: 2vw;
  344. border-bottom: 1px solid var(--f9Color);
  345. .time {
  346. text-align: center;
  347. padding: 2vw;
  348. margin: 2vw;
  349. border-radius: 10px;
  350. border: 1px solid;
  351. }
  352. .time_1 {
  353. color: var(--f3CColor);
  354. }
  355. .time_2 {
  356. padding: 2vw;
  357. font-size: var(--font12Size);
  358. color: var(--fF0Color);
  359. }
  360. }
  361. .one_3 {
  362. display: flex;
  363. justify-content: space-between;
  364. padding: 4vw 2vw;
  365. border-bottom: 1px solid var(--f9Color);
  366. .left {
  367. font-size: var(--font18Size);
  368. font-weight: bold;
  369. }
  370. }
  371. .one_4 {
  372. font-size: var(--font18Size);
  373. font-weight: bold;
  374. padding: 2vw;
  375. border-bottom: 1px solid var(--f9Color);
  376. }
  377. }
  378. .two {
  379. margin: 0 2vw;
  380. padding: 2vw;
  381. border-radius: 10px;
  382. background-color: var(--mainColor);
  383. .two_1 {
  384. padding: 2vw;
  385. border-bottom: 1px solid var(--f9Color);
  386. .text_1 {
  387. font-size: var(--font18Size);
  388. }
  389. .text_2 {
  390. font-size: var(--font14Size);
  391. color: var(--f85Color);
  392. padding: 0 2vw;
  393. .num {
  394. padding: 0 2px;
  395. color: var(--fF0Color);
  396. }
  397. }
  398. }
  399. .two_2 {
  400. display: flex;
  401. justify-content: space-between;
  402. align-items: center;
  403. padding: 2vw;
  404. border-bottom: 1px solid var(--f9Color);
  405. .list_1 {
  406. display: flex;
  407. flex-direction: column;
  408. align-items: center;
  409. font-size: var(--font14Size);
  410. color: var(--f85Color);
  411. text {
  412. padding: 2px 0;
  413. }
  414. }
  415. .list_2 {
  416. .form_1 {
  417. width: 55vw;
  418. padding: 0 2px;
  419. .form_1_1 {
  420. padding: 3px 0;
  421. font-size: var(--font12Size);
  422. }
  423. }
  424. .form_2 {
  425. color: var(--f3CColor);
  426. font-size: var(--font14Size);
  427. }
  428. }
  429. .list_3 {
  430. font-size: var(--font12Size);
  431. }
  432. }
  433. }
  434. }
  435. .foot {
  436. display: flex;
  437. justify-content: space-between;
  438. align-items: center;
  439. padding: 2vw;
  440. background-color: var(--mainColor);
  441. .money {
  442. text-align: right;
  443. color: var(--fF0Color);
  444. font-size: var(--font16Size);
  445. font-weight: bold;
  446. text:first-child {
  447. text-decoration: line-through;
  448. color: var(--f69Color);
  449. font-size: var(--font12Size);
  450. font-weight: 400;
  451. }
  452. }
  453. .button {
  454. button {
  455. width: 30vw;
  456. font-size: var(--font14Size);
  457. border-radius: 40px;
  458. background: linear-gradient(to right, #00BFFF, #007AFF);
  459. }
  460. }
  461. }
  462. }
  463. .uni-popup {
  464. z-index: 9999 !important;
  465. }
  466. .popup {
  467. display: flex;
  468. flex-direction: column;
  469. width: 100vw;
  470. height: 60vh;
  471. .close {
  472. display: flex;
  473. justify-content: space-between;
  474. padding: 2vw;
  475. text:first-child {
  476. font-size: var(--font16Size);
  477. font-weight: bold;
  478. }
  479. }
  480. .info_1 {
  481. position: relative;
  482. display: flex;
  483. flex-direction: column;
  484. height: 54vh;
  485. padding: 2vw;
  486. button {
  487. font-size: var(--font14Size);
  488. background: linear-gradient(to right, #00BFFF, #007AFF);
  489. }
  490. }
  491. }
  492. .scroll-view {
  493. position: absolute;
  494. top: 0;
  495. left: 0;
  496. right: 0;
  497. bottom: 0;
  498. .list-scroll-view {
  499. display: flex;
  500. flex-direction: column;
  501. }
  502. }
  503. </style>