let _Http = getApp().globalData.http;
Page({
    data: {
        form: [{
            label: "优势信息",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "优势信息",
            valueName: "advantage",
            checking: "base",
            required: true
        }, {
            label: "劣势信息",
            error: false,
            errMsg: "",
            type: "textarea",
            value: "",
            placeholder: "劣势信息",
            valueName: "inferiority",
            checking: "base",
            required: true
        }],
        "content": {
            "sa_competitorid": 0,
            "isdefault": 0,
            sa_competitor_advid: 0
        },
        disabled: true
    },
    onLoad(options) {
        this.data.content.sa_competitorid = options.id;
        if (options.data) {
            let data = JSON.parse(options.data),
                content = {
                    "sa_competitorid": data.sa_competitorid,
                    "isdefault": data.isdefault,
                    sa_competitor_advid: data.sa_competitor_advid
                };
            this.setData({
                content,
                'form[0].value': data.advantage,
                'form[1].value': data.inferiority,
                disabled: false
            })
        }
        getApp().globalData.Language.getLanguagePackage(this, (options.data ? '编辑' : '添加') + '优势劣势');
    },
    /* 表单必填项是否完成 */
    onConfirm({
        detail
    }) {
        this.setData({
            disabled: detail
        })
    },
    // 是否显示全部
    onChange({
        detail
    }) {
        this.setData({
            showAll: detail
        })
    },
    submit() {
        let content = {
            ...this.data.content,
            ...this.selectComponent("#Form").submit()
        };
        _Http.basic({
            "id": 2025031809205102,
            content
        }).then(res => {
            console.log("新建或保存优劣势", res)
            getApp().globalData.Language.showToast(res.code != 1 ? res.msg : "保存成功", res.code == 1)
            if (res.code == 1) {
                getCurrentPages().find(v => v.__route__ == 'packageA/opponent/detail').selectComponent("#AAD").getList(0, true)
                if (content.isdefault) getCurrentPages().find(v => v.__route__ == 'packageA/opponent/detail').getDetail()
                setTimeout(() => {
                    wx.navigateBack()
                }, 300)
            }
        })
    },
})