order.vue 13 KB

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