crm_second_opening_mini/pages/index/groupCompany/bills/addBills.js

307 lines
7.5 KiB
JavaScript
Raw Normal View History

2023-03-15 04:59:31 +00:00
// pages/index/groupCompany/bills/addBills.js
const app = getApp(); //全局app
Page({
/**
* 页面的初始数据
*/
data: {
BASE_IMG_URL: app.globalData.BASE_IMG_URL,
BASE_URL:app.globalData.BASE_URL,
reviseId:'', //修改过来的ID
agreementId:'',//从合同里面过来的ID
corporation:[], //关联公司名称
corporationList:[], //关联公司
corporationIndex:0,
agreement:[], //关联合同名称
agreementList:[],//关联合同
agreementIndex:0,
billsObj:{
corporation_id:'', //开票公司ID
contract_id:'', //关联合同ID
money:'',
remark:''
} //提交的数据
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
console.log(options)
let that = this;
this.getCorporation();
this.getAgreement();
setTimeout(function(){
if(options.id) {
that.setData({
reviseId:options.id
})
that.getRevise();
}
if(options.agreementId) {
that.setData({
agreementId:options.agreementId
})
console.log(that.data.agreementId)
that.getAgreementId();
}
},400)
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
// 获取所有关联公司
getCorporation() {
let that = this;
wx.request({
url: this.data.BASE_URL + '/addons/crmx/bill/getCorporationList',
data: {},
header: {
'content-type': 'application/json', // 默认值
'token': wx.getStorageSync('token'),
},
success (res) {
console.log(res.data,'公司列表')
let corporation = res.data.data.map(item => {
return item.name
})
that.setData({
corporation:corporation,
corporationList:res.data.data,
})
that.data.billsObj.corporation_id = res.data.data[that.data.corporationIndex].id;
}
})
},
// 获取所有关联合同
getAgreement() {
let that = this;
wx.request({
url: this.data.BASE_URL + '/addons/crmx/bill/getContractList',
data: {},
header: {
'content-type': 'application/json', // 默认值
'token': wx.getStorageSync('token'),
},
success (res) {
console.log(res.data,'合同列表')
let agreement = res.data.data.map(item => {
return item.name
})
that.setData({
agreement:agreement,
agreementList:res.data.data,
})
that.data.billsObj.contract_id = that.data.agreementList[that.data.agreementIndex].id;
}
})
},
// 选择关联公司
bindCorporation(e){
let value = e.detail.value;
this.setData({
corporationIndex:value,
})
this.data.billsObj.corporation_id = this.data.corporationList[e.detail.value].id;
},
// 选择关联合同
bindAgreement(e){
let value = e.detail.value;
this.setData({
agreementIndex:value,
})
this.data.billsObj.contract_id = this.data.agreementList[e.detail.value].id;
},
// 发票金额
bindMoney(e) {
let that = this;
that.data.billsObj.money = e.detail.value;
},
// 备注
bindRemark(e) {
let that = this;
that.data.billsObj.remark = e.detail.value;
},
// 添加按钮
addBills() {
console.log(this.data.billsObj,'aaaa')
let that = this;
let pargms = that.data.billsObj;
if(pargms.money == '') {
wx.showToast({
title:"请填写发票金额",
icon: 'error',
duration: 1000,
mask: false,
})
}else {
wx.request({
url: this.data.BASE_URL + '/addons/crmx/bill/addBill',
method:'POST',
data: {
contract_id:pargms.contract_id,
money:pargms.money,
corporation_id:pargms.corporation_id,
remark:pargms.remark
},
header: {
'content-type': 'application/json', // 默认值
'token': wx.getStorageSync('token'),
},
success (res) {
if(res.data.code == 1) {
console.log(res.data,'提交成功')
wx.showToast({
title:"保存成功",
icon: 'success',
duration: 1500,
mask: false,
})
setTimeout(function(){
wx.navigateBack({
delta: 1
});
},1700)
}
}
})
}
},
// 修改的内容
getRevise() {
let that = this;
wx.request({
url: this.data.BASE_URL + '/addons/crmx/bill/billInfo',
data: {
id:that.data.reviseId
},
header: {
'content-type': 'application/json', // 默认值
'token': wx.getStorageSync('token'),
},
success (res) {
console.log(res.data,'修改列表')
let corporation_name = res.data.data.corporation.name;
let agreement_name = res.data.data.contract.name;
let index = that.data.corporation.indexOf(corporation_name);
let index2 = that.data.agreement.indexOf(agreement_name);
that.setData({
corporationIndex:index,
agreementIndex:index2,
billsObj:{
corporation_id:that.data.corporationList[index].id, //开票公司ID
contract_id:that.data.agreementList[index2].id, //关联合同ID
money:res.data.data.money,
remark:res.data.data.remark
}
})
console.log(that.data.corporationIndex,that.data.agreementIndex,'默认')
}
})
},
//修改按钮
reviseBills() {
console.log(this.data.billsObj,'bbb')
let that = this;
let pargms = that.data.billsObj;
wx.request({
url: this.data.BASE_URL + '/addons/crmx/bill/editBill',
method:'POST',
data: {
contract_id:pargms.contract_id,
money:pargms.money,
corporation_id:pargms.corporation_id,
remark:pargms.remark,
id:that.data.reviseId,
},
header: {
'content-type': 'application/json', // 默认值
'token': wx.getStorageSync('token'),
},
success (res) {
if(res.data.code == 1) {
console.log(res.data,'修改成功')
wx.showToast({
title:"修改成功",
icon: 'success',//图标,支持"success"、"loading"
duration: 1200,//提示的延迟时间单位毫秒默认1500
mask: false,//是否显示透明蒙层防止触摸穿透默认false
})
setTimeout(function(){
wx.navigateBack({
delta: 1
});
},1250)
}
}
})
},
// 获取合同过来的合同名称并选中
getAgreementId() {
let that = this;
let agreementId = Number(that.data.agreementId);
let agreementIdList = that.data.agreementList.map(item => {
return item.id
})
let index = agreementIdList.indexOf(agreementId);
that.setData({
agreementIndex:index,
});
that.data.billsObj.corporation_id = that.data.corporationList[that.data.corporationIndex].id; //开票公司ID
that.data.billsObj.contract_id = that.data.agreementList[index].id; //关联合同ID
}
})