// pages/customerChooseTemplate/customerChooseTemplate.js
|
|
|
|
var app = getApp()
|
|
var network = require("../../utils/net.js")
|
|
var dateTimePicker = require('../../utils/dateTimePicker.js');
|
|
var utilll = require('../../utils/util.js');
|
|
var fromPage = '';
|
|
|
|
var getAccountingUnit = "/MainSystem/B3MiniProgramRpc/Rpcs/BaseInfoRpc/GetAccountingUnit";
|
|
var getCustomer = "/MainSystem/B3MiniProgramRpc/Rpcs/BaseInfoRpc/GetCustomer";
|
|
|
|
Page({
|
|
|
|
data: {
|
|
winHeight: app.globalData.winHeight,
|
|
currentTab: 0,
|
|
collectionArray: [],
|
|
customerArray: [],
|
|
checkBoxArray: [],
|
|
storageCheckBoxArray: [],
|
|
},
|
|
|
|
getCustomerBySearchString:function(event){
|
|
var searchStr =event.detail.value;
|
|
this.GetCustomer(searchStr);
|
|
},
|
|
|
|
GetCustomer: function (inputValue) {
|
|
var that =this;
|
|
let method = getCustomer;
|
|
let params = [{
|
|
"InputValue": inputValue,
|
|
"PageIndex": 0,
|
|
"PageSize": 100
|
|
}];//, ["CustomerCatalog_Name"]
|
|
network.transfer_request(method, params, function(res) {
|
|
that.setData({
|
|
customerArray: res.result
|
|
})
|
|
})
|
|
},
|
|
|
|
// 多选框数值变化
|
|
checkboxValueChange: function (e) {
|
|
// 新建预报页面只允许选取一位客户
|
|
if (fromPage == "newForecast" && e.detail.value.length > 0) {
|
|
this.setData({
|
|
checkBoxArray: e.detail.value,
|
|
})
|
|
this.addCustomerName();
|
|
}
|
|
|
|
this.setData({
|
|
checkBoxArray: e.detail.value,
|
|
})
|
|
},
|
|
|
|
// 点击添加存货明细按钮 存数据进入global
|
|
addCustomerName: function () {
|
|
|
|
let choseCheck = []
|
|
// 对比原有数组和选中的数组 存在,将数组包含的其他值也取出加载
|
|
for (var i = 0; i < this.data.customerArray.length; i++) {
|
|
for (var j = 0; j < this.data.checkBoxArray.length; j++) {
|
|
if (Number(this.data.customerArray[i].ID) == this.data.checkBoxArray[j]) {
|
|
choseCheck.push(this.data.customerArray[i])
|
|
}
|
|
}
|
|
}
|
|
app.globalData.customerArray = choseCheck;
|
|
var pages = getCurrentPages();
|
|
var currPage = pages[pages.length - 1]; //当前页面
|
|
var prevPage = pages[pages.length - 2]; //上一个页面
|
|
//直接调用上一个页面对象的setData()方法,把数据存到上一个页面中去
|
|
prevPage.setData({
|
|
backPage: "customerChoosePage",
|
|
});
|
|
wx.navigateBack({
|
|
delta: 1
|
|
})
|
|
|
|
},
|
|
|
|
// 收藏夹点击添加客户 存数据进入global
|
|
storageAddCustomerArrayBack: function () {
|
|
let choseCheck = []
|
|
// 对比原有数组和选中的数组 存在,将数组包含的其他值也取出加载
|
|
for (var i = 0; i < this.data.collectionArray.length; i++) {
|
|
for (var j = 0; j < this.data.storageCheckBoxArray.length; j++) {
|
|
if (Number(this.data.collectionArray[i].ID) == this.data.storageCheckBoxArray[j]) {
|
|
choseCheck.push(this.data.collectionArray[i])
|
|
}
|
|
}
|
|
}
|
|
app.globalData.customerArray = choseCheck;
|
|
|
|
var pages = getCurrentPages();
|
|
var currPage = pages[pages.length - 1]; //当前页面
|
|
var prevPage = pages[pages.length - 2]; //上一个页面
|
|
//直接调用上一个页面对象的setData()方法,把数据存到上一个页面中去
|
|
prevPage.setData({
|
|
backPage: "customerChoosePage",
|
|
});
|
|
|
|
wx.navigateBack({
|
|
delta: 1,
|
|
})
|
|
},
|
|
|
|
// 点击了收藏按钮 (参数数组为定义)
|
|
storegeBtnClick: function () {
|
|
var that = this;
|
|
|
|
// 获取收藏的存货信息
|
|
var oldCollectionArr = this.data.collectionArray;
|
|
var waitStorageArr = this.data.checkBoxArray;
|
|
var customerArrayAll = this.data.customerArray;
|
|
|
|
if (waitStorageArr.length <= 0) {
|
|
wx.showToast({
|
|
title: '请选择客户',
|
|
})
|
|
return;
|
|
} else {
|
|
|
|
// 对比所选存货是否已经存在于收藏中 有:不重复添加 返回未添加过的数组
|
|
for (var i = 0; i < waitStorageArr.length; i++) {
|
|
for (var j = 0; j < oldCollectionArr.length; j++) {
|
|
if (Number(waitStorageArr[i]) == Number(oldCollectionArr[j].ID)) {
|
|
waitStorageArr.splice(i, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
// 对比原有数组和选中的数组 存在,将数组包含的其他值也取出加载
|
|
let choseCheck = [];
|
|
for (var i = 0; i < that.data.customerArray.length; i++) {
|
|
for (var j = 0; j < waitStorageArr.length; j++) {
|
|
if (Number(customerArrayAll[i].ID) == waitStorageArr[j]) {
|
|
choseCheck.push(customerArrayAll[i])
|
|
}
|
|
}
|
|
}
|
|
oldCollectionArr = oldCollectionArr.concat(choseCheck);
|
|
that.setData({
|
|
collectionArray: oldCollectionArr,
|
|
currentTab: 1,
|
|
});
|
|
wx.setStorage({
|
|
key: "storageCustomerKey",
|
|
data: oldCollectionArr,
|
|
success: function () {
|
|
wx.showToast({
|
|
title: '收藏成功',
|
|
});
|
|
},
|
|
})
|
|
}
|
|
},
|
|
|
|
// 收藏夹页面多选框值变化
|
|
storageCheckboxValueChange: function (e) {
|
|
|
|
// 新建预报页面只允许选取一位客户
|
|
if (fromPage == "newForecast" && e.detail.value.length > 0) {
|
|
this.setData({
|
|
storageCheckBoxArray: e.detail.value,
|
|
})
|
|
this.storageAddCustomerArrayBack();
|
|
}
|
|
|
|
this.setData({
|
|
storageCheckBoxArray: e.detail.value,
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
var that =this;
|
|
fromPage = options.fromePage;
|
|
this.GetCustomer();
|
|
// 获取收藏的客户信息
|
|
wx.getStorage({
|
|
key: 'storageCustomerKey',
|
|
success(res) {
|
|
console.log(res.data);
|
|
if (res.data.length > 0) {
|
|
that.setData({
|
|
collectionArray: res.data,
|
|
})
|
|
}
|
|
}
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 滑动切换tab
|
|
*/
|
|
bindChange: function (e) {
|
|
var that = this;
|
|
that.setData({
|
|
currentTab: e.detail.current
|
|
});
|
|
|
|
},
|
|
|
|
/**
|
|
* 点击tab切换
|
|
*/
|
|
swichNav: function (e) {
|
|
var that = this;
|
|
if (this.data.currentTab === e.target.dataset.current) {
|
|
return false;
|
|
} else {
|
|
that.setData({
|
|
currentTab: e.target.dataset.current
|
|
})
|
|
}
|
|
},
|
|
|
|
})
|