123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- import Dialog from '@vant/weapp/dialog/dialog';
- const util = require('../../../utils/util');
- const check = require('../../../utils/check');
- const api = require('../../../config/api');
- const user = require('../../../utils/user.js');
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- code: '',
- showSubmitBtn: true,
- userInfo: {
- nickName: '点击登录',
- avatarUrl: '/static/images/new/icon-user.png',
- isDis: false
- },
- hasLogin: false,
- myqr_show: false,
- infoGoods: app.globalData.infoGoods,
- customerName: '',
- customerTel: '',
- address: '',
- addressId: '',
- serviceModelText: '请选择',
- serviceModel: '',
- // startServiceTime:'请选择',
- typePickerShow: false,
- timePickerShow: false,
- serviceModelList: [{
- id: '1',
- name: '钟点工'
- },
- {
- id: '2',
- name: '白班保姆'
- },
- {
- id: '3',
- name: '住家保姆'
- },
- {
- id: '4',
- name: '月嫂'
- },
- {
- id: '5',
- name: '代班保姆-钟点工'
- },
- {
- id: '6',
- name: '代班保姆-保姆'
- },
- ],
- typeColumns: ['钟点工', '白班保姆', '住家保姆', '月嫂', '代班保姆-钟点工', '代班保姆-保姆'],
- //typeColumns: ['钟点工', '白班保姆', '住家保姆', '月嫂', '育儿嫂', '其他'],
- currentDate: new Date().getTime(),
- minDate: new Date().getTime(),
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- },
- showPoster() {
- this.setData({
- myqr_show: true
- });
- },
- hidePoster() {
- this.setData({
- myqr_show: false
- });
- },
- selectAddress() {
- if (this.data.hasLogin == false) {
- wx.navigateTo({
- url: "/pages/auth/login/login"
- });
- return;
- }
- wx.navigateTo({
- url: '/pages/ucenter/address/address',
- })
- },
- formatterDate(type, value) {
- if (type === 'year') {
- return `${value}年`;
- }
- if (type === 'month') {
- return `${value}月`;
- }
- return value;
- },
- onTimeCancel() {
- this.setData({
- timePickerShow: false,
- });
- },
- onTimeConfirm(event) {
- console.log(event);
- this.setData({
- startServiceTime: util.formetdate(new Date(event.detail)),
- timePickerShow: false,
- });
- },
- showServicePicker() {
- this.setData({
- typePickerShow: true,
- });
- },
- showTimePicker() {
- this.setData({
- timePickerShow: true,
- });
- },
- onTypeCancel: function () {
- this.setData({
- typePickerShow: false,
- });
- },
- onTypeConfirm: function (event) {
- this.setData({
- serviceModel: this.data.serviceModelList[event.detail.index].id,
- serviceModelText: event.detail.value,
- typePickerShow: false,
- });
- },
- confirmSubmit() {
- if (this.data.hasLogin == false) {
- wx.navigateTo({
- url: "/pages/auth/login/login"
- });
- return;
- }
- if (this.data.customerName == '') {
- wx.showToast({
- title: '请输入客户名称',
- icon: 'none',
- duration: 2000
- });
- return false;
- }
- if (this.data.customerTel == '') {
- wx.showToast({
- title: '请输入手机号',
- icon: 'none',
- duration: 2000
- });
- return false;
- }
- if (this.data.customerTel=='') {
- // util.showErrorToast('请输入正确的手机号码');
- wx.showToast({
- title: '输入正确的手机号码',
- icon: 'none',
- duration: 2000
- });
- return false;
- }
- if (this.data.address == '') {
- wx.showToast({
- title: '请输入详细住址',
- icon: 'none',
- duration: 2000
- });
- return false;
- }
- if (this.data.serviceModelText == '请选择') {
- wx.showToast({
- title: '请选择服务类型',
- icon: 'none',
- duration: 2000
- });
- return false;
- }
- let that = this;
- console.log('校验成功');
- wx.showLoading({
- title: '提交中...',
- mask: true,
- });
- util.request(api.addClueMs, {
- "customerName": this.data.customerName,
- "customerTel": this.data.customerTel,
- "address": this.data.address,
- "serviceModel": this.data.serviceModel,
- "userId": this.data.userInfo.id
- }, "POST")
- .then((res) => {
- wx.hideLoading();
- if (res.errno == 0) {
- that.showPoster();
- that.setData({
- showSubmitBtn: false
- })
- } else {
- util.showErrorToast(res.errmsg);
- }
- }).catch(() => {
- wx.hideLoading();
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- let that = this;
- if (app.globalData.hasLogin) {
- let userInfo = wx.getStorageSync('userInfo');
- this.setData({
- userInfo: userInfo,
- hasLogin: true,
- customerTel:userInfo.mobile
- });
- app.globalData.userInfo = userInfo;
- } else {
- user.login().then(res => {
- console.info(res)
- that.setData({
- code: res.code
- })
- })
- }
- },
- getPhoneNumber: function (e) {
- var ivObj = e.detail.iv
- var telObj = e.detail.encryptedData
- var that = this;
- //------执行Login---------
- util.request(api.AuthRegister, {
- code: that.data.code,
- encryptedData: telObj,
- iv: ivObj,
- r_userid: 0
- }).then(function (res) {
- if (res.errno === 0) {
- //存储用户信息
- app.globalData.hasLogin = true;
- app.globalData.userInfo = res.data.userInfo;
- wx.setStorageSync('userInfo', res.data.userInfo);
- wx.setStorageSync('token', res.data.token);
- that.setData({
- hasLogin:true,
- userInfo:res.data.userInfo,
- customerTel:res.data.userInfo.mobile
- });
- wx.showToast({
- title: '授权手机号成功',
- icon: 'success',
- duration: 2000,
- })
- } else {
- console.info(res);
- wx.showToast({
- title: '授权失败请重试',
- icon: 'error',
- duration: 3000
- });
- }
- });
- //-----------------是否授权,授权通过进入主页面,授权拒绝则停留在登陆界面
- if (e.detail.errMsg == 'getPhoneNumber:fail user deny') { //用户点击拒绝
- wx.showModal({
- title: '警告',
- content: '您点击了拒绝授权,部分功能无法使用!!!',
- showCancel: false,
- confirmText: '确定',
- success: function (res) {
- // 用户没有授权成功,不需要改变 isHide 的值
- if (res.confirm) {
- };
- }
- })
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|