const _Http = getApp().globalData.http;
Component({
    options: {
        addGlobalClass: true
    },
    properties: {
        list: Array,
        changeTotal: Function,
        disabled: Boolean
    },
    data: {
        radio: 0
    },
    methods: {
        //打开详情
        onClick(e) {
            const {
                item
            } = e.currentTarget.dataset;
            wx.navigateTo({
                url: '/packageA/setclient/modules/financing/detail/index?sys_enterprise_financeid=' + item.sys_enterprise_financeid,
            })
        },
        /* 处理快捷小按钮 */
        handleItem(e) {
            const {
                name,
                item
            } = e.target.dataset,
                that = this;
            if (!name) return;
            switch (name) {
                case "call":
                    wx.makePhoneCall({
                        phoneNumber: item.phonenumber,
                    })
                    break;
                case "copy":
                    wx.setClipboardData({
                        data: `开票抬头：${item.enterprisename}\n企业税号：${item.taxno}\n开票地址：${item.address}\n开户银行：${item.bank}\n开户账号：${item.bankcardno}`,
                    })
                    break;
                case "delete":
                    wx.showModal({
                        title: '提示',
                        content: '是否确认作废',
                        complete: (res) => {
                            if (res.confirm) {
                                _Http.basic({
                                    "id": 20221013160502,
                                    "content": {
                                        "sys_enterprise_financeids": [item.sys_enterprise_financeid]
                                    },
                                }).then(res => {
                                    if (res.msg != '成功') return wx.showToast({
                                        title: res.msg,
                                        icon: "none"
                                    });
                                    let page = null;
                                    getCurrentPages().forEach(v => {
                                        switch (v.__route__) {
                                            //退出详情界面
                                            case 'packageA/setclient/modules/financing/detail/index':
                                                wx.navigateBack()
                                                break;
                                                //列表页更新数据
                                            case 'packageA/setclient/detail':
                                                page = v.selectComponent("#Financing");
                                                page.setData({
                                                    list: page.data.list.filter(v => v.sys_enterprise_financeid != item.sys_enterprise_financeid)
                                                });
                                                page.changeTotal();
                                                break;
                                            case 'packageA/publicCustomer/detail':
                                                page = v.selectComponent("#Financing");
                                                page.setData({
                                                    list: page.data.list.filter(v => v.sys_enterprise_financeid != item.sys_enterprise_financeid)
                                                });
                                                page.changeTotal();
                                                break;
                                            case 'packageA/setclient/modules/financing/search/index':
                                                v.setData({
                                                    list: v.data.list.filter(v => v.sys_enterprise_financeid != item.sys_enterprise_financeid)
                                                });
                                                break;
                                        }
                                    });
                                    wx.showToast({
                                        title: '作废成功',
                                        icon: "none"
                                    });
                                });
                            }
                        }
                    })
                    break;
                case "edit":
                    wx.navigateTo({
                        url: '/packageA/setclient/modules/financing/add/index?data=' + JSON.stringify(item),
                    });
                    break;
            }
        },
        /* 查询默认项目 */
        queryDefault() {
            const item = this.data.list.find(v => v.isdefault == 1);
            if (!item) return;
            this.setData({
                radio: item.sys_enterprise_financeid
            })
        },
        /* 修改默认项 */
        onChange({
            detail
        }) {
            _Http.basic({
                "id": 20221013160702,
                "content": {
                    "sys_enterprise_financeid": detail
                },
            }).then(res => {
                if (res.msg != '成功') return wx.showToast({
                    title: res.data,
                    icon: "none"
                });
                this.setData({
                    list: this.data.list.map(v => {
                        v.isdefault = v.sys_enterprise_financeid == detail ? 1 : 0
                        return v
                    }),
                    radio: detail
                })
            })
        },
    }
})