我不确定该项目正在发生什么,它在本地工作,但是在服务器上有问题

时间:2019-11-18 14:41:41

标签: javascript vue.js

我正在尝试将项目从本地移动到服务器,但无法像在本地那样工作,并且我不知道发生了什么。我有产品,当我编辑它们时,它并没有像本地一样从数据库中获取信息,当我知道数据库中没有这些数字为0时,它将2个非常重要的数字作为0,否则就无法计算价格。

这是产品带来的信息

[ { "country": { "id": 1, "name": "COSTA RICA", "currency_symbol": "CRC" }, "country_id": 1, "margin": 0, "fi": 0 }, 
{ "country": { "id": 2, "name": "NICARAGUA", "currency_symbol": "COR" }, "country_id": 2, "margin": 0, "fi": 0 }, 
{ "country": { "id": 3, "name": "HONDURAS", "currency_symbol": "HNL" }, "country_id": 3, "margin": 0, "fi": 0 } ]

该产品在数据库中的边距和fi均为

product_id: 1
country_id: 1
margin: 0.65
fi: 0.50

product_id: 1
country_id: 2
margin: 0.65
fi: 0.50

product_id: 1
country_id: 3
margin: 0.65
fi: 0.50

编辑产品是创建模型的克隆,由于某种原因,它没有带来应有的信息。

此功能可打开创建和编辑对话框。

showDialog(model) {
    if (this.processing) {
        return;
    }
    if (model) {
        let cloneModel = {...model};
        this._formatModel(cloneModel);
        this.actionText = 'Actualizar';
        this.form = cloneModel
    } else {
        this.dialogTitle = 'Nuevo';
        this.actionText = 'Agregar';
        this._isNew();
            if (this.form.id) {
                this._resetForm();
                this.$refs.form.resetFields()
            }
    }

    this.dialogTitle = this._getDialogTitle(this.form);
    this.dialogVisible = true
}

_formatModel(model) {
    this.productCategories = [];

    this.loadingResource = true;
    this.$http.post(this.baseUrl + '/show/' + model.id).then(
        (res) => {
            this.model.export_factors = this.countries.map((country) => {
            let result = res.body.export_factors.filter((item) => item.country_id === country.id);
            let margin = 0;
            let fi = 0;

            if (result.length > 0) {
                margin = result[0].margin;
                fi = result[0].fi;
            }
            return {
                country: country,
                country_id: country.id,
                margin: margin,
                fi: fi,
            }
        });
        this.model.prices = this.countries.map((country) => {
            let result = res.body.prices.filter((item) => item.country_id === country.id);
            let resultExport = res.body.export_factors.filter((item) => item.country_id === country.id);
            let price = 0;

            if (result.length > 0) {
                price = (this.form.cif / resultExport[0].margin) / resultExport[0].fi;
            }
            return {
                country: country,
                country_id: country.id,
                price: price.toFixed(2),
            }
        });
        this.productCategories = res.body.categories.map((category) => {
            category.fields = category.fields.map(item => {
                item.allFields = [item.field];
                return item;
            });
            return category;
        });
        this.form.tags = res.body.tags;
        this.form.sizes = res.body.sizes;
        this.loadingResource = false;
    },
    (res) => {
        this.loadingResource = false;
        this.dialogVisible = false;
        this.$message.error(parseError(res)[0])
    }
  )
},

_isNew() {
    this.model.prices = this.countries.map((country) => {
        return {
            country: country,
            country_id: country.id,
            price: 0,
        }
    });

    this.model.export_factors = this.countries.map((country) => {
        return {
            country: country,
            country_id: country.id,
            fi: 0,
            margin: 0
        }
    });
    this.productCategories = [];
}

会发生什么?

1 个答案:

答案 0 :(得分:1)

在过滤器函数中进行比较可能会出现问题。您可以将ID解析为整数,同时比较两个ID,如下所示。我只是在纠正您的_formatModel

_formatModel(model) {
this.productCategories = [];

this.loadingResource = true;
this.$http.post(this.baseUrl + '/show/' + model.id).then(
    (res) => {
        this.model.export_factors = this.countries.map((country) => {
        let result = res.body.export_factors.filter((item) => parseInt(item.country_id) === parseInt(country.id));
        let margin = 0;
        let fi = 0;

        if (result.length > 0) {
            margin = result[0].margin;
            fi = result[0].fi;
        }
        return {
            country: country,
            country_id: country.id,
            margin: margin,
            fi: fi,
        }
    });
    this.model.prices = this.countries.map((country) => {
        let result = res.body.prices.filter((item) => parseInt(item.country_id) === parseInt(country.id));
        let resultExport = res.body.export_factors.filter((item) => parseInt(item.country_id) === parseInt(country.id));
        let price = 0;

        if (result.length > 0) {
            price = (this.form.cif / resultExport[0].margin) / resultExport[0].fi;
        }
        return {
            country: country,
            country_id: country.id,
            price: price.toFixed(2),
        }
    });
    this.productCategories = res.body.categories.map((category) => {
        category.fields = category.fields.map(item => {
            item.allFields = [item.field];
            return item;
        });
        return category;
    });
    this.form.tags = res.body.tags;
    this.form.sizes = res.body.sizes;
    this.loadingResource = false;
},
(res) => {
    this.loadingResource = false;
    this.dialogVisible = false;
    this.$message.error(parseError(res)[0])
}

) }