var em = new Vue({
el:"#boxAdd",
data:{
basicInformation:{},
// 水产
aquaticProductData:{
id:'',
priceType:'1',
lowestPrice:'',//最低价
price:'',//价格
description:'',//备注
},
// 水产信息录入是否禁止输入
aquaticProductFlag:false,
//肉类
meatData:{
id:'',
priceType:'单',
lowestPrice:'',//最低价
price:'',//价格
description:'',//备注
},
// 肉类信息录入是否禁止输入
meatTypeFlag:false,
// 肉类计费规则,默认:单 == 1
moneyRulerName:1, //2 //3
//肉类柜规格计价数据
moneyRulerData:[],
},
created:function(){
this.createdInit()
},
methods:{
createdInit:function(){
var _this = this
this.basicInformation=eval(${fns:toJson(internationalCostomsBroker)})
this.moneyRulerData=[]
for (var i = 0; i <this.basicInformation.detailList.length ; i++) {
console.log(this.basicInformation.detailList[i].type)
if (this.basicInformation.detailList[i].type==1) {
this.aquaticProductFlag = true
this.aquaticProductData = this.basicInformation.detailList[i]
}
if (this.basicInformation.detailList[i].type==2) {
this.meatTypeFlag = true
this.moneyRulerName =this.basicInformation.detailList[i].priceType
if (this.basicInformation.detailList[i].priceType !=3){
this.meatData = this.basicInformation.detailList[i]
}else {
this.moneyRulerData.push(this.basicInformation.detailList[i])
}
}
}
},
addMeatNorm:function(){
let obj = {containerType:'',price:'',lowestPrice:'',description:'',id:''}
this.moneyRulerData.push(obj)
},
// 第一次选中肉类规格
selectMoneyRuler:function(e){
e.target.value==1?this.meatData.priceType=="1":
e.target.value==2?this.meatData.priceType=="2":
e.target.value==3?this.meatData.priceType=="3":''
if(this.moneyRulerName == '3' && this.moneyRulerData.length==0){
this.addMeatNorm()
}
},
// 点击添加规格
addRuler:function(){
if(this.moneyRulerName == '3' ){
this.addMeatNorm()
}
},
deleteCurrItem(index) {
this.moneyRulerData.splice(index,1);
},
// 保存
save(){
let _this = this
let file = document.querySelector('#dow').value
let basicInformation = this.basicInformation
let aquaticProductData = this.aquaticProductData
let meatData = this.meatData
if(basicInformation.name == ''){
alert('报关行名称不能为空');
return false;
}
if(!(/^1[3456789]\d{9}$/.test(basicInformation.phone))){
alert("手机号码有误,请重填");
return false;
}
if(basicInformation.contact == ''){
alert('联系人不能为空');
return false;
}
if(file == ''){
alert('报关行文件不能为空');
return false;
}
if(basicInformation.contractStart == ''){
alert('起止时间不能为空');
return false;
}
if(basicInformation.contractEnd == ''){
alert('结束时间不能为空');
return false;
}
if(basicInformation.region == ''){
alert('地区不能为空');
return false;
}
var objs =[]
if (this.aquaticProductFlag){ // 水产
var obj ={}
obj.type=1; //类型
obj.priceType = this.aquaticProductData.priceType; //计费类型
obj.containerType=''; //柜规格
obj.price = this.aquaticProductData.price; //计费单价
obj.id = this.aquaticProductData.id; //计费单价
obj.lowestPrice =this.aquaticProductData.lowestPrice; //最低价
obj.description =this.aquaticProductData.description; //备注
if (obj.price==''){
alert("计费单价不能为空")
return false;
}
if (obj.lowestPrice==''){
alert("最低价不能为空")
return false;
}
objs.push(obj);
}else {
alert("水产规则不能为空")
return false;
}
if (this.meatTypeFlag) {
if (this.moneyRulerName == 3) { //柜规格
for (var i = 0; i < this.moneyRulerData.length; i++) {
var obj = {}
obj.type = 2; //类型
obj.priceType = this.moneyRulerName; //计费类型
obj.containerType = this.moneyRulerData[i].containerType; //柜规格
obj.price = this.moneyRulerData[i].price; //计费单价
obj.id = this.moneyRulerData[i].id; //计费单价
obj.lowestPrice = this.moneyRulerData[i].lowestPrice; //最低价
obj.description = this.moneyRulerData[i].description; //备注
if (obj.containerType == '') {
alert("柜规格不能为空")
return false;
}
if (obj.price == '') {
alert("计费单价不能为空")
return false;
}
if (obj.lowestPrice == '') {
alert("最低价不能为空")
return false;
}
objs.push(obj);
}
} else { //单或吨 2
var obj = {}
obj.type = 2; //类型
obj.priceType = this.moneyRulerName; //计费类型
obj.id = this.meatData.id; //计费类型
obj.containerType = ''; //柜规格
obj.price = this.meatData.price; //计费单价
obj.lowestPrice = this.meatData.lowestPrice; //最低价
obj.description = this.meatData.description; //备注
if (obj.price == '') {
alert("计费单价不能为空")
return false;
}
if (obj.lowestPrice == '') {
alert("最低价不能为空")
return false;
}
objs.push(obj);
}
}
var html = ''
for (var i = 0; i <objs.length ; i++) {
html+="<input type='hidden' name='details["+i+"].type' value='"+objs[i].type+"'>"
html+="<input type='hidden' name='details["+i+"].id' value='"+objs[i].id+"'>"
html+="<input type='hidden' name='details["+i+"].priceType' value='"+objs[i].priceType+"'>"
html+="<input type='hidden' name='details["+i+"].containerType' value='"+objs[i].containerType+"'>"
html+="<input type='hidden' name='details["+i+"].price' value='"+objs[i].price+"'>"
html+="<input type='hidden' name='details["+i+"].lowestPrice' value='"+objs[i].lowestPrice+"'>"
html+="<input type='hidden' name='details["+i+"].description' value='"+objs[i].description+"'>"
}
$('#inputForm').append(html)
$('#inputForm').submit()
},
},
watch: {
moneyRulerName() {
if(this.moneyRulerName != 3) {
this.moneyRulerData = [];
}
},
},
})