|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- // pages/yuyue/yuyue.js
- const app = getApp()
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
-
- },
-
- /**
- * 组件的初始数据
- */
- data: {
- imgUrl: app.globalData.urlStatic,//图片路径
- agreement:false,
- isAgreement: true,//是否同意协议
- phoneInputShow: false,//是否显示电话输入框
- siteSelect: false,//是否显示位置选择框
- provinceDataAll: null,//地区所有数据
- provinceDataArr: [[""], [""]],//省市数据
- provinceDataValue: [0, 0],//选中的省市下标
- nowProvince: "",//选中的省市文字
- storeArr: [],//专营店数据
- storeValue: 0,//选中的专营店下标
- verificationCode: '获取验证码',//验证码文案
- sendCode: true,
- appointment: true,
- mobile2:"",
- subscribeData: {
- realname: "",//姓名
- mobile: "",//手机号---无验证码
- captcha: "",//验证码
- province: "",//省份
- city:"",//城市
- agent_code: "",//经销商编码
- agentDetail: "",//经销商详细信息
- parentOpenid: app.globalData.parentOpenid,//好友openid
- scene: app.globalData.sceneSource
- },
- mobileType:2,
- userData:null
- },
- ready:function(){
- if (app.globalData.openid) {
- this.loadFun();
- } else {
- app.globalData.openidSuccessFuc = this.loadFun;
- }
- },
- /**
- * 组件的方法列表
- */
- methods: {
- closeXieyi: function () {
- this.triggerEvent('yuyue')
- },
- getRealname: function (e) {//获取用户输入的姓名
- this.data.subscribeData.realname = e.detail.value;
- },
- getMobile: function (e) {//获取用户输入的电话---有验证码
- this.data.subscribeData.mobile = e.detail.value;
- },
- getMobile2: function (e) {//获取用户输入的电话---无验证码
- this.data.mobile2 = e.detail.value;
- },
- getCaptcha: function (e) {//获取用户输入的验证码
- this.data.subscribeData.captcha = e.detail.value;
- },
- loadFun: function () {
- if (app.globalData.userMobile) {
- this.data.subscribeData.mobile = app.globalData.userMobile;
- this.setData({
- phoneInputShow: true,
- subscribeData: this.data.subscribeData
- })
- }
- if (app.globalData.userInfoData) {
- this.setData({
- userData: app.globalData.userInfoData
- })
- }
- this.getUserLocation();//获取用户当前位置
- },
- getDistributorList: function (longitude, latitude) {//获取经销商列表
- app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude }, res => {
- if (res.code == 200) {
- //整理数据
- var datas = res.data;
- var province = [];
- var city = [];
- for (let i = 0; i < res.data.list.length; i++) {
- province.push(res.data.list[i].province);
- }
- for (let j = 0; j < res.data.list[res.data.nearData.provinceIndex].children.length; j++) {
- city.push(res.data.list[res.data.nearData.provinceIndex].children[j].city)
- }
- //将数据赋值给变量
- this.setData({
- provinceDataAll: res.data.list,
- provinceDataArr: [province, city],
- provinceDataValue: [res.data.nearData.provinceIndex, res.data.nearData.cityIndex],
- nowProvince: province[res.data.nearData.provinceIndex] + " " + city[res.data.nearData.cityIndex],
- storeArr: res.data.list[res.data.nearData.provinceIndex].children[res.data.nearData.cityIndex].children,
- storeValue: res.data.nearData.agentIndex
- })
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this);
- },
- getCode: function (e) {//获取验证码
- if (!app.mobileVerify(this.data.mobile2)) {
- if (this.data.mobile2) {
- wx.showToast({
- title: '请输入正确的电话',
- icon: 'none'
- })
- } else {
- wx.showToast({
- title: '请输入电话',
- icon: 'none'
- })
- }
- return;
- }
- if (!this.data.sendCode) {
- return;
- }
- this.data.sendCode = false;
- app.wxRequest(app.globalData.urlRoot + "captcha/sendCaptcha", { mobile: this.data.mobile2 }, res => {
- if (res.code == 200) {
- this.countDown();
- wx.showToast({
- title: '验证码获取成功',
- icon: "none"
- })
- this.setData({
- verificationCode: 60
- })
- } else {
- this.data.sendCode = true;
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this)
- },
- countDown: function () {//倒计时
- setTimeout(() => {
- this.setData({
- verificationCode: this.data.verificationCode - 1
- })
- if (this.data.verificationCode > 0) {
- this.countDown();
- } else {
- this.setData({
- verificationCode: "获取验证码"
- })
- this.data.sendCode = true;
- }
- }, 1000);
- },
- subscribeFun: function (e) {//预约鉴赏
- if (!this.data.subscribeData.realname) {
- wx.showToast({
- title: '请输入姓名',
- icon: "none"
- })
- return;
- }
- if (!this.data.mobile2 && this.data.mobileType==2) {
- wx.showToast({
- title: '请输入电话',
- icon: "none"
- })
- return;
- }
- if (this.data.mobileType == 2) {
- if (!this.data.subscribeData.captcha) {
- wx.showToast({
- title: '请输入验证码',
- icon: "none"
- })
- return;
- }
- }
- if (!this.data.isAgreement) {
- wx.showToast({
- title: '请同意协议',
- icon: 'none'
- })
- return;
- }
- if (!this.data.appointment) {
- return;
- }
- this.data.appointment = false;
- this.data.subscribeData.province = this.data.provinceDataArr[0][this.data.provinceDataValue[0]];
- this.data.subscribeData.city = this.data.provinceDataArr[1][this.data.provinceDataValue[1]];
- this.data.subscribeData.agent_code = this.data.storeArr[this.data.storeValue].agent_code;
- this.data.subscribeData.agentDetail = this.data.storeArr[this.data.storeValue].agent_detail;
- var sourceMobile = this.data.subscribeData.mobile;
- if(this.data.mobileType==2){
- this.data.subscribeData.mobile = this.data.mobile2;
- }
- this.data.subscribeData.parentOpenid = app.globalData.parentOpenid;
- app.wxRequest(app.globalData.urlRoot + "userInfo/submitOrderInfo", this.data.subscribeData, res => {
- this.data.subscribeData.mobile = sourceMobile;
- this.data.appointment = true;
- if (res.code == 200) {
- if (app.globalData.nowPage=='0'){
- wx.reLaunch({
- url: '/pages/index/index'
- })
- return;
- }
- wx.showToast({
- title: '预约成功',
- mask:true
- })
- setTimeout(()=>{
- this.closeXieyi();
- },1500)
- // this.data.subscribeData.realname = "";
- // this.data.subscribeData.captcha = "";
- // this.setData({
- // subscribeData: this.data.subscribeData,
- // verificationCode: '获取验证码',
- // })
- // this.setData({
- // siteSelect: false
- // })
- // this.setData({
- // isRegister: true
- // })
- // app.globalData.isRegister = true;
- // app.globalData.userMobile = this.data.subscribeData.mobile;
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this, "POST")
- },
- provinceDataChange: function (e) {
- if (e.detail.column == 0) {
- var city = [];
- for (let i = 0; i < this.data.provinceDataAll[e.detail.value].children.length; i++) {
- city.push(this.data.provinceDataAll[e.detail.value].children[i].city);
- }
- this.data.provinceDataArr[1] = city;
- this.setData({
- provinceDataArr: this.data.provinceDataArr
- })
- }
- },
- provinceDataChane: function (e) {
- this.setData({
- provinceDataValue: e.detail.value,
- nowProvince: this.data.provinceDataArr[0][e.detail.value[0]] + " " + this.data.provinceDataArr[1][e.detail.value[1]],
- storeArr: this.data.provinceDataAll[e.detail.value[0]].children[e.detail.value[1]].children,
- storeValue: 0
- })
- },
- storeChane: function (e) {
- this.setData({
- storeValue: e.detail.value
- })
- },
- getUserPhone: function (e) {//获取用户手机号
- if (e.detail.errMsg == 'getPhoneNumber:ok') {
- app.getMobile(e.detail.encryptedData, e.detail.iv, res => {
- if (res.code == 200) {
- this.setData({
- phoneInputShow: true
- })
- this.cutType();
- if (res.data && res.data.decodeData) {
- this.data.subscribeData.mobile = res.data.decodeData.phoneNumber;
- this.setData({
- subscribeData: this.data.subscribeData
- })
- }
- } else {
- wx.showToast({
- title: res.msg,
- icon: "none"
- })
- }
- }, this);
- }
- },
- agreementState: function () {//协议
- this.setData({
- isAgreement: !this.data.isAgreement
- })
- },
- lookMore: function () {
- wx.navigateTo({
- url: '/pages/moreType/moreType',
- })
- },
- showSite: function () {//显示地址选择框
- if (!this.data.siteSelect) {
- if (!app.globalData.myCenterData) {
-
- } else {
- this.setData({
- siteSelect: true
- })
- }
- }
- },
- getUserLocation: function (e) {
- wx.getLocation({
- type: 'gcj02', //wgs84
- success: (res) => {
- this.getDistributorList(res.longitude, res.latitude);
- },
- fail: (res) => {
- this.getDistributorList("", "");
- }
- })
- },
- agreementControl: function () {
- this.setData({
- agreement: !this.data.agreement
- })
- },
- cutType:function(){
- this.setData({
- mobileType: this.data.mobileType==1?2:1
- })
- },
- getUserWxMsg:function(e){//通过微信获取用户信息
- if (e.detail.errMsg == "getUserInfo:ok") {
- this.data.userData = {};
- this.data.userData.avatarUrl = e.detail.userInfo.avatarUrl;
- this.data.userData.nickName = e.detail.userInfo.nickName;
- this.setData({
- userData: this.data.userData
- })
- app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
- }
- }
- }
- })
|