123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917 |
- //获取应用实例
- var util = require('../../../utils/util.js');
- var api = require('../../../config/api.js');
- var check = require('../../../utils/check.js');
- var app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- // serviceId:'ea11209c0e',
- // cusId:'931400',
- serviceId:'',
- cusId:'',
- gender: '2',
- address: {
- id: 0,
- areaCode: 0,
- address: '',
- name: '',
- tel: '',
- isDefault: 0,
- province: '',
- city: '',
- county: '',
- latitude: '',
- longitude: '',
- addressDetail: '',
- detail: '',
- addressname: '',
- },
- addressIdSave: '', //新增地址保存
- orderInfo: {
- },
- addressId: '',
- checkedAddress: {
- },
- addressList: [],
- addressShow: false,
- remark: '',
- remarkPopupShow: false,
- remarkList: [
- '上门前提前电话联系',
- '请准时到达',
- '请自带打扫工具',
- '主要打扫厨房&卫生间',
- '家里有宠物'
- ],
- remarkActive: '',
- message: '',
- remarkShow: false,
- addressId: '',
- addressName: '',
- noAppoint: '',
- aftersaleStatus: '',
- orderId: '',
- order: '',
- bookId: '',
- bookCount: 0,
- orderStatusText: '订单服务中',
- activeTab: 1,
- orderBook: {
- status: ''
- },
- orderChannel: 0,
- jzOrderBookDetails: [],
- unusedSerList: [],
- usedSerList: [],
- serList: [],
- choosePopup: false,
- timeList: [],
- // dateList: util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24 * 0), 1, 30),
- dateList:[],
- timeIndex: '',
- //选中的时间段
- dateIndex: 0, //选中的日期
- appointDate: '', //显示信息
- isHide: false,
- product: {
- serviceTimes: '',
- price: ''
- },
- noonType: 1,
- selectTimeValue: '',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log(options);
- // if (options.serviceId) {
- // this.setData({
- // serviceId: options.serviceId
- // });
- // }
- // if (options.orderId) {
- // this.setData({
- // orderId: options.orderId
- // });
- // }
- if(options.scene){
- var scene = decodeURIComponent(options.scene);
- // scene='id,221e10b7ae;cid,931400: ""';
- console.log(scene);
- // id,46dd84a816;cid,931400 id,221e10b7ae;cid,931400: ""
- let sceneStr=scene.split(';');
- if(scene.indexOf(':')>0){
- let validStr=scene.split(':')[0];
- sceneStr=validStr.split(';');
- }
-
- if(scene.indexOf('cid')>=0){
- this.setData({
- serviceId:sceneStr[0].split(",")[1] ,
- cusId:sceneStr[1].split(",")[1]
- });
- this.getOrderDetail();
- }
- }
- app.globalData.mapSelectFinish = false;
- // this.getOrderDetail();
-
- },
- getOrderDetail: function () {
- wx.showLoading({
- title: '加载中'
- });
-
- util.request(api.getOrderInfo, {
- serviceId: this.data.serviceId,
- cusId:this.data.cusId
- }).then(res => {
- wx.hideLoading();
- if (res.errno === 0) {
-
- console.log(res.data);
- this.setData({
- orderInfo: res.data,
- addressId: res.data.addressId,
- dyDetails: res.data.dyDetails,
- afterSale: res.data.afterSale,
- payOverTime: res.data.payOverTime,
- remainTimes: res.data.serviceTimes - res.data.servedTimes,
- // orderGoods: res.data.orderGoods,
- // handleOption: res.data.orderInfo.handleOption,
- // expressInfo: res.data.expressInfo
- });
- if (res.data.addressId) {
- this.getAddressList();
- }
- }else{
- util.showErrorToast(res.errmsg);
- }
- }).catch(err=>{
- wx.hideLoading();
- });
- },
- getAddressList() {
- util.request(api.getCusAddressList,{
- cusId:this.data.cusId
- }).then(res => {
- if (res.errno === 0) {
- this.setData({
- addressList: res.data.list,
- });
- let current = this.data.addressList.filter(item => {
- return item.id == this.data.addressId
- });
- if (current.length > 0) {
- this.setData({
- checkedAddress: current[0]
- });
- }
- }
- });
- },
- onShow: function () {
- // this.getOrderDetail();
- if (app.globalData.mapSelectFinish) {
- let poi = app.globalData.mapSelectPoi;
- let location = poi.location;
- let address = this.data.address;
- address.lng = location.split(',')[0];
- address.lat = location.split(',')[1];
- address.addressname = poi.address;
- this.setData({
- address: address,
- // selectAddress:poi.address
- });
- console.log(this.data.address);
- this.getAreaCode();
- }
- },
- getServiceDetail: function () {
- let that =this;
- if(that.data.orderId ==null ||that.data.orderId===undefined){
- util.showErrorToast('页面已过期,请刷新页面重新查看');
- return ;
- }
- util.request(api.ServiceDetail, {
- order_id: this.data.orderId
- }).then(res => {
- if (res.errno === 0) {
- let jzOrderBookDetails = res.data.jzOrderBookDetails;
- let unusedSerList = jzOrderBookDetails.filter(item => {
- return item.status === 0 || item.status == 1;
- });
- let usedSerList = jzOrderBookDetails.filter(item => {
- return item.status == 3 || item.status == 4;
- });
- this.setData({
- aftersaleStatus: res.data.order ? res.data.order.aftersaleStatus : '',
- noAppoint: res.data.noAppoint,
- goods: res.data.goods,
- orderBook: res.data.orderBook,
- jzOrderBookDetails: jzOrderBookDetails,
- activeTab: 1,
- unusedSerList: unusedSerList,
- usedSerList: usedSerList,
- serList: unusedSerList,
- orderChannel: res.data.orderChannel,
- addressId: res.data.order.addressId,
- addressName: res.data.order.address,
- mobile: res.data.order.mobile,
- product: res.data.product
- });
- }
- });
- },
- showAppoint(e) {
- // 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;
- // }
- // }
- // if (this.data.order.aftersaleStatus == 1 || this.data.order.aftersaleStatus == 2) {
- // util.showErrorToast("退款中,无法预约");
- // return;
- // }
- // console.info(this.data.addressName)
- // if (this.data.addressId == 0||this.data.addressName==null||this.data.addressName=='') {
- // util.showErrorToast("请输入服务地址");
- // return;
- // }
- if(this.data.appointDate!=''){
- this.setData({
- choosePopup: true,
- });
- return false;
- }else{
- this.setData({
- choosePopup: true,
- noonType:1,
- timeIndex: 0
- });
- let params = {
- days:30,
- // orderBookId:this.data.bookId,
- bookId:this.data.serviceId,
- goodsId: this.data.orderInfo.goodsId,
- serviceDuration: this.data.orderInfo.serviceDuration
- }
- this.getDayTime(params);
- }
- },
- getTimeList() {
- let timeList = util.getBeginTimeList(this.data.orderInfo.serviceDuration, this.data.noonType, this.data.dateList[this.data.dateIndex].name);
- this.setData({
- timeList: timeList,
- selectTimeValue: timeList.length == 0 ? '' : timeList[0].value
- });
- if(this.data.timeList.length==0){
- this.setData({
- timeIndex:''
- });
- }
- },
- getDayStock() {
- if (this.data.dateIndex < 0) {
- return false;
- }
- let params = {
- day: this.data.dateList[this.data.dateIndex].date,
- goodsId: this.data.orderInfo.goodsId,
- addressId: this.data.addressId == 0 ? this.data.addressIdSave : this.data.checkedAddress.id,
- productId: this.data.orderInfo.productId,
- orderId: this.data.orderInfo.id,
- serviceDuration: this.data.orderInfo.serviceDuration
- };
- wx.showLoading({
- title: '加载中'
- });
- util.request(api.EveryDayStock, params, "GET").then(res => {
- wx.hideLoading();
- if (res.errno == 0) {
- this.setData({
- timeList: res.data
- });
- 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(err=> {
- console.log(err);
- wx.hideLoading();
- wx.showToast({
- title: err.errMsg,
- icon: 'none'
- });
- this.setData({
- timeList: [],
- timeIndex: ''
- });
- });
- },
- onClose() {
- this.setData({
- choosePopup: false
- });
- },
- getDayTime(params) {
-
- 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(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;
- 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:''
- });
- }
-
- // let dateName = this.data.dateList[this.data.dateIndex].name;
- // this.setData({
- // dateIndex: index
- // });
- // let curDateName = this.data.dateList[this.data.dateIndex].name;
- // if ((curDateName == '今天') || ((new Date()).getHours() >18&&curDateName == "明天")) {
- // this.setData({
- // noonType: 2
- // })
- // }
- // this.getTimeList();
-
- },
- 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)
- });
- }
- // this.setData({
- // timeIndex: index,
- // selectTimeValue: this.data.timeList[index].value
- // });
- },
- submitBook() { //提交预约
- if (this.data.addressId == '' && this.data.addressIdSave == '') {
- util.showErrorToast("请输入服务地址");
- return;
- }
- if (this.data.timeIndex === ''||this.data.timeIndex<0) {
- util.showErrorToast("请选择服务时间");
- return false;
- }
- // if (this.data.mobile == null || this.data.mobile.length != 11) {
- // util.showErrorToast("请填写手机号码");
- // return;
- // }
-
- 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 = {
- cusId:this.data.cusId,
- serviceId : this.data.serviceId,
- date: date,
- startTime: time.split('-')[0],
- endTime: time.split('-')[1],
- addressId: (this.data.addressId == 0||this.data.addressId == null) ? this.data.addressIdSave : this.data.checkedAddress.id,
- remark: this.data.remark + this.data.message
- };
- console.info(params);
- wx.showLoading({
- title: '加载中...'
- });
- util.request(api.customerBook, params, "POST").then(res => {
- if (res.errno == 0) {
- wx.hideLoading();
- this.setData({
- isHide: true
- });
- wx.showToast({
- title: '预约成功',
- icon: 'none',
- duration: 2000
- });
-
- // setTimeout(() => {
- // wx.navigateTo({
- // url: "/pages/ucenter/orderDetail/orderDetail?id=" + this.data.orderId
- // });
- // }, 2000);
- } else {
- wx.showToast({
- title: res.errmsg,
- icon: 'none'
- });
- // util.showErrorToast(res.errmsg);
- }
- });
- },
- confirmTime() {
- if (this.data.timeIndex === ''||this.data.timeIndex<0) {
- util.showErrorToast('请选择服务时间');
- 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;
- this.setData({
- choosePopup: false,
- appointDate: date + ' ' + week + ' ' + time
- });
- },
- selectAddress() {
- //已经输入过地址的订单 不允许再次选择地址
- if (this.data.order.addressId > 0) return;
- wx.navigateTo({
- url: '/pages/ucenter/address/address'
- });
- },
- showRemark() {
- this.setData({
- remarkShow: true
- });
- },
- onRemarkClose() {
- this.setData({
- remarkShow: false
- });
- },
- confirmRemark() {
- this.setData({
- remarkShow: false
- });
- },
- bindMessageInput: function (e) {
- this.setData({
- message: e.detail.value
- });
- },
- bindPhone(e) {
- this.setData({
- mobile: e.detail.value
- })
- },
- copyOrder() {
- wx.setClipboardData({
- data: this.data.orderInfo.orderSn,
- success: function (res) {
- wx.getClipboardData({
- success: function (res) {
- wx.showToast({
- title: '订单编号复制成功',
- icon: 'success',
- duration: 2000
- });
- }
- });
- }
- });
- },
- onAddressClose() {
- this.setData({
- addressShow: false
- })
- },
- onAddressClick() {
- //阻止事件冒泡,不要删
- },
- addressConfirm(e) {
- let address = e.currentTarget.dataset.address;
- this.setData({
- checkedAddress: address,
- addressShow: false
- });
- },
- addressSelect() {
- this.setData({
- addressShow: true
- });
- },
- showRemarkSelect() {
- this.setData({
- remarkPopupShow: true
- });
- },
- onRemarkPopupClose() {
- this.setData({
- remarkPopupShow: false
- })
- },
- onRemarkClick() {
- //阻止事件冒泡,不要删
- },
- remarkItemSelect(e) {
- let remark = e.currentTarget.dataset.remark;
- this.setData({
- remark: remark,
- remarkActive: remark,
- });
- },
- remarkItemConfirm() {
- if (this.data.remarkActive === '') {
- util.showErrorToast("请选择备注");
- return false;
- }
- this.setData({
- remarkPopupShow: false
- });
- },
- bindinputMobile(event) {
- let address = this.data.address;
- address.tel = event.detail.value;
- this.setData({
- address: address
- });
- },
- bindinputName(event) {
- let address = this.data.address;
- address.name = event.detail.value;
- this.setData({
- address: address
- });
- },
- bindinputAddress(event) {
- let address = this.data.address;
- address.detail = event.detail.value.replace(/[,,]/g, '');
- this.setData({
- address: address
- });
- // return value.replace(/[,,]/g,'');
- },
- bindAddressDetail(event) {
- let address = this.data.address;
- address.addressname = event.detail.value.replace(/[,,]/g, '');
- this.setData({
- address: address
- });
- },
- submitAll() {
- if ((this.data.addressId == ''||this.data.addressId == null) && this.data.addressIdSave == '') {
- this.saveAddress();
- } else {
- this.submitBook();
- }
- },
- async saveAddress() {
- console.log(this.data.address);
- let address = this.data.address;
- // if (address.addressname == 0) {
- // util.showErrorToast('请选择服务地址');
- // return false;
- // }
- if (address.addressname == '') {
- util.showErrorToast('请选择服务地址');
- return false;
- }
- if (address.name == '') {
- util.showErrorToast('请输入姓名');
- return false;
- }
- if (address.detail == '') {
- util.showErrorToast('请输入门牌号');
- return false;
- }
- if (this.data.gender == null || this.data.gender == '') {
- util.showErrorToast('请选择性别');
- return false;
- }
- if (address.tel == '') {
- util.showErrorToast('请输入手机号码');
- return false;
- }
- if (!check.isValidPhone(address.tel)) {
- util.showErrorToast('手机号不正确');
- return false;
- }
- let that = this;
- let addressString = address.detail == '' ? address.addressname : address.addressname + ',' + address.detail;
- wx.showLoading({
- title: '加载中...'
- });
- let res = await util.request(api.addCusAddress, {
- gender: this.data.gender,
- addressId: address.id,
- name: address.name,
- tel: address.tel,
- province: address.province,
- city: address.city,
- county: address.county,
- areaCode: address.areaCode,
- addressDetail: addressString,
- isDefault: address.isDefault,
- lat: Number(address.lat).toFixed(5),
- lng: Number(address.lng).toFixed(5),
- cusId:this.data.cusId
- }, 'POST');
- wx.hideLoading();
- if (res.errno === 0) {
- that.setData({
- addressIdSave: res.data
- })
- that.submitBook();
- } else {
- wx.showModal({
- title: '提醒',
- showCancel: false,
- content: res.errmsg
- });
- }
- },
- goMap() {
- // const key = "JA2BZ-XGOEU-UNZVD-46G64-S6MYJ-6BBF4";
- //使用在腾讯位置服务申请的key
- // const key = '6TRBZ-XXC6F-BWWJB-N75ME-BQNOF-YKFQY';
- // const referer = '鲸致生活LifePlus';
- // const category = '小区,生活服务,娱乐休闲';
- // wx.navigateTo({
- // url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer + '&category=' + category
- // });
- let that = this;
- // wx.authorize({
- // scope: "scope.userLocation",
- // success: (res) => {
- // console.log("authorize", res);
- wx.chooseLocation({
- success: (location) => {
- console.log("chooseLocation success: ", location);
- console.log(`经度${location.longitude},维度${location.latitude}`);
- console.log(location);
- if (location != null) {
- let address = that.data.address;
- address.lat = location.latitude;
- address.lng = location.longitude;
- address.addressname = location.address;
- that.setData({
- address: address,
- // selectAddress:location.address
- });
- console.log(that.data.address);
- that.getAreaCode();
- }
- },
- fail: (err) => {
- console.log("chooseLocation fail: " + err.errMsg);
- },
- });
- // },
- // fail: () => {
- // wx.openSetting({});
- // },
- // });
- },
- goMap() {
- console.log('gomap');
- app.globalData.mapSelectFinish = false;
- // wx.navigateTo({
- // url: '/pages/map/mapContent/mapContent',
- // });
- if (this.data.address.lng && this.data.address.lat) {
- let city = (this.data.address.city == '市辖区' ? this.data.address.province : this.data.address.city)
- wx.navigateTo({
- url: '/pages/map/mapContent/mapContent?lng=' + this.data.address.lng + '&lat=' + this.data.address.lat + '&addressname=' + this.data.address.addressname + '&city=' + city,
- });
- } else {
- wx.navigateTo({
- url: '/pages/map/mapContent/mapContent',
- });
- }
- },
- maleSelect() {
- this.setData({
- gender: 1
- });
- },
- femaleSelect() {
- this.setData({
- gender: 2
- });
- },
- getAreaCode() {
- let param ={
- location: this.data.address.lng + ',' + this.data.address.lat,
- extensions: 'all',
- key: api.gdKey,
- radius: 3000,
- };
- wx.request({
- url: api.gdUrl,
- data: param,
- method: 'GET',
- header: {
- 'Content-Type': 'application/json'
- },
- success: res => {
- console.log(res);
- if (res.data.infocode == "10000") {
- if (res.data.info == "OK") {
- // let ad_info = res.data.result.ad_info;
- // let areaCode = res.data.result.ad_info.adcode;
- let regeocode = res.data.regeocode.addressComponent;
- let cityName=(regeocode.city==null||regeocode.city.length==0)?regeocode.province:regeocode.city;
- let district= (regeocode.district==null||regeocode.district.length==0)?'':regeocode.district;
- this.setData({
- ['address.areaCode']: regeocode.adcode,
- ['address.province']:regeocode.province,
- ['address.city']: cityName,
- ['address.county']:district,
- // ['address.addressname']:res.data.result.address
- });
- } else {
- wx.showToast({
- title: '获取地区码失败',
- icon: 'none',
- duration: 3000
- });
- }
- } else {
- wx.showToast({
- title: '获取地区码失败',
- icon: 'none',
- duration: 3000
- });
- }
- },
- fail: function (err) {
- reject(err);
- }
- });
- },
- goAddAddress() {
- wx.navigateTo({
- url: '/pages/ucenter/addressAdd/addressAdd?id=' + 0
- });
- },
- 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
- });
- }
- });
|