| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- var http = require('../../utils/http.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- orderItemInfo: {
- images: [],
- content: "",
- score: 5,
- isAnonymous: 1,
- evaluate: 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;
- if(orderItemInfo.content.trim()==""){
- return wx.showToast({
- title: '评价不能为空',
- icon:"none"
- })
- }
- wx.showLoading();
- var pics = '';
- orderItemInfo.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.content,
- score: orderItemInfo.score,
- evaluate: orderItemInfo.evaluate,
- isAnonymous: orderItemInfo.isAnonymous,
- orderItemId: orderItemInfo.orderItemId,
- prodId: orderItemInfo.prodId,
- pics: pics
- },
- callBack: (res) => {
-
- wx.hideLoading();
- wx.navigateTo({
- url: '/pages/commResult/commResult',
- })
- }
- };
- http.request(params);
-
- },
- /**
- * 上传图片
- */
- getUploadImg: function(e) {
- 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.images.push(img);
- ths.setData({
- orderItemInfo: orderItemInfo
- })
- }
- };
- http.upload(params);
- }
- })
- },
- /**
- * 删除图片
- */
- removeImage(e) {
- const idx = e.target.dataset.idx
- var orderItemInfo = this.data.orderItemInfo;
- orderItemInfo.images.splice(idx, 1)
- this.setData({
- orderItemInfo: orderItemInfo
- });
- },
- onContentInput:function(e){
- const index = e.target.dataset.index
- var orderItemInfo = this.data.orderItemInfo;
- orderItemInfo.content = e.detail.value;
- this.setData({
- orderItemInfo: orderItemInfo
- });
- },
- /**
- * 匿名评价
- * 每一项的选择事件
- */
- onSelectedItem: function (e) {
- var orderItemInfo = this.data.orderItemInfo;// 获取评论项
- var isAnonymous = orderItemInfo.isAnonymous; // 获取当前评价的选中状态
- if (isAnonymous==1){
- isAnonymous = 0;
- }else{
- isAnonymous = 1;
- }
- orderItemInfo.isAnonymous = isAnonymous; // 改变状态
- this.setData({
- orderItemInfo: orderItemInfo
- });
- },
- onStarChange:function(e){
- var index = e.detail.idx;
- var val = e.detail.val;
- console.log(e);
- var evaluate = 0;
- var orderItemInfo = this.data.orderItemInfo;
- if(val<3){
- evaluate = 2;
- }else if(val==3){
- evaluate = 1;
- }
- orderItemInfo.score = val;
- orderItemInfo.evaluate = evaluate;
- this.setData({
- orderItemInfo: orderItemInfo
- });
- },
- /**
- * 评价图片预览
- */
- comPicPreView(e){
- var idx = e.currentTarget.dataset.idx
- var urls = []
- this.data.orderItemInfo.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 () {
- }
- })
|