RecommendCar.js 5.9 KB
import {
  request
} from "../../request/index.js"
const a = getApp()
var timer = ''
Page({
  data: {
    imagesUrl: a.globalData.baseUrl,
    msg: '',
    name: '', //姓名
    phone: '', //手机号
    code: '', //验证码
    yv_pay: '', // 购买预算
    pin1: '', // 意向品牌1[品牌至少一个]
    pin2: '', // 意向品牌2
    pin3: '', // 意向品牌3
    s4_id: '', //推荐4s店的id
    bei: '', //
    intention: [], // 意向品牌
    city_id: '', // 城市id
    arr4S: [],
    intention: [],
    SugImage: '',
    ajxtrue: false,
    brand: false,
    downBrand: true,
    pin_id: '',
    CarBrandName1: '',
    CarBrandName2: '',
    CarBrandName3: '',
    pinP1: 1,
    pinP2: 2,
    pinP3: 3,
    time: 60,
    countDownNum: 60,
    sendNum: 0,
    s4_id: '',
  },


  onLoad: function (options) {
    //  console.log(options);
    let that = this
    that.setData({
      s4_id: options.s4_id || '',
      CarBrandName1: options.CarBrandName1 || '',
      CarBrandName2: options.CarBrandName2 || '',
      CarBrandName3: options.CarBrandName3 || '',
      pin_id: options.id || '',
    })
    let token = wx.getStorageSync("token")
    if (token) {
      that.getSugImage()
    } else {
      that.popConfirm()
    }

  },
  onReady: function () {},
  onShow: function () {},

  popConfirm: function () {
    wx.showModal({
      title: '提示',
      content: '您尚未登录,请登录后操作',
      success: function (res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/authorization/authorization'
          })
        } else {
          wx.switchTab({
            url: '/pages/home/home'
          })
        }
      }
    })

  },
  async formSubmit(e) {
    let that = this
    let nn = e.detail.value
    try {
      const {
        data
      } = await request({
        url: 'api/shop4s/sugCar',
        data: {
          name: nn.nickename,
          phone: nn.phone,
          code: nn.pass,
          yv_pay: nn.yv_pay,
          pin1: nn.pin1,
          pin2: nn.pin2,
          pin3: nn.pin3,
          s4_id: that.data.s4_id,
          bei: nn.bei,
        }
      })
      //  console.log(data);
      a.popSuccessTest(data.msg)
      setTimeout(() => {
        wx.navigateBack()
      }, 1200);
    } catch (err) {
      //  console.log(err);
      a.popTest(err.msg)
    }
  },
  sendmima() { // 获取code
    let that = this,
      phone = a.setPhone(that.data.phone);
    if (phone) {
      that.countown()
      //  console.log(phone);
      // return
      setTimeout(async () => {
        try {
          const {
            data: {
              data
            }
          } = await request({
            url: 'api/shop4s/faCode',
            data: {
              phone: phone
            }
          })
          //  console.log(data);
          that.setData({
            code: data.code
          })
        } catch (err) {
          clearInterval(that.data.timer);
          that.setData({
            sendNum: 0
          })
          //  console.log(err);
          a.popTest(err.msg)
        }
      }, 1000);

    }
  },
  countown() {
    let that = this;
    let countDownNum = that.data.countDownNum; //获取倒计时初始值
    that.setData({
      sendNum: 1,
      timer: setInterval(function () {
        countDownNum--;
        that.setData({
          countDownNum: countDownNum
        })
        if (that.data.countDownNum == 0) {
          clearInterval(timer);
          that.setData({
            countDownNum: 60,
            sendNum: 0
          })
        }
      }, 1000)
    })
  },
  async getSugImage() { // 获取
    let that = this;
    try {
      const {
        data: {
          data
        }
      } = await
      request({
        url: 'api/common/img',
      })
      that.setData({
        SugImage: data
      })

    } catch (err) {
      //  console.log(err);
      a.popTest(err.msg)
    }
  },
  goRuleBook() {
    let that = this
    let s4_id = that.data.s4_id
    wx.navigateTo({
      url: '/pages/ruleBook/ruleBook?s4_id=' + s4_id
    })
  },
  async getPinChe() { // 获取车辆品牌
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/index/pin',
        method: 'GET'
      })
      let obj = []
      data.forEach((value) => {
        obj.push(value.name)
      })
      that.setData({
        intention: obj,
        arrayChe: data
      })
    } catch (err) {
      //  console.log(err);
      a.popTest(err.msg)
    }
  },

  blurPhone(e) {
    let phone = e.detail.value;
    let that = this
    that.setData({
      phone
    })
  },
  downBrand() {
    this.setData({
      brand: true,
      downBrand: false
    })
  },
  goCarBrand() {
    wx.navigateTo({
      url: '/pages/CarBrand/CarBrand?pinP=' + this.data.pinP1
    })
  },
  goCarBrand2() {
    wx.navigateTo({
      url: '/pages/CarBrand/CarBrand?pinP=' + this.data.pinP2
    })
  },
  goCarBrand3() {
    wx.navigateTo({
      url: '/pages/CarBrand/CarBrand?pinP=' + this.data.pinP3
    })
  },
  go4Ssearch() {
    let that = this
    if (that.data.CarBrandName3 || that.data.CarBrandName2 || that.data.CarBrandName1) {
      wx.navigateTo({
        url: '/pages/4Ssearch/4Ssearch?pin_id=' + this.data.pin_id + '&city_id=' + this.data.city_id
      })
    } else {
      a.popTest('尚未选择意向品牌,请先选择意向品牌')
    }
  },

  onShareAppMessage(options) {
    var that = this;
    var shareObj = {
      title: "同放分享", // 默认是小程序的名称(可以写slogan等)
      path: '/pages/RecommendCar/RecommendCar', // 默认是当前页面,必须是以‘/’开头的完整路径
      imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
    };
    // 返回shareObj
    return shareObj;

  },


})