123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- const App = getApp();
- const Dialog = require('../../../components/dialog/dialog');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- is_read: false,
- disabled: false,
- submsgSetting: {}, // 订阅消息配置
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- let _this = this;
- // 获取订阅消息配置
- _this.getSubmsgSetting();
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- let _this = this;
- // 获取分销商申请状态
- _this.getApplyState();
- },
- /**
- * 获取订阅消息配置
- */
- getSubmsgSetting() {
- let _this = this;
- App._get('wxapp.submsg/setting', {}, (result) => {
- _this.setData({
- submsgSetting: result.data.setting
- });
- });
- },
- /**
- * 获取分销商申请状态
- */
- getApplyState() {
- let _this = this;
- App._get('user.dealer/apply', {
- referee_id: _this.getRefereeid()
- }, (result) => {
- let data = result.data;
- // 当前是否已经为分销商
- if (data.is_dealer) {
- wx.redirectTo({
- url: '../index/index'
- });
- }
- // 设置当前页面标题
- wx.setNavigationBarTitle({
- title: data.words.apply.title.value
- });
- data.isData = true;
- _this.setData(data);
- });
- },
- /**
- * 显示申请协议
- */
- toggleApplyLicense() {
- Dialog({
- title: '申请协议',
- message: this.data.license,
- selector: '#zan-base-dialog',
- isScroll: true, // 滚动
- buttons: [{
- text: '我已阅读',
- color: 'red',
- type: 'cash'
- }]
- }).then(() => {
- // console.log('=== dialog resolve ===', 'type: confirm');
- });
- },
- /**
- * 已阅读
- */
- toggleSetRead() {
- let _this = this;
- _this.setData({
- is_read: !this.data.is_read
- });
- },
- /**
- * 提交申请
- */
- onFormSubmit(e) {
- let _this = this,
- values = e.detail.value;
- // 验证姓名
- if (!values.name || values.name.length < 1) {
- App.showError('请填写姓名');
- return false;
- }
- // 验证手机号
- if (!/^\+?\d[\d -]{8,12}\d/.test(values.mobile)) {
- App.showError('手机号格式不正确');
- return false;
- }
- // 验证是否阅读协议
- if (!_this.data.is_read) {
- App.showError('请先阅读分销商申请协议');
- return false;
- }
- // 按钮禁用
- _this.setData({
- disabled: true
- });
- // 数据提交
- App._post_form('user.dealer.apply/submit', values, () => {
- // 获取分销商申请状态
- _this.getApplyState();
- }, null, () => {
- // 解除按钮禁用
- _this.setData({
- disabled: false
- });
- });
- },
- /**
- * 去商城逛逛
- */
- navigationToIndex(e) {
- // 跳转到首页
- wx.switchTab({
- url: '/pages/index/index',
- })
- },
- /**
- * 订阅消息通知
- */
- onSubMsg() {
- let _this = this;
- let tmplItem = _this.data.submsgSetting.dealer.apply.template_id;
- if (tmplItem.length > 0) {
- wx.requestSubscribeMessage({
- tmplIds: [tmplItem],
- success(res) {},
- fail(res) {},
- complete(res) {},
- });
- }
- },
- /**
- * 获取推荐人id
- */
- getRefereeid() {
- return wx.getStorageSync('referee_id');
- },
- })
|