operations.payment.Index.js 4.85 KB
webpackJsonp([120],[
/* 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: '支付名称', render:function(item){
	            return item.payName;
	            //if(item.id=='4'){
	            //    return "Apple Pay(北京银联)";
	            //}else if(item.id=='5'){
	            //    return "银联支付(北京银联)";
	            //}else if(item.id=='24'){
	            //    return "Apple Pay(江苏银联)";
	            //}else if(item.id=='26'){
	            //    return "银联支付(江苏银联)";
	            //}else{
	            //    return item.payName;
	            //}
	        }},
	        {display: "前端显示排序", name: "sortNumber"},
	        {display: "推荐语", name: "recommendText1"},
	        {display:"未开通文案",name:"noOpenText"},
	        //{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 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)){
	                        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();
	        })
	    });
	});

/***/ }
]);