You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

420 lines
17 KiB

const pricereviewCreate = ()=>{
return {
init(){
},
modalShow:{
elevator: false,
other:false,
otherToElevator:false,
},
vol_no: vol_no,
apply_key: apply_key,
customer:customer,
manager:manager,
salesman:salesman,
salesman_name:salesman_name,
pre_order_date:pre_order_date,
address:address,
progress_status:progress_status,
total_spec:total_spec,
elevators: hope_elevators,
case_name:case_name, //案件名稱
contract_status:contract_kind, // 契約性質
pay_method:payment_kind, // 付款方式
startDate:contract_begin_date, //合約開始日期
endDate:contract_end_date, // 合約結束日期
brand:brand,
modalElevatorInfo:{
spec:'',
person:'',
weight:'',
stop:'',
speed:'',
permitNumber:'', //許可證號碼
brand:'', //品牌
m1:'N', //贈送M1
months:12, // 保養月數
cycle:'', // 保養週期
method:'', //保養方式
checkYear:'', //竣工檢查年度
lastDate:'', // 上次年檢日期
yearCheckFee:'', //年檢費用
price:'', //公司發布價(月)
qty:1, //電梯數量
sale_price:'', //契約報價
},
otherOptions: otherOptions,
modalOtherOptionInfo:{
pr_no:"",
name:"",
price: 0,
num:"",
memo:"",
},
otherOptionKey: otherOptionKey,
currentOtherOptionKey:'',
toElevators:[],
toElevatorNo:'',
serviceFee: service_fee,
remark:memo,
penalty: penalty,
deposit_rate: deposit_rate,
keep_rate: keep_rate,
warranty_rate: warranty_rate,
openCreateElevatorModal(){
this.modalShow.elevator = true;
body.style.overflow = 'hidden';
},
hideCreateElevatorModal(){
this.modalShow.elevator = false;
body.style.overflow = 'auto';
this.modalElevatorInfo = {
spec:'',
person:'',
weight:'',
stop:'',
speed:'',
permitNumber:'', //許可證號碼
brand:'', //品牌
m1:'N', //贈送M1
months:12, // 保養月數
cycle:'', // 保養週期
method:'', //保養方式
checkYear:'', //竣工檢查年度
lastDate:'', // 上次年檢日期
yearCheckFee:'', //年檢費用
price:'', //公司發布價(月)
qty:1, //電梯數量
sale_price:'', //契約報價
};
},
createElevatorFn(){
// if(this.modalElevatorInfo.spec == '') return alert("請選擇電梯規格");
// if(this.modalElevatorInfo.person == '') return alert("請選擇人乘");
// if(this.modalElevatorInfo.weight == '') return alert("請輸入載重");
// if(this.modalElevatorInfo.stop == '') return alert("請輸入停數");
// if(this.modalElevatorInfo.speed == '') return alert("請選擇速度");
// if(this.modalElevatorInfo.brand == '') return alert("請選擇品牌");
// if(this.modalElevatorInfo.months == '') return alert("請輸入保養月數");
// if(this.modalElevatorInfo.method == '') return alert("請選擇保養方式");
// if(this.modalElevatorInfo.cycle == '') return alert("請選擇保養週期");
// if(this.modalElevatorInfo.checkYear == '') return alert("請輸入竣工檢查年度");
// if(this.modalElevatorInfo.price == '') return alert("請選擇正確規格");
// if(this.modalElevatorInfo.sale_price == '') return alert("請輸入契約報價");
this.total_spec ++;
this.elevators.push({
id: this.total_spec,
spec: this.modalElevatorInfo.spec,
person: this.modalElevatorInfo.person,
weight: this.modalElevatorInfo.weight,
stop: this.modalElevatorInfo.stop,
speed: this.modalElevatorInfo.speed,
permitNumber: this.modalElevatorInfo.permitNumber,
brand: this.modalElevatorInfo.brand,
m1: this.modalElevatorInfo.m1,
months:this.modalElevatorInfo.months, // 保養月數
cycle: this.modalElevatorInfo.cycle,
method:this.modalElevatorInfo.method, // 保養方法
checkYear: this.modalElevatorInfo.checkYear,
lastDate: this.modalElevatorInfo.lastDate,
yearCheckFee: this.modalElevatorInfo.yearCheckFee,
price: this.modalElevatorInfo.price,
qty: this.modalElevatorInfo.qty,
sale_price: this.modalElevatorInfo.sale_price
})
this.hideCreateElevatorModal();
},
copyElevator(idx){
const spec = this.elevators[idx].spec;
const person = this.elevators[idx].person;
const stop = this.elevators[idx].stop;
const weight = this.elevators[idx].weight
const speed = this.elevators[idx].speed;
const brand = this.elevators[idx].brand;
const m1 = this.elevators[idx].m1;
const months = this.elevators[idx].months;
const method = this.elevators[idx].method;
const cycle = this.elevators[idx].cycle;
const checkYear = this.elevators[idx].checkYear;
const lastDate = this.elevators[idx].lastDate;
const yearCheckFee = this.elevators[idx].yearCheckFee;
const price = this.elevators[idx].price;
const qty = this.elevators[idx].qty;
const sale_price = this.elevators[idx].sale_price;
this.total_spec ++;
this.elevators.push({
id: this.total_spec,
spec: spec,
person: person,
stop: stop,
weight:weight,
speed: speed,
permitNumber: '',
brand: brand,
m1: m1,
months: months,
method: method,
cycle: cycle,
checkYear: checkYear,
lastDate: lastDate,
yearCheckFee: yearCheckFee,
price: price,
qty: qty,
sale_price: sale_price
})
},
removeElevator(id){
if(!confirm('確定刪除該電梯?')) return;
this.elevators = this.elevators.filter(elevator=> elevator.id != id)
const issetElevators = [];
this.elevators.forEach(elevator=>{
issetElevators.push(elevator.id);
})
this.otherOptions.forEach(option=>{
option.toElevator = option.toElevator.filter(el=>{
return issetElevators.includes(el.id)
})
})
},
openCreateOtherOptionFn(){
this.modalShow.other = true
body.style.overflow = 'hidden'
},
createOtherOptionFn(){
this.otherOptionKey ++;
this.otherOptions.push({
id: this.otherOptionKey,
pr_no: this.modalOtherOptionInfo.pr_no,
name: this.modalOtherOptionInfo.name,
price: this.modalOtherOptionInfo.price,
num: this.modalOtherOptionInfo.num,
memo: this.modalOtherOptionInfo.memo,
toElevator:[],
})
this.modalOtherOptionInfo = {
pr_no: '',
name: '',
price: 0,
num: '',
memo: '',
}
this.hideCreateOtherOptionModal();
},
hideCreateOtherOptionModal(){
this.modalShow.other = false
// this.$refs.createOtherOptionModal.style.display = 'none';
body.style.overflow = 'auto'
},
addOtherOptionToElevator(id){
this.currentOtherOptionKey = id;
this.toElevators = [];
this.toElevatorNo = "";
const matchElevators = this.otherOptions.filter(option=> option.id == id)[0].toElevator.map(elevator=> elevator.id)
this.toElevatorNo = matchElevators[0]
console.log(this.elevators);
this.elevators.forEach(elevator=>{
if(elevator.price > 0){
let model = ''
model = elevator.spec
this.toElevators.push({
id: elevator.id,
model: model,
checked: matchElevators.includes(elevator.id) ? 1: 0,
})
}
})
this.modalShow.otherToElevator = true
body.style.overflow = 'hidden'
},
hideToOtherOptionElevatorModal(){
this.modalShow.otherToElevator = false
body.style.overflow = 'auto'
},
copyOtherOption(id){
this.otherOptionKey++;
const copyOption = this.otherOptions.filter(option=> option.id === id)[0]
console.log(copyOption);
this.otherOptions.push({
id: this.otherOptionKey,
name: copyOption.name,
price: copyOption.price,
num: copyOption.num,
toElevator: [],
pr_no: copyOption.pr_no
})
console.log(this.otherOptions);
},
chkOtherOptionToElevators(){
const checkedOptions = [];
const matchElevators = this.elevators.filter(elevator=> elevator.id == this.toElevatorNo)[0]
console.log(matchElevators);
checkedOptions.push({
id: this.toElevatorNo,
model: matchElevators['spec'],
})
this.otherOptions.forEach(option=>{
if(option.id == this.currentOtherOptionKey){
option.toElevator = [];
option.toElevator.push(...checkedOptions)
}
})
console.log(this.otherOptions);
this.currentOtherOptionKey = ''
this.hideToOtherOptionElevatorModal();
},
removeOtherOption(id){
this.otherOptions = this.otherOptions.filter(option=> option.id != id)
},
get totalPrice(){
let total_price = this.elevators.reduce((accumulator, el) => accumulator + Number(el.price*el.months), 0);
let total_other_price = this.otherOptions.reduce((accumulator, option) => accumulator + Number(option.price*option.num), 0);
return total_price + total_other_price;
},
get totalSalePrice(){
let total_sale_price = this.elevators.reduce((accumulator, el) => accumulator + Number(el.sale_price*el.months), 0);
return total_sale_price + Number(this.serviceFee);
},
get totalElevatorsNum(){
let total_num = this.elevators.reduce((accumulator, el) => accumulator + Number(el.qty), 0);
return total_num;
},
get totalOtherOptionsNum(){
let total_other_num = this.otherOptions.reduce((accumulator, option) => accumulator + Number(option.num), 0);
return total_other_num;
},
get totalOtherOptionsPrice(){
let total_other_price = this.otherOptions.reduce((accumulator, option) => accumulator + Number(option.price*option.num), 0);
return total_other_price;
},
async getModalElevatorPrice(){
const spec = this.modalElevatorInfo.spec
const person = this.modalElevatorInfo.person
const stop = this.modalElevatorInfo.stop
const weight = this.modalElevatorInfo.weight
const speed = this.modalElevatorInfo.speed
const m1 = this.modalElevatorInfo.m1
const method = this.modalElevatorInfo.method
const cycle = this.modalElevatorInfo.cycle
try{
const res = await axios.get('./api/getElevatorPrice.php', {params: {spec: spec, person:person, weight: weight, stop: stop, speed: speed, m1: m1, method: method, cycle:cycle}})
this.modalElevatorInfo.price = res.data;
console.log(res.data);
}catch (error) {
console.error("Error message:", error);
}
},
async getElevatorPrice(idx){
const spec = this.elevators[idx].spec
const person = this.elevators[idx].person
const stop = this.elevators[idx].stop
const weight = this.elevators[idx].weight
const speed = this.elevators[idx].speed
const m1 = this.elevators[idx].m1
const method = this.elevators[idx].method
const cycle = this.elevators[idx].cycle
try{
const res = await axios.get('./api/getElevatorPrice.php', {params: {spec: spec, person:person, weight: weight, stop: stop, speed: speed, m1: m1, method: method, cycle:cycle}})
this.elevators[idx].price = res.data;
console.log(res.data);
}catch (error) {
console.error("Error message:", error);
}
},
save(){
const form = new FormData();
form.append('vol_no', this.vol_no);
form.append('apply_key', this.apply_key);
form.append('customer', this.customer);
form.append('brand', this.brand);
form.append('address', this.address);
form.append('case_name', this.case_name);
form.append('brand', this.brand);
form.append('num', this.totalElevatorsNum);
form.append('salesman', this.salesman);
form.append('contract_begin_date', this.startDate);
form.append('contract_end_date', this.endDate);
form.append('contract_kind', this.contract_status);
form.append('progress_status', this.progress_status);
form.append('serviceFee', this.serviceFee);
form.append('penalty', this.penalty);
form.append('deposit_rate', this.deposit_rate);
form.append('keep_rate', this.keep_rate);
form.append('warranty_rate', this.warranty_rate);
form.append('remark', this.remark);
form.append('creater', user_id);
form.append('pay_method', this.pay_method);
form.append('status', 'Y1');
form.append('total_price', this.totalPrice);
form.append('total_sale_price', this.totalSalePrice);
form.append('elevators', JSON.stringify(this.elevators));
form.append('otherOptions', JSON.stringify(this.otherOptions));
axios.post('./api/postElevatorPricereview.php', form).then(res=>{
console.log(res.data);
if(res.data == 'success'){
alert("保存成功!");
window.location.reload();
}
})
},
submit(){
const form = new FormData();
form.append('vol_no', this.vol_no);
form.append('apply_key', this.apply_key);
form.append('customer', this.customer);
form.append('brand', this.brand);
form.append('address', this.address);
form.append('case_name', this.case_name);
form.append('brand', this.brand);
form.append('num', this.totalElevatorsNum);
form.append('salesman', this.salesman);
form.append('contract_begin_date', this.startDate);
form.append('contract_end_date', this.endDate);
form.append('contract_kind', this.contract_status);
form.append('progress_status', this.progress_status);
form.append('serviceFee', this.serviceFee);
form.append('penalty', this.penalty);
form.append('deposit_rate', this.deposit_rate);
form.append('keep_rate', this.keep_rate);
form.append('warranty_rate', this.warranty_rate);
form.append('remark', this.remark);
form.append('creater', user_id);
form.append('pay_method', this.pay_method);
form.append('status', 'YS');
form.append('total_price', this.totalPrice);
form.append('total_sale_price', this.totalSalePrice);
form.append('elevators', JSON.stringify(this.elevators));
form.append('otherOptions', JSON.stringify(this.otherOptions));
axios.post('./api/postElevatorPricereview.php', form).then(res=>{
console.log(res.data);
if(res.data == 'success'){
alert("送審成功!");
// window.location.reload();
// window.location.href = './pricereview-index.php?' + token;
}
})
},
async getUsername(user_id){
if(user_id == '') return '---'
const res = await axios.get('./api/getUsername.php', {params: {user_id: user_id}})
return res.data ;
},
}
}
const pricereviewCheck = ()=>{
return {
init(){
console.log(123);
},
elevators: elevators,
}
}