vue中多商品评价对用户评价信息的处理

369 阅读1分钟

商城对每个订单进行评价,但是订单商品数量不确定,根据后台接口反的数据渲染需要评价的商品信息

创建存储变量

循环后台反的list数组,在每一个商品对象中添加字段,用来存储用户对每个商品的评价信息

init() {
  this.axios
    .post("/api/mobile/index.php?w=member_evaluate&t=again", {
      order_id: this.order_id
    })
    .then(res => {
      console.log(res);
      this.goods = res.data.evaluate_goods;
      this.goods.forEach((item, index) => {
        // 动态设置data  对象 字段名 字段值
        this.$set(item, "text", ""); //存评价文字
        this.$set(item, "loading", false); //是否显示上传图片的加载动画
        this.$set(item, "imgs", {
          img1: "",
          img2: "",
          img3: ""
        }); //存图片   //必须先定义对象中的变量名,之后才可以在方法中修改变量值
      });
    });
},

获取存储的评价信息,上传接口

publish() {
  let goodsArr = [];  //所有评价信息数组
  this.goods.forEach((item, i) => {    //循环评价商品列表,组合每个商品信息对象,push进大数组
    let good = {  //每个商品信息对象
      anony: 0,
      comment: item.text,
      evaluate_image:[item.imgs.img1, item.imgs.img2, item.imgs.img3],
      geval_id: item.geval_id
    };
    goodsArr.push(good);
  });

  this.axios
    .post("/api/mobile/index.php?w=member_evaluate&t=save_again", {
      geval_orderid: this.order_id,
      goods: goodsArr   //评价信息上传
    })
    .then(res => {
      if (res.status == 1) {
        this.$toast("追加评价成功");
    });
},