123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- var http = require('../../utils/http.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- orderItemInfo: [], //订单列表页参数
- submitCommCount:0 //已经提交的评论数量
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- // 获取上页(订单列表)数据
- var orderItemInfo = wx.getStorageSync("orderItemInfo");
- // console.log(orderItemInfo);
- for (var i = 0; i < orderItemInfo.length; i++){
- orderItemInfo[i].images = [];
- orderItemInfo[i].content = "";
- orderItemInfo[i].score = 5;
- orderItemInfo[i].isAnonymous = 1;
- orderItemInfo[i].evaluate = 0;
- }
- this.setData({
- orderItemInfo: orderItemInfo
- })
- console.log(orderItemInfo)
- },
-
- /**
- * 发表评论
- */
- submitComm: function (e) {
- var orderItemInfo = this.data.orderItemInfo;
- var allFill = true;
- for (var i = 0; i < orderItemInfo.length; i++) {
- var cont = orderItemInfo[i].content.trim();
- if(cont==""){
- wx.showToast({
- title: '评价不能为空',
- icon:"none"
- })
- allFill = false;
- break;
- }
- }
- if (allFill){
- for (var i = 0; i < orderItemInfo.length; i++) {
- wx.showLoading();
- var pics = '';
- orderItemInfo[i].images.forEach(function(item){
- pics += item.path + ',';
- });
- if(pics!=''){
- pics = pics.substring(0,pics.length-1)
- }
- // 发布评论
- var params = {
- url: "/p/prodComm",
- method: "POST",
- data: {
- content: orderItemInfo[i].content,
- score: orderItemInfo[i].score,
- evaluate: orderItemInfo[i].evaluate,
- isAnonymous: orderItemInfo[i].isAnonymous,
- orderItemId: orderItemInfo[i].orderItemId,
- prodId: orderItemInfo[i].prodId,
- pics: pics
- },
- callBack: (res) => {
- this.setData({
- submitCommCount: this.data.submitCommCount+1
- });
- if (this.data.submitCommCount == orderItemInfo.length) {
- wx.showModal({
- title: '',
- content: '评价成功,感谢您!',
- showCancel:false,
- success(res) {
- wx.navigateBack();
- }
- })
- }
- wx.hideLoading();
- }
- };
- http.request(params);
- }
-
- }
- },
- /**
- * 上传图片
- */
- getUploadImg: function(e) {
- const idx = e.target.dataset.idx
- console.log(idx);
- var ths = this;
- wx.chooseImage({
- count: 1, // 默认9
- sizeType: ['compressed'],
- sourceType: ['album', 'camera'],
- success: function (res) {
- var tempFilePaths = res.tempFilePaths;
- wx.showLoading({
- mask: true
- })
- var params = {
- url: "/p/file/upload",
- filePath: tempFilePaths[0],
- name: 'file',
- callBack: function (res2) {
- wx.hideLoading();
- var img = {};
- img.path = JSON.parse(res2).filePath;
- img.url = JSON.parse(res2).resourcesUrl + JSON.parse(res2).filePath;
- var orderItemInfo = ths.data.orderItemInfo;
- orderItemInfo[idx].images.push(img);
- ths.setData({
- orderItemInfo: orderItemInfo
- })
- }
- };
- http.upload(params);
- }
- })
- },
- /**
- * 删除图片
- */
- removeImage(e) {
- const idx = e.target.dataset.idx
- const index = e.target.dataset.index
- var orderItemInfo = this.data.orderItemInfo;
- orderItemInfo[index].images.splice(idx, 1)
- this.setData({
- orderItemInfo: orderItemInfo
- });
- },
- onContentInput:function(e){
- const index = e.target.dataset.index
- var orderItemInfo = this.data.orderItemInfo;
- orderItemInfo[index].content = e.detail.value;
- this.setData({
- orderItemInfo: orderItemInfo
- });
- },
- /**
- * 匿名评价
- * 每一项的选择事件
- */
- onSelectedItem: function (e) {
- var index = e.target.dataset.index;// 获取data- 传进来的index
- var orderItemInfo = this.data.orderItemInfo;// 获取评论项
- var isAnonymous = orderItemInfo[index].isAnonymous; // 获取当前评价的选中状态
- if (isAnonymous==1){
- isAnonymous = 0;
- }else{
- isAnonymous = 1;
- }
- orderItemInfo[index].isAnonymous = isAnonymous; // 改变状态
- this.setData({
- orderItemInfo: orderItemInfo
- });
- },
- onStarChange:function(e){
- var index = e.detail.idx;
- var val = e.detail.val;
- var evaluate = 0;
- var orderItemInfo = this.data.orderItemInfo;
- if(val<3){
- evaluate = 2;
- }else if(val==3){
- evaluate = 1;
- }
- orderItemInfo[index].score = val;
- orderItemInfo[index].evaluate = evaluate;
- this.setData({
- orderItemInfo: orderItemInfo
- });
- },
- /**
- * 评价图片预览
- */
- comPicPreView(e){
- var index = e.currentTarget.dataset.index
- var idx = e.currentTarget.dataset.idx
- var urls = []
- this.data.orderItemInfo[index].images.forEach(el => {
- urls.push(el.url)
- })
- wx.previewImage({
- current: urls[idx],
- urls: urls
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|