//#import $owl_mall_sku:services/modelService.jsx

var SkuSearchUtil = (function () {
    var f = {
        /**
         * 获取商品的所有sku
         */
        getSkuList: function (productId) {
            var searchArgs = {
                "product_id": productId
            }
            var skuResult = owl_mall_skuService.search("", searchArgs, "", 0, 1000, null);
            if (skuResult.state == 'ok') {
                return skuResult.list;
            }
            return [];
        },
        /**
         * 根据sku编码获取sku
         */
        getSkuByCode: function (merchantId, code) {
            var searchArgs = {
                "_orgId": merchantId
            }
            searchArgs["code"] = code;
            var skuResult = owl_mall_skuService.search("", searchArgs, "", 0, 1, null);
            if (skuResult.state == 'ok') {
                var skuList = skuResult.list;
                if (skuList.length > 0) {
                    return skuList[0];
                }
            }
            return null;
        },
        /**
         * 根据条形码获取sku
         */
        getSkuByBarcode: function (merchantId, barcode) {
            var searchArgs = {
                "_orgId": merchantId
            }
            searchArgs["barcode"] = barcode;
            var skuResult = owl_mall_skuService.search("", searchArgs, "", 0, 1, null);
            if (skuResult.state == 'ok') {
                var skuList = skuResult.list;
                if (skuList.length > 0) {
                    return skuList[0];
                }
            }
            return null;
        },
        /**
         * 判断sku编码或者条形码在商家中是否已经存在
         */
        checkIsExist: function (merchantId, key, value) {
            var searchArgs = {
                "_orgId": merchantId
            }
            searchArgs[key] = value;
            var skuResult = owl_mall_skuService.search("", searchArgs, "", 0, 1, null);
            if (skuResult.state == 'ok') {
                var skuList = skuResult.list;
                if (skuList.length > 0) {
                    return true;
                }
            }
            return false;
        }
    };
    return f;
})();