let util = require('../../../utils/util')
// const apiArr = require('../../../api/water_filter')
const apiArr = require('../../../api/partner')
const apiArr2 = require('../../../api/water_filter')

const app = getApp({ allowDefault: true })



// packages/partner/pages/partner.js
const __staticUrl = require('../../../config/env.js').static_url
Page({

    /**
     * 页面的初始数据
     */
    data: {
        s: app.system.statusBarHeight, // 状态栏高度
        n: (app.menu.top - app.system.statusBarHeight) * 2 + app.menu.height, // 导航栏高度
        t: app.menu.top, // 胶囊局顶部距离
        h: app.menu.height, // 胶囊高度

        nav_list: {},
        foot_width: "",
        funcList: [

            {
                text: "新装工单",
                img: (__staticUrl + '/water_filter/partner/partner_icon3.png?1'),
                url: "../pages/WorkOrder/WorkOrder",
            },
            {
                text: "维修工单",
                img: (__staticUrl + '/water_filter/partner/partner_icon4.png?1'),
                url: "../../WaterPurifier/pages/upKeep/upKeep",
            },
            {
                text: "拆除工单",
                img: (__staticUrl + '/removeIcon.png'),
                url: "../pages/removeOrder/removeOrder",
            },
            {
                text: "滤芯更换工单",
                img: (__staticUrl + '/partsIcon.png'),
                url: "../pages/partsOrder/partsOrder",
            },
        ],
        funcList2: [
            {
                text: "滤芯预警营销",
                img: (__staticUrl + '/filterStock.png'),
                url: "/packages/partner/pages/marketingOrder1/marketingOrder1",
            },
            {
                text: "套餐预警营销",
                img: (__staticUrl + '/filterStock.png'),
                url: "/packages/partner/pages/marketingOrder2/marketingOrder2",
            },
        ],
        funcList3: [
            {
                text: "滤芯订单(零售)",
                img: (__staticUrl + '/filterStock.png'),
                url: "/packages/partner/pages/order1/order1",
            },
            {
                text: "套餐订单(租赁)",
                img: (__staticUrl + '/filterStock.png'),
                url: "/packages/partner/pages/order2/order2",
            },
        ],
        Info: "",
        order: "",

        serverInfo: ""
    },
    callPhone() {
        let that = this
        wx.makePhoneCall({
            phoneNumber: that.data.serverInfo.customer_phone,
        })
    },
    getServerInfo() {
        let that = this
        util.postUrl(apiArr2.getServerInfo, '', res => {
            res.qr_code = res.qr_code.startsWith('http') ? res.qr_code : util.img_url + res.qr_code
            console.log(res.qr_code);
            that.setData({
                serverInfo: res
            })
        })
    },
    back() {
        wx.reLaunch({
            url: '/pages/newLogin/newLogin',
        })
    },
    editAdmin() {
        wx.navigateTo({
            url: '/packages/partner/pages/editAdmin/editAdmin',
        })
    },
    padToEightDigits(number) {
        // 将数字转换为字符串，并使用 padStart 补足到 8 位
        return String(number).padStart(8, '0');
    },

    getOrderList() {
        let that = this
        let admin = wx.getStorageSync('admin')
        util.postUrl4(apiArr.getPartnerOrder, {
            dealer_id: admin.shop_id
        }, res => {
            that.setData({
                order: res
            })
        })
    },

    getParter() {
        let that = this
        wx.showLoading({
            title: '加载中...',
            mask: true
        })
        let admin = wx.getStorageSync('admin')
        util.postUrl4(apiArr.getPartner, {
            deal_id: admin.shop_id
        }, res => {
            wx.hideLoading()
            res.No = that.padToEightDigits(res.deal_id)
            if (res.deal_icon) {
                res.deal_icon = res.deal_icon.startsWith('http') ? res.deal_icon : util.img_url + res.deal_icon
            }
            console.log(admin.shop_id);
            if (admin.shop_id != 1) {
                let funcList = that.data.funcList
                funcList.splice(7, 1)
                that.setData({
                    funcList
                })
            }
            that.setData({
                Info: res
            })
        })
    },

    jump(e) {
        console.log(e);
        if (!e.currentTarget.dataset.url) {
            return wx.showToast({
                title: '功能暂未开通',
                icon: "none"
            })
        }
        wx.navigateTo({
            url: e.currentTarget.dataset.url,
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that = this
        that.getServerInfo()
        // that.getOrderList()
        wx.showShareMenu({
            withShareTicket: true,
            menus: ['shareAppMessage', 'shareTimeline']
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let that = this
        that.getParter()
    },

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

    },

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

    },

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

    },

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

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {
        return {
            title: '人人爱净水',  // 分享卡片标题（必填）
            path: '/pages/water_filter/water_filter',  // 用户点击后跳转的路径（可选，默认当前页）
            imageUrl: (__staticUrl + '/share.png')  // 自定义图片（可选，比例建议 5:4）
        }
    },
    onShareTimeline() {
        return {
            title: '人人爱净水', // 自定义标题
            query: '', // 自定义页面路径中的参数
            imageUrl: (__staticUrl + '/share.png') // 自定义分享图片路径
        }
    },
})