// pages/specialOrderApplication/specialOrderApplyDetail/specialOrderApplyDetail.js
|
|
|
|
var network = require("../../../utils/net.js");
|
|
const app = getApp();
|
|
var dateTimePicker = require('../../../utils/dateTimePicker.js');
|
|
var timechage = require("../../../utils/dateTimeUtil.js")
|
|
|
|
var getDept = "/MainSystem/B3MiniProgramRpc/Rpcs/BaseInfoRpc/GetDepartment";
|
|
var getSaleKind = "/MainSystem/B3MiniProgramRpc/Rpcs/BaseInfoRpc/GetSaleKind"
|
|
var getPrice = "/MainSystem/B3MiniProgramRpc/Rpcs/BaseInfoRpc/GetGoodsPirce";
|
|
var insert = '/MainSystem/B3MiniProgramRpc/XuRpcs/Employee/MarketingActivityRpc/Insert';
|
|
|
|
function GetSaleKind(that, v) {
|
|
let method = getSaleKind;
|
|
let params = [{
|
|
"InputValue": v,
|
|
"PageIndex": 0,
|
|
"PageSize": 100
|
|
}];
|
|
network.transfer_request(method, params, function (res) {
|
|
that.setData({
|
|
currency: res.result,
|
|
saletype: res.result
|
|
})
|
|
})
|
|
that.setData({
|
|
which: "销售类型"
|
|
})
|
|
}
|
|
|
|
function GetDepartment(that, inputValue) {
|
|
let method = getDept;
|
|
let params = [{
|
|
"InputValue": inputValue,
|
|
"PageIndex": 0,
|
|
"PageSize": 100
|
|
}];
|
|
network.transfer_request(method, params, function (res) {
|
|
that.setData({
|
|
currency: res.result,
|
|
department: res.result
|
|
})
|
|
})
|
|
that.setData({
|
|
which: "部门"
|
|
})
|
|
}
|
|
|
|
function GetAccountingUnit(that, inputValue) {
|
|
let method = "/MainSystem/B3MiniProgramRpc/Rpcs/BaseInfoRpc/GetAccountingUnit";
|
|
let params = [{
|
|
"InputValue": inputValue,
|
|
"PageIndex": 0,
|
|
"PageSize": 100
|
|
}];
|
|
network.transfer_request(method, params, function (res) {
|
|
that.setData({
|
|
currency: res.result,
|
|
unit: res.result
|
|
})
|
|
})
|
|
that.setData({
|
|
which: "会计部门"
|
|
})
|
|
}
|
|
|
|
Page({
|
|
|
|
data: {
|
|
currentTab: 0,
|
|
winHeight: app.globalData.winHeight,
|
|
// 从哪个页面返回当前页面
|
|
backPage: "",
|
|
dateTimeArray: null,
|
|
dateTime: null,
|
|
startYear: 2018,
|
|
endYear: 2030,
|
|
// 用户数组
|
|
customerArr: [],
|
|
// 存货数组
|
|
goodsNameArr: [],
|
|
which: "",
|
|
idx: 0,
|
|
currency: [],
|
|
saletypeIndex: 0,
|
|
saletype: [{
|
|
ID: 0,
|
|
Name: "请选择销售类型"
|
|
}],
|
|
|
|
customerIndex: 0,
|
|
customer: [{
|
|
ID: 0,
|
|
Name: "请选择客户"
|
|
}],
|
|
isUnit: 0,
|
|
unit: [], //会计单位
|
|
departmentIndex: 0,
|
|
department: [], //销售部门
|
|
name: "",
|
|
remark: '',
|
|
},
|
|
|
|
// 添加名称
|
|
getName: function (e) {
|
|
this.data.name = e.detail.value;
|
|
},
|
|
|
|
// 添加摘要
|
|
getRemark: function (e) {
|
|
this.data.remark = e.detail.value;
|
|
},
|
|
|
|
|
|
// 获取输入框值进行保存
|
|
getInputValue: function (e) {
|
|
var style = e.currentTarget.dataset.datastyle
|
|
var itemIndex = e.currentTarget.dataset.index;
|
|
var array = this.data.goodsNameArr;
|
|
|
|
let value = e.detail.value;
|
|
let end = value.charAt(value.length - 1)
|
|
if (end != ".") {
|
|
array[itemIndex][style] = Number(value),
|
|
this.setData({
|
|
goodsNameArr: array,
|
|
})
|
|
}
|
|
},
|
|
|
|
// 获取存货时间变化进行保存
|
|
bindTimeChange: function (e) {
|
|
var style = e.currentTarget.dataset.datastyle
|
|
var itemIndex = e.currentTarget.dataset.index;
|
|
var array = this.data.goodsNameArr;
|
|
array[itemIndex][style] = e.detail.value,
|
|
this.setData({
|
|
goodsNameArr: array,
|
|
})
|
|
},
|
|
|
|
// 基本信息日期
|
|
changeDateTime(e) {
|
|
this.setData({
|
|
dateTime: e.detail.value
|
|
});
|
|
|
|
},
|
|
|
|
// 添加客户
|
|
addCustomer: function () {
|
|
wx.navigateTo({
|
|
url: '../../customerChooseTemplate/customerChooseTemplate?fromePage=specialOrder',
|
|
})
|
|
},
|
|
|
|
// 添加存货
|
|
addGoodsName: function () {
|
|
var that = this;
|
|
let unitID = that.data.unit[that.data.isUnit].ID;
|
|
var customerArr = that.data.customerArr;
|
|
if (unitID && customerArr.length > 0) {
|
|
let customerID = customerArr[0].ID;
|
|
wx.navigateTo({
|
|
url: '../../goodaNameChooseTemplate/goodaNameChooseTemplate?unitID=' + unitID + '&customerID' + customerID,
|
|
})
|
|
} else {
|
|
wx.showModal({
|
|
title: '提示',
|
|
content: '请先选择客户及会计单位',
|
|
})
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 滑动切换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
|
|
})
|
|
}
|
|
},
|
|
|
|
// 遮罩的搜索框事件
|
|
select: function (e) {
|
|
var that = this;
|
|
// 自定义的类型
|
|
var which = e.currentTarget.dataset.item;
|
|
// 输入的值
|
|
var value = e.detail.value;
|
|
if (which == "会计部门") {
|
|
GetAccountingUnit(that, value)
|
|
} else if (which == "购货客户") {
|
|
GetCustomer(that, value)
|
|
} else if (which == "部门") {
|
|
GetDepartment(that, value)
|
|
} else if (which == "销售类型") {
|
|
GetSaleKind(that, value)
|
|
}
|
|
},
|
|
|
|
// 判断条件进行遮罩内容选取
|
|
powerDrawer: function (e) {
|
|
let that = this;
|
|
let x = e.currentTarget.dataset.x;
|
|
if (x == "会计部门") {
|
|
GetAccountingUnit(that, "")
|
|
} else if (x == "购货客户") {
|
|
GetCustomer(that, "")
|
|
} else if (x == "部门") {
|
|
GetDepartment(that, "")
|
|
} else if (x == "销售类型") {
|
|
GetSaleKind(that, "")
|
|
}
|
|
let currentStatu = e.currentTarget.dataset.statu;
|
|
// 添加动画打开遮罩
|
|
this.util(currentStatu)
|
|
},
|
|
|
|
// 遮罩层点击选中具体条目
|
|
itemclick: function (e) {
|
|
var that = this;
|
|
var which = e.currentTarget.dataset.item;
|
|
var idx = e.currentTarget.dataset.idx;
|
|
|
|
if (which == "会计部门") {
|
|
that.setData({
|
|
isUnit: idx
|
|
})
|
|
} else if (which == "购货客户") {
|
|
that.setData({
|
|
customerIndex: idx
|
|
})
|
|
GetSpecifiedCustomer(that, idx)
|
|
} else if (which == "部门") {
|
|
that.setData({
|
|
departmentIndex: idx
|
|
})
|
|
} else if (which == "销售类型") {
|
|
that.setData({
|
|
saletypeIndex: idx
|
|
})
|
|
}
|
|
this.setData({
|
|
showModalStatus: false,
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 存货明细保存按钮 点击新建单据 内部做逻辑判断 存储值是否都已经加载
|
|
*/
|
|
submitOrder: function () {
|
|
var that = this;
|
|
let unitID = this.data.unit[this.data.isUnit].ID;
|
|
let departmentID = this.data.department[this.data.departmentIndex].ID;
|
|
|
|
let year = this.data.dateTimeArray[0][this.data.dateTime[0]]
|
|
let month = this.data.dateTimeArray[1][this.data.dateTime[1]]
|
|
let date = this.data.dateTimeArray[2][this.data.dateTime[2]]
|
|
let hour = this.data.dateTimeArray[3][this.data.dateTime[3]]
|
|
let minu = this.data.dateTimeArray[4][this.data.dateTime[4]]
|
|
|
|
let stringTime = year + "/" + month + "/" + date + " " + hour + ":" + minu + ":00"
|
|
let timestamp2 = Date.parse(new Date(stringTime));
|
|
let update = "/Date(" + timestamp2 + "+0800)/";
|
|
|
|
if (unitID == 0) {
|
|
wx.showToast({
|
|
title: '请选择会计单位'
|
|
})
|
|
return;
|
|
}
|
|
|
|
if (departmentID == 0) {
|
|
wx.showToast({
|
|
title: '请选择销售部门',
|
|
})
|
|
return;
|
|
}
|
|
|
|
if (this.data.customerArr.length <= 0) {
|
|
wx.showToast({
|
|
title: '客户不能为空',
|
|
})
|
|
return;
|
|
}
|
|
|
|
let customerDetailsArray = [];
|
|
var customerArray = this.data.customerArr;
|
|
for (var i = 0; i < customerArray.length; i++) {
|
|
|
|
var dmo = {
|
|
Customer_ID: customerArray[i].ID,
|
|
// CustomerCatalog_Name: customerArray[i].CustomerCatalog_Name,
|
|
}
|
|
customerDetailsArray.push(dmo)
|
|
}
|
|
|
|
if (this.data.goodsNameArr.length <= 0) {
|
|
wx.showToast({
|
|
title: '存货不能为空',
|
|
})
|
|
return;
|
|
}
|
|
|
|
let goodsDetailsArray = [];
|
|
var goodsNameArray = this.data.goodsNameArr;
|
|
for (var i = 0; i < goodsNameArray.length; i++) {
|
|
|
|
if (goodsNameArray[i].applicationPrice == "") {
|
|
wx.showToast({
|
|
title: '特价价格不能为空',
|
|
})
|
|
return;
|
|
}
|
|
if (goodsNameArray[i].applicationNum == '') {
|
|
wx.showToast({
|
|
title: '申请数量不能为空',
|
|
})
|
|
return;
|
|
}
|
|
|
|
let beginTime = timechage.formatymdERTDate(goodsNameArray[i].applicationStartTime);
|
|
let endTime = timechage.formatymdERTDate(goodsNameArray[i].applicationEndTime);
|
|
var dmo = {
|
|
SaleGoods_ID: goodsNameArray[i].SaleGoods_ID,
|
|
LastPrice: goodsNameArray[i].Price,
|
|
Price: goodsNameArray[i].applicationPrice,
|
|
BeginTime: beginTime,
|
|
EndTime: endTime,
|
|
Number: goodsNameArray[i].applicationNum,
|
|
Unit: goodsNameArray[i].applicationUnit,
|
|
}
|
|
goodsDetailsArray.push(dmo)
|
|
}
|
|
|
|
|
|
let method = insert;
|
|
let params = [{
|
|
"Name": this.data.name,
|
|
"MarketingActivityDate": update,
|
|
"AccountingUnit_ID": unitID,
|
|
"Department_ID": departmentID,
|
|
"Remark": this.data.remark,
|
|
"GoodsDetails": goodsDetailsArray,
|
|
"CustomerDetails": customerDetailsArray,
|
|
|
|
}];
|
|
network.transfer_request(method, params, function (res) {
|
|
if (res.result != null) {
|
|
wx.showModal({
|
|
title: '新建申请单No.' + res.result,
|
|
content: '新建成功,是否返回上级列表',
|
|
success: function (res) {
|
|
if (res.cancel) { } else {
|
|
wx.navigateBack({
|
|
delta: 1
|
|
})
|
|
}
|
|
},
|
|
fail: function (res) { }
|
|
})
|
|
}
|
|
})
|
|
|
|
},
|
|
|
|
// 删除客户明细
|
|
deleteCustomerItem: function (event) {
|
|
var id = event.target.dataset.idx;
|
|
var array = this.data.customerArr;
|
|
array.splice(id, 1);
|
|
this.setData({
|
|
customerArr: array,
|
|
})
|
|
},
|
|
|
|
// 删除存货明细
|
|
deleteGoodsItem: function (event) {
|
|
var id = event.target.dataset.id;
|
|
var array = this.data.goodsNameArr;
|
|
array.splice(id, 1);
|
|
this.setData({
|
|
goodsNameArr: array,
|
|
})
|
|
},
|
|
|
|
onLoad: function (options) {
|
|
//正常登录流程进入值为0,分享页面直接进入值为1
|
|
if (app.globalData.shareInState == 1) {
|
|
return;
|
|
}
|
|
|
|
if (app.globalData.shareInParameter.id) {
|
|
var detailItemID = parseInt(app.globalData.shareInParameter.id);
|
|
// wx.showModal({
|
|
// title: '看下ID值',
|
|
// content: '+++' + detailItemID + '+++',
|
|
// })
|
|
// detailItemType = app.globalData.shareInParameter.detailItemType;
|
|
} else {
|
|
var detailItemID = parseInt(options.ID);
|
|
}
|
|
var that = this;
|
|
var method ='/MainSystem/B3MiniProgramRpc/XuRpcs/Employee/MarketingActivityRpc/Load';
|
|
let params = [detailItemID];
|
|
network.transfer_request(method, params, function (res) {
|
|
app.globalData.shareInParameter = {};
|
|
// 获取数据加载页面
|
|
let goodsDetailsArray = [];
|
|
var goodsNameArray = res.result.GoodsDetails;
|
|
for (var i = 0; i < goodsNameArray.length; i++) {
|
|
let beginTime = timechage.formatTimeTwo(goodsNameArray[i].BeginTime.substring(6, 19), 'Y-M-D')
|
|
let endTime = timechage.formatTimeTwo(goodsNameArray[i].EndTime.substring(6, 19), 'Y-M-D')
|
|
var dmo = {
|
|
SaleGoods_ID: goodsNameArray[i].SaleGoods_ID,
|
|
Goods_Name: goodsNameArray[i].Goods_Name,
|
|
Price: goodsNameArray[i].LastPrice,
|
|
applicationPrice: goodsNameArray[i].Price,
|
|
applicationStartTime: beginTime,
|
|
applicationEndTime: endTime,
|
|
applicationNum: goodsNameArray[i].Number,
|
|
applicationUnit: goodsNameArray[i].Unit,
|
|
}
|
|
goodsDetailsArray.push(dmo)
|
|
}
|
|
|
|
let customerDetailsArray = [];
|
|
var customerArray = res.result.CustomerDetails;
|
|
for (var i = 0; i < customerArray.length; i++) {
|
|
var dmo = {
|
|
ID: customerArray[i].Customer_ID,
|
|
CustomerCatalog_Name: customerArray[i].CustomerCatalog_Name,
|
|
Name: customerArray[i].Customer_Name,
|
|
}
|
|
customerDetailsArray.push(dmo)
|
|
}
|
|
|
|
let loadtimee = timechage.formatTimeTwo(res.result.MarketingActivityDate.substring(6, 19), 'Y-M-D h:m')
|
|
|
|
|
|
let unitOld = [{
|
|
ID: res.result.AccountingUnit_ID,
|
|
Name: res.result.AccountingUnit_Name
|
|
}]
|
|
|
|
let departmentOld = [{
|
|
ID: res.result.Department_ID,
|
|
Name: res.result.Department_Name
|
|
}]
|
|
|
|
that.setData({
|
|
name: res.result.Name,
|
|
remark: res.result.Remark,
|
|
goodsNameArr: goodsDetailsArray,
|
|
customerArr: customerDetailsArray,
|
|
department: departmentOld,
|
|
unit: unitOld,
|
|
// name: res.result.Name,
|
|
// remark: res.result.Name,
|
|
})
|
|
|
|
|
|
|
|
})
|
|
|
|
// 获取完整的年月日 时分秒,以及默认显示的数组
|
|
var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
|
|
// 精确到分的处理,将数组的秒去掉
|
|
var lastArray = obj1.dateTimeArray.pop();
|
|
var lastTime = obj1.dateTime.pop();
|
|
|
|
this.setData({
|
|
dateTimeArray: obj1.dateTimeArray,
|
|
dateTime: obj1.dateTime,
|
|
unit: [{
|
|
ID: app.globalData.accountingUnit_ID,
|
|
Name: app.globalData.accountingUnit_Name
|
|
}],
|
|
department: [{
|
|
ID: app.globalData.department_ID,
|
|
Name: app.globalData.department_Name
|
|
}],
|
|
});
|
|
},
|
|
|
|
GetGoodsPrice: function (Goods_ID, Unit, index) {
|
|
var that = this;
|
|
let timestamp = Date.parse(new Date());
|
|
let date = "/Date(" + timestamp + "+0800)/";
|
|
let unitID = that.data.unit[that.data.isUnit].ID;
|
|
let customerID = that.data.customerArr[0].ID;
|
|
|
|
let method = getPrice;
|
|
let params = [{
|
|
"Goods_ID": Goods_ID, //请求货物接口后返回的字段
|
|
"Unit": Unit, //请求货物接口后返回的字段
|
|
"Customer_ID": parseInt(customerID),
|
|
"AccountingUnit_ID": parseInt(unitID),
|
|
"Date": date
|
|
}];
|
|
network.transfer_request(method, params, function (res) {
|
|
var array = that.data.goodsNameArr;
|
|
array[index].Price = res.result.Price;
|
|
that.setData({
|
|
goodsNameArr: array,
|
|
})
|
|
})
|
|
},
|
|
|
|
onShow: function () {
|
|
var that = this;
|
|
|
|
if (this.data.backPage == "customerChoosePage") {
|
|
// 返回的用户只能是一条,所以index只能为0
|
|
var currentCustomerArr = app.globalData.customerArray;
|
|
if (currentCustomerArr.length > 0) {
|
|
this.setData({
|
|
customerArr: currentCustomerArr,
|
|
})
|
|
}
|
|
}
|
|
|
|
if (this.data.backPage == "goodsNameChoosePage") {
|
|
// 获取存货 加载完成后计算价格政策
|
|
var goodsArr = app.globalData.goodsNameArray;
|
|
if (goodsArr.length > 0) {
|
|
// 在此添加货品价格的请求
|
|
let backGoodsArr = [];
|
|
for (var i = 0; i < goodsArr.length; i++) {
|
|
// 存货名称
|
|
var name = goodsArr[i].Goods_Name;
|
|
// 存货ID
|
|
var id = goodsArr[i].SaleGoods_ID;
|
|
// 获取价格
|
|
var unit = goodsArr[i].Unit;
|
|
// 原单价
|
|
var infoprice = goodsArr[i].Price;
|
|
if (infoprice == null) {
|
|
infoprice = "";
|
|
}
|
|
// 特价
|
|
var policyPrice = "";
|
|
// 开始时间
|
|
var infoStartTime = timechage.formatTimeTwo(Date.parse(new Date()), 'Y-M-D');
|
|
// 结束时间
|
|
var infoEndTime = timechage.formatTimeTwo(Date.parse(new Date()), 'Y-M-D');
|
|
// 申请数量
|
|
var infoNum = "";
|
|
|
|
let goodsNameObj = {
|
|
Goods_Name: name,
|
|
SaleGoods_ID: Number(id),
|
|
Price: infoprice,
|
|
applicationPrice: policyPrice,
|
|
applicationStartTime: infoStartTime,
|
|
applicationEndTime: infoEndTime,
|
|
applicationNum: infoNum,
|
|
applicationUnit: unit,
|
|
}
|
|
backGoodsArr.push(goodsNameObj)
|
|
|
|
// 获取原单价
|
|
that.GetGoodsPrice(id, unit, i);
|
|
}
|
|
|
|
this.setData({
|
|
goodsNameArr: backGoodsArr,
|
|
})
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
app.globalData.goodsNameArray = [];
|
|
app.globalData.customerArray = [];
|
|
},
|
|
|
|
util: function (currentStatu) {
|
|
/* 动画部分 */
|
|
// 第1步:创建动画实例
|
|
var animation = wx.createAnimation({
|
|
duration: 200, //动画时长
|
|
timingFunction: "linear", //线性
|
|
delay: 0 //0则不延迟
|
|
});
|
|
|
|
// 第2步:这个动画实例赋给当前的动画实例
|
|
this.animation = animation;
|
|
|
|
// 第3步:执行第一组动画
|
|
animation.opacity(0).rotateX(-100).step();
|
|
|
|
// 第4步:导出动画对象赋给数据对象储存
|
|
this.setData({
|
|
animationData: animation.export()
|
|
})
|
|
|
|
// 第5步:设置定时器到指定时候后,执行第二组动画
|
|
setTimeout(function () {
|
|
// 执行第二组动画
|
|
animation.opacity(1).rotateX(0).step();
|
|
// 给数据对象储存的第一组动画,更替为执行完第二组动画的动画对象
|
|
this.setData({
|
|
animationData: animation
|
|
})
|
|
|
|
//关闭
|
|
if (currentStatu == "close") {
|
|
this.setData({
|
|
showModalStatus: false,
|
|
});
|
|
}
|
|
}.bind(this), 200)
|
|
|
|
// 显示
|
|
if (currentStatu == "open") {
|
|
// 调用函数时,传入new Date()参数,返回值是日期和时间
|
|
// var timet = utilll.formatTime(new Date());
|
|
// 再通过setData更改Page()里面的data,动态更新页面的数据
|
|
this.setData({
|
|
// time: timet,
|
|
showModalStatus: true,
|
|
});
|
|
}
|
|
},
|
|
util1: function (currentStatu) {
|
|
/* 动画部分 */
|
|
// 第1步:创建动画实例
|
|
var animation = wx.createAnimation({
|
|
duration: 200, //动画时长
|
|
timingFunction: "linear", //线性
|
|
delay: 0 //0则不延迟
|
|
});
|
|
|
|
// 第2步:这个动画实例赋给当前的动画实例
|
|
this.animation = animation;
|
|
|
|
// 第3步:执行第一组动画
|
|
animation.opacity(0).rotateX(-100).step();
|
|
|
|
// 第4步:导出动画对象赋给数据对象储存
|
|
this.setData({
|
|
animationData: animation.export()
|
|
})
|
|
|
|
// 第5步:设置定时器到指定时候后,执行第二组动画
|
|
setTimeout(function () {
|
|
// 执行第二组动画
|
|
animation.opacity(1).rotateX(0).step();
|
|
// 给数据对象储存的第一组动画,更替为执行完第二组动画的动画对象
|
|
this.setData({
|
|
animationData: animation
|
|
})
|
|
|
|
//关闭
|
|
if (currentStatu == "close") {
|
|
this.setData({
|
|
showModalStatus1: false
|
|
});
|
|
}
|
|
}.bind(this), 200)
|
|
|
|
// 显示
|
|
if (currentStatu == "open") {
|
|
// 调用函数时,传入new Date()参数,返回值是日期和时间
|
|
// var timet = utilll.formatTime(new Date());
|
|
// 再通过setData更改Page()里面的data,动态更新页面的数据
|
|
this.setData({
|
|
// time: timet,
|
|
showModalStatus1: true
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
})
|