goods.price.PriceChange.js 20.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
webpackJsonp([49],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';
	var $ = __webpack_require__(1),
	    common = __webpack_require__(2);

	/***********************变价列表***********************/

	new common.dropDown({
	    el: '#shop',
	    ajax: 'shopsRest'
	});
	new common.dropDown({
	    el: '#supplier',
	    ajax: 'querySupplier'
	});
	new common.dropDown({
	    el: '#brand',
	    ajax: 'brand',
	    params:function(){
	        return {userLimitFlag:true};
	    }
	});
	new common.dropDown({
	    el: '#cate',
	    ajax: 'maxSort'
	});
	new common.dropDown({
	    el: "#jit"
	});
	new common.dropDown({
	    el: "#status"
	});
	new common.dropDown({
	    el: "#stock"
	});
	new common.dropDown({
	    el: "#sex"
	});

	var ENUM = {
	    vipType: {
	        1: '正常折扣',
	        2: '统一折扣',
	        3: '无折扣',
	        4: '固定折扣',
	        5: '自定义折扣'
	    },
	    gender: {
	        1: '男',
	        2: '女',
	        3: '通用'
	    }
	};

	//多级菜单
	var tabTree = new common.tabTree("#sortTree", {status: 1, sortLevel: 1});
	tabTree.init();

	var g = new common.grid({
	    el: "#basicTable",
	    parms: function() {
	        var select = tabTree.getAddress();
	        return {
	            product_skn: common.util.__input("skn"),
	            shop_id: common.util.__input("shop"),
	            brand_id: common.util.__input("brand"),
	            supplier_id: common.util.__input("supplier"),
	            is_jit: common.util.__input("jit"),
	            is_auditing: common.util.__input("status"),
	            stock: common.util.__input("stock"),
	            gender: common.util.__input("sex"),
	            max_sort_id: select[0] ? select[0].id : "",
	            middle_sort_id: select[1] ? select[1].id : "",
	            small_sort_id: select[2] ? select[2].id : ""
	        }
	    },
	    columns: [
	        {display: 'SKN', name: 'product_skn'},
	        {display: '商品信息', render: function(item) {
	            var html = '<p>名称:' + item.product_name + '</p><p>品牌:' + item.brand_name + '</p>' +
	                '<div>类目:'+ item.middle_sort_name;
	            if(item.middle_sort_name) {html += '&nbsp;>&nbsp;' + item.middle_sort_name;}
	            if(item.small_sort_name) {html += '&nbsp;>&nbsp;' + item.small_sort_name;}
	            return html + "</div>";
	        }},
	        {display: '供应商/店铺', render: function(item) {
	            var html = '';
	            if (item.supplier_name) {
	                html += item.supplier_name;
	                if (item.shop_name) {html += '/';}
	            }
	            if (item.shop_name) {html += item.shop_name;}
	            return html;
	        }},
	        {display: '性别', render: function(item) {
	            return ENUM.gender[item.gender];
	        }},
	        {display: '吊牌价', name: 'retail_price'},
	        {display: '销售价', name: 'sales_price'},
	        {display: '学生价', name: 'student_price'},
	        {display: 'VIP折扣类型', render: function(item) {
	            return ENUM.vipType[item.vip_discount_type];
	        }},
	        {display: 'VIP价', name: 'vip_price'},
	        {display: '白金', name: 'vip3_price'},
	        {display: '金卡', name: 'vip2_price'},
	        {display: '银卡', name: 'vip1_price'},
	        {display: '生效时间', name: 'effectiveTime'},
	        {display: '操作信息', render: function(item) {
	            var html = '';
	            if (item.founder_name) {html += '<p>' + item.founder_name + '</p>';}
	            if (item.updateTime) {html += '<div style="color: #999;font-size: 12px">' + item.updateTime + '</div>';}
	            return html;
	        }},
	        {display: '操作', render: function(item) {
	            return '<a href="javascript:;" class="btn btn-info btn-xs modify-btn" data-skn="' + item.product_skn + '">修改</a><br>' +
	                '<a href="javascript:;" class="btn btn-primary btn-xs history-btn" data-skn="' + item.product_skn + '" style="margin-top: 10px">变价记录</a>'
	        }
	        }]
	});
	g.init('/goods/price/list');

	//获取变价记录列表并渲染
	function getHistoryList(skn) {
	    $.ajax({
	        type: 'POST',
	        dataType: 'json',
	        url: '/goods/queryProductPriceListBySkn',
	        data: {param: skn},
	        success: function (rs) {
	            var data = rs;
	            $('.historyDetail').html($(common.util.__template2($("#template2").html(), data.data)));
	            if(data.code != 200){
	                common.util.__tip(rs.message);
	            }
	        },
	        error: function (rs) {
	            $('.historyDetail').html($(common.util.__template2($("#template2").html(), {})));
	            common.util.__tip(rs.message);
	        }
	    });
	}

	//单个变价修改
	$(document).on('click', '.modify-btn', function() {
	    var skn = $(this).data('skn'),
	        parentTr = $(this).parent().parent(),
	        sknTd = parentTr.find('td').eq(0);

	    if($(this).hasClass('open')){
	        $(this).removeClass('open');
	        $(this).text('修改');
	        sknTd.removeAttr('rowspan','2');
	        parentTr.next('.product-detail').remove();
	        parentTr.next('.extraTr').remove();
	    }else{
	        $(this).addClass('open');
	        $(this).text('收起');
	        sknTd.attr('rowspan','2');
	        parentTr.after('<tr class="product-detail"><td colspan="15">加载中...若长时间加载不出来,请重新刷新页面!</td>' +
	            '</tr><tr class="extraTr"></tr>');

	        common.util.__ajax({
	            url:'/goods/getPrice',
	            data: {product_skn: skn}
	        },function(rs){
	            var data = rs.data;
	            parentTr.next('.product-detail').html($(common.util.__template($("#template").html(), data)));
	            new common.edit(".product-detail").init();

	            var $wrap = parentTr.next('.product-detail'),
	                $price = $wrap.find('.sale-price'),
	                $select = $wrap.find('.discount-select'),
	                $vipPrice = $wrap.find('.vip-price'),
	                $vip3Price = $wrap.find('.vip3-price'),
	                $vip2Price = $wrap.find('.vip2-price'),
	                $vip1Price = $wrap.find('.vip1-price'),
	                $student_price = $wrap.find('.student_price'),
	                $startDate = $wrap.find('.startDate'),
	                $endDate = $wrap.find('.endDate'),
	                $submitBtn = $wrap.find('.sure-modify');
	            $select.val(data.vip_discount_type);

	            vipPrice($wrap);
	            $select.on('change', function() {
	                vipPrice($wrap);
	            });
	            $vipPrice.on('blur', function() {
	                vipPrice($wrap);
	            });
	            $price.on('blur', function() {
	                vipPrice($wrap);
	            });
	            $submitBtn.on('click', function() {
	                if($price.val() != 0){
	                    common.util.__ajax({
	                        url: '/goods/updatePrice',
	                        data: {
	                            product_skn: skn,
	                            sales_price: $price.val(),
	                            vip_discount_type: $select.val(),
	                            vip_price: $vipPrice.val(),
	                            vip1_price: $vip1Price.val(),
	                            vip2_price: $vip2Price.val(),
	                            vip3_price: $vip3Price.val(),
	                            student_price: $student_price.val(),
	                            cgpriceStartTime:$startDate.val(),
	                            cgpriceEndTime:$endDate.val(),
	                            interfaceResource:'0'
	                        }
	                    }, function(res) {
	                        if (res.code == 200) {g.reload()}
	                    })
	                }else{
	                    common.util.__tip("销售价不能为0!");
	                }
	            });
	        },true);
	    }

	    function vipPrice($wrap) {
	        var $price = $wrap.find('.sale-price'),
	            $select = $wrap.find('.discount-select'),
	            $vipPrice = $wrap.find('.vip-price'),
	            $vip3Price = $wrap.find('.vip3-price'),
	            $vip2Price = $wrap.find('.vip2-price'),
	            $vip1Price = $wrap.find('.vip1-price');

	        var price = $price.val(),
	            vipPrice = $vipPrice.val(),
	            selectVal = $select.val() - 1,
	            priceArr = [];

	        priceArr.push([price * 0.95, price * 0.9, price * 0.88]);
	        priceArr.push([price * 0.95, price * 0.95, price * 0.95]);
	        priceArr.push([price, price, price]);
	        priceArr.push([vipPrice, vipPrice, vipPrice]);

	        if (selectVal == 4) {
	            $vip1Price.removeAttr('disabled');
	            $vip2Price.removeAttr('disabled');
	            $vip3Price.removeAttr('disabled');
	        } else {
	            $vip1Price.attr('disabled', true).val(Number(priceArr[selectVal][0]).toFixed(2));
	            $vip2Price.attr('disabled', true).val(Number(priceArr[selectVal][1]).toFixed(2));
	            $vip3Price.attr('disabled', true).val(Number(priceArr[selectVal][2]).toFixed(2));
	        }
	    }
	});
	//变价记录
	$(document).on('click', '.history-btn', function () {
	    var skn = $(this).data('skn');
	    var option = {
	        title:'变价记录详情',
	        content:"<div class='historyDetail'>加载变价记录...</div>",
	        width:'70%',
	        button:[{value:"关闭", css:"btn-primary"}]
	    };
	    new common.dialog(option);
	    getHistoryList(skn);
	});
	//删除变价记录
	$(document).on('click', '.deleteHistory', function () {
	    var skn = $(this).data('skn');
	    var planId = $(this).data('planid');
	    new common.dialog({
	        title: "删除变价记录确认",
	        width: "360px",
	        content: '确认删除该变价记录么?',
	        zIndex: 52,
	        button: [
	            {value: "确认", css:"btn-primary", callback: function () {
	                common.util.__ajax({
	                    url: '/goods/deletePricePlan',
	                    data: {param:planId}
	                }, function () {
	                    getHistoryList(skn);
	                });
	            }},
	            {value: "取消", css:"btn-default"}
	        ]
	    });
	});
	//筛选
	$(document).on('click', '#filter-btn', function () {
	    g.reload(1);
	});
	//回车筛选
	$(document).on('keyup', 'body', function (event) {
	    if (event.keyCode == 13) {
	        $("#filter-btn").trigger('click');
	    }
	});
	//全部
	$(document).on('click', '#all-btn', function () {
	    location.href = '';
	});
	//批量导入按钮点击事件
	$(document).on('click', '#import-btn', function () {
	    $('#basicTable').hide();
	    $('#priceChangeSearch').hide();
	    $('.bulk-import').show();
	});

	/***********************批量导入***********************/

	var loadModal = null;
	var importPriceChangeData;
	var path = ''; //确定变价后返回的excel名
	var p = new common.grid({
	    el: "#importResultTable",
	    columns: [
	        {display: 'SKN', render: function(item) {
	            return item.newProductPriceBo.product_skn;
	        }},
	        {display: '吊牌价', render: function(item) {
	            return '<p>'+item.newProductPriceBo.retail_price + '</p><div style="color: #999;">' + item.oldProductPriceBo.retail_price + '</div>';
	        }},
	        {display: '销售价', render: function(item) {
	            var newPrice = item.newProductPriceBo,
	                newPriceHtml = '<p>'+newPrice.sales_price+'</p>';
	            if (newPrice.sales_price < (newPrice.retail_price / 2)) {
	                newPriceHtml = '<p style="color: red">' + newPrice.sales_price + '</p>';
	            }
	            return newPriceHtml + '<div style="color: #999;">' + item.oldProductPriceBo.sales_price + '</div>';
	        }},
	        {display: '学生价', render: function(item) {
	            var newPrice = item.newProductPriceBo,
	                newPriceHtml = '';
	            if (newPrice.student_price) {
	                if (newPrice.student_price < (newPrice.retail_price / 2)) {
	                    newPriceHtml = '<p style="color: red">' + newPrice.student_price + '</p>';
	                }else{
	                    newPriceHtml = '<p>'+newPrice.student_price+'</p>';
	                }
	            } else {
	                newPriceHtml = '<p>-</p>'
	            }
	            if(item.oldProductPriceBo.student_price){
	                newPriceHtml += '<div style="color: #999;">' + item.oldProductPriceBo.student_price + '</div>';
	            }else{
	                newPriceHtml += '<div>-</div>';
	            }
	            return newPriceHtml;
	        }},
	        {display: 'VIP折扣类型', render: function(item) {
	            return '<p>'+ENUM.vipType[item.newProductPriceBo.vip_discount_type] + '</p>'+
	                '<div style="color: #999;">' + ENUM.vipType[item.oldProductPriceBo.vip_discount_type] + '</div>';
	        }},
	        {display: 'VIP价', render: function(item) {
	            var newPrice = item.newProductPriceBo,
	                newPriceHtml = '';
	            if (newPrice.vip_price) {
	                if (newPrice.vip_price < (newPrice.retail_price / 2)) {
	                    newPriceHtml = '<p style="color: red">' + newPrice.vip_price + '</p>';
	                }else{
	                    newPriceHtml = '<p>'+newPrice.vip_price+'</p>';
	                }
	            } else {
	                newPriceHtml = '<p>-</p>'
	            }
	            if(item.oldProductPriceBo.vip_price){
	                newPriceHtml += '<div style="color: #999;">' + item.oldProductPriceBo.vip_price + '</div>';
	            }else{
	                newPriceHtml += '<div>-</div>';
	            }
	            return newPriceHtml;
	        }},
	        {display: '白金价', render: function(item) {
	            var newPrice = item.newProductPriceBo,
	                newPriceHtml = '';
	            if (newPrice.vip3_price){
	                if (newPrice.vip3_price < (newPrice.retail_price / 2)) {
	                    newPriceHtml = '<p style="color: red">' + newPrice.vip3_price + '</p>';
	                }else{
	                    newPriceHtml = '<p>'+newPrice.vip3_price+'</p>';
	                }
	            }else{
	                newPriceHtml = '<p>-</p>'
	            }
	            if(item.oldProductPriceBo.vip3_price){
	                newPriceHtml += '<div style="color: #999;">' + item.oldProductPriceBo.vip3_price + '</div>';
	            }else{
	                newPriceHtml += '<div>-</div>';
	            }
	            return newPriceHtml;
	        }},
	        {display: '金卡价', render: function(item) {
	            var newPrice = item.newProductPriceBo,
	                newPriceHtml = '';
	            if (newPrice.vip2_price){
	                if (newPrice.vip2_price < (newPrice.retail_price / 2)) {
	                    newPriceHtml = '<p style="color: red">' + newPrice.vip2_price + '</p>';
	                }else {
	                    newPriceHtml = '<p>'+newPrice.vip2_price+'</p>';
	                }
	            }else{
	                newPriceHtml = '<p>-</p>'
	            }
	            if(item.oldProductPriceBo.vip2_price){
	                newPriceHtml += '<div style="color: #999;">' + item.oldProductPriceBo.vip2_price + '</div>';
	            }else{
	                newPriceHtml += '<div>-</div>';
	            }
	            return newPriceHtml;
	        }},
	        {display: '银卡价', render: function(item) {
	            var newPrice = item.newProductPriceBo,
	                newPriceHtml = '';
	            if (newPrice.vip1_price){
	                if (newPrice.vip1_price < (newPrice.retail_price / 2)) {
	                    newPriceHtml = '<p style="color: red">' + newPrice.vip1_price + '</p>';
	                }else{
	                    newPriceHtml = '<p>'+newPrice.vip1_price+'</p>';
	                }
	            }else{
	                newPriceHtml = '<p>-</p>'
	            }
	            if(item.oldProductPriceBo.vip1_price){
	                newPriceHtml += '<div style="color: #999;">' + item.oldProductPriceBo.vip1_price + '</div>';
	            }else{
	                newPriceHtml += '<div>-</div>';
	            }
	            return newPriceHtml;
	        }},
	        {display: '操作', render: function(item) {
	            return '<a class="btn btn-danger btn-xs deleteImport" data-idx="' + item.__index + '" href="javascript:;">删除</a>';
	        }}
	    ]
	});

	common.edit.ajaxfileupload("#priceChangeUpload", {
	    params: {
	        type: "price",
	        __type: "batch-import"
	    },
	    onStart: function() {
	        loadModal = common.dialog.load();
	        clearImportResult()
	    },
	    onComplete: function(response) {
	        console.log("批量接口返回数据",response);
	        if (loadModal) loadModal.close();

	        if(response.code == 200){
	            if(response.data.failFileReason && response.data.failFileReason.length > 0){
	                showImportMessage(response.data.failFileReason.join('<br/>'), "error");
	            }else {
	                showImportMessage("批量导入全部成功!", "success");
	            }
	            if(response.data.successList && response.data.successList.length > 0){
	                showImportTable(response.data);
	            }
	        }else{
	            showImportMessage(response.message, "error");
	            common.util.__tip(response.message);
	        }
	    }
	});

	//显示批量导入结果
	function showImportMessage(message, statue){
	    $("#priceChangeImportMessage").removeAttr("class").addClass(statue).show();
	    $("#detailMassage").html(message);
	}
	//显示批量导入数据表
	function showImportTable(data){
	    importPriceChangeData = data.successList;

	    p.init(importPriceChangeData);
	    $("#priceChangeImportResultSet").show();
	    $("#priceChangeImportResult").show();
	    new common.edit("#priceChangeImportResultSet").init();
	}
	//清除批量导入结果及列表
	function clearImportResult(){
	    $("#detailMassage").empty();
	    $("#importResultTable").empty();
	    $("#priceChangeImportResultSet input").val('');

	    $('#download-btn').hide();
	    $("#priceChangeImportMessage").hide();
	    $("#priceChangeImportResultSet").hide();
	    $("#priceChangeImportResult").hide();
	}

	//全部删除
	$(document).on('click', '#deleteAllImport', function () {
	    common.dialog.confirm(
	        '删除确认提示',
	        '你确定<b><font color="#ff0000">全部删除</font></b>已成功导入的变价么?',
	        function () {
	            importPriceChangeData.length = 0;
	            p.reload();
	        }
	    );
	});
	//单个删除
	$(document).on('click', '.deleteImport', function () {
	    var idx = $(this).data("idx")
	    common.dialog.confirm(
	        '删除确认提示',
	        '你确定<b><font color="#ff0000">删除</font></b>该变价么?',
	        function () {
	            var index = $(this).data("index");
	            if(importPriceChangeData){
	                [].splice.call(importPriceChangeData,idx,1);
	                p.reload();
	            }
	        }
	    );
	});
	//确定提交批量
	$(document).on('click', '.btn-submit-priceChange', function () {
	    if(importPriceChangeData.length < 1){
	        common.util.__tip("没有可提交的变价,请重新导入!");
	        return false;
	    }
	    common.dialog.confirm(
	        '提交确认提示',
	        '你确定<b><font color="#449d44">提交并保存</font></b>成功导入的变价么?',
	        function () {
	            var arr = [];
	            $.each(importPriceChangeData, function(i, value) {
	                arr.push(value.newProductPriceBo);
	            });
	            common.util.__ajax({
	                url: '/goods/batchUpdatePrice',
	                data: {
	                    batchList: JSON.stringify(arr),
	                    cgpriceStartTime:$('#importStartDate').val(),
	                    cgpriceEndTime:$('#importEndDate').val(),
	                    interfaceResource:'0'
	                }
	            }, function(res) {
	                path = res.data;
	                importPriceChangeData.length = 0;
	                clearImportResult();
	                if(path && path != ''){
	                    $('#download-btn').show();
	                }
	            });
	        }
	    );
	});
	//下载导入结果
	$(document).on('click', '#download-btn', function() {
	    location.href = '/ajax/download?path=' + path;
	});
	//返回列表
	$(document).on('click', '#return-btn', function () {
	    if(path == ''){
	        $("#priceChangeImportMessage").hide();
	        $('.bulk-import').hide();
	        $('#basicTable').show();
	        $('#priceChangeSearch').show();
	    }else{
	        location.href = '';
	    }
	});

/***/ }
]);