From 8e81a112f07e399418cac0042bea21a8d6a184d7 Mon Sep 17 00:00:00 2001 From: 10994015 Date: Mon, 26 Feb 2024 09:44:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E5=BE=A9pricereview=20Alpine=20js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wms/mkt/assets/js/pricereviewAlpine.js | 308 ++++++++++++------------- 1 file changed, 154 insertions(+), 154 deletions(-) diff --git a/wms/mkt/assets/js/pricereviewAlpine.js b/wms/mkt/assets/js/pricereviewAlpine.js index b8af842a..75e82180 100644 --- a/wms/mkt/assets/js/pricereviewAlpine.js +++ b/wms/mkt/assets/js/pricereviewAlpine.js @@ -1,6 +1,6 @@ -const pricereviewCreate = () => { +const pricereviewCreate = ()=>{ return { - init() { + init(){ this.elevators = elevators; this.is_renovation = is_renovation this.selectedOptions = selectedOptions; @@ -15,21 +15,20 @@ const pricereviewCreate = () => { 9:"CO" }, optionalArr: { - 1: '標配', - 2: '選配', - 3: '選配', + 1:'標配', + 2:'選配', + 3:'選配', }, total_spec: total_spec, options: options, - // orioptions: options, searchtext: '', kind: 1, subkind: 1, buttons: [], modalSelectedOptions: {}, - selectedOptions: [], + selectedOptions:[], elevators: [], - toElevators: [], + toElevators:[], toElevatorNo: '', currentOptionKey: '', currentOtherOptionKey: '', @@ -46,23 +45,23 @@ const pricereviewCreate = () => { speed:'', open:'CO', num: 1, - price: '', - sale_price: '', + price:'', + sale_price:'', facility_id: '', model:'', }, otherOptions: [], - modalOtherOptionInfo: { - pr_no: "", - name: "", + modalOtherOptionInfo:{ + pr_no:"", + name:"", price: 0, - num: "", + num:"", }, - maintainOptions: [], - modalMaintainInfo: { - price: 0, - num: "", - memo: "", + maintainOptions:[], + modalMaintainInfo:{ + price:0, + num:"", + memo:"", }, demolishOptions: demolishOptions, modalDemolishOptionsInfo:{ @@ -89,8 +88,6 @@ const pricereviewCreate = () => { uscc: uscc, person: salesman, }, - attatch1:"", - attatch2:"", weightArr: { 6: 450, 8: 550, @@ -105,6 +102,8 @@ const pricereviewCreate = () => { 24:1600, }, is_renovation: is_renovation, + attatch1:"", + attatch2:"", async getElevatorPrice(idx){ const spec = this.elevators[idx].specifications const person = this.elevators[idx].person @@ -124,14 +123,15 @@ const pricereviewCreate = () => { try{ const res = await axios.get("./api/getElevatorPrice.php", {params: {model: model, kind: spec}}) console.log(res.data); - if (res.data == null || res.data == "") { + if(res.data.id == null || res.data.id == ""){ console.log("公司並無提供此規格!!"); } - this.elevators[idx].price = res.data - } catch (error) { + this.elevators[idx].price = res.data.price + this.elevators[idx].facility_id = res.data.id + }catch (error) { console.error("Error fetching elevator price:", error); } - + }, async getModalElevatorPrice(){ let model = ""; @@ -143,16 +143,15 @@ const pricereviewCreate = () => { model = this.modalElevatorInfo.spec + '-' + this.modalElevatorInfo.person + '*' + this.modalElevatorInfo.stop + '-' + this.modalElevatorInfo.open + this.modalElevatorInfo.speed; this.modalElevatorInfo.model = this.modalElevatorInfo.spec + '-' + this.modalElevatorInfo.person + '*' + this.modalElevatorInfo.stop + '-' + this.modalElevatorInfo.open + this.modalElevatorInfo.speed; } - console.log(model); try{ const res = await axios.get("./api/getElevatorPrice.php", {params: {model: model, kind:kind}}) console.log(res.data); - if (res.data == null || res.data == "") { + if(res.data.id == null || res.data.id == ""){ console.log("公司並無提供此規格!!"); } this.modalElevatorInfo.price = res.data.price - this.modalElevatorInfo.id = res.data.id - } catch (error) { + this.modalElevatorInfo.facility_id = res.data.id + }catch (error) { console.error("Error fetching elevator price:", error); } }, @@ -230,65 +229,65 @@ const pricereviewCreate = () => { } }, optionSubCategory: 1, - initOptinos() { - this.options.forEach(option => { + initOptinos(){ + this.options.forEach(option=>{ option.isShow = 1; }) }, - searchOptions(kind = this.kind, subkind = this.subkind) { - if (kind != null) this.kind = kind; - if (subkind != null) this.subkind = subkind; + searchOptions(kind=this.kind, subkind=this.subkind){ + if(kind!=null) this.kind = kind; + if(subkind!=null) this.subkind = subkind; this.initOptinos(); this.initButtons(kind); - this.options.forEach(option => { - if (option.kind != this.kind && this.kind != 1) { + this.options.forEach(option=>{ + if(option.kind != this.kind && this.kind != 1){ option.isShow = 0; - } else { - if (option.subkind != this.subkind && this.subkind != 1) { + }else{ + if(option.subkind != this.subkind && this.subkind != 1){ option.isShow = 0; } } - if (option.isShow == 1) { - if (option.group_name == null) option.group_name = '' - if (option.spec == null) option.spec = '' - if (option.memo == null) option.memo = '' - if (option.price == null) option.price = 0 - if (option.unit == null) option.unit = '' - if (String(option.id).includes(this.searchtext) || option.group_name.includes(this.searchtext) || option.memo.toLowerCase().includes(this.searchtext) || option.spec.toLowerCase().includes(this.searchtext) || option.unit.includes(this.searchtext) || String(option.price).includes(this.searchtext)) { + if(option.isShow == 1){ + if(option.group_name == null) option.group_name = '' + if(option.spec == null) option.spec = '' + if(option.memo == null) option.memo = '' + if(option.price == null) option.price = 0 + if(option.unit == null) option.unit = '' + if(String(option.id).includes(this.searchtext) || option.group_name.includes(this.searchtext) || option.memo.toLowerCase().includes(this.searchtext) || option.spec.toLowerCase().includes(this.searchtext) || option.unit.includes(this.searchtext) || String(option.price).includes(this.searchtext)){ option.isShow = 1 - } else { + }else{ option.isShow = 0 } } }) }, - selectOption(idx, id, name, price, memo) { - this.options[idx].selected = this.options[idx].selected == 1 ? 0 : 1; - - if (this.modalSelectedOptions.hasOwnProperty(idx)) { + selectOption(idx, id, name, price, memo){ + this.options[idx].selected = this.options[idx].selected==1 ? 0 : 1; + + if(this.modalSelectedOptions.hasOwnProperty(idx)){ delete this.modalSelectedOptions[idx]; - } else { + }else{ //this.optionKey => 已選option 流水號, idx:option表內的流水號, id:option 資料庫的ID - this.modalSelectedOptions[idx] = { key: this.optionKey, 'idx': idx, 'id': id, 'name': name, 'price': price, qty: 1, 'memo': memo, 'toElevator': [] } + this.modalSelectedOptions[idx] = {key:this.optionKey, 'idx':idx, 'id': id, 'name': name, 'price': price, qty:1, 'memo': memo, 'toElevator':[] } } - this.optionKey++; + this.optionKey ++; }, - initModalSelectedOptions() { + initModalSelectedOptions(){ this.modalSelectedOptions = {} - this.options.forEach(option => { + this.options.forEach(option=>{ option.selected = 0 }) this.$refs.optionsModal.style.display = "block" body.style.overflow = 'hidden' }, - chkOptions() { - Object.keys(this.modalSelectedOptions).forEach(option => { + chkOptions(){ + Object.keys(this.modalSelectedOptions).forEach(option=>{ this.selectedOptions.push(this.modalSelectedOptions[option]) }) console.log(this.selectedOptions); this.hideOptionsModal(); }, - hideOptionsModal() { + hideOptionsModal(){ this.$refs.optionsModal.style.display = 'none'; body.style.overflow = 'auto' }, @@ -356,33 +355,33 @@ const pricereviewCreate = () => { return total + (elevator.spec_num * elevator.price); }, 0); }, - totalElevatorsNum() { + totalElevatorsNum(){ return this.elevators.reduce((total, elevator) => { return total + Number(elevator.spec_num); }, 0) }, - totalElevatorsSalePrice() { + totalElevatorsSalePrice(){ return this.elevators.reduce((total, elevator) => { return total + (elevator.spec_num * elevator.spec_price); }, 0); }, - totalOptionsPrice() { + totalOptionsPrice(){ return this.selectedOptions.reduce((total, option) => { return total + (option.qty * option.price); }, 0); }, - openAddElevatorFn() { + openAddElevatorFn(){ }, - createElevatorFn() { - if (this.modalElevatorInfo.spec == '') return alert("請選擇電梯規格"); - if (this.modalElevatorInfo.stop == '') return alert("請填入停數"); - if (this.modalElevatorInfo.speed == '') return alert("請選擇速度"); - if (this.modalElevatorInfo.open == '') return alert("請選擇開梯方式"); - if (this.modalElevatorInfo.person == '') return alert("請填入人乘/載重"); - if (this.modalElevatorInfo.num == '') return alert("請填入數量"); - if (this.modalElevatorInfo.sale_price == '') return alert("請填入售價"); - this.total_spec++; + createElevatorFn(){ + if(this.modalElevatorInfo.spec == '') return alert("請選擇電梯規格"); + if(this.modalElevatorInfo.stop == '') return alert("請填入停數"); + if(this.modalElevatorInfo.speed == '') return alert("請選擇速度"); + if(this.modalElevatorInfo.open == '') return alert("請選擇開梯方式"); + if(this.modalElevatorInfo.person == '') return alert("請填入人乘/載重"); + if(this.modalElevatorInfo.num == '') return alert("請填入數量"); + if(this.modalElevatorInfo.sale_price == '') return alert("請填入售價"); + this.total_spec ++; this.elevators.push({ id: this.total_spec, specifications: this.modalElevatorInfo.spec, @@ -392,7 +391,7 @@ const pricereviewCreate = () => { open_converted: this.modalElevatorInfo.open, spec_price: this.modalElevatorInfo.sale_price, price: this.modalElevatorInfo.price, - open: '', + open:'', spec_num: this.modalElevatorInfo.num, facility_id: this.modalElevatorInfo.facility_id, model: this.modalElevatorInfo.model, @@ -400,7 +399,7 @@ const pricereviewCreate = () => { console.log(this.elevators); this.hideCreateElevatorModal(); }, - copyElevator(idx) { + copyElevator(idx){ const spec = this.elevators[idx].specifications const person = this.elevators[idx].person const stop = this.elevators[idx].stop @@ -413,7 +412,7 @@ const pricereviewCreate = () => { const facility_id = this.elevators[idx].facility_id const model = this.elevators[idx].model - this.total_spec++; + this.total_spec ++; this.elevators.push({ id: this.total_spec, specifications: spec, @@ -486,11 +485,11 @@ const pricereviewCreate = () => { this.$refs.toElevatorModal.style.display = 'block'; body.style.overflow = 'hidden' }, - addOtherOptionToElevator(id) { + addOtherOptionToElevator(id){ this.currentOtherOptionKey = id; this.toElevators = []; this.toElevatorNo = ""; - const matchElevators = this.otherOptions.filter(option => option.id == id)[0].toElevator.map(elevator => elevator.id) + const matchElevators = this.otherOptions.filter(option=> option.id == id)[0].toElevator.map(elevator=> elevator.id) this.toElevatorNo = matchElevators[0] this.elevators.forEach(elevator=>{ if(elevator.price > 0){ @@ -512,7 +511,7 @@ const pricereviewCreate = () => { this.$refs.toOtherOptionElevatorModal.style.display = 'block'; body.style.overflow = 'hidden' }, - chkOptionToElevators() { + chkOptionToElevators(){ const checkedOptions = []; const matchElevators = this.elevators.filter(elevator=> elevator.id == this.toElevatorNo)[0] @@ -520,8 +519,8 @@ const pricereviewCreate = () => { id: this.toElevatorNo, model: matchElevators['model'] , }) - this.selectedOptions.forEach(option => { - if (option.key == this.currentOptionKey) { + this.selectedOptions.forEach(option=>{ + if(option.key == this.currentOptionKey){ option.toElevator = []; option.toElevator.push(...checkedOptions) } @@ -529,7 +528,7 @@ const pricereviewCreate = () => { this.currentOptionKey = '' this.hideToElevatorModal(); }, - chkOtherOptionToElevators() { + chkOtherOptionToElevators(){ const checkedOptions = []; const matchElevators = this.elevators.filter(elevator=> elevator.id == this.toElevatorNo)[0] @@ -537,8 +536,8 @@ const pricereviewCreate = () => { id: this.toElevatorNo, model: matchElevators['model'], }) - this.otherOptions.forEach(option => { - if (option.id == this.currentOtherOptionKey) { + this.otherOptions.forEach(option=>{ + if(option.id == this.currentOtherOptionKey){ option.toElevator = []; option.toElevator.push(...checkedOptions) } @@ -548,36 +547,36 @@ const pricereviewCreate = () => { this.hideToOtherOptionElevatorModal(); }, - removeElevator(id) { - if (!confirm("確定刪除嗎?")) return; - this.elevators = this.elevators.filter(elevator => elevator.id != id) + removeElevator(id){ + if(!confirm("確定刪除嗎?")) return; + this.elevators = this.elevators.filter(elevator=> elevator.id != id) const issetElevators = []; - this.elevators.forEach(elevator => { + this.elevators.forEach(elevator=>{ issetElevators.push(elevator.id); }) - this.selectedOptions.forEach(option => { - option.toElevator = option.toElevator.filter(el => { + this.selectedOptions.forEach(option=>{ + option.toElevator = option.toElevator.filter(el=>{ return issetElevators.includes(el.id) }) }) console.log(this.selectedOptions); }, - removeOption(key) { + removeOption(key){ console.log(this.selectedOptions); - this.selectedOptions = this.selectedOptions.filter(option => option.key != key) + this.selectedOptions = this.selectedOptions.filter(option=> option.key != key) }, - removeOtherOption(id) { - this.otherOptions = this.otherOptions.filter(option => option.id != id) + removeOtherOption(id){ + this.otherOptions = this.otherOptions.filter(option=> option.id != id) }, - createOtherOptionFn() { + createOtherOptionFn(){ this.otherOptions.push({ id: this.otherOptionKey, pr_no: this.modalOtherOptionInfo.pr_no, name: this.modalOtherOptionInfo.name, price: this.modalOtherOptionInfo.price, num: this.modalOtherOptionInfo.num, - toElevator: [], + toElevator:[], }) this.modalOtherOptionInfo = { pr_no: '', @@ -585,35 +584,34 @@ const pricereviewCreate = () => { price: 0, num: '', } - this.otherOptionKey++; - console.log(this.otherOptions); - this.$refs.closeCreateOtherOptionModalBtn.click(); + this.otherOptionKey ++; + this.hideCreateOtherOptionModal(); }, - totalOtherOptionsPrice() { + totalOtherOptionsPrice(){ return this.otherOptions.reduce((total, option) => { return total + (Number(option.num) * Number(option.price)); }, 0); }, - totalOtherOptionsNum() { + totalOtherOptionsNum(){ return this.otherOptions.reduce((total, option) => { return total + Number(option.num); }, 0); }, - createMaintainOptionFn() { + createMaintainOptionFn(){ this.maintainOptions.push({ id: this.maintainOptionKey, price: this.modalMaintainInfo.price, num: this.modalMaintainInfo.num, memo: this.modalMaintainInfo.memo, - toElevator: [], + toElevator:[], }) this.modalMaintainInfo = { - price: 0, - num: "", - memo: "", + price:0, + num:"", + memo:"", } - this.maintainOptionKey++; - this.$refs.closeCreateMaintainOptionModalBtn.click(); + this.maintainOptionKey ++; + this.hideCreateMaintainModal(); }, createDemolishOptionFn(){ this.demolishOptions.push({ @@ -639,7 +637,7 @@ const pricereviewCreate = () => { return total + (Number(option.num) * Number(option.price)); }, 0); }, - totalMaintainOptionsNum() { + totalMaintainOptionsNum(){ return this.maintainOptions.reduce((total, option) => { return total + Number(option.num); }, 0); @@ -662,8 +660,8 @@ const pricereviewCreate = () => { id: this.toElevatorNo, model: matchElevators['model'], }) - this.maintainOptions.forEach(option => { - if (option.id == this.currentMaintainOptionKey) { + this.maintainOptions.forEach(option=>{ + if(option.id == this.currentMaintainOptionKey){ option.toElevator = []; option.toElevator.push(...checkedOptions) } @@ -691,7 +689,7 @@ const pricereviewCreate = () => { this.currentMaintainOptionKey = id; this.toElevators = []; this.toElevatorNo = ""; - const matchElevators = this.maintainOptions.filter(option => option.id == id)[0].toElevator.map(elevator => elevator.id) + const matchElevators = this.maintainOptions.filter(option=> option.id == id)[0].toElevator.map(elevator=> elevator.id) this.toElevatorNo = matchElevators[0] this.elevators.forEach(elevator=>{ if(elevator.price > 0){ @@ -748,19 +746,19 @@ const pricereviewCreate = () => { totalPrice(){ return this.totalElevatorsPrice() + this.totalOptionsPrice() + this.totalOtherOptionsPrice() + this.totalMaintainOptionsPrice(); }, - totalSalePrice() { + totalSalePrice(){ return this.elevators.reduce((total, elevator) => { return total + (elevator.spec_num * elevator.spec_price); }, 0); }, - scalePrice(scale) { - if (scale === '') return 0; + scalePrice(scale){ + if(scale === '') return 0; return this.totalSalePrice() * scale / 100; }, - totalScale() { + totalScale(){ let total = 0; - Object.keys(this.paymentRatio).forEach(pay => { - if (this.paymentRatio[pay].scale != '' && this.paymentRatio[pay].scale > 0) { + Object.keys(this.paymentRatio).forEach(pay=>{ + if(this.paymentRatio[pay].scale != '' && this.paymentRatio[pay].scale > 0){ total += Number(this.paymentRatio[pay].scale) } }) @@ -806,12 +804,12 @@ const pricereviewCreate = () => { errortext += err+'\n'; }) alert(errortext) - return; + return false; } }, submit(){ - this.validation(); - + const validation = this.validation(); + if(!validation) return const form = new FormData(); form.append('contractno', contractno); form.append('ekind', (is_renovation=="Y") ? "汰改" : "新梯"); @@ -821,7 +819,7 @@ const pricereviewCreate = () => { form.append('address', this.customerInfo.address); form.append('price_lowest', this.totalPrice()); form.append('price_total', this.totalSalePrice()); - form.append('price_rate', Math.round(this.totalSalePrice() / this.totalPrice() * 100 * 10) / 10); + form.append('price_rate', Math.round(this.totalSalePrice() / this.totalPrice() * 100 *10) / 10); form.append('special_fee', this.serviceFee); form.append('predeal_date', this.transactionDate); form.append('facilitok_date', this.shippingDate); @@ -843,21 +841,20 @@ const pricereviewCreate = () => { form.append('demolishOptions', JSON.stringify(this.demolishOptions)); form.append('paymentRatio', JSON.stringify(this.paymentRatio)); - - axios.post('./api/postNewElevatorPricereview.php', form).then(res => { + + axios.post('./api/postNewElevatorPricereview.php', form).then(res=>{ console.log(res.data); - if (res.data == "success") { + if(res.data == "success"){ alert("送審成功!"); window.location.href = './pricereview-index.php?' + token_link; } - }).catch(err => { + }).catch(err=>{ console.error(err); }) }, save(){ - console.log(this.attatch1); - return; - this.validation(); + const validation = this.validation(); + if(!validation) return const form = new FormData(); form.append('contractno', contractno); form.append('ekind', (is_renovation=="Y") ? "汰改" : "新梯"); @@ -903,7 +900,9 @@ const pricereviewCreate = () => { }, } } -const pricereviewCheck = () => { + + +const pricereviewCheck = ()=>{ return { init(){ this.elevators = elevators @@ -927,8 +926,8 @@ const pricereviewCheck = () => { if(option.option_relate_spec == elevator.item_no){ elevator.optionsTotalPrice += option.option_mi * option.item_qty this.elevators[idx].options.push({ - 'id': option.id, - 'item_spec': option.item_spec.trim(), + 'id': option.id, //&lt;br&gt;() + 'item_spec': option.item_spec.trim().replaceAll('&', '').replaceAll('lt;', '').replaceAll('br', '').replaceAll('gt;', '').replaceAll('()', ''), 'item_unit_price': option.item_unit_price, 'item_qty': option.item_qty, 'mi': Math.round(option.option_mi), @@ -937,11 +936,11 @@ const pricereviewCheck = () => { } }) - this.otherOptions.forEach(option => { - if (option.option_relate_spec == elevator.item_no) { + this.otherOptions.forEach(option=>{ + if(option.option_relate_spec == elevator.item_no){ elevator.otherOptionsTotalPrice += option.item_unit_price * option.item_qty this.elevators[idx].otherOptions.push({ - 'id': option.id, + 'id': option.id, 'item_spec': option.item_spec.trim(), 'item_unit_price': option.item_unit_price, 'item_qty': option.item_qty, @@ -950,8 +949,8 @@ const pricereviewCheck = () => { } }) - this.maintainOptions.forEach(option => { - if (option.option_relate_spec == elevator.item_no) { + this.maintainOptions.forEach(option=>{ + if(option.option_relate_spec == elevator.item_no){ elevator.maintainOptionsTotalPrice += option.item_unit_price * option.item_qty this.elevators[idx].maintainOptions.push({ 'id': option.id, @@ -983,14 +982,14 @@ const pricereviewCheck = () => { let stop = model.split('-')[1].split('*')[1].split('-')[0]; let open = model.split('-')[2]; let speed = ''; - for (let i = 0; i < this.openFn.length; i++) { - if (open.includes(this.openFn[i])) { + for(let i=0;i { 'add_price':0, } } - + console.log(this.elevators[idx]); - } catch (error) { + }catch (error) { console.error("Error fetching elevator price:", error); } }, - isNotfoundMi: false, - openFn: [ + isNotfoundMi:false, + openFn:[ 'CO', '2S', '2U', '4PCO', '6PCO' ], - sign1: '', - sign2: '', - sign3: '', - sign4: '', + sign1:'', + sign2:'', + sign3:'', + sign4:'', is_renovate: false, elevators_total_price: 0, contractno: contractno, @@ -1064,24 +1063,25 @@ const pricereviewCheck = () => { memo: memo, qty: 0, pays: pays, - elevators: [], + elevators:[], options: [], otherOptions: [], maintainOptions: [], demolishOptions:[], mid: mid, user_id: user_id, - optionsTotalPrice() { + reviewcomment:'', + optionsTotalPrice(){ return this.options.reduce((total, option) => { return total + (option.item_qty * option.item_unit_price); }, 0); }, - otherOptionsTotalPrice() { + otherOptionsTotalPrice(){ return this.otherOptions.reduce((total, option) => { return total + (option.item_qty * option.item_unit_price); }, 0); }, - maintainOptionsTotalPrice() { + maintainOptionsTotalPrice(){ return this.maintainOptions.reduce((total, option) => { return total + (option.item_qty * option.item_unit_price); }, 0); @@ -1093,7 +1093,7 @@ const pricereviewCheck = () => { }, totalScale(){ return this.pays.reduce((total, option) => { - return total + Number(option.pay_scale); + return total + Number(option.pay_scale ); }, 0); }, totalElevatorsPrice(){ @@ -1111,9 +1111,10 @@ const pricereviewCheck = () => { form.append('mid', this.mid); form.append('result', status); form.append('user_id', this.user_id); - axios.post('./api/postPricereviewSign.php', form).then(res => { + form.append('reviewcomment', this.reviewcomment); + axios.post('./api/postPricereviewSign.php', form).then(res=>{ console.log(res.data); - if (res.data == 1) { + if(res.data == 1){ alert("簽核成功!"); window.location.reload() } @@ -1125,6 +1126,5 @@ const pricereviewCheck = () => { const res = await axios.get('./api/getUsername.php', {params: {user_id: user_id}}) return res.data ; }, - } } \ No newline at end of file