123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- window.onload = function (ev) {
- init();
- }
- init = function () {
- getAttributeInfo();
- }
- getAttributeInfo = function () {
- var parameter = urlEncode(["SelectAllProductAttribute"]);
- $.ajax({
- type: "post",
- url: "/taiwan/php/index.php",
- data: {mode: parameter},
- dataType: "json",
- success: function (data) {
- if (data[0].length == 0 || data == -1) {
- var th = '<th colspan="9" scope="col" class="text-c f-20" style="padding: 50px 0;">暂无数据</th>';
- $("#warp").html(th);
- return;
- }
- printAttributeInfo(data);
- console.log(data);
- }
- });
- }
- printAttributeInfo = function (data) {
- var warp = $("#warp"),
- tr,
- href,
- title = "'查看商品信息'";
- warp.html("");
- for (var i = 0; i < data.length; i++) {
- href = "'product-add.html?pid=" + data[i].ProductId + "'";
- tr = $('<tr class="text-c">' +
- '<td>' + data[i].ProductInfoClassId + '</td>' +
- '<td>' + data[i].ProductInfoClassName + '</td>' +
- '<td>' + data[i].InfoClassIdAddTime + '</td>' +
- '<td>' +
- '<a class="btn btn-primary radius td-button" onclick=deleteAttribute("' + data[i].ProductInfoClassId + '")>删除</>' +
- '<a class="btn btn-primary radius td-button" onclick=showUpdateAttribute("' + data[i].ProductInfoClassName + '","' + data[i].ProductInfoClassId + '")>修改</>' +
- '</td></tr>'
- )
- ;
- warp.append(tr);
- }
- $("#loading").css({"display": "none"});
- $("#warp").css({"display": "table-row-group"});
- }
- showAddWarp = function () {
- $("#modal-demo").modal("show");
- }
- setAttribute = function (jugde, text, aid) {
- var _el = $("#addAttribute");
- if (jugde) {
- $(_el).bind("click", function () {
- addAttribute();
- });
- }
- else {
- $(_el).bind("click", function () {
- updateAttribute(text, aid);
- });
- }
- }
- addAttribute = function () {
- var name = $("#AttributeName").val();
- if (name == "" || name.trim() == "") {
- $.Huimodalalert('请输入属性名!', 2000);
- }
- else {
- var parameter = urlEncode(["InsertAttribute", name]);
- $.ajax({
- type: "post",
- url: "/taiwan/php/index.php",
- data: {mode: parameter},
- dataType: "json",
- success: function (data) {
- $("#AttributeName")[0].value = "";
- getAttributeInfo();
- }
- });
- $("#warp").css({"display": "none"});
- $("#modal-demo").modal("hide");
- $("#loading").css({"display": "block"});
- }
- }
- deleteAttribute = function (aid) {
- layer.confirm('是否删除属性?', {
- btn: ['确定', '取消'] //按钮
- }, function (e, a) {
- var parameter = urlEncode(["DeleteAttribute", aid]);
- $.ajax({
- type: "post",
- url: "/taiwan/php/index.php",
- data: {mode: parameter},
- dataType: "json",
- success: function (data) {
- if (data[0].mode == 1) {
- getAttributeInfo();
- $.Huimodalalert('删除成功', 2000);
- console.log(data);
- }
- }
- });
- $(a).prev().remove();
- $(a).remove();
- $("#warp").css({"display": "none"});
- $("#loading").css({"display": "block"});
- });
- }
- showUpdateAttribute = function (text, aid) {
- showAddWarp();
- $("#AttributeName").val(text);
- setAttribute(false, text, aid);
- }
- updateAttribute = function (text, aid) {
- var name = $("#AttributeName").val();
- if (name == "" || name.trim() == "") {
- $.Huimodalalert('请输入属性名!', 2000);
- }
- else {
- var parameter = urlEncode(["UpdateAttributeName", aid, name]);
- $.ajax({
- type: "post",
- url: "/taiwan/php/index.php",
- data: {mode: parameter},
- dataType: "json",
- success: function (data) {
- $("#AttributeName")[0].value = "";
- getAttributeInfo();
- }
- });
- $("#warp").css({"display": "none"});
- $("#modal-demo").modal("hide");
- $("#loading").css({"display": "block"});
- }
- }
- urlEncode = function (arr) {
- var i; //循环初始化
- for (i = 0; i < arr.length; i++) {
- arr[i] = encodeURIComponent(encodeURIComponent(arr[i]));
- }
- return arr.join();
- }
|