Files
income_payments_applet/pages/signUpDraftTeamPage/signUpDraftTeamPage.js
T

237 lines
5.5 KiB
JavaScript

import UserApi from "../../assets/js/http/userApi";
// pages/signUpDraftTeamPage/signUpDraftTeamPage.js
Page({
/**
* 页面的初始数据
*/
data: {
pageTitle: '起草组报名',
// page-container 相关的配置
statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
// 当前起草组项目id
id: '',
// 是否需要权限
nolimitBool: false,
// 选择的用户
selectedPerson: {},
// 选择用户下标
selectedPersonIndex: null,
// 当前选择的企业
selectedCompany: {},
// 企业联系人
personList: [{}, {}, {}],
},
// 选择参会单位
selectCompany() {
wx.navigateTo({
url: `../companyList/companyList?nolimit=true`,
})
},
setIdentityDisabled () {},
// 选择联系人
selectPerson(e) {
const that = this
// 设置操作的下标,onLoad事件将数据放入数组
console.log('操作企业联系人下标', e.currentTarget.dataset.index);
this.setData({
selectedPersonIndex: e.currentTarget.dataset.index
})
if (!!this.data.selectedCompany.id) {
wx.navigateTo({
url: `../personList/personList?companyId=${this.data.selectedCompany.id}&selectType=${e.currentTarget.dataset.selecttype}&nolimit=${that.data.nolimitBool}`,
})
} else {
wx.showToast({
title: '请先选择参会单位',
icon: "none",
duration: 800,
});
}
},
// 添加企业联系人
handleAddContacts () {
if (this.data.personList.length >= 10) {
wx.showToast({
title: '最多添加十个企业联系人',
icon: "none",
duration: 800,
});
return
}
this.data.personList.push({})
this.setData({
personList: this.data.personList
})
},
// 删除企业联系人
handleDelContacts (e) {
const index = e.currentTarget.dataset.index
if (this.data.personList.length === 1) {
wx.showToast({
title: '最少需要一个企业联系人',
icon: "none",
duration: 800,
});
} else {
this.setData({
personList: this.data.personList.filter((_, i) => index !== i)
})
}
},
// 企业联系人备注
inputContactsRemarks (e) {
const index = e.currentTarget.dataset.index
this.data.personList[index].remarks = e.detail.value || ''
this.setData({
personList: this.data.personList
})
},
// 提交
formSubmit(e) {
// 参会单位必填
if (!this.data.selectedCompany.id) {
wx.showToast({
title: '请先选择参会单位',
icon: "none",
duration: 800,
});
return
}
// 企业联系人1必填
if (!this.data.personList[0].contactsId) {
wx.showToast({
title: '请选择企业联系人1',
icon: 'none',
duration: 2000
})
return
}
// 企业联系人不能重复
const personIds = this.data.personList.filter(item => item.contactsId).map(item => item.contactsId)
if (Array.from(new Set(personIds)).length !== personIds.length) {
wx.showToast({
title: '请选择不同的联系人',
icon: 'none',
duration: 2000
})
return
}
const params = {}
// 报名起草组id
params.draftingGroupId = this.data.id
// 审核状态 1未审核 2已审核 3已驳回
params.checkResult = 1
// 选择的企业
params.chargeCompanyId = this.data.selectedCompany.id
params.chargeCompanyTemporaryName = this.data.selectedCompany.companyName
// 总备注
params.remarks = e.detail.value.remarks || ''
// 联络人列表
params.payDraftingGroupSubItemContactsList = this.data.personList.filter(item => item.contactsId)
console.log(params);
wx.showLoading({
title: '加载中',
mask: true
})
UserApi.draftingGroupRegistration(params).then(res => {
if (res.success) {
wx.showToast({
title: res.message,
icon: 'loading',
duration: 1500,
success: () => {
this.goBack()
}
})
} else {
wx.showToast({
title: res.message,
icon: 'none',
duration: 2000
})
}
}).catch(e => {
wx.showToast({
title: '操作失败',
icon: 'error',
duration: 2000
})
})
},
goBack(){
wx.navigateBack()
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.setData({
id: options.id
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
console.log('选择的用户', this.data.selectedPersonIndex, this.data.selectedPerson);
if (this.data.selectedPersonIndex !== null && this.data.selectedPersonIndex !== undefined) {
const { id, name } = this.data.selectedPerson || {}
this.data.personList[this.data.selectedPersonIndex] = {
contactsId: id,
contactsTemporaryName: name,
remarks: ''
}
this.setData({
selectedPerson: {},
selectedPersonIndex: null,
personList: this.data.personList
})
}
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})