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

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

创建存储变量

// 循环后台反的list数组,在每一个商品对象中添加字段,用来存储用户对每个商品的评价信息
init() {
	this.axios.post("/api/mobile/index.php", {
		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() {
	//1.处理评价信息
	let goodsArr = [];  //所有评价信息数组
	this.goods.forEach((item, i) => {    //循环评价商品列表,组合每个商品信息对象,push进大数组
		let good = {  //每个商品信息对象
			comment: item.text,//评价内容
			evaluate_image:[item.imgs.img1, item.imgs.img2, item.imgs.img3],//评价图片
			geval_id: item.geval_id//评价的商品id
		};
		goodsArr.push(good);
	});
	
	//2.评价信息上传
	this.axios.post("/api/mobile/index.php", {
		geval_orderid: this.order_id,
		goods: goodsArr   
	}).then(res => {
		if (res.status == 1) {
			this.$toast("评价成功");
		}
	});
},

发布了97 篇原创文章 · 获赞 152 · 访问量 6518

猜你喜欢

转载自blog.csdn.net/qq_40745143/article/details/104837015
今日推荐