// components/input/index.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {
        value: '',
        type: {
            type: String,
            value: ''
        },
        // 数组
        itemData: {
            type: Object,
            value: function () {
                return {}
            }
        },
        isDisable: {
            type: Boolean,
            value: true
        },
        // 空调
        aircondition: {
            type: Boolean,
            value: false
        },
        // 	投影
        projection: {
            type: Boolean,
            value: false
        },
        // 左侧数组
        leftList: {
            type: Array,
            value: function () {
                return []
            }
        },
        // 右侧数组
        rightList: {
            type: Array,
            value: function () {
                return []
            }
        },
    },

    /**
     * 组件的初始数据
     */
    data: {},
    lifetimes: {
        attached: function () {},
        detached: function () {
            // 在组件实例被从页面节点树移除时执行
        },
    },

    /**
     * 组件的方法列表
     */
    methods: {
        // 茶水
        getWater(e) {
            if (!this.data.isDisable) {
                this.triggerEvent('teaWater', e)
            }
        },
        cleaeTea(e) {
            this.triggerEvent('cleaeTea', e)
        },
        // 点心
        getSnack(e) {
            if (!this.data.isDisable) {
                this.triggerEvent('snack', e)
            }
        },
        // 桌签
        getMonogram(e) {
            let dataset = e.currentTarget.dataset
            let {leftList,rightList}=this.data
            if (!this.data.isDisable) {
                var that = this;
                wx.showModal({
                    title: '桌签内容',
                    content: dataset.type === 'left' ? leftList[dataset.index].monogram : rightList[dataset.index].monogram,
                    showCancel: true,
                    editable: true,
                    success: function (res) {
                        dataset.val = res.content
                        if (res.confirm) {
                            that.triggerEvent('monogram', dataset)
                        } else if (res.cancel) {}
                    }
                })
            }

        },
        // 大屏/投影
        largeScreenFun(e) {
            // console.log(e);
            if (!this.data.isDisable) {
                let index = e.currentTarget.dataset.index
                switch (e.currentTarget.dataset.type) {
                    case '1':
                        this.triggerEvent('change', 'projection')
                        break;
                    case '2':
                        this.triggerEvent('change', 'aircondition')
                        break;
                    case '3':
                        this.setData({
                            [`list[${index}].isTable`]: !this.data.list[index].isTable
                        })
                        break;
                    case '4':
                        this.setData({
                            [`list[${index}].isWater`]: !this.data.list[index].isWater
                        })
                        break;
                    case '5':
                        this.setData({
                            [`list[${index}].isDessert`]: !this.data.list[index].isDessert
                        })
                        break;
                    case '6':
                        this.setData({
                            [`list1[${index}].isTable`]: !this.data.list1[index].isTable
                        })
                        break;
                    case '7':
                        this.setData({
                            [`list1[${index}].isWater`]: !this.data.list1[index].isWater
                        })
                        break;
                    case '8':
                        this.setData({
                            [`list1[${index}].isDessert`]: !this.data.list1[index].isDessert
                        })
                        break;
                    default:
                        break;
                }
            }
        }
    }
})