Files
lelong-web-pembida/src/components/Cart.vue
T
2022-06-09 15:32:15 +08:00

926 lines
28 KiB
Vue

<template>
<Navbar />
<div
v-if="loading"
style="min-height: 70vh; display: grid; place-items: center"
>
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
<div v-else class="container">
<div>
<button
class="btn btn-secondary float-start"
style="margin: 5px"
onclick="history.back()"
>
Kembali <i class="bi bi-backspace-fill"></i>
</button>
<div class="wrapper wrapper-content animated fadeInRight">
<h1>Troli <i class="bi bi-cart3"></i></h1>
<div class="row">
<div class="col-lg-9 col-sm-12" style="overflow-x: auto">
<div class="ibox">
<div class="table-responsive">
<div class="accordion-body">
<div class="ibox-content" style="padding-bottom: none">
<table class="table shoping-cart-table">
<thead>
<tr>
<td>Maklumat Marhun</td>
<td
width="30"
style="width: 145.82px; text-align: center"
>
Harga Asas
</td>
<td
width="120"
style="width: 145.82px; text-align: center"
>
Harga Bida
</td>
<td
width="80"
style="width: 145.82px; text-align: center"
>
Tindakan
</td>
</tr>
</thead>
</table>
</div>
<div
class="ibox-content"
v-for="senaraiCart in senaraiCarts.slice().reverse()"
:key="senaraiCart.id"
style="border-bottom: 1px solid #e7eaec"
>
<table class="table shoping-cart-table">
<tbody>
<tr>
<td class="desc">
<h3 class="text-primary">
{{ senaraiCart.datalelongbid.norujukan }}
</h3>
<dl class="small m-b-none">
<p>
Marhun:
{{ senaraiCart.datalelongbid.marhun }}
</p>
<p>
Berat:
{{ senaraiCart.datalelongbid.berat }}g
</p>
<p>
Cawangan:
{{
senaraiCart.datalelongbid.cawangan.caw_name
}}
</p>
</dl>
<div class="m-t-sm">
<button
class="btn btn-outline-danger"
data-bs-toggle="modal"
data-bs-target="#deleteModal"
@click="deleteModal(senaraiCart)"
>
Hapus
</button>
</div>
</td>
<td
width="30"
style="width: 145.82px; text-align: center"
>
RM{{ senaraiCart.datalelongbid.hargaasas }}
</td>
<td
width="30"
style="width: 145.82px; text-align: center"
>
<h4>RM{{ senaraiCart.hargabida }}</h4>
</td>
<td
width="120"
style="width: 145.82px; text-align: center"
>
<button
class="btn btn-outline-warning"
data-bs-toggle="modal"
data-bs-target="#editModal"
@click="editModal(senaraiCart)"
>
Ubah
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="col-3">
<div
class="ibox"
v-if="feeStatus == 2"
style="border: #e7eaec solid 1px"
>
<div class="ibox-title" style="padding: 20px">
<h5>Yuran</h5>
</div>
<div class="ibox-content">
<!-- <div class="small m-t-xs">
<div class="d-flex justify-content-between">
<p class="mb-0">Jumlah Bilangan Surat</p>
<p class="mb-0">{{ total_sag }}</p>
</div>
</div>
<hr />
<div class="small m-t-xs">
<div class="d-flex justify-content-between">
<p class="mb-0">Jumlah Bidaan</p>
<p class="mb-0">RM{{ total_bidaan }}</p>
</div>
</div>
<hr />
<span> Yuran </span> -->
<h2 class="font-bold">RM10.00</h2>
<hr />
<span class="text-muted small">
<i>*Anda perlu membayar yuran sebelum membuat bidaan.</i>
</span>
<div class="m-t-sm">
<!-- <div class="btn-group">
<button
data-bs-toggle="modal"
data-bs-target="#payModal"
class="btn btn-primary"
>
Teruskan <i class="fa fa-shopping-cart"></i>
</button>
</div> -->
<div class="btn-group">
<button
data-bs-toggle="modal"
data-bs-target="#payModal"
class="btn btn-primary"
>
Bayar Yuran
</button>
</div>
</div>
</div>
</div>
<div
class="ibox"
v-if="feeStatus == 1"
style="border: #e7eaec solid 1px"
>
<!-- <div class="ibox-title" style="padding: 20px">
<h5>Yuran</h5>
</div> -->
<div class="ibox-content">
<!-- <div class="small m-t-xs">
<div class="d-flex justify-content-between">
<p class="mb-0">Jumlah Bilangan Surat</p>
<p class="mb-0">{{ total_sag }}</p>
</div>
</div>
<hr />
<div class="small m-t-xs">
<div class="d-flex justify-content-between">
<p class="mb-0">Jumlah Bidaan</p>
<p class="mb-0">RM{{ total_bidaan }}</p>
</div>
</div>
<hr />
<span> Yuran </span> -->
<h4 class="text-success">
Yuran Telah Berjaya Dibayar
<i class="bi bi-check2-circle"></i>
</h4>
<hr />
<span class="text-muted small">
<i>*Anda boleh membuat bidaan.</i>
</span>
<!-- <div class="m-t-sm">
<div class="btn-group">
<button
data-bs-toggle="modal"
data-bs-target="#payModal"
class="btn btn-primary"
>
Bayar Yuran
</button>
</div>
</div> -->
</div>
</div>
<div class="ibox" style="border: #e7eaec solid 1px">
<div class="ibox-title" style="padding: 20px">
<h5>Ringkasan Troli</h5>
</div>
<div class="ibox-content">
<div class="small m-t-xs">
<div class="d-flex justify-content-between">
<p class="mb-0">Jumlah Bilangan Surat</p>
<p class="mb-0">{{ total_sag }}</p>
</div>
</div>
<hr />
<div class="small m-t-xs">
<div class="d-flex justify-content-between">
<p class="mb-0">Jumlah Bidaan</p>
<p class="mb-0">RM{{ total_bidaan }}</p>
</div>
</div>
<!-- <hr />
<span> Yuran </span>
<h2 class="font-bold">RM10.00</h2>
<hr />
<span class="text-muted small">
<i
>*Caj yuran akan dikenakan untuk membuat pendaftaran
bidaan.</i
>
</span> -->
<div v-if="feeStatus == 1" class="m-t-sm">
<div class="btn-group">
<button
data-bs-toggle="modal"
data-bs-target="#bidModal"
class="btn btn-primary"
>
Teruskan <i class="fa fa-shopping-cart"></i>
</button>
</div>
<!-- <div class="btn-group">
<button @click="feePayment()" class="btn btn-primary">
try bavayar
</button>
</div> -->
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- <div>{{$store.state.cart}}</div> -->
<!-- <div>{{ myValue.lelong_id }}</div> -->
<!-- modal ubah bidaan -->
<div
class="modal fade"
id="editModal"
tabindex="-1"
aria-labelledby="editModalLabel"
aria-hidden="true"
data-bs-backdrop="static"
>
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editModalLabel">
{{ test.norujukan }}
</h5>
<button
type="button"
class="btn-close"
ref="ubahClose"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">
<div class="row m-2">
<div class="col">
<!-- <p>Marhun: {{ test.marhun }}</p> -->
<p>Jumlah Berat: {{ test.berat }}g</p>
<table class="table table-bordered">
<tbody>
<tr class="table-light">
<th scope="col">No</th>
<th scope="col">Jenis Marhun</th>
<th scope="col">Karat</th>
<th scope="col">Berat</th>
<th scope="col">Nota</th>
<th scope="col">Harga Asas</th>
</tr>
<tr v-for="(data, index) in test2" :key="index.id">
<td>{{ index + 1 }}</td>
<td>{{ data.marhun }}</td>
<td>{{ data.karat }}</td>
<td>{{ data.berat }}g</td>
<td>{{ data.nota }}</td>
<td>RM{{ data.hargaasas }}</td>
</tr>
</tbody>
</table>
<div class="row justify-content-center">
<div class="col-3">
<label class="col-form-label text-end"
>Jumlah Harga Asas</label
>
</div>
<div class="col-4">
<div class="input-group mb-3">
<span class="input-group-text">RM</span>
<div
style="background-color: #e9ecef; padding-bottom: 0px"
class="form-control text-start justify-content-start"
disabled
>
{{ test.hargaasas }}
</div>
</div>
</div>
</div>
<div class="row justify-content-center mb-3">
<div class="col-3">
<label class="col-form-label">Tambahan Harga Bida</label>
</div>
<div class="col-4">
<div class="input-group">
<span class="input-group-text">RM</span>
<input
v-model="tambahan"
type="text"
id="tambahanbida"
class="form-control"
@change="calcTotal()"
/>
</div>
</div>
<div class="col-7">
<div
style="font-size: 15px"
class="fst-italic text-danger"
v-if="v$.tambahan.$error"
>
<div class="text-end">
*Minimum tambahan harga bida adalah RM1.
</div>
<div class="text-end">
*Gandaan ringgit sahaja dibenarkan.
</div>
</div>
</div>
</div>
<div class="row justify-content-center">
<div class="col-3">
<label class="col-form-label">Jumlah Harga Bida</label>
</div>
<div class="col-4">
<div class="input-group mb-3">
<span class="input-group-text">RM</span>
<input
type="text"
class="form-control"
v-model="formEdit.hargabida"
disabled
/>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button
type="submit"
class="btn btn-danger me-2"
data-bs-dismiss="modal"
>
Batal
</button>
<button type="submit" class="btn btn-success" @click="updateItem()">
Ubah
</button>
</div>
</div>
</div>
</div>
<!-- modal padam bidaan -->
<div
class="modal fade"
id="deleteModal"
tabindex="-1"
aria-labelledby="deleteModalLabel"
aria-hidden="true"
data-bs-backdrop="static"
data-bs-keyboard="false"
>
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<button
type="button"
class="btn-close"
ref="padamClose"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">
<h1><i class="bi bi-exclamation-triangle text-warning"></i></h1>
<h5>ADAKAH ANDA PASTI?</h5>
<p>Padam item dalam troli.</p>
<table class="table table-bordered">
<tbody>
<tr class="bg-light">
<th>SAG</th>
<th>Harga Bida</th>
</tr>
<tr>
<td>{{ test.norujukan }}</td>
<td>RM{{ data.hargabida }}</td>
</tr>
</tbody>
</table>
<p class="text-danger text-sm mt-3">
<i>*Tindakan ini tidak dapat dikembalikan</i>
</p>
</div>
<div class="modal-footer">
<button
type="submit"
class="btn btn-secondary me-2"
data-bs-dismiss="modal"
>
Kembali
</button>
<button
type="submit"
class="btn btn-danger"
@click="deleteCart(data.id)"
>
Padam
</button>
</div>
</div>
</div>
</div>
<!-- modal daftar bidaan -->
<div
class="modal fade"
id="bidModal"
tabindex="-1"
aria-labelledby="payModalLabel"
aria-hidden="true"
data-bs-backdrop="static"
data-bs-keyboard="false"
>
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editModalLabel">Daftar Bidaan</h5>
<button
type="button"
class="btn-close"
ref="daftarBidaanClose"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">
<h1><i class="bi bi-exclamation-triangle text-warning"></i></h1>
<p>ADAKAH ANDA PASTI?</p>
<h4 class="text-danger">
<i>*Bidaan tidak dapat diubah selepas didaftarkan.</i>
</h4>
<table class="table table-bordered">
<tbody>
<tr class="bg-light">
<th>Jumlah Surat</th>
<th>Jumlah Bidaan</th>
</tr>
<tr>
<td>{{ total_sag }}</td>
<td>RM{{ total_bidaan }}</td>
</tr>
</tbody>
</table>
</div>
<div class="modal-footer">
<button
type="submit"
class="btn btn-secondary me-2"
data-bs-dismiss="modal"
>
Kembali
</button>
<button type="submit" class="btn btn-success" @click="bidderSelectBidItem()">Daftar Bidaan</button>
<p
class="fst-italic mt-3 fw-lighter"
style="text-align: right; font-size: small"
>
<!-- *Pelayar akan dialihkan ke halaman pembayaran jika butang 'Bayar'
ditekan. -->
</p>
</div>
</div>
</div>
</div>
<!-- modal bayar yuran -->
<div
class="modal fade"
id="payModal"
tabindex="-1"
aria-labelledby="payModalLabel"
aria-hidden="true"
data-bs-backdrop="static"
data-bs-keyboard="false"
>
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="editModalLabel">Bayar Yuran</h5>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body">
<h1><i class="bi bi-exclamation-triangle text-warning"></i></h1>
<p>ADAKAH ANDA PASTI?</p>
<h4 class="text-danger">
<i
>Caj yuran, RM10 akan dikenakan untuk setiap kali pendaftaran
bidaan.</i
>
</h4>
<!-- <table class="table table-bordered">
<tbody>
<tr class="bg-light">
<th>Jumlah Surat</th>
<th>Jumlah Bidaan</th>
</tr>
<tr>
<td>{{ total_sag }}</td>
<td>RM{{ total_bidaan }}</td>
</tr>
</tbody>
</table> -->
</div>
<div class="modal-footer">
<button
type="submit"
class="btn btn-secondary me-2"
data-bs-dismiss="modal"
>
Kembali
</button>
<button type="submit" class="btn btn-success" @click="feePayment()">
Bayar
</button>
<p
class="fst-italic mt-3 fw-lighter"
style="text-align: right; font-size: small"
>
*Pelayar akan dialihkan ke halaman pembayaran jika butang 'Bayar'
ditekan.
</p>
</div>
</div>
</div>
</div>
</div>
<Footer />
</template>
<script>
import Navbar from "./Navbar.vue";
import Footer from "./Footer.vue";
import axios from "axios";
import useVuelidate from "@vuelidate/core";
import { required, integer, numeric, minValue } from "@vuelidate/validators";
import { mapGetters, mapState } from "vuex";
export default {
name: "Cart",
components: {
Navbar,
Footer,
},
data() {
return {
v$: useVuelidate(),
loading: false,
senaraiCarts: [],
tambahan: "",
test: "",
test2: [],
abc: "",
data: "",
feeStatus: "2",
formEdit: {
id: "",
hargabida: "",
},
formPayment: {
email: "amirhamzan30@gmail.com",
notel: "0198900990",
name: "amir",
user_id: "8",
lelong_id: "4",
},
formCheck: {
user_id: localStorage.getItem("id"),
lelong_id: "4",
},
formRegisterBid: {
lelong_id: "4",
user_id: localStorage.getItem("id"),
name: "pembida",
},
};
},
validations() {
return {
tambahan: { required, numeric, integer, minValue: minValue(1) },
};
},
computed: {
total_sag() {
return this.senaraiCarts.length;
},
total_bidaan() {
let total = 0;
this.senaraiCarts.forEach((val) => {
total += parseFloat(val.hargabida);
});
return total.toFixed(2);
},
// ...mapGetters(["idLelong"])
...mapState(["idLelong"]),
myValue() {
return this.$store.state.lelong_id;
},
count () {
return store.state.lelong_id;
}
},
mounted: function () {
this.listCart();
this.checkFeePayment();
},
methods: {
trybayar() {
axios
.post("/feepayment", this.formPayment)
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
},
listCart() {
this.loading = true;
axios
.get("/cart/" + localStorage.getItem("id"))
.then((response) => {
this.senaraiCarts = response.data;
this.loading = false;
})
.catch((error) => {
console.log(error);
});
},
calcTotal() {
this.formEdit.hargabida =
parseFloat(this.tambahan) + parseFloat(this.test.hargaasas);
},
editModal(data) {
this.data = data;
this.test = this.data.datalelongbid;
this.test2 = this.data.datalelongbid.lelongbidmarhun;
this.formEdit.id = this.data.id;
this.tambahan = this.data.hargabida - this.test.hargaasas;
this.formEdit.hargabida = this.data.hargabida;
console.log(this.data.hargabida);
},
updateItem() {
this.v$.$validate();
if (!this.v$.$error) {
axios
.post("/updateItem", this.formEdit, {
headers: {
Authorization: "Bearer " + localStorage.getItem("token"),
},
})
.then((response) => {
console.log(response);
this.$refs.ubahClose.click();
location.reload();
})
.catch((error) => {
console.log(error);
});
} else {
}
},
deleteModal(data) {
this.data = data;
this.test = this.data.datalelongbid;
console.log(data.datalelongbid.norujukan);
},
deleteCart(id) {
axios
.get("/deleteItem/" + id, {
headers: {
Authorization: "Bearer " + localStorage.getItem("token"),
},
})
.then((response) => {
console.log(response);
this.$refs.padamClose.click();
location.reload();
})
.catch((error) => {
console.log(error);
});
},
feePayment() {
axios
.post("/feepayment", this.formPayment)
.then((response) => {
window.open(response.data.message + "?auto_submit=true");
// window.location.href = response.data.message + '?auto_submit=true';
})
.catch((error) => {
// console.log("test");
console.log(error);
// console.log(this.formPayment);
});
},
checkFeePayment() {
// let test = this.store.state.idLelong;
// console.log(test);
axios
.get("/bidder/hisfeepay", {
headers: {
Authorization: "Bearer " + localStorage.getItem("token"),
},
params: {
user_id: localStorage.getItem("id"),
lelong_id: "4",
},
})
// .post("/addToCart", this.form, {
// headers: {
// Authorization: "Bearer " + localStorage.getItem("token"),
// },
// }
.then((response) => {
this.feeStatus = response.data.status;
// console.log(this.idLelong);
// console.log(response.data.status);
// this.$refs.padamClose.click();
// location.reload();
})
.catch((error) => {
console.log(error);
});
},
bidderSelectBidItem() {
axios
.post("/bidder/biditem", this.formRegisterBid, {
headers: {
Authorization: "Bearer " + localStorage.getItem("token"),
},
})
.then((response) => {
console.log(response);
this.$refs.daftarBidaanClose.click();
location.reload();
})
.catch((error) => {
console.log(error);
});
},
},
};
</script>
<style >
body {
margin-top: 20px;
background: #eee;
}
h3 {
font-size: 16px;
}
.text-navy {
color: #1ab394;
}
.cart-product-imitation {
text-align: center;
padding-top: 30px;
height: 80px;
width: 80px;
background-color: #f8f8f9;
}
.product-imitation.xl {
padding: 120px 0;
}
.product-desc {
padding: 20px;
position: relative;
}
.ecommerce .tag-list {
padding: 0;
}
.ecommerce .fa-star {
color: #d1dade;
}
.ecommerce .fa-star.active {
color: #f8ac59;
}
.ecommerce .note-editor {
border: 1px solid #e7eaec;
}
table.shoping-cart-table {
margin-bottom: 0;
}
table.shoping-cart-table tr td {
border: none;
text-align: right;
}
table.shoping-cart-table tr td.desc,
table.shoping-cart-table tr td:first-child {
text-align: left;
}
table.shoping-cart-table tr td:last-child {
width: 80px;
}
.ibox {
clear: both;
margin-bottom: 25px;
margin-top: 0;
padding: 0;
}
.ibox.collapsed .ibox-content {
display: none;
}
.ibox:after,
.ibox:before {
display: table;
}
.ibox-title {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #ffffff;
border-color: #e7eaec;
border-image: none;
border-style: solid solid none;
border-width: 3px 0 0;
color: inherit;
margin-bottom: 0;
padding: 14px 15px 7px;
min-height: 48px;
}
.ibox-content {
background-color: #ffffff;
color: inherit;
padding: 15px 20px 20px 20px;
border-color: #e7eaec;
border-image: none;
border-style: solid solid none;
border-width: 1px 0;
}
.ibox-footer {
color: inherit;
border-top: 1px solid #e7eaec;
font-size: 90%;
background: #ffffff;
padding: 10px 15px;
}
</style>