const { envList } = require('../../envList.js');
const db = wx.cloud.database();

Page({
    /**
     * 页面的初始数据
     */
    data: {
        vote: [],
        value: []

    },

    onLoad: function (options) {

    },
    tovotecontent(e) {
        let id =  e.currentTarget.dataset.id;
        wx.navigateTo({
          url: '/pages/voteContent/index?id='+id,
        })
    },
    getsearchvalue(res) {
        // console.log(res.detail.value);
            this.setData({
            value: res.detail.value
        })
        
    },
    searchRe(res) {
        var that = this;
        wx.showToast({
          title: '搜索中',
          icon:'loading',
          duration:200
        })
        db.collection('Vote').where({
            votename: db.RegExp({
                regexp: that.data.value,
                options: 'i'
            })
        }).get().then(res => {
            if (res.data.length != 0) {
                this.setData({
                    vote: res.data
                })
            } else {
                wx.showToast({
                    title: '未找到相关公告',
                    icon: 'error'
                })
                this.setData({
                    vote: []
                })
            }
        })      
        // .get({
        //     success(res) {
        //         console.log(res);
        //         that.setData({
        //             vote:res.data
        //         })
        //     }
        // })

    },
});
