/**
* v_addUnlockInfo.js
* Version: 0.1
* User: wy
* Date: 2017-10-09
* Copyright(c)  2017. U-GEN Tech.Co,Ltd. All Rights Reserved.
* 绑定开锁信息页面
*/

import {iot, uPublic, uComponents} from '../../public/public.js';

iot.ready(init);
function init() {
    //通用 select、按钮、dialog、loading组件
    uPublic.componentsInit(['u-select','u-button','u-dialog','u-loading']);
    const app = new Vue({
        data:{     
            recordSelectIndex: 0,
            recordSelectList: [],   
            waysOpenDoor: [{mode: 0, text: '指纹'},{mode: 1, text: '密码'},{mode: 2, text: 'IC卡'},{mode: 3, text: '钥匙'},{mode: 4, text: '劫持指纹'},{mode: 5, text: '远程开门'},{mode: 5, text: '远程开门'}],
            selectedMode: 0,
            //配置组件
            componentsConfig: initComponentsConfig()   
        },
        mounted(){    
        	resolve(this);
        },
        methods:{
        	getSelectedMode(){
        		return this.selectedMode;
        	},
        	setSelectedMode(mode){
        		this.selectedMode = mode
        	},
            //tap <
            onBackTap(){
                backTap();
            },
            onRecordSelectChange(value) {
                recordSelectChange(this, value);
            },
            //tap 添加
            onAddButtonTap(){
                addButtonTap();
            },
            onSelectOpenDoorModeTap(index){
            	selectOpenDoorModeTap(this, index);
            }
        }   
    }).$mount('#app');
}

//配置组件参数
function initComponentsConfig() {
    return {
        recordSelect: {
            initParam: {
                class: 'custom-select',
                list: [
                    {value: 1, title: '16:35',subtitle: 'ID:001'},
                    {value: 2, title: '15:33',subtitle: 'ID:002'},
                    {value: 3, title: '15:06',subtitle: 'ID:007'}
                ],
                pagesize: Number.MAX_VALUE
            }
        },
        //添加 button 参数
        addButton: {   
            initParam: {
                class: 'custom-button',
                text: Vue.t('btn.add')
            }
        },
        dialog: {
            initParam: {
                class: 'custom-dialog'
            }
        },
        loading: {
            initParam: {
                class: 'custom-loading'
            }
        }               
    }
}

function resolve(self){
	getTodayReccordByMode(self,self.getSelectedMode());
}

//tap <
function backTap(){
    iot.navigator.back();
}

function recordSelectChange(self, value) {
    self.recordSelectIndex = value;
    console.log('recordSelectChange:' + self.recordSelectIndex);
}

//tap 添加 
function addButtonTap(){
    iot.navigator.back();
}

function selectOpenDoorModeTap(self, index){
	self.setSelectedMode(index);
	getTodayReccordByMode(self,index);
}

function getTodayReccordByMode(self, mode){
	
}
