addComment.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. imgUrl:[],
  6. uploadImg:[],
  7. fcontent:'',
  8. datas:{},
  9. submitData:{},
  10. act:'',
  11. atype:'',
  12. },
  13. onLoad(options) {
  14. let orderid = options.orderid;
  15. let type = options.otype;
  16. let act = options.act || '';
  17. this.getData(options.orderid,options.type,options.act)
  18. },
  19. getData(orderid,type,act){
  20. let userInfo = app.globalData.userInfo;
  21. let that = this;
  22. util.ajax({
  23. func:"v2/order/detail",
  24. data:{"orderid":orderid,"type":(type != undefined ? type : ""),}
  25. },function(res){
  26. if(res.code == 0){
  27. let atype = res.data.atype;
  28. let datas = res.data.comment;
  29. let uploadImg = datas.additionalComment.images || [];
  30. let fcontent = datas.additionalComment.content ? datas.additionalComment.content.replace(/<br\/>/g,'\n') : '';
  31. let submitData = {};
  32. submitData.aid = res.data.aid;
  33. submitData.orderid = res.data.orderid;
  34. submitData.cid = act == "edit" ? datas.additionalComment.cid : datas.cid;
  35. submitData.rid = userInfo ? userInfo['rid']:"";
  36. that.setData({uploadImg,fcontent,submitData,act,datas,atype})
  37. }else
  38. util.showTips(res.reason);
  39. })
  40. },
  41. submit(){
  42. var submitData = this.data.submitData,that = this;
  43. submitData['image'] = this.data.uploadImg.join(",");
  44. submitData['content'] = this.data.fcontent.replace(/\n/g,'<br/>');
  45. if(util.isEmpty(submitData.content)){
  46. util.showTips("请填写追加的评价。");
  47. return false;
  48. }
  49. util.ajax({
  50. func: (that.data.act == 'edit' ? "v2/comments/order/update" :"v2/comments/order/additional"),
  51. data:submitData,
  52. method: "POST",
  53. load:true,
  54. title:'提交中'
  55. },function(res){
  56. if(res.code == 0){
  57. util.showTips('评价提交成功');
  58. setTimeout(function(){
  59. wx.navigateBack();
  60. },2000)
  61. }else{
  62. util.showTips(res.reason);
  63. }
  64. });
  65. },
  66. chooseImg(){
  67. let that = this, uploadImg = that.data.uploadImg, count = 8;
  68. wx.chooseImage({
  69. count:count,
  70. sizeType: ['original', 'compressed'],
  71. sourceType: ['album', 'camera'],
  72. success: function (res) {
  73. var imgUrl = res.tempFilePaths;
  74. if (count - (imgUrl.length + uploadImg.length) < 0) {
  75. util.showTips("最多只能上传" + count + "张图片");
  76. return false;
  77. }
  78. wx.showLoading({ title: '上传中…' });
  79. let img = [];
  80. that.data.upImg = [];
  81. for(let i in imgUrl){//上传图片
  82. wx.uploadFile({
  83. url: util.config.apiServer + 'user/upload_img_app.do',
  84. filePath: imgUrl[i],
  85. name: 'avatarFile',
  86. formData:{"rid":app.globalData.userInfo['rid']},
  87. success: function(reason){
  88. let datas = JSON.parse(reason.data);
  89. if (reason.statusCode==200&&datas.code == 0) {
  90. img.push(datas.data.image);
  91. that.setData({ uploadCount: imgUrl.length, uploadImg, upImg: img });
  92. if (that.data.upImg.length == that.data.uploadCount) {
  93. that.data.uploadImg = [...that.data.upImg, ...that.data.uploadImg];
  94. that.setData({ uploadImg: that.data.uploadImg });
  95. wx.hideLoading();
  96. }
  97. }
  98. }
  99. })
  100. }
  101. }
  102. })
  103. },
  104. delImg(e){
  105. let index = e.currentTarget.dataset.index,uploadImg = this.data.uploadImg;
  106. uploadImg.splice(index,1);
  107. this.setData({uploadImg})
  108. },
  109. bindblur(e){
  110. this.setData({fcontent:e.detail.value})
  111. }
  112. })