var orderView = {
// 第一步
created: function () {
orderView.getOrderList()
},
// 第二步
// 獲取后臺數(shù)據(jù)
getOrderList: function () {
var url = 'http://132.232.87.95:3000/api/order/getList?pageNum=1'
axios.get(url).then(function (res) {
if (res.data.status == 0) {
orderView.renderList(res.data.list)
} else {
alert(res.data.msg)
}
}).catch(
function (error) {
// alert('網(wǎng)絡(luò)異常,請稍后再試')
alert(error)
}
)
},
// 第三步
// 渲染列表
renderList: function (orderList) {
var htmlStr = ''
for (var i = 0; i < orderList.length; i++) {
var order = orderList[i].skuList[0];
// 日期處理
var wetchTime = orderView.getTime(order.extraInfo.watchTime * 1000)
// 星期處理
var weekDay = orderView.getWeek(order.extraInfo.watchTime * 1000)
var orderId = orderList[i].payOrderId;
var str = ` <li class="bg-fff pd-l-17 mg-b-10">
<a href="dingdanxiangqing.html?orderId=${orderId}" class="h100 bd-gray flex ai-center pd-r-17">
<img class="h70 w50" src="${order.imgUrl}" alt="">
<div class="mg-l-14 h60 fdc jc-sb fg1">
<p>${order.productName}</p>
<p>${weekDay} ${wetchTime}</p>
<p class="flex-sb">
<span>
<span class="orangr">¥${order.price / 100}</span>
<s>$60</s>
</span>
<span>x ${order.count}</span>
</p>
</div>
</a>
<div class="h39 bd-gray flex jc-end ai-center pd-r-17">
<span>共1件商品</span>
<span class="mg-l-20 orangr">$33</span>
</div>
<div class="h48 flex-sb pd-r-17">
<span class="f999">訂單取消</span>
<span>再次購買</span>
</div>
</li>`
htmlStr += str
}
document.querySelector('.order-list').innerHTML = htmlStr
},
// 第四步
// 日期編寫
getTime: function (time) {
var today = new Date(time);
var Y = today.getFullYear();
var M = orderView.addZero(today.getMonth() + 1)
var D = orderView.addZero(today.getDate())
var h = orderView.addZero(today.getHours())
var m = orderView.addZero(today.getMinutes())
var s = orderView.addZero(today.getSeconds())
// var dayStr = `${Y}-${M}-${D} ${h}:${m}:${s}`;
var dayStr = `${Y}-${M}-${D} ${h}:${m}:${s}`;
return dayStr;
},
// 第五步
addZero: function (num) {
if (num < 10) {
return '0' + num;
} else {
return num;
}
},
// 第六步
// 星期編寫
getWeek: function (time) {
var today = new Date(time);
var tay = today.getDay()
var week = {
'0': '星期天',
'1': '星期一',
'2': '星期二',
'3': '星期三',
'4': '星期四',
'5': '星期五',
'6': '星期六',
}
return week[tay]
},
}
// 第七步
orderView.created()
var home = {
// 第一步
created: function () {
var url = location.href;
var index = url.indexOf("=") + 1;
var orderId = url.substring(index);
home.obtainOrderDetails(orderId);
},
// 第二步
// 獲取數(shù)據(jù)
obtainOrderDetails: function (orderId) {
var url = "http://132.232.87.95:3000/api/order/findById?orderId=" + orderId;
axios.get(url)
.then(function (response) {
console.log(response)
home.renderOrder(response.data);
})
.catch(function (error) {
console.log(error)
// console.log('報錯信息')
});
},
// 第三步
// 渲染列表
renderOrder: function (obj) {
// 用戶號碼
document.querySelector(".phone").innerHTML = obj.mobile;
// 電影圖片
document.querySelector(".img").src = obj.imgUrl;
// 電影名稱
document.querySelector(".names").innerHTML = obj.productName;
// 電影地址和播放地區(qū)
document.querySelector(".name").innerHTML = obj.cinemaInfo.name;
document.querySelector(".address").innerHTML = obj.cinemaInfo.name;
// 電影大廳號
document.querySelector(".addres").innerHTML = obj.goodsInfo[0].seatExtInfo.hallName;
document.querySelector(".region").innerHTML = obj.goodsInfo[0].seatExtInfo.hallName;
// 電影座位
document.querySelector(".seat").innerHTML = obj.goodsInfo[0].seatExtInfo.seats;
document.querySelector(".seats").innerHTML = obj.goodsInfo[0].seatExtInfo.seats;
// 電影價格和電影票
document.querySelector(".thirty").innerHTML = obj.price / 100;
document.querySelector(".fifty").innerHTML = obj.marketPrice / 100;
document.querySelector(".one").innerHTML = obj.count;
// 電影實時價
document.querySelector(".amount").innerHTML = obj.price / 100;
document.querySelector(".payment").innerHTML = obj.finalPrice / 100;
// 播放時間和星期
document.querySelector(".week").innerHTML = home.getWeek(obj.goodsInfo[0].seatExtInfo.watchTime * 1000);
document.querySelector(".ates").innerHTML = home.getTime(obj.goodsInfo[0].seatExtInfo.watchTime * 1000);
// 下單時間
document.querySelector(".place").innerHTML = home.getTime(obj.goodsInfo[0].seatExtInfo.watchTime * 1000);
},
// 第四步
// 時間處理
getTime: function (time) {
var today = new Date(time);
var Y = today.getFullYear();
var M = home.addZero(today.getMonth() + 1)
var D = home.addZero(today.getDate())
var h = home.addZero(today.getHours())
var m = home.addZero(today.getMinutes())
var s = home.addZero(today.getSeconds())
// var dayStr = `${ Y }-${ M } -${ D } ${ h }: ${ m }: ${ s } `;
var dayStr = `${Y} -${M} -${D} ${h}: ${m}: ${s} `;
return dayStr;
},
// 第五步
// 星期處理
getWeek: function (time) {
var today = new Date(time);
var tay = today.getDay()
var week = {
'0': '星期天',
'1': '星期一',
'2': '星期二',
'3': '星期三',
'4': '星期四',
'5': '星期五',
'6': '星期六',
}
return week[tay]
},
// 第六步
addZero: function (num) {
if (num < 10) {
return '0' + num;
} else {
return num;
}
}
}
// 第七步
home.created();
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者