You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

269 lines
6.1 KiB

import https from "../../../utils/https";
// pages/supplier/apply/index.js
import util from "../../../utils/util"
Page({
/**
* 页面的初始数据
*/
data: {
info:{
supplier_name:"",
manager_name:"",
banner_img:"",
licence_img:"",
business_license:"",
address:"",
email:"",
manager_tel:"",
phone:""
},
error:{
manager_tel:"",
phone:"",
email:""
},
submitFlag:false,
oldInfo:null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let info = this.data.info;
https.user_post("supplierapply/get_supplier_apply",{}).then(res=>{
if(res.data){
for(let i in info){
info[i] = res.data[i];
}
this.setData({
info:info,
oldInfo:res.data,
submitFlag:true
})
}
})
},
changeInfo(e){
let info = this.data.info,name = e.currentTarget.dataset.name;
info[name] = e.detail.value
this.setData({
info:info
})
let flag = true;
for(let i in info){
if(!info[i]){
flag = false;
break;
}
else if((i=='phone' || i=='manager_tel') && !util.isTel(info[i])){
// 判断手机号
flag = false;
break;
}
else if(i=='email' && !util.isMail(info[i])){
// 判断手机号
flag = false;
break;
}
}
let error = this.data.error;
if(name=='phone' && util.isTel(info[name])){
error[name] = "";
}
if(name=='manager_tel' && util.isTel(info[name])){
error[name] = "";
}
if(name=='email' && util.isMail(info[name])){
error[name] = "";
}
if(name=='supplier_name' && info[name]){
error[name] = "";
}
if(name=='manager_name' && info[name]){
error[name] = "";
}
if(name=='address' && info[name]){
error[name] = "";
}
this.setData({
submitFlag:flag,
error:error
})
},
blur:function(e){
let error = this.data.error,name = e.currentTarget.dataset.name,info = this.data.info;
if(name=='phone' && !util.isTel(info[name])){
error[name] = "请输入正确的联系电话";
}
if(name=='manager_tel' && !util.isTel(info[name])){
error[name] = "请输入正确的负责人联系电话";
}
if(name=='email' && !util.isMail(info[name])){
error[name] = "请输入正确的邮箱";
}
if(name=='supplier_name' && !info[name]){
error[name] = "请输入名称";
}
if(name=='manager_name' && !info[name]){
error[name] = "请输入姓名";
}
if(name=='address' && !info[name]){
error[name] = "请输入地址";
}
this.setData({
error:error
})
},
upload(e){
let name = e.currentTarget.dataset.name,that = this,info = this.data.info,error=this.data.error;
wx.chooseImage({
count: 1,
success:function(res){
if(res && res.tempFilePaths && res.tempFilePaths[0]){
wx.showLoading({
title: '上传中',
mask:true
})
wx.uploadFile({
filePath: res.tempFilePaths[0],
name: 'file',
url: https.baseUrl + 'pbservice.other/upload',
header:{
token: wx.getStorageSync('jstrip_token'),
},
success:function(r){
var r = JSON.parse(r.data);
let img = r.data.url;
info[name] = img;
error[name]=""
that.setData({
info:info,
error:error
})
wx.hideLoading();
}
})
}
}
})
},
delimg(e){
let name = e.currentTarget.dataset.name,info = this.data.info,that=this;
wx.showModal({
title:"提示",
content:"确定删除此照片?",
success(res){
console.log(res)
if(res.confirm){
// 确定删除
info[name]="";
that.setData({
info:info
})
}
}
})
},
submit:function(){
if(this.data.submitFlag){
https.user_post("supplierapply/apply",this.data.info).then(res=>{
if(res && res.code==1){
wx.showToast({
title: '提交成功',
icon:'success'
})
setTimeout(()=>{
util.back()
},1000)
}
})
}
else {
let info = this.data.info,error={};
for(let name in info){
if(name=='phone' && !util.isTel(info[name])){
error[name] = "请输入正确的联系电话";
}
if(name=='manager_tel' && !util.isTel(info[name])){
error[name] = "请输入正确的负责人联系电话";
}
if(name=='email' && !util.isMail(info[name])){
error[name] = "请输入正确的邮箱";
}
if(name=='supplier_name' && !info[name]){
error[name] = "请输入名称";
}
if(name=='manager_name' && !info[name]){
error[name] = "请输入姓名";
}
if(name=='address' && !info[name]){
error[name] = "请输入地址";
}
if(name=='licence_img' && !info[name]){
error[name] = "请上传营业执照";
}
if(name=='business_license' && !info[name]){
error[name] = "请上传经营许可证";
}
if(name=='banner_img' && !info[name]){
error[name] = "请上传门头照";
}
}
this.setData({
error:error
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})