import {
    TestVerify
} from "../../utils/verify";
import {
    ApiModel
} from "../../utils/api"
const _Http = new ApiModel();
const _Verify = new TestVerify();
const processingData = require("../../utils/processingData.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        tabsList: ['通告', '供需', '直播'],
        ftype: 3, //1：直播，2：供需，3：通告
        annunciateList: [], //通告列表
        liveList: [], //直播列表
        supplyanddemandList: [], //供需列表
        showPlaceholder: true, //是否显示占位图
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },
    //切换搜索类型
    tabsSelectedIitem({
        detail
    }) {
        let ftype = this.data.ftype;
        switch (detail) {
            case "通告":
                ftype = 3;
                break;
            case "供需":
                ftype = 2;
                break;
            case "直播":
                ftype = 1;
                break;
        }
        if (ftype == this.data.ftype) return;
        this.setData({
            ftype
        });
        this.isPlaceholder()
    },
    /* 搜索关键字 */
    searchContent(e) {
        let {
            value
        } = e.detail;
        value = _Verify.Eliminate(value.trim());
        if (value) {
            _Http.basic({
                "classname": "publicmethod.homepage.homepage",
                "method": "searchPortalInfo",
                "content": {
                    "getdatafromdbanyway": true,
                    "keyStr": value,
                    "ftype": ""
                }
            }).then(res => {
                if (res.msg != '成功') return wx.showToast({
                    title: res.data,
                    icon: 'none'
                })
                let annunciateList = res.data.TNOTICE,
                    supplyanddemandList = res.data.tsupplyanddemand;
                if (annunciateList.length != 0) annunciateList = processingData.annunciateCheckdate(annunciateList);
                if (supplyanddemandList.length != 0) supplyanddemandList = processingData.annunciateCheckdate(supplyanddemandList);
                this.setData({
                    annunciateList,
                    liveList: res.data.tlive,
                    supplyanddemandList
                })
                this.isPlaceholder()
            })
        } else {
            this.setData({
                annunciateList: [],
                liveList: [],
                supplyanddemandList: []
            })
            this.isPlaceholder()
        }
    },
    /* 是否显示占位图 */
    isPlaceholder() {
        let showPlaceholder = false;
        switch (this.data.ftype) {
            case 3:
                showPlaceholder = (this.data.annunciateList.length == 0) ? true : false;
                break;
            case 2:
                showPlaceholder = (this.data.supplyanddemandList.length == 0) ? true : false;
                break;
            case 1:
                showPlaceholder = (this.data.liveList.length == 0) ? true : false;
                break;
        }
        this.setData({
            showPlaceholder
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})