import ListCategory from '../listCategory/ListCategory';
import {Message} from '@hot/pc-es-cn-shop-ui';
const CategoryType = {
    TYPE_SYS: 1,    
    TYPE_CUSTOM:2   
}
class NavCategory extends ListCategory{
    constructor(config) {
        config = config || {};
        config.className = 'cd-nav-category';
        config.name1Editable = 1;
        config.tips = `请上传宽高范围为68-800px，大小不超过${window.page_config.chooseSizeLimit}KB，形状为正方形的jpg、png图片。为了页面更美观，建议使用圆角图片。`;
        config.format = '68-800,68-800';
        config.useSquare = true;
        super(config);
    }
    renderItem(data){
        if(data){
            data.name1Editable = 1;
            super.renderItem(data);
        }
    }
    render() {
        super.render();
        this.$sysCategoryTip.hide();
        this.$displayLayer.hide();
    }
    validateData() {
        let itemData = this._getData();
        let subList = itemData.subList;
        if(subList.length>0){
            let hasImg = false;
            let hasNoImg = false;
            for(let i=0,len=subList.length;i<len;i++){
                let item = subList[i];
                if(this.type == CategoryType.TYPE_CUSTOM){
                    if(!item.cateName){
                        Message.error('二级类目文案不能为空。');
                        return false;
                    }
                    if($.isEmptyObject(item.linkInfo)){
                        Message.error('二级类目链接不能为空。');
                        return false;
                    }
                }
                if(item.imageUrl && item.imageUrl.value){
                    hasImg = true;
                }
                else{
                    hasNoImg = true;
                }
            }
            if(hasNoImg){
                Message.error('保存失败。请保证该类目下均有图片。');
                return false;
            }
        }
        return true;
    }
    _getData(){
        let subList = this.getSubListData();
        let itemData = {
            type: this.type,
            cateId: this.$categoryWrapper.find('.J_item').attr('cate-id')
        }
        itemData.cateName = this.$categoryWrapper.find('.J_cateName').text();
        itemData.subList = subList;
        return itemData;
    }
}
export default NavCategory;