 (function(KDApi, $){
    // 构造函数，变量名随意，与最后一句代码的KDApi.register的第二个参数一致即可
    function HelloWorld (model) {
        this._setModel(model)
    }
    var data = {};
    var index = 0;
    //列表展示几个元素
    var num = 7;
    var mymodel;

    // 原型中封装生命周期函数，固定格式
    HelloWorld.prototype = {
        _setModel: function(model) {
            this.model = model
        },
        init: function(props){
			index = 0;
            initFunc(this.model, props);
        },
        update: function(props){
			index = 0;
			initFunc(this.model, props);
        },
        destoryed: function(){

        }
    }
    // Other Code
    var initFunc = function(model, props) {
		console.log("init");
		if(props.data.list.length === 0){
			return;
		}

	KDApi.loadFile("./css/fi_er_tripcitylist.css", model, function () {
		num = parseInt(props.configItems[0].value);
		data = props.data;
		var tempArr = [];
		if (data.list.length > num) {
			tempArr = tempArr.concat(data.list.slice(0, num));
		}else {
			 tempArr = data.list;
		}
		setHtml(model, tempArr);
        })
    }

    function setHtml(model, tempArr){
            KDApi.templateFilePath('./html/fi_er_tripcitylist.html', model, {"list": tempArr}).then(
                function (result) {
                    model.dom.innerHTML = result;
                    var left = $('.kingdee-fi-ertripcitylist-move-left', model.dom)[0];
                    var right= $('.kingdee-fi-ertripcitylist-move-right', model.dom)[0];
                    $('.kingdee-fi-ertripcitylist-move-left', model.dom).click(function(){
                        qiehuan(-1, model);
                    });
                    $('.kingdee-fi-ertripcitylist-move-right', model.dom).click(function(){
                        qiehuan(1, model);
                    });
                    if(data.list.length <= num){
                        $('.kingdee-fi-ertripcitylist-move-left', model.dom)[0].style.display = "none";
                        $('.kingdee-fi-ertripcitylist-move-right', model.dom)[0].style.display = "none";
                    }
                    if(index <= 0){
                        index = 0;
                        left.style.pointerEvents = 'none';
                        left.classList.add("kingdee-fi-ertripcitylist-move-left-disenable");
                        left.classList.remove("kingdee-fi-ertripcitylist-move-left-enable");
                    }else{
                        left.style.pointerEvents = 'auto';
                        left.classList.remove("kingdee-fi-ertripcitylist-move-left-disenable");
                        left.classList.add("kingdee-fi-ertripcitylist-move-left-enable");
                    }
                    if(index >= data.list.length - num){
                        index = data.list.length - num;
                        right.style.pointerEvents = 'none';
                        right.classList.add("kingdee-fi-ertripcitylist-move-right-disenable");
                        right.classList.remove("kingdee-fi-ertripcitylist-move-right-enable");
                    }else{
                        right.style.pointerEvents = 'auto';
                        right.classList.remove("kingdee-fi-ertripcitylist-move-right-disenable");
                        right.classList.add("kingdee-fi-ertripcitylist-move-right-enable");
                    }
                 })
    }
	
	function qiehuan(i, model){
		index = index + i;
		if(index <= 0){
			index = 0;
		}
		if(index >= data.list.length - num){
			index = data.list.length - num;
		}
		var tempArr = new Array();
		if (i < data.list.length) {
			var end = index + num  > data.list.length ? data.list.length :  index + num;
			tempArr = tempArr.concat(data.list.slice(index, end));
		}
		setHtml(model, tempArr);
	}
    // 你只需知道第一个参数是你接下来要新增控件方案时填的方案id，第二个参数是上面声明的构造函数
    KDApi.register('kingdee-fi-ertripcitylist', HelloWorld)
})(window.KDApi, jQuery) // 这里的jQuery不是必须要传进去的，可移除，要用到的时候才传，PC端系统默认会有jQuery对象，版本是1.12.4