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.
554 lines
24 KiB
554 lines
24 KiB
'use strict';
|
|
var oTWCity = [];
|
|
var oTruck = [];
|
|
var fnPageInit = function () {
|
|
var sLang = g_ul.GetLang(),
|
|
oGrid = null,
|
|
canDo = new CanDo({
|
|
/**
|
|
* 當前程式所有ID名稱集合
|
|
*/
|
|
idKeys: ['OrgID', 'QSID','LangID'],
|
|
/**
|
|
* 當前程式所有參數名稱集合
|
|
*/
|
|
paramKeys: ['QSID', 'LangID'],
|
|
/**
|
|
* 查詢當前資料
|
|
* @param {Object} pargs CanDo 對象
|
|
* @param {Object} data 當前資料實體
|
|
*/
|
|
getOneBack: function (pargs, data) {
|
|
var oRes = data;
|
|
oRes.CostRules = $.parseJSON(oRes.CostRules || '[]');
|
|
oRes.TruckCostRules = $.parseJSON(oRes.TruckCostRules || '[]');
|
|
oRes.TruckHolidayPay = $.parseJSON(oRes.TruckHolidayPay || '[]');
|
|
oRes.TruckMarkupByModel = $.parseJSON(oRes.TruckMarkupByModel || '[]');
|
|
disableInput(pargs._form, '#QuotationType,#LangID', false);
|
|
},
|
|
/**
|
|
* 處理新增資料參數
|
|
* @param {Object} pargs CanDo 對象
|
|
* @param {Object} data 當前表單資料
|
|
*/
|
|
getInsertParams: function (pargs, data) {
|
|
|
|
data.CostRules = '[]';
|
|
data.TruckCostRules = '[]';
|
|
data.TruckHolidayPay = '[]';
|
|
data.TruckMarkupByModel = '[]';
|
|
|
|
if (data.QuotationType == '01') {
|
|
//堆高機費用表
|
|
if (typeof pargs.data.CostRules === 'string') {
|
|
pargs.data.CostRules = JSON.parse(pargs.data.CostRules || '[]');
|
|
}
|
|
data.CostRules = JSON.stringify(pargs.data.CostRules);
|
|
|
|
}
|
|
else if(data.QuotationType == '02') {
|
|
//卡車費用表
|
|
var saTruckCostRules = [];
|
|
var trlist = $("#table_FreeTb").find("tr");
|
|
for (var i = 0; i < trlist.length; i++) {
|
|
var tr = $(trlist[i]);
|
|
var tdlist = $(tr).find("td");
|
|
for (var j = 1; j < tdlist.length; j++) {
|
|
var td = $(tdlist[j]);
|
|
var sCityID = $(td).find('input').attr("data-cityid");
|
|
var sTruckID = $(td).find('input').attr("data-truckid");
|
|
var iPrice = $(td).find('input[data-input=Price]').val();
|
|
|
|
var oNewKey = {};
|
|
//oNewKey.Guid = guid();
|
|
oNewKey.TruckID = sTruckID;
|
|
oNewKey.CityID = sCityID;
|
|
oNewKey.Price = iPrice;
|
|
saTruckCostRules.push(oNewKey);
|
|
}
|
|
|
|
}
|
|
|
|
data.TruckCostRules = JSON.stringify(saTruckCostRules);
|
|
//假日加班費
|
|
var saTruckHolidayPay = [];
|
|
trlist = $("#table_HolidayOvertimePay").find("tr");
|
|
tr = $(trlist[0]);
|
|
tdlist = $(tr).find("td");
|
|
for (var j = 1; j < tdlist.length; j++) {
|
|
var td = $(tdlist[j]);
|
|
var sTruckID = $(td).find('input').attr("data-truckid");
|
|
var iPrice = $(td).find('input[data-input=Price]').val();
|
|
|
|
var oNewKey = {};
|
|
//oNewKey.Guid = guid();
|
|
oNewKey.TruckID = sTruckID;
|
|
oNewKey.Type = '1';//1:假日加班費 2:車型加價
|
|
oNewKey.Price = iPrice;
|
|
saTruckHolidayPay.push(oNewKey);
|
|
}
|
|
|
|
data.TruckHolidayPay = JSON.stringify(saTruckHolidayPay);
|
|
//車型加價
|
|
var saTruckMarkupByModel = [];
|
|
trlist = $("#table_MarkupByModel").find("tr");
|
|
tr = $(trlist[0]);
|
|
tdlist = $(tr).find("td");
|
|
for (var j = 1; j < tdlist.length; j++) {
|
|
var td = $(tdlist[j]);
|
|
var sTruckID = $(td).find('input').attr("data-truckid");
|
|
var iPrice = $(td).find('input[data-input=Price]').val();
|
|
|
|
var oNewKey = {};
|
|
//oNewKey.Guid = guid();
|
|
oNewKey.TruckID = sTruckID;
|
|
oNewKey.Type = '2';//1:假日加班費 2:車型加價
|
|
oNewKey.Price = iPrice;
|
|
saTruckMarkupByModel.push(oNewKey);
|
|
}
|
|
|
|
data.TruckMarkupByModel = JSON.stringify(saTruckMarkupByModel);
|
|
|
|
|
|
}
|
|
|
|
return data;
|
|
},
|
|
/**
|
|
* 處理修改資料參數
|
|
* @param {Object} pargs CanDo 對象
|
|
* @param {Object} data 當前表單資料
|
|
*/
|
|
getUpdateParams: function (pargs, data) {
|
|
return pargs.options.getInsertParams(pargs, data);
|
|
},
|
|
/**
|
|
* 驗證規則
|
|
*/
|
|
validRules: {
|
|
//若是換頁新增會出錯,必須驗證隱藏的tab
|
|
ignore: [],
|
|
onfocusout: false,
|
|
rules: {
|
|
Email: {
|
|
email: true
|
|
},
|
|
TaxNumber: {
|
|
taxnumberlen: true,
|
|
taxnumberrule: true
|
|
|
|
}
|
|
},
|
|
messages: {
|
|
Email: i18next.t("message.IncorrectEmail"),// ╠message.IncorrectEmail⇒郵箱格式不正確╣
|
|
TaxNumber: {
|
|
taxnumberlen: i18next.t("message.UniCodeLength"),// ╠message.UniCodeLength⇒客戶統一編號必須是8碼╣
|
|
taxnumberrule: i18next.t("message.Data_Repeat")// ╠message.Data_Repeat⇒此筆資料已建檔╣
|
|
}
|
|
}
|
|
},
|
|
/**
|
|
* 須初始化的UEEditer 的物件ID集合
|
|
*/
|
|
ueEditorIds: ['ExpensesMemo'],//, 'ServicesMemo'
|
|
/**
|
|
* 頁面初始化
|
|
* @param {Object} pargs CanDo 對象
|
|
*/
|
|
pageInit: function (pargs) {
|
|
var postArray = [];
|
|
if (pargs.action === 'upd') {
|
|
postArray.push(pargs._getOne());
|
|
}
|
|
else {
|
|
pargs.data.CostRules = [];
|
|
pargs.data.TruckCostRules = [];
|
|
pargs.data.TruckHolidayPay = [];
|
|
pargs.data.TruckMarkupByModel = [];
|
|
}
|
|
postArray.push(fnSetArgDrop([
|
|
{
|
|
ArgClassID: 'LanCountry',
|
|
Select: $('#LangID'),
|
|
ShowId: true,
|
|
DefultVal: sLang,
|
|
CallBack: function (data) {
|
|
|
|
}
|
|
}
|
|
]));
|
|
postArray.push(fnSetArgDrop([
|
|
{
|
|
ArgClassID: 'ServiceItem',
|
|
Level: 1,
|
|
Select: $('#QuotationType'),
|
|
ShowId: true
|
|
}
|
|
]));
|
|
postArray.push(fnSetArgDrop([
|
|
{
|
|
ArgClassID: 'Currency',
|
|
Select: $('#CurrencyID'),
|
|
ShowId: true
|
|
}
|
|
]));
|
|
postArray.push(fnGetTruckInfoList());
|
|
postArray.push(fnGetTWCityList());
|
|
//加載語系類別,報價表類型
|
|
$.whenArray(postArray).done(function (res) {
|
|
$('#EscortFreeCityID').append(createOptions(oTWCity, 'id', 'text', false));
|
|
|
|
if (pargs.action === 'upd' && res[0].RESULT) {
|
|
var oRes = res[0].DATA.rel;
|
|
pargs._setFormVal(oRes);
|
|
pargs._setUEValues(oRes);
|
|
if ($('#QuotationType').val() == '01') {
|
|
$('.Stacker').show();
|
|
$('.Truck').hide();
|
|
fnBindCostRules();
|
|
}
|
|
else if ($('#QuotationType').val() == '02') {
|
|
$('.Truck').show();
|
|
$('.Stacker').hide();
|
|
|
|
fnBindFreeTb();
|
|
fnBindHolidayOvertimePay();
|
|
fnBindMarkupByModel();
|
|
}
|
|
pargs._getPageVal();//緩存頁面值,用於清除
|
|
$('#LangID').prop('disabled', true);
|
|
$('#QuotationType').prop('disabled', true);
|
|
}
|
|
else {
|
|
$('#QuotationType').on('change', function () {
|
|
if ($('#QuotationType').val() == '01') {
|
|
$('.Stacker').show();
|
|
$('.Truck').hide();
|
|
$('.jsGridCostRules').html('');
|
|
pargs.CostRules = [];
|
|
fnBindCostRules();
|
|
}
|
|
else if ($('#QuotationType').val() == '02') {
|
|
$('.Truck').show();
|
|
$('.Stacker').hide();
|
|
$('.jsGridCostRules').html('');
|
|
$('#EscortFreeCityID').val();
|
|
fnBindFreeTb();
|
|
fnBindHolidayOvertimePay();
|
|
fnBindMarkupByModel();
|
|
}
|
|
else if ($('#QuotationType').val() == '') {
|
|
$('.Truck').hide();
|
|
$('.Stacker').hide();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
/**
|
|
* Grid客戶化計價模式控件
|
|
* @param {Sring}flag 要綁定的資料標記
|
|
* @return {HTMLElement} DIV 物件
|
|
*/
|
|
fnCreatePriceModeInput = function (flag) {
|
|
var $div = $('<div>'),
|
|
data = [{ id: 'N', text: i18next.t('common.ByNumber') }, { id: 'T', text: i18next.t('common.ByWeight') }];//╠common.ByNumber⇒按件數計價╣ ╠common.ByWeight⇒按重量計價╣
|
|
$div.html(createRadios(data, 'id', 'text', '~PricingMode' + flag, flag, false, false));
|
|
return $div;
|
|
},
|
|
/**
|
|
* 取得卡車信息
|
|
*/
|
|
fnGetTruckInfoList = function () {
|
|
return g_api.ConnectLite(canDo.QueryPrgId, "QueryTruckInfoList", { }, function (res) {
|
|
if (res.RESULT) {
|
|
oTruck = res.DATA.rel;
|
|
|
|
}
|
|
});
|
|
},
|
|
/**
|
|
* 取得台灣城市信息
|
|
*/
|
|
fnGetTWCityList = function () {
|
|
return g_api.ConnectLite(Service.com, ComFn.GetArguments,
|
|
{
|
|
ArgClassID: 'TW',
|
|
ParentID: '',
|
|
ArgIDs: '',
|
|
LevelOfArgument: -1,
|
|
OrgID: ''
|
|
}, function (res) {
|
|
if (res.RESULT) {
|
|
oTWCity = res.DATA.rel;
|
|
}
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 綁定堆高機費用表
|
|
*/
|
|
fnBindCostRules = function () {
|
|
$("#jsGridCostRules").jsGrid({
|
|
width: "100%",
|
|
height: "auto",
|
|
autoload: true,
|
|
filtering: false,
|
|
inserting: true,
|
|
editing: true,
|
|
pageLoading: true,
|
|
confirmDeleting: true,
|
|
invalidMessage: i18next.t('common.InvalidData'),// ╠common.InvalidData⇒输入的数据无效!╣
|
|
deleteConfirm: i18next.t('message.ConfirmToDelete'),// ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣
|
|
pageIndex: 1,
|
|
pageSize: 10000,
|
|
fields: [
|
|
{
|
|
name: "Index", title: '#', width: 50, align: 'center'
|
|
},
|
|
{// ╠common.Weight_Min⇒重量(小)╣
|
|
name: "Weight_Min", title: 'common.Weight_Min', width: 120, align: 'center', type: "text", validate: { validator: 'required', message: i18next.t('common.Weight_Min_required') }//╠common.Weight_Min_required⇒請輸入重量(小)╣
|
|
},
|
|
{// ╠common.Weight_Max⇒重量(大)╣
|
|
name: "Weight_Max", title: 'common.Weight_Max', width: 120, align: 'center', type: "text", validate: { validator: 'required', message: i18next.t('common.Weight_Max_required') }//╠common.Weight_Max_required⇒請輸入重量(大)╣
|
|
},
|
|
{// ╠common.Price⇒價格╣
|
|
name: "Price", title: 'common.Price', width: 120, align: 'right', type: "text", validate: { validator: 'required', message: i18next.t('common.Price_required') },//╠common.Price_required⇒請輸入價格╣
|
|
itemTemplate: function (val, item) {
|
|
return fMoney(val, 2, item.Currency);
|
|
},
|
|
insertTemplate: function (val, item) {
|
|
var oControl = $('<input type="text" class="form-control w100p" data-type="money" data-name="int" />');
|
|
moneyInput(oControl, 2);
|
|
return this.insertControl = oControl;
|
|
},
|
|
insertValue: function () {
|
|
return this.insertControl.attr('data-value');
|
|
},
|
|
editTemplate: function (val, item) {
|
|
var oControl = $('<input type="text" class="form-control w100p" data-type="money" data-name="int" />').val(val);
|
|
moneyInput(oControl, 2);
|
|
return this.editControl = oControl;
|
|
},
|
|
editValue: function () {
|
|
return this.editControl.attr('data-value');
|
|
}
|
|
},
|
|
{// ╠common.PricingMode⇒計價模式╣
|
|
name: "PricingMode", title: 'common.PricingMode', align: 'center', width: 180, type: "text",
|
|
itemTemplate: function (val, item) {
|
|
var oControl = fnCreatePriceModeInput(item.Index);
|
|
oControl.find(':input[value="' + val + '"]').click();
|
|
uniformInit(oControl);
|
|
return oControl;
|
|
},
|
|
insertTemplate: function (val, item) {
|
|
var oControl = fnCreatePriceModeInput('add');
|
|
setTimeout(function () {
|
|
oControl.find('label:first').click();
|
|
uniformInit(oControl);
|
|
}, 100);
|
|
return this.insertControl = oControl;
|
|
},
|
|
insertValue: function () {
|
|
return this.insertControl.find(':input:checked').val();
|
|
},
|
|
editTemplate: function (val, item) {
|
|
var oControl = fnCreatePriceModeInput('edit');
|
|
oControl.find(':input[value="' + val + '"]').click();
|
|
uniformInit(oControl);
|
|
return this.editControl = oControl;
|
|
},
|
|
editValue: function () {
|
|
return this.editControl.find(':input:checked').val();
|
|
}
|
|
},
|
|
{
|
|
name: "Memo", title: 'common.Memo', width: 200, type: "textarea"
|
|
},
|
|
{
|
|
type: "control", width: 50
|
|
}
|
|
],
|
|
controller: {
|
|
loadData: function (args) {
|
|
return {
|
|
data: canDo.data.CostRules,
|
|
itemsCount: canDo.data.CostRules.length //data.length
|
|
};
|
|
},
|
|
insertItem: function (args) {
|
|
args.Guid = guid();
|
|
args.Index = canDo.data.CostRules.length + 1;
|
|
canDo.data.CostRules.push(args);
|
|
},
|
|
updateItem: function (args) {
|
|
},
|
|
deleteItem: function (args) {
|
|
canDo.data.CostRules = Jsonremove(canDo.data.CostRules, 'Guid', args.Guid);
|
|
$.each(canDo.data.CostRules, function (idx, _data) {
|
|
_data.Index = idx + 1;
|
|
});
|
|
}
|
|
},
|
|
onInit: function (args) {
|
|
oGrid = args.Guid;
|
|
}
|
|
});
|
|
},
|
|
|
|
/**
|
|
* 綁定卡車費用表參數
|
|
*/
|
|
fnBindFreeTb = function () {
|
|
|
|
var sHeaderHtml = '';
|
|
//表頭
|
|
sHeaderHtml = '<tr><th>車型</th>';
|
|
$.each(oTruck, function (idx, item) {
|
|
sHeaderHtml += '<th>' + item.TruckName + '</th>';
|
|
});
|
|
sHeaderHtml += '</tr>';
|
|
|
|
sHeaderHtml += '<tr><th>最大載重</th>';
|
|
$.each(oTruck, function (idx, item) {
|
|
sHeaderHtml += '<th>' + item.MaxWeight + '</th>';
|
|
});
|
|
sHeaderHtml += '</tr>';
|
|
|
|
sHeaderHtml += '<tr><th>車廂尺寸</th>';
|
|
$.each(oTruck, function (idx, item) {
|
|
sHeaderHtml += '<th>' + item.Size + '</th>';
|
|
});
|
|
sHeaderHtml += '</tr>';
|
|
|
|
sHeaderHtml += '<tr><th>貨物限高</th>';
|
|
$.each(oTruck, function (idx, item) {
|
|
sHeaderHtml += '<th>' + item.GoodsHeight + '</th>';
|
|
});
|
|
sHeaderHtml += '</tr>';
|
|
$('#thFreeTbHeader').html(sHeaderHtml);
|
|
var sKeysHtml = '';
|
|
$.each(oTWCity, function (idx, item) {
|
|
sKeysHtml += '<tr data-id="' + item.id + '">\
|
|
<td class="wcenter">' + item.text + '</td>';
|
|
$.each(oTruck, function (idx1, item1) {
|
|
sKeysHtml += '<td><input type="text" data-cityid="' + item.id + '" data-truckid="' + item1.TruckID + '" data-input="Price" class="form-control w100p" ></td>';
|
|
});
|
|
sKeysHtml += '</tr>';
|
|
|
|
});
|
|
|
|
$('#table_FreeTb').html(sKeysHtml);
|
|
var saTruckCostRules = canDo.data.TruckCostRules;
|
|
if (saTruckCostRules.length > 0) {
|
|
|
|
var trlist = $("#table_FreeTb").find("tr");
|
|
for (var i = 0; i < trlist.length; i++) {
|
|
var tr = $(trlist[i]);
|
|
var tdlist = $(tr).find("td");
|
|
for (var j = 0; j < tdlist.length; j++) {
|
|
var td = $(tdlist[j]);
|
|
var sCityID = $(td).find('input').attr("data-cityid");
|
|
var sTruckID = $(td).find('input').attr("data-truckid");
|
|
var iPrice = $(td).find('input[data-input=Price]').val();
|
|
var saTemp = saTruckCostRules.filter((item) => item.TruckID == sTruckID && item.CityID == sCityID);
|
|
if (saTemp.length > 0) {
|
|
$(td).find('input[data-input=Price]').val(saTemp[0].Price);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
},
|
|
|
|
/**
|
|
* 綁定卡車費用假日加班費用
|
|
*/
|
|
fnBindHolidayOvertimePay = function () {
|
|
var sHeaderHtml = '';
|
|
//表頭
|
|
sHeaderHtml = '<tr><th>車型</th>';
|
|
$.each(oTruck, function (idx, item) {
|
|
sHeaderHtml += '<th>' + item.TruckName+'</th>';
|
|
});
|
|
sHeaderHtml += '</tr>';
|
|
$('#thHolidayOvertimePay').html(sHeaderHtml);
|
|
//内容
|
|
sHeaderHtml = '<tr><td></td>';
|
|
$.each(oTruck, function (idx, item) {
|
|
sHeaderHtml += '<td><input type="text" data-truckid="' + item.TruckID + '" data-input="Price" class="form-control w100p" ></td>';
|
|
});
|
|
sHeaderHtml += '</tr>';
|
|
$('#table_HolidayOvertimePay').html(sHeaderHtml);
|
|
|
|
var saTruckHolidayPay = canDo.data.TruckHolidayPay;
|
|
if (saTruckHolidayPay.length > 0) {
|
|
|
|
var trlist = $("#table_HolidayOvertimePay").find("tr");
|
|
var tr = $(trlist[0]);
|
|
var tdlist = $(tr).find("td");
|
|
for (var j = 1; j < tdlist.length; j++) {
|
|
var td = $(tdlist[j]);
|
|
var sTruckID = $(td).find('input').attr("data-truckid");
|
|
|
|
var saTemp = saTruckHolidayPay.filter((item) => item.TruckID == sTruckID);
|
|
if (saTemp.length > 0) {
|
|
$(td).find('input[data-input=Price]').val(saTemp[0].Price);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
* 綁定卡車費用車型加價
|
|
*/
|
|
fnBindMarkupByModel = function () {
|
|
var sHeaderHtml = '';
|
|
//表頭
|
|
sHeaderHtml = '<tr><th>車型</th>';
|
|
$.each(oTruck, function (idx, item) {
|
|
sHeaderHtml += '<th>' + item.TruckName + '</th>';
|
|
});
|
|
sHeaderHtml += '</tr>';
|
|
$('#thMarkupByModel').html(sHeaderHtml);
|
|
//内容
|
|
sHeaderHtml = '<tr><td class="wcenter">尾門</td>';
|
|
$.each(oTruck, function (idx, item) {
|
|
|
|
sHeaderHtml += '<td><input type="text" data-truckid="' + item.TruckID + '" data-input="Price" class="form-control w100p" ></td>';
|
|
|
|
});
|
|
sHeaderHtml += '</tr>';
|
|
$('#table_MarkupByModel').html(sHeaderHtml);
|
|
var saTruckMarkupByModel = canDo.data.TruckMarkupByModel;
|
|
if (saTruckMarkupByModel.length > 0) {
|
|
|
|
var trlist = $("#table_MarkupByModel").find("tr");
|
|
var tr = $(trlist[0]);
|
|
var tdlist = $(tr).find("td");
|
|
for (var j = 1; j < tdlist.length; j++) {
|
|
var td = $(tdlist[j]);
|
|
var sTruckID = $(td).find('input').attr("data-truckid");
|
|
|
|
var saTemp = saTruckMarkupByModel.filter((item) => item.TruckID == sTruckID);
|
|
if (saTemp.length > 0) {
|
|
$(td).find('input[data-input=Price]').val(saTemp[0].Price);
|
|
}
|
|
}
|
|
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
require(['base', 'select2', 'jsgrid', 'formatnumber', 'util', 'cando'], fnPageInit);
|