/Diamond_Dev/Client/Web/Scripts/private.js
JavaScript | 2268 lines | 1959 code | 234 blank | 75 comment | 151 complexity | 89b465e37b0df4daf01fd5eb784b9af3 MD5 | raw file
Possible License(s): LGPL-2.0
Large files files are truncated, but you can click here to view the full file
- /// <reference path="jquery-1.11.3.js" />
- /// <reference path="jquery-ui-1.11.4.js" />
- /// <reference path="bootstrap.js" />
- /// <reference path="odatajs-4.0.0.js" />
- /// <reference path="common.js" />
-
- /* global odatajs, $home */
-
- // *** private helper ***
-
- $home.private = (function () {
- var result = {};
-
- result.productImportHelper = function () {
- this.params = arguments[0];
- this.prefix = "#" + this.params.prefix;
- };
- result.productImportHelper.prototype.init = function () {
- var self = this;
- $(this.prefix + "-import-append-update").prop("checked", true);
- $(this.prefix + "-import-running," + this.prefix + "-import-success," + this.prefix + "-import-failure").css("visibility", "hidden");
- $(this.prefix + "-import-upload").click(function () {
- $(self.prefix + "-import-form").submit();
- });
- };
- result.productImportHelper.prototype.submit = function () {
- $(this.prefix + "-import-running").css("visibility", "visible");
- $(this.prefix + "-import-success," + this.prefix + "-import-failure").css("visibility", "hidden");
- };
-
- result.productImportHistoryHelper = function () {
- this.params = arguments[0];
- this.prefix = "#" + this.params.prefix;
- this.url = this.params.url;
- }
- result.productImportHistoryHelper.prototype.init = function () {
- var page = $(this.prefix + "-import-history"),
- fromDatePicker = $(this.prefix + "-import-history-from"),
- toDatePicker = $(this.prefix + "-import-history-to"),
- personControl = $(this.prefix + "-import-history-person"),
- searchResult = $(this.prefix + "-import-history-result"),
- clearButton = $(this.prefix + "-import-history-clear"),
- searchUrl = null,
- pagination = new $home.pagination({
- callback: search,
- search: $(this.prefix + "-import-history-search"),
- previous: $(this.prefix + "-import-history-prev"),
- next: $(this.prefix + "-import-history-next")
- }),
- self = this;
-
- fromDatePicker.datepicker({ maxDate: "+0d" });
- toDatePicker.datepicker({ maxDate: "+0d" });
- clearButton.click(clear);
-
- function search(rebuild, skip) {
- if (rebuild) {
- var query = "Count ne null",
- from = fromDatePicker.datepicker("getDate"),
- to = toDatePicker.datepicker("getDate"),
- person = personControl.val();
-
- if (from) {
- from = $home.utility.odata.toODataDateTimeOffset(from);
- from = odatajs.oData.utils.formatDateTimeOffset(from);
- query += (" and Created ge " + from);
- }
-
- if (to) {
- to.setDate(to.getDate() + 1);
- to = $home.utility.odata.toODataDateTimeOffset(to);
- to = odatajs.oData.utils.formatDateTimeOffset(to);
- query += (" and Created lt " + to);
- }
-
- if (person.length > 0) {
- person = "'" + person + "'";
- query += (" and CreatedBy eq " + person);
- }
-
- searchUrl = self.url + "?" +
- "$filter=" +
- encodeURIComponent(query) +
- "&$orderby=" +
- encodeURIComponent("Created desc");
- }
-
- $home.ui.wait(true);
- var url = searchUrl + "&$skip=" + skip + "&$top=" + pagination.option("max");
- odatajs.oData.read(url, function (data) {
- $("tbody", searchResult).empty();
-
- $.each(data.value, function (index, item) {
- $("<tr/>")
- .append($("<td/>").text($home.utility.date.toLocalDateTimeString(new Date(item.Created))))
- .append($("<td/>").text(item.CreatedBy))
- .append($("<td/>").text($home.business.getDisplayText($home.business.ImportTypes, item.Type)))
- .append($("<td class='text-right'/>").text(item.Count))
- .appendTo($("tbody", searchResult))
- .data(item);
- });
-
- pagination.searched(data.value.length);
-
- $home.ui.wait(false);
- }, function () {
- $home.ui.wait(false);
- alert("查询失败。");
- });
- }
-
- function clear() {
- $("form input,form select", page).val("");
- }
- };
-
- result.productUploadHelper = function () {
- this.params = arguments[0];
- this.prefix = "#" + this.params.prefix;
- this.type = this.params.type;
- };
- result.productUploadHelper.prototype.init = function () {
- var appendOrUpdateRadio = $(this.prefix + "-upload-append-update"),
- replaceRadio = $(this.prefix + "-upload-replace"),
- uploadTypeRadios = appendOrUpdateRadio.add(replaceRadio),
- uploadButton = $(this.prefix + "-upload-upload"),
- self = this;
- appendOrUpdateRadio.prop("checked", true);
-
- uploadButton.click(function () {
- $home.ui.wait(true);
- odatajs.oData.request({
- requestUri: "/productservice/Upload()",
- method: "POST",
- data: {
- productType: self.type,
- uploadType: uploadTypeRadios.filter(":checked").val()
- }
- }, function () {
- $home.ui.wait(false);
- alert("上传成功。");
- }, function () {
- $home.ui.wait(false);
- alert("上传失败。");
- });
- });
- };
-
- result.productUploadHistoryHelper = function () {
- this.params = arguments[0];
- this.prefix = "#" + this.params.prefix;
- this.type = this.params.type;
- };
- result.productUploadHistoryHelper.prototype.init = function () {
- var page = $(this.prefix + "-upload-history"),
- fromDatePicker = $(this.prefix + "-upload-history-from"),
- toDatePicker = $(this.prefix + "-upload-history-to"),
- personControl = $(this.prefix + "-upload-history-person"),
- searchResult = $(this.prefix + "-upload-history-result"),
- clearButton = $(this.prefix + "-upload-history-clear"),
- searchUrl = null,
- pagination = new $home.pagination({
- callback: search,
- search: $(this.prefix + "-upload-history-search"),
- previous: $(this.prefix + "-upload-history-prev"),
- next: $(this.prefix + "-upload-history-next")
- }),
- self = this;
-
- fromDatePicker.datepicker({ maxDate: "+0d" });
- toDatePicker.datepicker({ maxDate: "+0d" });
- clearButton.click(clear);
-
- function search(rebuild, skip) {
- if (rebuild) {
- var query = "Count ne null",
- from = fromDatePicker.datepicker("getDate"),
- to = toDatePicker.datepicker("getDate"),
- person = personControl.val();
-
- if (from) {
- from = $home.utility.odata.toODataDateTimeOffset(from);
- from = odatajs.oData.utils.formatDateTimeOffset(from);
- query += (" and Created ge " + from);
- }
-
- if (to) {
- to.setDate(to.getDate() + 1);
- to = $home.utility.odata.toODataDateTimeOffset(to);
- to = odatajs.oData.utils.formatDateTimeOffset(to);
- query += (" and Created lt " + to);
- }
-
- if (person.length > 0) {
- person = "'" + person + "'";
- query += (" and CreatedBy eq " + person);
- }
-
- query += (" and ProductType eq Home.Services.ProductService.ProductType'" + self.type + "' ");
-
- searchUrl = "/productservice/Uploads?" +
- "$filter=" +
- encodeURIComponent(query) +
- "&$orderby=" +
- encodeURIComponent("Created desc");
- }
-
- $home.ui.wait(true);
- var url = searchUrl + "&$skip=" + skip + "&$top=" + pagination.option("max");
- odatajs.oData.read(url, function (data) {
- $("tbody", searchResult).empty();
-
- $.each(data.value, function (index, item) {
- $("<tr/>")
- .append($("<td/>").text($home.utility.date.toLocalDateTimeString(new Date(item.Created))))
- .append($("<td/>").text(item.CreatedBy))
- .append($("<td/>").text($home.business.getDisplayText($home.business.ProductTypes, item.ProductType)))
- .append($("<td/>").text($home.business.getDisplayText($home.business.ProductUploadTypes, item.UploadType)))
- .append($("<td class='text-right'/>").text(item.Count))
- .append($("<td/>").text($home.business.getDisplayText($home.business.ProductUploadStatuses, item.Status)))
- .appendTo($("tbody", searchResult))
- .data(item);
- });
-
- pagination.searched(data.value.length);
-
- $home.ui.wait(false);
- }, function () {
- $home.ui.wait(false);
- alert("查询失败。");
- });
- }
-
- function clear() {
- $("form input,form select", page).val("");
- }
- };
-
- return result;
- })();
-
- // *** pages ***
-
- $home.pages = (function () {
- return {
- "dashboard-page": {
- title: $($("#home-navbar > ul > li > a").get(0)).text(),
- init: function () {
- $("#dashboard-page-print").click(function () {
- $home.navigation.modal("print-sale");
- });
- }
- },
-
- // "customer-management": {
- // title: $($("#home-navbar > ul > li > a").get(2)).text(),
- // init: function () {
- // }
- // },
-
- // "control-panel": {
- // title: $($("#home-navbar > ul > li > a").get(4)).text(),
- // init: function () {
- // }
- // },
-
- // "help-page": {
- // title: $($("#home-navbar > ul > li > a").get(5)).text(),
- // init: function () {
- // }
- // },
-
- "product-management": {
- title: $($("#home-navbar > ul > li > a").get(2)).text(),
- init: function () {
- $("#product-management-diamond-on-sale").click(function () {
- $home.navigation.navigate("diamond-on-sale");
- });
-
- $("#product-management-diamond-import").click(function () {
- $home.navigation.modal("diamond-import");
- });
-
- $("#product-management-diamond-import-history").click(function () {
- $home.navigation.navigate("diamond-import-history");
- });
-
- $("#product-management-diamond-upload").click(function () {
- $home.navigation.modal("diamond-upload");
- });
-
- $("#product-management-diamond-upload-history").click(function () {
- $home.navigation.navigate("diamond-upload-history");
- });
- }
- },
-
- "diamond-on-sale": {
- title: "裸钻数据",
- init: function () {
- var page = $("#diamond-on-sale"),
- shapeControl = $("#diamond-on-sale-shape"),
- reportNumberControl = $("#diamond-on-sale-report-number"),
- reportTypeControl = $("#diamond-on-sale-report-type"),
- priceFromControl = $("#diamond-on-sale-price-from"),
- priceToControl = $("#diamond-on-sale-price-to"),
- weightFromControl = $("#diamond-on-sale-weight-from"),
- weightToControl = $("#diamond-on-sale-weight-to"),
- colorControl = $("#diamond-on-sale-color"),
- clarityControl = $("#diamond-on-sale-clarity"),
- cutControl = $("#diamond-on-sale-cut"),
- polishControl = $("#diamond-on-sale-polish"),
- symmetryControl = $("#diamond-on-sale-symmetry"),
- typeControl = $("#diamond-on-sale-type"),
- coloredColorControl = $("#diamond-on-sale-colored-color"),
- clearButton = $("#diamond-on-sale-clear"),
- searchResult = $("#diamond-on-sale-result"),
- searchUrl = null,
- pagination = new $home.pagination({
- callback: search,
- search: $("#diamond-on-sale-search"),
- previous: $("#diamond-on-sale-prev"),
- next: $("#diamond-on-sale-next")
- });
-
- clearButton.click(clear);
-
- function search(rebuild, skip) {
- if (rebuild) {
- var query = "Index ne null",
- type = typeControl.val().trim(),
- shape = shapeControl.val().trim(),
- reportNumber = reportNumberControl.val().trim(),
- reportType = reportTypeControl.val().trim(),
- priceFrom = parseFloat(priceFromControl.val().trim()),
- priceTo = parseFloat(priceToControl.val().trim()),
- weightFrom = parseFloat(weightFromControl.val().trim()),
- weightTo = parseFloat(weightToControl.val().trim()),
- color = colorControl.val().trim(),
- coloredColor = coloredColorControl.val().trim(),
- clarity = clarityControl.val().trim(),
- cut = cutControl.val().trim(),
- polish = polishControl.val().trim(),
- symmetry = symmetryControl.val().trim();
-
- if (type.length !== 0) {
- query += (" and Type eq Home.Services.ProductService.DiamondType'" + type + "'");
- }
- if (shape.length !== 0) {
- query += (" and Shape eq Home.Services.ProductService.DiamondShape'" + shape + "'");
- }
- if (reportNumber.length !== 0) {
- query += (" and contains(ReportNumber,'" + reportNumber + "')");
- }
- if (reportType.length !== 0) {
- query += (" and ReportType eq Home.Services.ProductService.DiamondReport'" + reportType + "'");
- }
- if (!isNaN(priceFrom)) {
- query += (" and SalePrice ge " + priceFrom);
- }
- if (!isNaN(priceTo)) {
- query += (" and SalePrice le " + priceTo);
- }
- if (!isNaN(weightFrom)) {
- query += (" and Caret ge " + weightFrom);
- }
- if (!isNaN(weightTo)) {
- query += (" and Caret le " + weightTo);
- }
- if (color.length !== 0) {
- query += (" and Color eq Home.Services.ProductService.DiamondColor'" + color + "'");
- }
- if (coloredColor.length !== 0) {
- query += (" and contains(ColoredColor,'" + coloredColor + "')");
- }
- if (clarity.length !== 0) {
- query += (" and Clarity eq Home.Services.ProductService.DiamondClarity'" + clarity + "'");
- }
- if (cut.length !== 0) {
- query += (" and Cut eq Home.Services.ProductService.DiamondCut'" + cut + "'");
- }
- if (polish.length !== 0) {
- query += (" and Polish eq Home.Services.ProductService.DiamondPolish'" + polish + "'");
- }
- if (symmetry.length !== 0) {
- query += (" and Symmetry eq Home.Services.ProductService.DiamondSymmetry'" + symmetry + "'");
- }
-
- searchUrl = "/productservice/Diamonds?" +
- "$filter=" +
- encodeURIComponent(query) +
- "&$orderby=" +
- encodeURIComponent("Index");
- }
-
- $home.ui.wait(true);
- var url = searchUrl + "&$skip=" + skip + "&$top=" + pagination.option("max");
- odatajs.oData.read(url, function (data) {
- $("tbody", searchResult).empty();
-
- $.each(data.value, function (index, product) {
- $("<tr/>")
- .append($("<td class='text-left'/>").text(formatText(product.Index)))
- .append($("<td/>").text($home.business.getDisplayText($home.business.DiamondTypes, product.Type)))
- .append($("<td/>").text(formatText(product.Shape)))
- .append($("<td/>").text(formatText(product.ReportNumber)))
- .append($("<td/>").text(formatText(product.ReportType)))
- .append($("<td class='text-right'/>").text(formatText(product.Caret)))
- .append($("<td/>").text((product.Color === null || product.Color === undefined || product.Color.length === 0) ? formatText(product.ColoredColor) : formatText(product.Color)))
- .append($("<td/>").text(formatText(product.Clarity)))
- .append($("<td/>").text(formatText(product.Cut)))
- .append($("<td/>").text(formatText(product.Polish)))
- .append($("<td/>").text(formatText(product.Symmetry)))
- .append($("<td/>").text(formatText(product.Fluorescence)))
- .append($("<td class='text-right'/>").text(formatText(product.Cost)))
- .append($("<td class='text-right'/>").text(formatText(product.SalePrice)))
- .append($("<td/>").text($home.business.getDisplayText($home.business.ProductStatuses, product.Status)))
- .append($("<td/>").text(formatText(product.Comment)))
- .appendTo($("tbody", searchResult))
- .data(product);
- });
-
- pagination.searched(data.value.length);
-
- $home.ui.wait(false);
- }, function () {
- $home.ui.wait(false);
- alert("查询失败。");
- });
- }
-
- function clear() {
- $("form input, form select", page).val("");
- }
-
- function formatText(value) {
- if (value === undefined || value === null) {
- return "";
- }
- return value.toString();
- }
- }
- },
-
- "diamond-import": {
- title: "导入裸钻数据",
- init: function () {
- new $home.private.productImportHelper({ prefix: "diamond" }).init();
- }
- },
-
- "diamond-import-history": {
- title: "导入裸钻数据的历史",
- init: function () {
- new $home.private.productImportHistoryHelper({ prefix: "diamond", url: "/productservice/DiamondImports" }).init();
- }
- },
-
- "diamond-upload": {
- title: "上传裸钻数据到网站",
- init: function () {
- new $home.private.productUploadHelper({ prefix: "diamond", type: "Diamond" }).init();
- }
- },
-
- "diamond-upload-history": {
- title: "上传裸钻数据到网站的历史",
- init: function () {
- new $home.private.productUploadHistoryHelper({ prefix: "diamond", type: "Diamond" }).init();
- }
- },
-
- "print-sale": {
- title: "销售开单",
- init: function () {
- var baseBehavior = function () { };
- baseBehavior.prototype.init = $.noop;
- baseBehavior.prototype.add = $.noop;
- baseBehavior.prototype.edit = $.noop;
- baseBehavior.prototype.clear = $.noop;
- baseBehavior.prototype.format = function () {
- return "";
- };
- baseBehavior.prototype.validate = function () {
- return true;
- };
-
- var diamondBehavior = function () {
- baseBehavior.call(this);
- this.goodCertificate = $("#print-sale-good-certificate");
- this.goodCaret = $("#print-sale-good-caret");
- this.goodCut = $("#print-sale-good-cut");
- this.goodClarity = $("#print-sale-good-clarity");
- this.goodColor = $("#print-sale-good-color");
- };
- $home.utility.oo.extend(baseBehavior, diamondBehavior);
- diamondBehavior.prototype.init = $.noop;
- diamondBehavior.prototype.add = function (entity) {
- if (this.goodCertificate.val().length > 0) {
- entity.Certificate = this.goodCertificate.val();
- }
- if (this.goodCaret.val().length > 0) {
- entity.Caret = parseFloat(this.goodCaret.val());
- }
- if (this.goodCut.val().length > 0) {
- entity.Cut = this.goodCut.val();
- }
- if (this.goodClarity.val().length > 0) {
- entity.Clarity = this.goodClarity.val();
- }
- if (this.goodColor.val().length > 0) {
- entity.Color = this.goodColor.val();
- }
- };
- diamondBehavior.prototype.edit = function (entity) {
- this.goodCertificate.val(entity.Certificate);
- this.goodCaret.val(entity.Caret);
- this.goodCut.val(entity.Cut);
- this.goodClarity.val(entity.Clarity);
- this.goodColor.val(entity.Color);
- };
- diamondBehavior.prototype.clear = function () {
- this.goodCertificate.val("");
- this.goodCaret.val("");
- this.goodCut.val("");
- this.goodClarity.val("");
- this.goodColor.val("");
- };
- diamondBehavior.prototype.format = function () {
- var result = "";
- if (this.goodCertificate.val().length > 0) {
- result += "证书:" + this.goodCertificate.val() + " ";
- }
- if (this.goodCaret.val().length > 0) {
- result += "钻重:" + this.goodCaret.val() + " ";
- }
- if (this.goodCut.val().length > 0) {
- result += "切工:" + this.goodCut.val() + " ";
- }
- if (this.goodClarity.val().length > 0) {
- result += "净度:" + this.goodClarity.val() + " ";
- }
- if (this.goodColor.val().length > 0) {
- result += "颜色:" + this.goodColor.val() + " ";
- }
- return result;
- };
- diamondBehavior.prototype.validate = function () {
- return $home.validation.validateRequired(this.goodCaret) && $home.validation.validateFloat(this.goodCaret);
- };
-
- // members
- var sale = {},
- behavior = new baseBehavior(),
-
- dialog = $("#print-sale"),
-
- userInfo = $("#print-sale-user-info"),
- customerInfo = $("#print-sale-customer-info"),
- goodInfo = $("#print-sale-good-info"),
- goodSpecificInfo = $("#print-sale-good-info-specific"),
-
- customerWayButton = $("#print-sale-customer-way-button"),
- goodNameButton = $("#print-sale-good-name-button"),
- addGoodButton = $("#print-sale-add-good"),
- saveButton = $("#print-sale-save"),
- printServiceButton = $("#print-sale-print-service"),
- printReceiptButton = $("#print-sale-print-receipt"),
-
- userName = $("#print-sale-user"),
- receiptNumber = $("#print-sale-receipt-number"),
-
- customerName = $("#print-sale-customer-name"),
- customerPhone = $("#print-sale-customer-phone"),
- customerContact = $("#print-sale-customer-contact"),
- customerWay = $("#print-sale-customer-way"),
-
- goodName = $("#print-sale-good-name"),
- goodDescription = $("#print-sale-good-description"),
- goodQuantity = $("#print-sale-good-quantity"),
- goodPrice = $("#print-sale-good-price");
-
- // dialog
- dialog.on("shown.bs.modal", function () {
- // user
- userName.val($home.authentication.getUserInfo().id);
- // customer name
- customerName.focus();
- // customer way
- $home.ui.selectbutton(customerWayButton.parent());
- $("ul > li > a:first", customerWayButton.parent()).click();
- // good name
- $home.ui.editableselect(goodName.parent());
- goodNameButton.parent().on("hidden.bs.dropdown", replaceGoodInfo);
- goodName.keypress(function (e) {
- if (e.keyCode === 13) {
- replaceGoodInfo();
- }
- }).on("input", replaceGoodInfo);
- // table
- dialog.on("click", "table a[home-data-action='edit']", editFromTable);
- dialog.on("click", "table a[home-data-action='remove']", removeFromTable);
- // enable UI
- setEditable(true);
- // add good
- addGoodButton.click(addToTable);
- // save
- saveButton.click(save);
- });
-
- // disable enable
- function setEditable(enabled) {
- $("fieldset input, fieldset textarea", dialog).not(receiptNumber).prop("readonly", !enabled);
- $("fieldset button, fieldset select", dialog).prop("disabled", !enabled);
- if (enabled) {
- saveButton.prop("disabled", false);
- printServiceButton.prop("disabled", true).addClass("disabled", true);
- printReceiptButton.prop("disabled", true).addClass("disabled", true);
- $("table > tbody > tr > td > a", dialog).removeClass("disabled");
- } else {
- saveButton.prop("disabled", true);
- printServiceButton.prop("disabled", false).removeClass("disabled");
- printReceiptButton.prop("disabled", false).removeClass("disabled");
- $("table > tbody > tr > td > a", dialog).addClass("disabled", true);
- }
- }
-
- // calculate total price
- function calculateTotalPrice() {
- var totalPrice = 0;
- $.each($("table > tbody > tr", dialog), function (index, row) {
- var detail = $(row).data();
- totalPrice += (detail.Quantity * detail.UnitPrice);
- });
- $("table > tfoot > tr > th:last", dialog).prev().text(totalPrice.toString());
- }
-
- // edit good
- function editFromTable() {
- if (!$(this).hasClass("disabled")) {
- var row = $(this).parent().parent();
- var detail = row.data();
- goodName.val(detail.ProductName);
- goodDescription.val(detail.ProductDescription);
- goodQuantity.val(detail.Quantity);
- goodPrice.val(detail.UnitPrice);
- behavior.edit(detail);
- row.remove();
- calculateTotalPrice();
- goodNameButton.focus();
- }
- }
-
- // remove good
- function removeFromTable() {
- if (!$(this).hasClass("disabled")) {
- var row = $(this).parent().parent();
- row.remove();
- calculateTotalPrice();
- goodNameButton.focus();
- }
- }
-
- // add good
- function addToTable() {
- function formatDescription() {
- var result = behavior.format();
- if (goodDescription.val().length > 0) {
- result += goodDescription.val();
- }
- return result;
- }
-
- $home.validation.cleanup(goodInfo);
- if (!($home.validation.validateRequired(goodName) &&
- $home.validation.validateRequired(goodQuantity) &&
- $home.validation.validateInteger(goodQuantity) &&
- $home.validation.validateRequired(goodPrice) &&
- $home.validation.validateInteger(goodPrice) &&
- behavior.validate())) {
- alert("请检查商品信息,有未填写的内容,请填写完整。");
- return;
- }
-
- var detail = {
- ProductName: goodName.val(),
- ProductDescription: goodDescription.val(),
- Quantity: parseInt(goodQuantity.val()),
- UnitPrice: parseInt(goodPrice.val())
- };
- behavior.add(detail);
-
- $("<tr></tr>")
- .append($("<td></td>").text(goodName.val()))
- .append($("<td></td>").text(formatDescription()))
- .append($("<td class='text-center'></td>").text(detail.Quantity.toString()))
- .append($("<td class='text-right'></td>").text(detail.UnitPrice.toString()))
- .append("<td>" +
- "<a href='javascript:void(0)' title='修改' role='button' home-data-action='edit'><span class='glyphicon glyphicon-pencil' aria-hidden='true'></span></a>" +
- "<a href='javascript:void(0)' title='删除' role='button' home-data-action='remove'><span class='glyphicon glyphicon-remove' aria-hidden='true'></span></a>" +
- "</td>")
- .data(detail)
- .appendTo("table > tbody", dialog);
- calculateTotalPrice();
-
- goodName.val("");
- goodDescription.val("");
- goodQuantity.val("");
- goodPrice.val("");
- behavior.clear();
- $home.validation.cleanup(goodInfo);
- goodNameButton.focus();
- }
-
- // save
- function save() {
- $home.validation.cleanup(userInfo);
- if (!($home.validation.validateRequired(userName))) {
- alert("请检查用户信息,有未填写的内容,请填写完整。");
- return;
- }
-
- $home.validation.cleanup(customerInfo);
- if (!($home.validation.validateRequired(customerName) &&
- $home.validation.validateRequired(customerPhone) &&
- $home.validation.validateRequired(customerContact))) {
- alert("请检查客户信息,有未填写的内容,请填写完整。");
- return;
- }
-
- sale.Items = [];
- $.each($("table > tbody > tr", dialog), function (index, row) {
- sale.Items.push($(row).data());
- });
- if (sale.Items.length === 0) {
- alert("没有添加任何商品,请添加商品之后继续。");
- return;
- }
-
- setEditable(false);
-
- sale.SalesPersonName = $("#print-sale-user-info option:selected").text();
- sale.CustomerName = customerName.val();
- sale.CustomerContacts = [
- { Method: "Phone", Value: customerPhone.val() },
- { Method: customerWay.val(), Value: customerContact.val() }
- ];
-
- $home.ui.wait(true);
- odatajs.oData.request({
- requestUri: "/salesservice/Sales",
- method: "POST",
- data: sale
- }, function (data) {
- receiptNumber.val(data.NumberText);
- printServiceButton.attr("href", "/pages/print-service?id=" + data.Id);
- printReceiptButton.attr("href", "/pages/print-receipt?id=" + data.Id);
- setEditable(false);
- $home.ui.wait(false);
- alert("保存成功,可以开始打印。");
- }, function () {
- $home.ui.wait(false);
- alert("保存失败。");
- setEditable(true);
- });
- }
-
- // good name changed event
- function replaceGoodInfo() {
- goodSpecificInfo.empty();
- switch (goodName.val()) {
- case $home.business.ProductNames.Diamond:
- behavior = new diamondBehavior();
- replaceUI("print-sale-diamond");
- break;
- default:
- behavior = new baseBehavior();
- behavior.init();
- break;
- }
-
- function replaceUI(id) {
- $home.navigation.embed(id, goodSpecificInfo, function () {
- behavior.init();
- });
- }
- }
- }
- },
-
- "print-sale-diamond": {
- title: "裸钻",
- init: $.noop
- },
-
- "sale-management": {
- title: $($("#home-navbar > ul > li > a").get(1)).text(),
- init: function () {
- $("#sale-management-print").click(function () {
- $home.navigation.modal("print-sale");
- });
-
- $("#sale-management-history").click(function () {
- $home.navigation.navigate("sale-history");
- });
-
- $("#sale-management-report").click(function () {
- $home.navigation.modal("sale-report");
- });
- }
- },
-
- "sale-history": {
- title: "销售历史数据查询",
- init: function () {
- var page = $("#sale-history"),
- fromDatePicker = $("#sale-history-from"),
- toDatePicker = $("#sale-history-to"),
- salePersonControl = $("#sale-history-sale-person"),
- searchResult = $("#sale-history-result"),
- clearButton = $("#sale-history-clear"),
- searchUrl = null,
- pagination = new $home.pagination({
- callback: search,
- search: $("#sale-history-search"),
- previous: $("#sale-history-prev"),
- next: $("#sale-history-next")
- });
-
- fromDatePicker.datepicker({ maxDate: "+0d" });
- toDatePicker.datepicker({ maxDate: "+0d" });
- clearButton.click(clear);
-
- function calculateAmount(sale) {
- var result = 0;
- $.each(sale.Items, function (index, detail) {
- result += detail.UnitPrice * detail.Quantity;
- });
- return result;
- }
-
- function formatContact(sale) {
- var result = "";
- $.each(sale.CustomerContacts, function (index, contact) {
- var method = "";
- $.each($home.business.ContactMethods, function (index, item) {
- if (item.value === contact.Method) {
- method = item.text;
- }
- });
- if (result.length > 0) {
- result += ",";
- }
- result += method;
- result += ":";
- result += contact.Value;
- });
- result += "。";
- return result;
- }
-
- function search(rebuild, skip) {
- if (rebuild) {
- var query = "Status eq Home.Services.SaleService.SaleStatus'Ok'",
- from = fromDatePicker.datepicker("getDate"),
- to = toDatePicker.datepicker("getDate"),
- person = salePersonControl.val();
-
- if (from) {
- from = $home.utility.odata.toODataDateTimeOffset(from);
- from = odatajs.oData.utils.formatDateTimeOffset(from);
- query += (" and Created ge " + from);
- }
-
- if (to) {
- to.setDate(to.getDate() + 1);
- to = $home.utility.odata.toODataDateTimeOffset(to);
- to = odatajs.oData.utils.formatDateTimeOffset(to);
- query += (" and Created lt " + to);
- }
-
- if (person.length > 0) {
- person = "'" + person + "'";
- query += (" and SalesPersonName eq " + person);
- }
-
- searchUrl = "/salesservice/Sales?$expand=" +
- encodeURIComponent("CustomerContacts,Items(") +
- "$filter=" +
- encodeURIComponent("Status eq Home.Services.SaleService.SaleStatus'Ok')") +
- "&$filter=" +
- encodeURIComponent(query) +
- "&$orderby=" +
- encodeURIComponent("Created desc,SalesPersonName");
- }
-
- $home.ui.wait(true);
- var url = searchUrl + "&$skip=" + skip + "&$top=" + pagination.option("max");
- odatajs.oData.read(url, function (data) {
- $("tbody", searchResult).empty();
-
- $.each(data.value, function (index, sale) {
- $("<tr/>")
- .append($("<td/>").append($("<a href='javascript:void(0)' role='button'/>").text(sale.NumberText)))
- .append($("<td/>").text(sale.CustomerName))
- .append($("<td/>").text(formatContact(sale)))
- .append($("<td class='text-right'/>").text(calculateAmount(sale)))
- .append($("<td/>").text(sale.SalesPersonName))
- .append($("<td/>").text($home.utility.date.toLocalDateTimeString(new Date(sale.Created))))
- .append($("<td/>").text($home.utility.date.toLocalDateTimeString(new Date(sale.Modified))))
- .appendTo($("tbody", searchResult))
- .data(sale);
- });
-
- $("tbody > tr > td > a", searchResult).click(function () {
- var sale = $(this).parent().parent().data();
- showSale(sale);
- });
-
- pagination.searched(data.value.length);
-
- $home.ui.wait(false);
- }, function () {
- $home.ui.wait(false);
- alert("查询失败。");
- });
- }
-
- function showSale(sale) {
- $home.navigation.modal("sale-view", function () {
- pagination.research();
- }, sale);
- }
-
- function clear() {
- $("form input,form select", page).val("");
- }
- }
- },
-
- "sale-view": {
- title: "销售记录",
- init: function (sale) {
- var baseBehavior = function () { };
- baseBehavior.prototype.init = $.noop;
- baseBehavior.prototype.save = function () { return true; };
-
- var diamondBehavior = function () {
- baseBehavior.call(this);
- };
- $home.utility.oo.extend(baseBehavior, diamondBehavior);
- diamondBehavior.prototype.init = function (entity, row, index) {
- var certificateId = "sale-view-product-certificate-" + (index + 1),
- caretId = "sale-view-product-caret-" + (index + 1),
- cutId = "sale-view-product-cut-" + (index + 1),
- clarityId = "sale-view-product-clarity-" + (index + 1),
- colorId = "sale-view-product-color-" + (index + 1),
- certificateField = $("<input type='text' class='form-control input-sm'/>").attr("id", certificateId),
- caretField = $("<input type='number' class='form-control input-sm'/>").attr("id", caretId),
- cutField = $("<select class='form-control input-sm'/>").attr("id", cutId),
- clarityField = $("<select class='form-control input-sm'/>").attr("id", clarityId),
- colorField = $("<select class='form-control input-sm'/>").attr("id", colorId);
- //// diamond cut
- cutField.append("<option value=''/>");
- $.each($home.business.DiamondCuts, function (index, item) {
- cutField.append($("<option/>").val(item).text(item));
- });
- //// diamond clarity
- clarityField.append("<option value=''/>");
- $.each($home.business.DiamondClarities, function (index, item) {
- clarityField.append($("<option/>").val(item).text(item));
- });
- //// diamond color
- colorField.append("<option value=''/>");
- $.each($home.business.DiamondColors, function (index, item) {
- colorField.append($("<option/>").val(item).text(item));
- });
-
- certificateField.val(entity.Certificate);
- caretField.val(entity.Caret);
- cutField.val(entity.Cut);
- clarityField.val(entity.Clarity);
- colorField.val(entity.Color);
-
- addFieldForInit(row, LINE_FIELD_MIDDLE_TEMPLATE, certificateId, certificateField, "证书");
- addFieldForInit(row, LINE_FIELD_MIDDLE_TEMPLATE, caretId, caretField, "钻重");
- addFieldForInit(row, LINE_FIELD_MIDDLE_TEMPLATE, cutId, cutField, "切工");
- addFieldForInit(row, LINE_FIELD_MIDDLE_TEMPLATE, clarityId, clarityField, "净度");
- addFieldForInit(row, LINE_FIELD_MIDDLE_TEMPLATE, colorId, colorField, "颜色");
- };
- diamondBehavior.prototype.save = function (entity, row) {
- var caretField = $($("input[type=number]", row)[0]);
- if ($home.validation.validateRequired(caretField) && $home.validation.validateFloat(caretField)) {
- entity.Certificate = getString($("input[type=text]", row)[1]);
- entity.Caret = getFloat(caretField);
- entity.Cut = getString($("select", row)[0]);
- entity.Clarity = getString($("select", row)[1]);
- entity.Color = getString($("select", row)[2]);
- return true;
- }
- return false;
- }
-
- var CONTROL_TEMPLATE =
- "<div class='input-group'>" +
- " <div class='input-group-btn'>" +
- " <button type='button' class='btn btn-default btn-sm dropdown-toggle' data-toggle='dropdown' aria-expanded='false'><span class='caret'></span></button>" +
- " <ul class='dropdown-menu' role='menu'></ul>" +
- " <input type='hidden'/>" +
- " </div>" +
- " <input type='text' class='form-control input-sm' />" +
- "</div>",
- CONTACT_TEMPLATE =
- "<div class='col-md-3'>" +
- " <div class='form-group'>" +
- " </div>" +
- "</div>",
- LINE_ROW_TEMPLATE =
- "<div class='row'>" +
- "</div>",
- LINE_FIELD_MIDDLE_TEMPLATE =
- "<div class='col-md-2'>" +
- " <div class='form-group'>" +
- " </div>" +
- "</div>",
- LINE_FIELD_LARGE_TEMPLATE =
- "<div class='col-md-6'>" +
- " <div class='form-group'>" +
- " </div>" +
- "</div>",
- receiptNumberField = $("#sale-view-receipt-number"),
- createdField = $("#sale-view-created"),
- createdByField = $("#sale-view-created-by"),
- modifiedField = $("#sale-view-modified"),
- modifiedByField = $("#sale-view-modified-by"),
- salerInfo = $("#sale-view-saler-info"),
- salerField = $("#sale-view-saler"),
- customerInfo = $("#sale-view-customer-info"),
- customerField = $("#sale-view-name"),
- lineInfo = $("#sale-view-line-info"),
- totalPriceField = $("#sale-view-total-price"),
- …
Large files files are truncated, but you can click here to view the full file