magento2-docker/app/code/IpSupply/QuoteIn/view/frontend/templates/index.phtml

166 lines
7.0 KiB
PHTML
Executable File

<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('\Magento\Customer\Model\Session');
$urlInterface = $objectManager->get('\Magento\Framework\UrlInterface');
if(!$customerSession->isLoggedIn()) {
$customerSession->setAfterAuthUrl($urlInterface->getCurrentUrl());
$customerSession->authenticate();
}
?>
<div class="table-wrapper orders-history">
<table class="data table table-order-items history" id="my-quote-in-table">
<thead>
<tr>
<th scope="col" class="col id">Code #</th>
<th scope="col" class="col date">Expiry Date</th>
<th scope="col" class="col status">Status</th>
<th scope="col" class="col actions">Action</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<script>
window.baseUrl = "<?php echo $this->getBaseUrl(); ?>";
require(['jquery'], function($) {
$( document ).ready(function() {
window.list_want_to_by = {
data_name : "quote_in",
setData : function(data) {
var quote_raw_items = JSON.parse(data);
if (quote_raw_items.hasOwnProperty("data")) {
var store_quote_items = {
data : []
}
for (let i = 0; i < quote_raw_items.data.length; i++) {
var quote_raw_item = quote_raw_items.data[i];
var store__quote_item = {
_id : quote_raw_item._id,
expectedDate : quote_raw_item.expectedDate,
wtbNum : quote_raw_item.wtbNum,
status : quote_raw_item.status,
wtbQuoteDetail : []
}
for (let j = 0; j < quote_raw_item.wtbQuoteDetail.length; j++) {
var product = quote_raw_item.wtbQuoteDetail[j];
var store_product = {
productId : product.productId,
productName : product.productName,
productCode : product.productCode,
condition : product.condition,
total : product.total
}
store__quote_item.wtbQuoteDetail.push(store_product);
}
store_quote_items.data.push(store__quote_item);
}
localStorage.setItem(this.data_name, JSON.stringify(store_quote_items));
}
},
deleteData : function(data) {
localStorage.removeItem(this.data_name);
},
getData : function() {
if (this.data_name in localStorage) {
return JSON.parse(localStorage.getItem(this.data_name));
} else {
return null;
}
},
isData : function() {
var data = this.getData();
if ( data != null && data["data"] != undefined) {
return true;
}
return false;
},
showContentLoading : function() {
var html = '<tr>'+
'<td colspan="5" style="'+
'text-align: center;'+
'">Loading</td>'+
'</tr>'
;
$("#my-quote-in-table tbody").append(html);
},
showContentNoItem : function() {
var html = '<tr>'+
'<td colspan="5" style="'+
'text-align: center;'+
'"><div class="message info empty"><span>You have no items.</span></div></td>'+
'</tr>'
;
$("#my-quote-in-table tbody").append(html);
},
appendItem : function(item) {
var date = new Date(item.expectedDate).toISOString().slice(0, 10);
var html = '<tr>'+
'<td data-th="Order #" class="col id">'+item.wtbNum+'</td>'+
'<td data-th="Date" class="col date">'+date+'</td>'+
'<td data-th="Status" class="col status">'+item.status+'</td>'+
'<td data-th="Actions" class="col actions">'+
'<a href="'+window.baseUrl +'quote_in/request/create/want_to_buy_id/'+item._id+'" class="action view">'+
'<span>Quote</span>'+
'</a>'+
'</td>'+
'</tr>'
;
$("#my-quote-in-table tbody").append(html);
},
getQuoteIns : function() {
var root = this;
debugger;
$.ajax({
type: "GET",
url: window.baseUrl+"quote_in/listdatas",
beforeSend: function() {
root.showContentLoading();
},
error: function(xhr) {
$("#my-quote-in-table tbody").html("");
root.showContentNoItem();
},
success: function(data)
{
debugger;
if (data == null ) {
$("#my-quote-in-table tbody").html("");
this.showContentNoItem();
} else {
root.setData(data);
root.renderListQuoteIn();
}
console.log(JSON.parse(data));
}
});
},
renderListQuoteIn : function() {
$("#my-quote-in-table tbody").html("");
if (this.isData()) {
var quote_in = this.getData();
var items = quote_in.data;
if (items.length > 0 ) {
for (let i = 0; i < items.length; i++) {
this.appendItem(items[i]);
}
return;
}
}
this.showContentNoItem();
}
}
window.list_want_to_by.getQuoteIns();
});
});
</script>