operations.shopsVersionUpdate.Index.js 5.43 KB
webpackJsonp([113],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by ty on 2016/6/3.
	 */
	var $ = __webpack_require__(1),
	    common = __webpack_require__(2);

	var VersionData = {};
	const iphoneUrl = "itms-services://?action=download-manifest&url=https://cdn.yoho.cn/applist/yohovendor/ios/manifest.plist";

	new common.dropDown({el: "#clientType"});

	var g = new common.grid({
	    el: "#list-content",
	    parms: function () {
	        return {
	            appVersion: common.util.__input('appVersion'),
	            clientType: common.util.__input('clientType')
	        };
	    },
	    columns: [
	        {display: "ID", name: "id"},
	        {display: "APP版本", name: "version"},
	        {display: "提醒内容", name: "content"},
	        {display: "跳转链接", name: "url"},
	        {display: "客户端类型", name: "clientType", render: function(item) {
	            if(item.clientType != null && item.clientType.trim() != "") {
	                var platform = item.clientType;
	                var temp = platform.replace("iphone", "IOS手机").replace("ipad", "IOS Pad")
	                    .replace("android", "安卓手机").replace("androidpad", "安卓Pad")
	                    .replace(/,/g, " ");
	                return temp;
	            }
	        }},
	        {display: "状态", name: "status", render: function(item) {
	            if(item.status == 1) {
	                return "已开启";
	            } else if(item.status == 0) {
	                return "已关闭";
	            }
	        }},
	        {
	            display: "操作",name: "", render: function (item) {
	            var arr = [];
	            if(item.status == 0) {
	                arr.push('<a class="btn btn-success btn-xs change-status" data-index="' + item.__index + '">开启</a>');
	            } else {
	                arr.push('<a class="btn btn-danger btn-xs change-status" data-index="' + item.__index + '">关闭</a>');
	            }
	            arr.push('<a class="btn btn-warning btn-xs del" data-index="' + item.__index + '">删除</a>');
	            return arr.join("");
	        }
	        }
	    ]
	});

	g.init('/AppVersionRest/getAppVersionList');

	var Bll = {
	    toast:function(url, item, hint) {
	        var e = new common.edit2("#base-form");

	        var dialog = common.dialog.confirm(hint,
	            common.util.__template2($("#template").html(), item),
	            function() {
	                if(e.validate()) {
	                    VersionData.status = $("#status").val();
	                    VersionData.url = $("#url").val();
	                    console.log(VersionData);
	                    common.util.__ajax({
	                        url: url,
	                        data: VersionData
	                    }, function (res) {
	                        dialog.close();
	                        g.reload();
	                    });
	                }
	                return false;
	            });
	        $("#appFile").ajaxfileupload({
	            'action': '/ajax/upload',
	            'params': {
	                bucket: "yohobuyzip",
	                __type: "fileupload-upload"
	            },
	            onComplete: function (response) {
	                if (response.status && response.code == 200) {
	                    if(response.data){
	                        $("#url").attr("value", response.data);
	                    }
	                } else {
	                    common.util.__tip(response.message);
	                }
	            },
	            valid_extensions: ["ipa", "apk"]
	        })

	        new common.dropDown({el: "#types"});
	        e.bind();
	    }
	};

	$(document).on('click', '#addAppVersion', function() {
	    VersionData = {};
	    Bll.toast("/AppVersionRest/setAppVersion", VersionData, "上传APP包");
	});

	$(document).on("change", ".observe", function () {
	    var name = $(this).data("field");
	    var val = $(this).val();
	    VersionData[name] = val;
	    if(name == "clientType") {
	        if (val == "iphone" || val == "ipad") {
	            $("#url").val(iphoneUrl);
	            $("#url").attr("disabled","disabled");
	            $("#appFile").hide();
	            $("#fileBtn").hide();
	        } else if(val == "android") {
	            $("#url").val("http://cdn.yoho.cn/applist/yohovendor/android/yhvendor081902.apk");
	            $("#appFile").show();
	            $("#fileBtn").show();
	            $("#url").removeAttr("disabled");
	        }else{
	            $("#url").val("");
	            $("#url").attr("disabled","disabled");
	            $("#appFile").hide();
	            $("#fileBtn").hide();
	        }
	    }
	});

	$(document).on("click", ".change-status", function () {
	    VersionData = g.rows[$(this).data("index")];
	    VersionData.status = 1 - VersionData.status;
	    common.util.__ajax({
	        url: "/AppVersionRest/editAppVersion",
	        data: {id: VersionData.id, status: VersionData.status}
	    }, function (res) {
	        g.reload();
	    });
	});

	$(document).on("click", ".del", function () {
	    VersionData = g.rows[$(this).data("index")];
	    common.dialog.confirm("警告",
	        "确认删除?",
	        function() {
	            common.util.__ajax({
	                url: "/AppVersionRest/delAppVersion",
	                data: {id: VersionData.id}
	            }, function () {
	                g.reload();
	            });
	        });
	});

	$(document).on("click", "#filter-btn", function () {
	    g.reload(1);
	});

/***/ }
]);