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

    /**
     * 页面的初始数据
     */
    data: {
        swiperBannerList: [], //轮播图
        tabsList: ['通告列表', '历史发布'], //tab列表
        tabsIndex: 0, //tab选中项
        showType: "官方", //请求列表类型
        pageNumber: 1, //获取页码
        pageTotal: 1, //总页码
        /* 圆角按钮tabs列表 */
        roundedList: ["全部通告", "家纺城通告", "合作商通告", "团队通告"],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        /* //分类
         _Http.basic({
            "accesstoken": wx.getStorageSync('userData').token,
            "classname": "enterprise.system.notice",
            "method": "query_typeselectList",
            "content": {}
        }).then(res => {
            console.log(res)
        }) */

        /* 获取轮播图 */
        const bannerList = wx.getStorageSync('bannerDataList').filter(value => value.flocation == 'home_head');
        this.setData({
            swiperBannerList: bannerList[0].banner
        });
    },
    /* 跳转详情 */
    toDetails(e) {
        const {
            index
        } = e.currentTarget.dataset;
        wx.navigateTo({
            url: './details?id=' + this.data.annunciateList[index].tnoticeid + '&type=' + this.data.tabsIndex,
        })
    },
    /* 获取列表 */
    getList() {
        //历史发布
        let data = {
            "accesstoken": wx.getStorageSync('userData').token,
            "classname": "customer.notice.notice",
            "method": "query_noticeList",
            "content": {
                "getdatafromdbanyway": true,
                "pageNumber": this.data.pageNumber,
                "pageSize": 20,
                "where": {
                    "condition": "",
                    "ftype": this.data.showType
                }
            }
        };
        if (this.data.tabsIndex == 1) {
            data.classname = 'customer.noticemag.noticemag';
            data.content.where.ftype = '';
        };
        _Http.basic(data).then(res => {
            console.log("通告列表",res)
            let list = processingData.annunciateCheckdate(res.data),
                data = [];
            if (this.data.pageNumber == 1) {
                data = processingData.imageType(list, 'cover');
            } else {
                let L = this.data.annunciateList;
                data = L.concat(processingData.imageType(list, 'cover'));
            }
            this.setData({
                annunciateList: data,
                pageTotal: res.pageTotal
            })
        })
    },
    /* 历史发布修改 */
    toChang(e) {
        const {
            index
        } = e.currentTarget.dataset;
        wx.navigateTo({
            url: './newAndChange?id=' + this.data.annunciateList[index].tnoticeid,
        });
    },
    /* 查询数据 */
    toQueryData(e) {
        const {
            index
        } = e.currentTarget.dataset;
        wx.navigateTo({
            url: './glanceover?id=' + this.data.annunciateList[index].tnoticeid,
        })
    },
    /* 发布公告 */
    toAnnounce() {
        wx.navigateTo({
            url: '/pages/annunciate/newAndChange',
        })
    },
    /* tab切换 */
    setIndex({
        detail
    }) {
        if (detail == this.data.tabsIndex) return;
        this.setData({
            tabsIndex: detail
        });
        this.initializePage();
        this.getList();
    },
    /* tabs回调 */
    tabsSelectedIitem({
        detail
    }) {
        let showType = null;
        switch (detail) {
            case "家纺城通告":
                showType = '官方'
                break;
            case "合作商通告":
                showType = '商户'
                break;
            case "团队通告":
                showType = '团队'
                break;
            default:
                showType = ''
                break;
        }
        this.setData({
            showType
        });
        this.initializePage();
        this.getList();
    },
    /* 初始化分页数据 */
    initializePage() {
        this.setData({
            pageNumber: 1,
            pageTotal: 1
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

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

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

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

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

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if (this.data.pageNumber < this.data.pageTotal) {
            this.setData({
                pageNumber: this.data.pageNumber + 1
            });
            this.getList()
        }
    },

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

    }
})