|
|
import 'activity/have-gain-apply.page.css';
|
|
|
import Page from 'yoho-page';
|
|
|
import $ from 'yoho-jquery';
|
|
|
import tip from 'plugin/tip';
|
|
|
import dialog from 'plugin/dialog';
|
|
|
import fillInHbs from 'activity/have-gain/fill-in.hbs';
|
|
|
import yoho from 'yoho-app';
|
|
|
|
|
|
class HaveGainApplyPage extends Page {
|
|
|
constructor() {
|
|
|
super();
|
|
|
|
|
|
this.selector = {
|
|
|
isFlag: false,
|
|
|
$nameInput: $('.section .name'),
|
|
|
$mobileInput: $('.section .mobile'),
|
|
|
$fillIn: $('.party-icon-item .fill-in'),
|
|
|
$added: $('.other .added'),
|
|
|
$agreement: $('.agreement-section .agreement'),
|
|
|
$applyBtn: $('.apply-btn'),
|
|
|
};
|
|
|
this.init();
|
|
|
}
|
|
|
|
|
|
init() {
|
|
|
this.bindEvents();
|
|
|
}
|
|
|
|
|
|
bindEvents() {
|
|
|
let that = this;
|
|
|
|
|
|
this.selector.$nameInput.on('input', this.changeBtnStatus.bind(this));
|
|
|
this.selector.$mobileInput.on('input', this.changeBtnStatus.bind(this));
|
|
|
this.selector.$fillIn.on('click', that.tapFillIn);
|
|
|
this.selector.$agreement.on('click', that.tapAgreement);
|
|
|
this.selector.$added.on('click', this.tapAdded.bind(this));
|
|
|
this.selector.$applyBtn.on('click', this.apply.bind(this));
|
|
|
}
|
|
|
|
|
|
changeBtnStatus() {
|
|
|
let errStatus = 0;
|
|
|
let name = $.trim(this.selector.$nameInput.val());
|
|
|
let mobile = $.trim(this.selector.$mobileInput.val());
|
|
|
|
|
|
if (name === '') {
|
|
|
errStatus = 1;
|
|
|
} else if (mobile === '') {
|
|
|
errStatus = 2;
|
|
|
} else if (!/^1[0-9]{10}$/.test(mobile)) {
|
|
|
errStatus = 21;
|
|
|
}
|
|
|
|
|
|
if (errStatus) {
|
|
|
this.selector.$applyBtn.addClass('disable');
|
|
|
return errStatus;
|
|
|
}
|
|
|
|
|
|
this.selector.$applyBtn.removeClass('disable');
|
|
|
|
|
|
return errStatus;
|
|
|
}
|
|
|
|
|
|
tapFillIn(event) {
|
|
|
let $event = $(event.target);
|
|
|
|
|
|
if ($event.hasClass('disable')) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
let $accountName = $event.closest('.party-icon-item').find('.account-name');
|
|
|
|
|
|
dialog.showDialog({
|
|
|
hasHeader: '填写信息',
|
|
|
hasClass: 'dialog-fill-apply',
|
|
|
dialogText: fillInHbs({
|
|
|
account: $accountName.find('em').eq(0).text() || '',
|
|
|
fans: $accountName.find('em').eq(1).data('fans') || ''
|
|
|
}),
|
|
|
hasFooter: {
|
|
|
leftBtnText: '取消',
|
|
|
rightBtnText: '确定'
|
|
|
}
|
|
|
}, function() {
|
|
|
let account = $.trim($('.dialog-fill-apply .account').val() || '');
|
|
|
let fans = $.trim($('.dialog-fill-apply .fans').val() || '');
|
|
|
let fansFix = Math.round((fans / 10000) * 100) / 100; // 保留二个小数
|
|
|
|
|
|
if (!account) {
|
|
|
return tip.show('请输入账号昵称');
|
|
|
}
|
|
|
|
|
|
if (fans === '') {
|
|
|
return tip.show('请输入粉丝数量');
|
|
|
}
|
|
|
|
|
|
fansFix = fansFix >= 10 ? fansFix + '万' : fans;
|
|
|
|
|
|
$accountName.html(`账号:<em>${account}</em> 粉丝:<em data-fans="${fans}">${fansFix}</em>`); // eslint-disable-line
|
|
|
dialog.hideDialog();
|
|
|
$event.text('已填写').addClass('disable');
|
|
|
});
|
|
|
}
|
|
|
|
|
|
tapAdded() {
|
|
|
let that = this;
|
|
|
|
|
|
yoho.invokeMethod('go.copy', {text: '有货有赚'});
|
|
|
dialog.showDialog({
|
|
|
dialogText: '“有货有赚”服务号已经复制,请去微信搜索添加',
|
|
|
hasClass: 'dialog-text-apply',
|
|
|
hasFooter: {
|
|
|
leftBtnText: '取消',
|
|
|
rightBtnText: '去添加'
|
|
|
}
|
|
|
}, function() {
|
|
|
that.awakeWeixin();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
awakeWeixin() {
|
|
|
window.location.href = 'weixin://';
|
|
|
}
|
|
|
|
|
|
tapAgreement(event) {
|
|
|
let $event = $(event.target);
|
|
|
|
|
|
if ($event.closest('a').length) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
$event.hasClass('activate') ? $event.removeClass('activate') : $event.addClass('activate');
|
|
|
}
|
|
|
|
|
|
apply() {
|
|
|
let that = this;
|
|
|
let errStatus = this.changeBtnStatus();
|
|
|
let socialMediaList = [];
|
|
|
|
|
|
if (errStatus === 1) {
|
|
|
tip.show('请输入姓名');
|
|
|
} else if (errStatus === 2) {
|
|
|
tip.show('请输入手机号');
|
|
|
} else if (errStatus === 21) {
|
|
|
tip.show('请输入正确的手机号');
|
|
|
}
|
|
|
|
|
|
if (errStatus) {
|
|
|
$('html,body').animate({scrollTop: 0}, 'slow');
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (!this.selector.$agreement.hasClass('activate')) {
|
|
|
return tip.show('请勾选《我已阅读并同意》');
|
|
|
}
|
|
|
|
|
|
this.selector.$fillIn.each((index, event) => {
|
|
|
let $accountName = $(event).closest('.party-icon-item').find('.account-name');
|
|
|
|
|
|
socialMediaList.push({
|
|
|
type: $accountName.data('type'),
|
|
|
account: $accountName.find('em').eq(0).text() || '',
|
|
|
fans: parseInt(`0${$accountName.find('em').eq(1).data('fans')}`, 10)
|
|
|
});
|
|
|
});
|
|
|
|
|
|
if (this.selector.isFlag) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
this.selector.isFlag = true;
|
|
|
|
|
|
return this.ajax({
|
|
|
type: 'post',
|
|
|
url: '/activity/have-gain/submitApply',
|
|
|
data: {
|
|
|
name: $.trim(this.selector.$nameInput.val()),
|
|
|
mobile: $.trim(this.selector.$mobileInput.val()),
|
|
|
socialMediaList: JSON.stringify(socialMediaList)
|
|
|
}
|
|
|
}).then(res => {
|
|
|
this.selector.isFlag = false;
|
|
|
|
|
|
if (res.code !== 200) {
|
|
|
return tip.show(res.message || '请稍后再试');
|
|
|
}
|
|
|
|
|
|
yoho.invokeMethod('go.copy', {text: '有货有赚'});
|
|
|
dialog.showDialog({
|
|
|
hasHeader: '申请成功',
|
|
|
hasClass: 'dialog-text-apply',
|
|
|
dialogText: '请等待工作人员审核,您可以关注“有货有赚”服务号,了解进度',
|
|
|
hasFooter: {
|
|
|
leftBtnText: '取消',
|
|
|
rightBtnText: '去添加'
|
|
|
}
|
|
|
}, function() {
|
|
|
that.awakeWeixin();
|
|
|
}, function() {
|
|
|
window.location.href = '//m.yohobuy.com/activity/have-gain/verify';
|
|
|
});
|
|
|
}).catch(() => {
|
|
|
this.selector.isFlag = false;
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$(() => {
|
|
|
new HaveGainApplyPage();
|
|
|
});
|
|
|
|
...
|
...
|
|