- 实验目的
- 掌握小程序API的使用;
- 掌握小程序API开发,能够实现仿智行火车票12306;
- 实验准备与环境
- PC
- Windows操作系统
- 微信开发者工具
- 实验要求
- 学习如何应用小程序API知识开发仿智行火车票12306;
- 实验步骤
功能要求:设计一款模拟“智行订票12306”的微信小程序,实现如下功能:
- 底部标签导航,包括火车票、飞机票、汽车票、个人中心标签页。
- 火车票有详情列表页。
- 个人中心有账号信息、订票信息。
- 完整代码实现(包含代码和运行截图)
-
Traintickets.wxml <!-- 轮播图 --> <view> <!-- 定义轮播图的轮播时间为3秒,更换时间为1秒 --> <swiper class="banneritem" autoplay="true" interval="3000" duration="1000"> <!-- 通过for循环获取ja中data的banneritem数组的bannerUrls属性,作为轮播图图片的路径 --> <swiper-item wx:for="{{bannerUrls}}" wx:key="url"> <image src='{{item.url}}' mode="widthFix"></image> </swiper-item> </swiper> </view> <!-- 选择出发地和到达地 --> <view class="content"> <!-- 样式选择 --> <view class="navbg"> <view id="0" class="{{currentTab == 0 ? 'select' : 'normal'}}" bindtap="switchNav">火车票</view> <view id="1" class="{{currentTab == 1 ? 'select' : 'normal'}}" bindtap="switchNavPlane">飞机票</view> <view id="2" class="{{currentTab == 2 ? 'select' : 'normal'}}" bindtap="switchNavBus">汽车票</view> </view> <view class="formbg"> <form bindsubmit="formSubmit"> <!-- 通过实现对data的startStation和endStation属性获取到初始的出发站和达到站 --> <view class="station"> <view> <input name="startStation" value="{{startStation}}" /> </view> <!-- 通过swapContent方法实现值得交换 --> <view bindtap="swapContent" data-start="{{startStation}}" data-end="{{endStation}}"> <image src="/images/train/换站.jpg" style="width:44px;height:45px;"></image> </view> <view> <input name="endStation" value="{{endStation}}" /> </view> </view> <view class="hr"></view> <!-- 获取到今天的日期并显示 --> <!-- <view class="station"> <picker name="date" value="{{todayDate}}" start="2019-1-1" end="2020-12-31" bindchange="bindDateChange"> <view>{{ todayDate}}</view> </picker> <view style="width:50%">></view> <view > <text style="color:#5495E6; margin-left: 20rpx; font-size: 10rpx;"> 今天 </text></view> <view class="week-box"> <input name="week" value="{{todayWeek}}" /> </view> </view> --> <view class="station"> <view> <!-- <picker name="date" value="{{todayDate}}" start="2019-1-1" end="2020-12-31" bindchange="bindDateChange"> <view>{{ todayDate}}</view> </picker> --> <input name="date" value="{{todayDate}}" /> </view> <view > <text style="color:#5495E6; margin-left: 20rpx; font-size: 10rpx;"> 今天 </text></view> <view class="week-box"> <input name="week" value="{{todayWeek}}" /> </view> </view> <!-- 查询车票 --> <button class="btn" form-type="submit">查询车票</button> </form> <view class="record" > <view wx:for="{{record}}" wx:key="id"> <text>{{item.lishi}}</text> </view> <!-- <text>南靖--福州</text> <text>漳州--厦门</text> <text>厦门--福州</text> <text>南靖--福州</text> --> <view bindtap="clearHistory"><text>清除历史</text> </view> </view> </view> </view> <!-- 快捷功能 --> <view class="icon"> <!-- <view wx:for="{{icon}}" wx:key="id"> <view class="item"> <view> <image src="{{item.iconurl}}" style="width:40px;height:40px;"></image> </view> <view class="menu">{{item.iconname}}</view> </view> </view> --> <!-- 第一行 --> <view class="item"> <view> <image src="/images/快捷功能/电视大屏.png" style="width:40px;height:40px;"></image> </view> <view class="menu">车站大屏</view> </view> <view class="item"> <view> <image src="/images/快捷功能/火车票.png" style="width:40px;height:40px;"></image> </view> <view class="menu">快捷火车票</view> </view> <view class="item"> <view> <image src="/images/快捷功能/铁路一卡通.jpg" style="width:40px;height:40px;"></image> </view> <view class="menu">铁路e卡通</view> </view> <view class="item"> <view> <image src="/images/快捷功能/时刻表.jpg" style="width:40px;height:40px;"></image> </view> <view class="menu">时刻表</view> </view> <view class="item"> <view> <image src="/images/快捷功能/温馨服务.jpg" style="width:40px;height:40px;"></image> </view> <view class="menu">温馨服务</view> </view> <!-- 第二行 --> <view class="item"> <view> <image src="/images/快捷功能/空铁联运.jpg" style="width:40px;height:40px;"></image> </view> <view class="menu">空铁联运</view> </view> <view class="item"> <view> <image src="/images/快捷功能/铁水联运.jpg" style="width:40px;height:40px;"></image> </view> <view class="menu">铁水联运</view> </view> <view class="item"> <view> <image src="/images/快捷功能/酒店住宿.jpg" style="width:40px;height:40px;"></image> </view> <view class="menu">酒店住宿</view> </view> <view class="item"> <view> <image src="/images/快捷功能/约车.jpg" style="width:40px;height:40px;"></image> </view> <view class="menu">约车</view> </view> <view class="item"> <view> <image src="/images/快捷功能/铁路游.jpg" style="width:40px;height:40px;"></image> </view> <view class="menu">铁路游</view> </view> <!-- 第三行 --> <view class="item"> <view> <image src="/images/快捷功能/电视大屏.png" style="width:40px;height:40px;"></image> </view> <view class="menu">车站大屏</view> </view> <view class="item"> <view> <image src="/images/快捷功能/火车票.png" style="width:40px;height:40px;"></image> </view> <view class="menu">快捷火车票</view> </view> <view class="item"> <view> <image src="/images/快捷功能/铁路一卡通.jpg" style="width:40px;height:40px;"></image> </view> <view class="menu">铁路e卡通</view> </view> <view class="item"> <view> <image src="/images/快捷功能/时刻表.jpg" style="width:40px;height:40px;"></image> </view> <view class="menu">时刻表</view> </view> <view class="item"> <view> <image src="/images/快捷功能/温馨服务.jpg" style="width:40px;height:40px;"></image> </view> <view class="menu">温馨服务</view> </view> </view> Traintickets.wxss /* 轮播图 */ .banneritem{ width: 100%; height: 200rpx; } .banneritem image{ width: 100%; height: 80rpx; overflow: hidden; } /* 选择框 */ .today1{ margin-left: 20rpx; font-size: 5rpx; } .content{ height: 500px; background-color: #f4f4f4; } /** 导航样式设置 */ .navbg{ width: 92%; background-color: #898989; height: 40px; margin: 0 auto; margin-top: -25rpx; border-top-left-radius: 5px; border-top-right-radius: 5px; display: flex; flex-direction: row; z-index: 9999; position:relative; } .normal{ width: 40%; height: 40px; line-height: 40px; text-align: center; color: #ffffff; font-size: 15px; margin: 0 auto; border-top-left-radius: 5px; border-top-right-radius: 5px; } .select{ width: 40%; height: 40px; line-height: 40px; text-align: center; color: #000000; font-size: 15px; margin: 0 auto; background-color: #ffffff; } .formbg{ width: 92%; background-color: #ffffff; margin: 0 auto; padding-top: 20px; padding-bottom: 10px; border-bottom-left-radius: 5px; border-bottom-right-radius: 5px; } .station{ display: flex; flex-direction: row; width: 90%; margin: 0 auto; text-align: center; } .station view{ height: 45px; line-height: 45px; font-size: 20px; width: 33%; } .station picker{ height: 45px; line-height: 45px; font-size: 20px; width: 33%; } .datapicker{ height: 45px; line-height: 45px; } .station input{ height: 45px; line-height: 45px; } .hr{ height: 1px; background-color: #cccccc; opacity: 0.2; margin-top: 5px; margin-bottom: 5px; } .btn{ width: 100%; height: 45px; line-height: 45px; color: #ffffff; text-align: center; font-size: 20px; background-color: #5495E6; margin: 0 auto; margin-top: 10px; border-radius: 5px; display: flex; align-items: center; justify-content: center; } .record{ text-align: center; margin-top: 10px; font-size: 10px; color: #999999; display: flex; flex-wrap: nowrap; white-space: nowrap; overflow-x: auto; } .record text{ margin-right: 20px; white-space: nowrap; overflow-x: auto; } .week-box{ color:#5495E6; font-size: large; } /*查询下面四个快捷查询按钮*/ .icon { display: flex; /* flex-direction: row; */ flex-wrap: wrap; /* 添加这一行 */ margin-top: -550rpx; height: 200px; background-color: #ffffff; padding: 10rpx; border-top-left-radius: 5px; border-top-right-radius: 5px; width: 92%; margin-bottom: 10px; /* 调整上下间距,可以根据需要调整具体数值 */ } .item { width: 20%; text-align: center; margin: 0 auto; } .menu { width: 20%; font-size: 11px; width: 100px; margin-left: -40rpx; } Traintickets.js // pages/Traintickets/Traintickets.js const app = getApp(); var page = 1; Page({ /** * 页面的初始数据 */ data: { //轮播图的图片路径和点击路径 bannerUrls: [{ url: '/images/Header/五一出行1.jpg', linkUrl: '五一出行' }, { url: '/images/Header/旅途佳肴.jpg', linkUrl: '旅途佳肴' } ], icon:[ { id:1, iconurl:'/images/快捷功能/电视大屏.png', iconname:"车站大屏" }, { id:2, iconurl:'/images/快捷功能/火车票.png', iconname:"火车票" }, { id:3, iconurl:'/images/快捷功能/铁路一卡通.jpg', iconname:"铁路e卡通" }, { id:4, iconurl:'/images/快捷功能/时刻表.jpg', iconname:"时刻表" }, { id:5, iconurl:'/images/快捷功能/温馨服务.jpg', iconname:"温馨服务" }, { id:6, iconurl:'/images/快捷功能/空铁联运.jpg', iconname:"温馨服务" }, { id:7, iconurl:'/images/快捷功能/铁水联运.jpg', iconname:"温馨服务" }, { id:8, iconurl:'/images/快捷功能/酒店住宿.jpg', iconname:"温馨服务" }, { id:9, iconurl:'/images/快捷功能/约车.jpg', iconname:"温馨服务" }, { id:10, iconurl:'/images/快捷功能/铁路游.jpg', iconname:"温馨服务" }, { id:11, iconurl:'/images/快捷功能/电视大屏.png', iconname:"温馨服务" }, { id:12, iconurl:'/images/快捷功能/电视大屏.png', iconname:"温馨服务" }, { id:13, iconurl:'/images/快捷功能/电视大屏.png', iconname:"温馨服务" }, { id:14, iconurl:'/images/快捷功能/电视大屏.png', iconname:"温馨服务" }, { id:15, iconurl:'/images/快捷功能/电视大屏.png', iconname:"温馨服务" }, ], // 导航栏样式切换 currentTab: 0, trainList: [ ], imgheights: '0', startStation: "福州", endStation: "漳州", todayDate: "", todayWeek: "", record: [{ id: 1, lishi: "南靖--厦门" }, { id:2, lishi: "漳州--厦门" }, { id:3, lishi: "厦门--福州" }, { id:4, lishi: "南靖--福州" } ] }, // 清除历史记录 clearHistory: function () { this.setData({ record: [] }); }, // 导航栏样式切换 // 获取到页面的id switchNav: function (e) { var id = e.currentTarget.id; this.setData({ currentTab: id }); }, // 点击跳转到飞机票订购页面 switchNavPlane: function () { this.setData({ currentTab: 1 }); wx.navigateTo({ url: '/pages/planeticket/planeticket', }); }, // 点击跳转到汽车票订购页面 switchNavBus: function () { this.setData({ currentTab: 2 }); wx.navigateTo({ url: '/pages/busticket/busticket', }); }, // 点击交换按钮,实现出发地点与目的地的值 swapContent: function (e) { const start = e.currentTarget.dataset.start; const end = e.currentTarget.dataset.end; this.setData({ startStation: end, endStation: start }); }, /** * 生命周期函数--监听页面加载 */ onLoad: function () { const date = new Date(); const month = date.getMonth() + 1; // 月份从0开始,需要加1 const day = date.getDate(); const formattedDate = month + "月" + day + "日"; const weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']; const formattedWeek = weekDays[date.getDay()]; this.setData({ todayDate: formattedDate, todayWeek: formattedWeek }); }, formSubmit: function (e) { console.log(e); var startStation = e.detail.value.startStation; //始发站 var endStation = e.detail.value.endStation; //终点站 var date = e.detail.value.date; //日期2月2日 var week = e.detail.value.week; //星期:周四 wx.navigateTo({ url: '../train/train?startStation=' + startStation + "&endStation=" + endStation + "&date=" + date + "&week" + week }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })
-
train.wxml <!--pages/trainList/trainList.wxml--> <!--日期的设计--> <view class="date"> <view>前一天</view> <view> {{date}} </view> <view>后一天</view> </view> <view class="content" style="height:{{winHeight}}px"> <block wx:for="{{trainList}}" wx:key="id"> <!--动态渲染,将trainList,winHeight动态绑定到界面--> <view class="bg"> <view class="item"> <!--始发站,终点站--> <view class="wrApper left"> <view class="normal">{{item.start_station}}</view> <view class="bule">{{item.start_time}}</view> </view> <!--车次,日期--> <view class="wrApper center"> <view class="normal">{{item.train_no}}</view> <view class="line"></view> <view class="small">{{item.run_time}}</view> </view> <!--时间--> <view class="wrApper right"> <view class="normal">{{item.end_station}}</view> <view class="normal">{{item.end_time}}</view> </view> <!--票价--> <view class="wrApper right"> <view class="blue">¥{{item.price_list[1].price}}起</view> </view> </view> <!--分割线--> <view class="hr"></view> <!--剩余座位信息--> <view class="seat"> <view wx:for="{{item.price_list}}" wx:key="id"> <view>{{item.type}}:<text style="color: rgb(14, 216, 14);">{{item.num}}</text>-----</view> </view> </view> </view> </block> <view class="bottomNav"> <view class="bottomNav-icon"> <image src="{{currentTab==0?'/images/火车票页面/筛选1.png':'/images/火车票页面/筛选.png'}}"></image> <view id="0" class="{{currentTab==0?'selected':'common'}}" bindtap="switchNav">筛选</view> </view> <view class="bottomNav-icon"> <image src="{{currentTab==1?'/images/火车票页面/耗时最短 1.png':'/images/火车票页面/耗时最短.png'}}" ></image> <view id="1" class="{{currentTab==1?'selected':'common'}}" bindtap="switchNav">耗时最短</view> </view> <view class="bottomNav-icon"> <image src="{{currentTab==2?'/images/火车票页面/tab-发时最早1.png':'/images/火车票页面/tab-发时最早.png'}}" ></image> <view id="2" class="{{currentTab==2?'selected':'common'}}" bindtap="switchNav">发时最早</view> </view> <view class="bottomNav-icon"> <image src="{{currentTab==3?'/images/火车票页面/回流区价格1.png':'/images/火车票页面/回流区价格.png'}}"></image> <view id="3" class="{{currentTab==3?'selected':'common'}}" bindtap="switchNav">价格最低</view> </view> <view class="bottomNav-icon"> <image src="{{currentTab==4?'/images/火车票页面/购物车1.png':'/images/火车票页面/购物车.png'}}"></image> <view class="bottomNav-text" id="4" class="{{currentTab==4?'selected':'common'}}" bindtap="switchNav">侯补下单</view> </view> </view> </view> train.js var trainData = require('../data/data.js'); Page({ data: { date: '', trainList: [], winHeight: 600, currentTab: '1', }, onLoad: function (e) { var startStation = e.startStation; var endStation = e.endStation; var date = e.date; var trainList = trainData.trainList; for (var i = 0; i < trainList.length; i++) { trainList[i].start_station = startStation; trainList[i].end_station = endStation; } console.log("startStation=" + startStation + "---endStation=" + endStation + "---date=" + date); console.log(trainList) wx.setNavigationBarTitle({ title: startStation + '→' + endStation }); this.setData({ date: date }); // 从data.js文件中获取火车票列表信息 var size = trainList.length; var winHeight = size * 100 + 30; this.setData({ trainList: trainList, winHeight: winHeight }); }, switchNav: function (e) { var id = e.currentTarget.id; console.log(id); this.setData({ currentTab: id }); }, }); train.wxss /* pages/trainList/trainList.wxss */ /*日期样式设置*/ .date{ height: 40px; background-color: #5495e6; display: flex; flex-direction: row; } .date view{ margin: 0 auto; color: #fff; padding-top: 10px; } .content{ height: 600px; background-color: #f4f4f4; padding-top: 10px; } .bg{ width: 95%; height: 90px; border: 1px #999 solid; background-color: #fff; margin: 0 auto; border-radius: 5px; margin-bottom: 10px; } .item{ /*弹性布局*/ display: flex; flex-direction: row; padding: 10px; } .wrApper{ width: 25%; } .left{ text-align: left; } .center{ text-align: center; } .right{ text-align: right; } .blue{ color: #5495e6; font-weight: bold; font-size: 14px; } .normal{ color: #000; font-weight: bold; font-size: 14px; } .small{ font-size: 13px; color: #666; } .line{ height: 1px; background-color: #ccc; opacity: 0.2; width: 80%; margin: 3px auto; } .buy{ background-color: red; width: 42px; height: 20px; line-height: 20px; font-size: 12px; color: #fff; text-align: center; float: right; border-radius: 20px; margin-right: 5px; } .hr{ height: 1px; background-color: #ccc; opacity: 0.2; } .seat{ font-size: 13px; display: flex; flex-direction: row; margin-top: 5px; margin-left: 10px; } .seat text{ color: red; } .yes{ margin-right: 10px; } .no{ color: #999; margin-right: 10px; } /*火车票列表底部导航样式*/ .bottomNav{ background-color: #ffffff; display: flex; flex-direction: row; height: 45px; line-height: 45px; position: fixed; bottom: 0px; width: 100%; /* height: 120rpx; */ } .bottomNav view{ margin: 0 auto; } .selected{ font-size: 13px; color: #5495e6; } .common{ font-size: 13px; color: rgb(0, 0, 0); } .bottomNav-icon{ display: flex; flex-direction: column; align-items: center; margin-bottom: -10rpx; } .bottomNav image{ width:10px; height:10px; margin-bottom: -10px; }
Home.wxml <!--pages/mycenter/mycenter.wxml--> <!--账号信息设计--> <view class="amountBg"> <!--头像--> <view class="img"> <image src="/images/home/头像.jpg" style="width:49px;height:47px;"></image> </view> <view class="account"> <view>李泉城</view> <view class="heyanbox"> <view class="heyan">手机核验成功<image class="heyanimage" src="/images/home/核验成功.png"></image> </view> <view class="heyan">已实名认证<image class="heyanimage" src="/images/home/核验成功.png"></image> </view> </view> </view> <view class="nav">></view> </view> <!--订单导航设计--> <view class="content"> <view class="order"> <view class="desc"> <view> <image src="/images/home/乘车人.jpg" style="width:22px;height:25px"></image> </view> <view>乘车人</view> </view> <view class="desc" bindtap="grabTicket"> <view> <image src="/images/home/订单.jpg" style="width:22px;height:25px" ></image> </view> <view>我的订单</view> </view> <view class="desc"> <view> <image src="/images/home/优惠卷.jpg" style="width:22px;height:25px"></image> </view> <view>优惠券</view> </view> </view> <!--列表导航设计--> <view class="clear"></view> <view> <image class="student" src="/images/home/学生票.jpg"></image> </view> <view class="line"></view> <view class="cxdx"> <view class="cxdx-title"> <h2>出行导向</h2> </view> <view class="hr"></view> <view class="cxdx1"> <view class="cxdxicon"> <view> <image src="/images/home/车站大屏.jpg" style="width:22px;height:25px"></image> </view> <view>车站大屏</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/时刻表.jpg" style="width:22px;height:25px"></image> </view> <view>时刻表</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/起售时间.jpg" style="width:22px;height:25px"></image> </view> <view>起售时间</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/正晚点查询.jpg" style="width:22px;height:25px"></image> </view> <view>正晚点查询</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/票价查询.jpg" style="width:22px;height:25px"></image> </view> <view>票价查询</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/换成时间.jpg" style="width:22px;height:25px"></image> </view> <view>换乘时间</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/代售点查询.jpg" style="width:22px;height:25px"></image> </view> <view>代售点查询</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/更多.jpg" style="width:22px;height:25px"></image> </view> <view>更多</view> </view> </view> </view> <!-- 常用功能 --> <view class="cygn"> <view class="cxdx-title"> <h2>常用功能</h2> </view> <view class="hr"></view> <view class="cxdx1"> <view class="cxdxicon"> <view> <image src="/images/home/人脸核验.jpg" style="width:22px;height:25px"></image> </view> <view>人脸核验</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/指纹登录.jpg" style="width:22px;height:25px"></image> </view> <view>指纹登录</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/修改密码.jpg" style="width:22px;height:25px"></image> </view> <view>修改密码</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/修改手机号.jpg" style="width:22px;height:25px"></image> </view> <view>修改手机号</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/通知设置.jpg "style="width:22px;height:25px"></image> </view> <view>通知设置</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/敬老版.jpg" style="width:22px;height:25px"></image> </view> <view>敬老版</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/快捷退票.jpg" style="width:22px;height:25px"></image> </view> <view>快捷退票</view> </view> <view class="cxdxicon"> <view> <image src="/images/home/学生资质核验.jpg" style="width:22px;height:25px"></image> </view> <view>学生资质核验</view> </view> </view> </view> </view> Home.js // pages/mycenter/mycenter.js /** * 动态获取昵称,使用App.getUserInfo接口来获取个人信息 */ var App=getApp() Page({ /** * 页面的初始数据 */ data: { userInfo:{} }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // var that=this // //以调用应用实例的方法获取全局时间 // App.getUserInfo(function(userInfo){ // console.log(userInfo); // //更新数据 // this.setData({ // userInfo:userInfo // }) // }) }, /** * 通过列表导航进入二级界面,实现方式和进入抢票界面一样 * 绑定跳转事件,配置相应的跳转路径 */ grabTicket:function(){ wx.navigateTo({ url:'../Ticket/Ticket' }) }, onTapStationScreen() { wx.showToast({ title: '查看车站大屏幕', icon: 'none', duration: 2000 }); // 在这里可以添加实际查看车站大屏幕的逻辑 }, onTapTimetable() { wx.showToast({ title: '查看时刻表', icon: 'none', duration: 2000 }); // 在这里可以添加实际查看时刻表的逻辑 }, onTapSaleTime() { wx.showToast({ title: '查看起售时间', icon: 'none', duration: 2000 }); // 在这里可以添加实际查看起售时间的逻辑 }, onTapDelayQuery() { wx.showToast({ title: '正晚点查询', icon: 'none', duration: 2000 }); // 在这里可以添加实际正晚点查询的逻辑 }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } }) Home.wxss /* pages/mycenter/mycenter.wxss */ /*账号信息样式*/ /* 顶部头像与账号信息样式 */ .amountBg{ height: 100px; background-color: #5495e6; display: flex; flex-direction: row; align-items: center; } /* 核验部分样式 */ .heyanbox{ display: flex; flex-direction: row; } .heyan{ display: flex; align-items: center; background-color: white; border-radius: 10px; padding: 5px; margin: 5px; height: 30rpx; font-size: 20rpx; color: black; width: 150rpx; } .heyanimage { width: 20rpx; height: 20rpx; margin-right: 5px; } /* 头像图片样式 */ .img{ margin-left: 20px; } .account{ width: 70%; color: #fff; margin-left: 10px; } .nav{ width: 15px; color: #fff; } /*订单区域样式*/ .content{ background-color: #f4f4f4; height: 500px; } .order{ width: 94%; height: 70px; display: flex; flex-direction: row; background-color: #fff; border-radius: 5px; text-align: center; align-items: center; position: absolute; top:90px; margin-left: 3%; } .desc{ width: 33%; font-size: 13px; } /*列表导航设计*/ .student{ width: 94%; height: 70px; display: flex; flex-direction: row; background-color: #fff; border-radius: 5px; text-align: center; align-items: center; position: absolute; margin-left: 3%; margin-bottom: 10rpx; } .clear{ padding-top: 70px; } .hr{ height: 1px; background-color: #ccc; opacity: 0.2; margin-bottom: 20rpx; } .cxdx{ width: 94%; height: 150px; background-color: #fff; border-radius: 5px; text-align: center; align-items: center; position: absolute; margin-left: 3%; margin-bottom: 10rpx; margin-top: 190rpx; } .cxdx1{ display: flex; flex-direction: row; flex-wrap: wrap; } .cxdxicon{ width: 25%; font-size: 13px; margin-bottom: 20rpx; } .cxdx-title { display: flex; justify-content: flex-start; /* 标题靠左对齐 */ align-items: center; padding: 10rpx 20rpx; /* 添加内边距 */ } .cygn{ width: 94%; height: 150px; background-color: #fff; border-radius: 5px; text-align: center; align-items: center; position: absolute; margin-left: 3%; margin-bottom: 10rpx; margin-top: 570rpx; }
-
Ticket.wxml <!--pages/trainList/trainList.wxml--> <!--日期的设计--> <view class="content" style="height:{{winHeight}}px"> <block wx:for="{{trainList}}" wx:key="id"> <!--动态渲染,将trainList,winHeight动态绑定到界面--> <view class="cxdx-title"> 乘车日期{{item.ccdata}} </view> <view class="bg"> <!-- <p>订单号:{{item.dindanID}}</p> --> <view class="dindantext"><p>订单号:{{item.dindanID}}</p></view> <view class="hr"></view> <view class="item"> <!--始发站,终点站--> <view class="wrApper left"> <view class="normal">{{item.st}}</view> <!-- <view class="normal">漳州</view> --> <view class="bule">{{item.start_time}}</view> </view> <!--车次,日期--> <view class="wrApper center"> <view class="normal">{{item.trainNumber}}</view> <view class="line"></view> <view class="small">{{item.departureTime}}</view> </view> <!--时间--> <view class="wrApper right"> <view class="normal">{{item.end_station}}</view> <view class="normal">{{item.end_time}}</view> </view> <!--票价--> <view class="wrApper right"> <view class="blue">¥{{item.price_list[1].price}}</view> </view> </view> <!--分割线--> <view class="hr"></view> <!--剩余座位信息--> <view class="seat"> <!-- <view wx:for="{{item.price_list}}" wx:key="id"> <view>{{item.type}}:<text style="color: rgb(14, 216, 14);">{{item.num}}</text>-----</view> </view> --> <view > <view>{{item.zhuangtai}}</view> <view>{{item.seatType}}</view> </view> </view> </view> </block> </view> Ticket.js var trainData = require('../data/data.js'); Page({ data: { date: '', trainList: [], winHeight: 600, currentTab: '1', }, onLoad: function (e) { var trainList = trainData.trainList; // wx.setNavigationBarTitle({ // title: startStation + '→' + endStation // }); this.setData({ date: trainData }); // 从data.js文件中获取火车票列表信息 var size = trainList.length; var winHeight = size * 100 + 30; this.setData({ trainList: trainList, winHeight: winHeight }); }, switchNav: function (e) { var id = e.currentTarget.id; this.setData({ currentTab: id }); }, }); Ticket.wxss /* pages/trainList/trainList.wxss */ /*日期样式设置*/ .content{ height: 650px; background-color: #f4f4f4; padding-top: 10px; /* padding: 5rpx; */ } .bg{ width: 95%; height: 120px; border: 1px #999 solid; background-color: #fff; margin: 0 auto; border-radius: 5px; margin-bottom: 10px; padding: 5rpx; } .item{ /*弹性布局*/ display: flex; flex-direction: row; padding: 10px; } .wrApper{ width: 25%; } .left{ text-align: left; } .center{ text-align: center; } .right{ text-align: right; } .blue{ color: #5495e6; font-weight: bold; font-size: 14px; margin-top: 100rpx; } .normal{ color: #000; font-weight: bold; font-size: 14px; } .small{ font-size: 13px; color: #666; } .line{ height: 1px; background-color: #ccc; opacity: 0.2; width: 80%; margin: 3px auto; } .buy{ background-color: red; width: 42px; height: 20px; line-height: 20px; font-size: 12px; color: #fff; text-align: center; float: right; border-radius: 20px; margin-right: 5px; } .hr{ height: 1px; background-color: #ccc; opacity: 0.2; margin-top: -10rpx; } .seat{ font-size: 13px; display: flex; flex-direction: row; /* margin-top: -10rpx; */ margin-left: 10px; margin-top: -20rpx; } .seat text{ color: red; } .yes{ margin-right: 10px; } .no{ color: #999; margin-right: 10px; } .cxdx-title { display: flex; justify-content: flex-start; /* 标题靠左对齐 */ align-items: center; padding: 10rpx 20rpx; /* 添加内边距 */ font-size: 30rpx; display: flex; align-items: center; background-color: rgb(172, 165, 165); border-radius: 10px; padding: 5px; margin: 5px; height: 20rpx; font-size: 20rpx; color: black; width: 270rpx; } .dindantext{ font-size: 20rpx; margin-left: 30rpx; margin-bottom: 20rpx; }