123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495 |
- var util = require('../../../utils/util.js');
- var api = require('../../../config/api.js');
- var check = require('../../../utils/check.js');
- var app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- orderId: '',
- serviceId: '',
- bookCount: 0,
- orderStatusText: '订单服务中',
- activeTab: 1,
- noAppoint: '',
- aftersaleStatus: '',
- orderBook: {
- status: '',
- },
- orderChannel: 0,
- jzOrderBookDetails: [],
- unusedSerList: [],
- usedSerList: [],
- serList: [],
- choosePopup: false,
- // timeList: check.getTimeList(1),
- timeList: [],
- // dateList: util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24 * 0), 1, 21),
- dateList:[],
- timeIndex: '', //选中的时间段
- dateIndex: 0, //
- checkedAddress: {
- addressId: 0
- }, //选中的地址信息
- isHaveAddress: false,
- noonType: 1,
- selectTimeValue: '',
- bookId:'',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- orderId: options.orderId
- });
- // this.getServiceDetail();
- },
- getServiceDetail: function () {
- // wx.showLoading({
- // title: '加载中',
- // });
- // setTimeout(function() {
- // wx.hideLoading();
- // }, 2000);
- util.request(api.ServiceDetail, {
- order_id: this.data.orderId
- // order_id: '1342922'
- }).then(res => {
- // wx.hideLoading();
- if (res.errno === 0) {
- let jzOrderBookDetails = res.data.jzOrderBookDetails;
- let unusedSerList = jzOrderBookDetails.filter(item => {
- return item.status === 0 || item.status == 1 || item.status == 7
- });
- let usedSerList = jzOrderBookDetails.filter(item => {
- return item.status == 3 || item.status == 4
- });
- // let timeList = check.getTimeList(res.data.goods.serviceDuration);
- this.setData({
- aftersaleStatus: res.data.order.aftersaleStatus,
- goods: res.data.goods,
- noAppoint: res.data.noAppoint,
- orderBook: res.data.orderBook,
- jzOrderBookDetails: jzOrderBookDetails,
- // activeTab: 1,
- unusedSerList: unusedSerList,
- usedSerList: usedSerList,
- serList: (this.data.activeTab == 1 ? unusedSerList : usedSerList),
- // timeList: timeList,
- orderChannel: res.data.orderChannel,
- isHaveAddress: res.data.order.addressId != null && res.data.order.addressId > 0 && res.data.order.address ? true : false
- });
- console.log(res.data.order.addressId);
- if (res.data.order.addressId) {
- console.info("set address")
- this.setData({
- checkedAddress: {
- addressId: res.data.order.addressId,
- address: res.data.order.address,
- tel: res.data.order.mobile,
- name: res.data.order.consignee
- }
- })
- console.info(this.data.checkedAddress)
- }
- }
- });
- },
- selectAddress() {
- wx.navigateTo({
- url: '/pages/ucenter/address/address',
- })
- },
- onTabChange(e) {
- this.setData({
- activeTab: e.detail.name,
- });
- if (this.data.activeTab == 1) {
- this.setData({
- serList: this.data.unusedSerList
- });
- } else {
- this.setData({
- serList: this.data.usedSerList
- })
- }
- },
- showAppoint(e) {
- //是否有地址 如果没有地址 必须先选择地址
- console.info(this.data.checkedAddress)
- if (this.data.checkedAddress.addressId == null
- ||this.data.checkedAddress.addressId =='') {
- wx.showToast({
- title: '请先选择服务地址',
- icon: 'none',
- duration: 2000
- });
- return false;
- }
- let status = e.currentTarget.dataset.status;
- if (status == 1) {
- let time = e.currentTarget.dataset.time;
- let str = time.substr(0, 16).replace(/-/g, '/');
- let isNear = (new Date(str)).getTime() - (new Date()).getTime() - 2 * 60 * 60 * 1000;
- console.log(isNear);
- if (isNear < 0) {
- wx.showToast({
- title: '服务时间小于2小时,不能修改预约',
- icon: 'none',
- duration: 2000
- });
- return false;
- }
- }
- this.setData({
- choosePopup: true,
- serviceId: e.currentTarget.dataset.id,
- bookId:e.currentTarget.dataset.bookid
- });
- // this.getDayStock();
- this.getDayTime();
- },
- getDayStock() {
- if (this.data.dateIndex < 0) {
- return false;
- }
- if( this.data.checkedAddress.addressId==null|| this.data.checkedAddress.addressId==0){
- wx.showToast({
- title: '请选择地址',
- icon:'none'
- })
- return false
- }
- let params = {
- day: this.data.dateList[this.data.dateIndex].date,
- goodsId: this.data.orderBook.goodsId,
- lng: this.data.orderBook.lng,
- lat: this.data.orderBook.lat,
- addressId: this.data.checkedAddress.addressId,
- productId: this.data.orderBook.productId,
- serviceDuration: this.data.orderBook.serviceDuration
- }
- wx.showLoading({
- title: '加载中',
- });
- util.request(api.EveryDayStock, params, "GET")
- .then(res => {
- wx.hideLoading();
- if (res.errno == 0) {
- this.setData({
- timeList: res.data,
- timeIndex: 0
- });
- // let validList = this.data.timeList.filter(item => {
- // return item.stock > 0
- // });
- // if (validList.length > 0) {
- // this.setData({
- // timeIndex: validList[0].id - 1
- // });
- // } else {
- // this.setData({
- // timeIndex: ''
- // });
- // }
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none',
- duration: 2000
- });
- this.setData({
- timeList: [],
- timeIndex: ''
- });
- }
- }).catch(function (err) {
- console.log(err);
- wx.hideLoading();
- wx.showToast({
- title: err.errMsg,
- icon: 'none'
- });
- this.setData({
- timeList: [],
- timeIndex: ''
- });
- });
- },
- onClose() {
- this.setData({
- choosePopup: false
- });
- },
- getDayTime() {
- let params = {
- days:30,
- orderBookId:this.data.bookId,
- bookId:this.data.serviceId,
- }
- wx.showLoading({
- title: '加载中',
- });
- util.request(api.everyDayTime, params, "GET")
- .then(res => {
- wx.hideLoading();
- if (res.errno == 0) {
- this.setData({
- dateList: res.data,
- dateIndex:0,
- timeIndex: -1,
- noonType:1
- });
- let period=res.data[0].period;
- let list=period.filter(item=>{
- return item.ofTime=='上午';
- });
- this.setData({
- timeList:list
- });
-
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none',
- duration: 2000
- });
- this.setData({
- timeList: [],
- timeIndex: ''
- });
- }
- }).catch(function (err) {
- console.log(err);
- wx.hideLoading();
- wx.showToast({
- title: err.errMsg,
- icon: 'none'
- });
- this.setData({
- timeList: [],
- timeIndex: ''
- });
- });
- },
- dateCheck(e) {
- let index = e.currentTarget.dataset.index;
- let date = e.currentTarget.dataset.date;
- let week = e.currentTarget.dataset.week;
- let isbook = e.currentTarget.dataset.isbook;
- // if (index >= 7 || (index >= 2 && index < 7 && (week != '周六' && week != '周日'))) {
- // this.setData({
- // dateIndex: index
- // });
- // }
- this.setData({
- dateIndex: index
- });
- let period=this.data.dateList[this.data.dateIndex].period;
- let current=(this.data.noonType==1?'上午':'下午');
- let list=period.filter(item=>{
- return item.ofTime==current;
- });
- this.setData({
- timeList:list
- });
- let isNoTime=list.every(item=>{
- return item.timeMsg&&item.timeMsg!=null;
- });
- if(isNoTime){
- this.setData({
- timeIndex:-1,
- selectTimeValue:''
- });
- }
- },
- timeCheck(e) {
- let index = e.currentTarget.dataset.index;
- // if (e.currentTarget.dataset.stock == 0) {
- // wx.showToast({
- // title: '所选时间无库存,请选择其他时间',
- // icon: 'none',
- // duration: 2000
- // });
- // return;
- // }
- let msg=e.currentTarget.dataset.msg;
- if (msg==null||msg=='') {
- let time= (this.data.timeList[index].begin).split(':')[0];
- this.setData({
- timeIndex: index,
- selectTimeValue: Number(time)
- });
- }
- },
- noonTab(e) {
- let noon = e.currentTarget.dataset.noon;
- this.setData({
- timeIndex: -1,
- noonType: noon,
- selectTimeValue:'',
- });
- let period=this.data.dateList[this.data.dateIndex].period;
- let current=(this.data.noonType==1?'上午':'下午');
- let list=period.filter(item=>{
- return item.ofTime==current;
- });
- this.setData({
- timeList:list
- });
-
- },
- confirmTime() {
- if (this.data.timeIndex === ''||this.data.timeIndex<0) {
- wx.showToast({
- title: '请选择服务时间',
- icon: 'none',
- duration: 2000
- });
- return false;
- }
- let date = this.data.dateList[this.data.dateIndex].bookdate;
- let week = this.data.dateList[this.data.dateIndex].weekOfDay;
- let time = this.data.timeList[this.data.timeIndex].begin+'-'+this.data.timeList[this.data.timeIndex].end;
- console.log(date, week, time);
- let params = {
- detail_id: this.data.serviceId,
- date: date,
- startTime: time.split('-')[0],
- endTime: time.split('-')[1],
- addressId: this.data.checkedAddress.addressId ? this.data.checkedAddress.addressId : 0
- };
- util.request(api.ServiceOrderBook, params, "GET")
- .then(res => {
- console.log(res);
- if (res.errno == 0) {
- wx.showToast({
- title: '预约成功',
- icon: 'none',
- duration: 2000
- });
- // this.setData({
- // // oneTimeAppoint:date+' '+week+' '+time,
- // choosePopup: false,
- // });
- // this.getServiceDetail();
- wx.navigateTo({
- url: '/pages/checkout/appointResult/appointResult?id=' + this.data.orderId,
- });
- } else {
- //util.showErrorToast(res.errmsg);
- wx.showToast({
- title: res.errmsg,
- icon: 'none',
- duration: 2000
- });
- }
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function (options) {
- let that = this;
- var addressInfo = wx.getStorageSync('addressInfo');
- if (addressInfo === "") {
- addressInfo = {};
- }
- that.setData({
- checkedAddress: addressInfo
- })
- console.info(this.data.checkedAddress)
- if (this.data.orderId) {
- this.getServiceDetail();
- }
- },
- goReVisit(e) {
- let id = e.currentTarget.dataset.id;
- wx.navigateTo({
- url: '/pages/extra/newRevisit/newRevisit?id=' + id,
- success: (res) => {
- },
- fail: (res) => {
- },
- });
- },
- goDiff(e){
- let id = e.currentTarget.dataset.id;
- wx.navigateTo({
- url: '/pages/diffOrder/diffOrder?id='+ id,
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|