operations.payment.Index.js 6.95 KB
webpackJsonp([119],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	var $ = __webpack_require__(1),
	    common = __webpack_require__(2);

	var ENUM = {
	    recommendOrderPage: ["否","是"],
	    displayFirstSight: ["否","是"]
	};
	var sortNumberList = []; //前端展示排序数组,用于校验前端排序是否重复

	var g = new common.grid({
	    el: '#payment-list',
	    columns: [
	        {display: "ID", name: "id"},
	        {display: '支付方式名称', name: "payName"},
	        {display: '推荐到确认订单页', render: function (item) {
	            var rop = ENUM.recommendOrderPage[item.recommendOrderPage];
	            return item.recommendOrderPage == 1 ? rop+"("+item.recommendWords+")" : rop;
	        }},
	        {display: '前端显示', render: function (item) {
	            var rop = ENUM.displayFirstSight[item.displayFirstSight];
	            return item.displayFirstSight == 1 ? rop+"("+item.displayFirstSight+")" : rop;
	        }},
	        {display: "前端排序", name: "sortNumber"},
	        {display: "推荐语1", name: "recommendText1"},
	        {display: "推荐语2", name: "recommendText2"},
	        {display: '操作', render: function (item) {
	            var HtmArr = [];
	            HtmArr.push('<a href="javascript:" class="btn btn-info btn-xs edit-btn" data-index="'+item.__index+'">编辑</a>');
	            if(item.status == 1){
	                HtmArr.push('<a href="javascript:" class="btn btn-danger btn-xs close-btn" data-index="'+item.__index+'">关闭</a>');
	            }else{
	                HtmArr.push('<a href="javascript:" class="btn btn-success btn-xs open-btn" data-index="'+item.__index+'">开启</a>');
	            }
	            return HtmArr.join('');
	        }}
	    ],
	    complete: function () {
	        $.each(g.rows, function (index, item) {
	            sortNumberList.push(item.sortNumber+'');
	        });
	    }
	});

	g.init("/Payment/findPayManageList");

	//编辑
	$(document).on("click", ".edit-btn", function () {
	    var _index = $(this).data("index");
	    var data = g.rows[_index];
	    var recommendOrderPage_old = data.recommendOrderPage;
	    var displayFirstSight_old = data.displayFirstSight;

	    var d = new common.dialog({
	        title: "支付方式编辑",
	        width: "50%",
	        content: common.util.__template2($("#template").html(), data),
	        button: [
	            {value: "确认", css:"btn-primary", callback: function () {
	                var dataArray = $('#paymentEdit').serializeArray();
	                var newData = {};
	                $.each(dataArray, function (index, item) {
	                    newData[item.name] = item.value;
	                });
	                if(checkPaymentData(newData, data)){
	                    //更变了推荐到确认订单页情况下,需要二次确认
	                    if(recommendOrderPage_old != newData.recommendOrderPage){
	                        new common.dialog({
	                            title: "温馨提示",
	                            width: "360px",
	                            content:newData.recommendOrderPage == 1 ? "你确认将这个支付方式<font color='#5cb85c'>推荐</font>到确认订单页面么?" : "你确认<font color='#ff0000'>取消</font>将这个支付方式推荐到确认订单页面么?",
	                            zIndex: 52,
	                            button:[
	                                {value: "确认", css:"btn-primary", callback: function () {
	                                    savePaymentData(newData);
	                                    d.close();
	                                }},
	                                {value: "取消", css:"btn-default"}
	                            ]
	                        });
	                        return false;
	                    } else if(displayFirstSight_old != newData.displayFirstSight){
	                        new common.dialog({
	                            title: "温馨提示",
	                            width: "360px",
	                            content:newData.displayFirstSight == 1 ? "你确认将这个支付方式<font color='#5cb85c'>首次显示</font>吗?" : "你确认<font color='#ff0000'>取消</font>将这个支付方式首次显示吗?",
	                            zIndex: 52,
	                            button:[
	                                {value: "确认", css:"btn-primary", callback: function () {
	                                    savePaymentData(newData);
	                                    d.close();
	                                }},
	                                {value: "取消", css:"btn-default"}
	                            ]
	                        });
	                        return false;
	                    } else{
	                        savePaymentData(newData);
	                    }
	                }else{
	                    return false;
	                }

	            }},
	            {value: "取消", css:"btn-default"}
	        ]
	    });
	    new common.edit("#paymentEdit").init();
	});

	//保存支付方式数据
	function savePaymentData(data) {
	    common.util.__ajax({
	        url: '/Payment/updatePayInfoById',
	        data: data
	    }, function () {
	        g.reload();
	    })
	}

	//校验支付方式数据
	function checkPaymentData(data, oldData) {
	    //前端排序不能重复
	    if(data.sortNumber != oldData.sortNumber){
	        if(sortNumberList.indexOf(data.sortNumber) > -1){
	            common.util.__tip("前端排序已存在,不能重复填写!");
	            return false;
	        }
	    }
	    //推荐到订单页为'是',推荐文案不能为空!
	    if(data.recommendOrderPage == 1){
	        if($.trim(data.recommendWords) == ""){
	            common.util.__tip("推荐到订单页为'是',推荐文案不能为空!");
	            return false;
	        }
	    }
	    //提示语2不为空时,需要校验提示语1不能为空
	    if($.trim(data.recommendText2) != ""){
	        if($.trim(data.recommendText1) == ""){
	            common.util.__tip("提示语2填写,则提示语1也必须填写!");
	            return false;
	        }
	    }
	    return true;
	}

	//开启
	$(document).on("click", ".open-btn", function () {
	    var _index = $(this).data("index");
	    var data = g.rows[_index];

	    common.dialog.confirm("温馨提示", "确认开启当前支付方式么?", function(){
	        common.util.__ajax({
	            url: '/Payment/openPayModeById',
	            data: {id: data.id}
	        }, function () {
	            g.reload();
	        })
	    });
	});

	//关闭
	$(document).on("click", ".close-btn", function () {
	    var _index = $(this).data("index");
	    var data = g.rows[_index];

	    common.dialog.confirm("温馨提示", "确认关闭当前支付方式么?", function(){
	        common.util.__ajax({
	            url: '/Payment/closePayModeById',
	            data: {id: data.id}
	        }, function () {
	            g.reload();
	        })
	    });
	});

/***/ }
]);