commentPost.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. var api = require('../../config/api.js');
  4. Page({
  5. data: {
  6. typeId: 0,
  7. mannerScore: 5,//服务态度
  8. speedScore: 5,//配送速度
  9. goodsList: [{
  10. score: 5,
  11. comment: '',
  12. pics: []
  13. },{
  14. score: 5,
  15. comment: '',
  16. pics: []
  17. }],
  18. orderId:0,
  19. orderInfo: {}, // 订单详情
  20. orderGoods: {}, // 订单商品
  21. coupon: {},
  22. handleDesc: ['很差','一般','满意','很满意','非常满意']
  23. },
  24. handleScore(e){
  25. let aim = e.currentTarget.dataset.aim;
  26. let score = e.currentTarget.dataset.score;
  27. let obj = {};
  28. obj[aim] = score;
  29. this.setData(obj);
  30. },
  31. previewPic(e){
  32. let urls = e.currentTarget.dataset.urls;
  33. wx.previewImage({
  34. urls
  35. })
  36. },
  37. handleDelete(e){
  38. let that = this;
  39. let src = e.currentTarget.dataset.src;
  40. let goodsIndex = e.currentTarget.dataset.goodsIndex;
  41. let pics = e.currentTarget.dataset.pics;
  42. pics = pics.filter(item => item != src);
  43. //
  44. let goodsList = that.data.goodsList;
  45. goodsList[goodsIndex].pics = pics;
  46. this.setData({
  47. goodsList:goodsList
  48. });
  49. },
  50. bindInpuntValue(event) {
  51. let that = this;
  52. let goodsIndex = event.target.dataset.goodsIndex;
  53. let value = event.detail.value;
  54. let goodsList = that.data.goodsList;
  55. goodsList[goodsIndex].comment = value
  56. this.setData({
  57. goodsList:goodsList
  58. })
  59. },
  60. chooseImageTap: function (e) {
  61. let that = this;
  62. let goodsIndex = e.currentTarget.dataset.goodsIndex;
  63. let pics = e.currentTarget.dataset.pics;
  64. wx.showActionSheet({
  65. itemList: ['从相册中选择', '拍照'],
  66. itemColor: "#f7982a",
  67. success: function (res) {
  68. if (!res.cancel) {
  69. if (res.tapIndex == 0) {
  70. that.chooseWxImage('album', goodsIndex, pics);
  71. } else if (res.tapIndex == 1) {
  72. that.chooseWxImage('camera', goodsIndex, pics);
  73. }
  74. }
  75. }
  76. })
  77. },
  78. chooseWxImage: function (type, goodsIndex, pics) {
  79. let _this = this;
  80. wx.chooseImage({
  81. sizeType: ['original', 'compressed'],
  82. sourceType: [type],
  83. success: function (res) {
  84. var tempFilePaths = res.tempFilePaths
  85. console.log(res);
  86. wx.uploadFile({
  87. url: api.UploadFileURL,
  88. filePath: tempFilePaths[0],
  89. name: 'file',
  90. header: {
  91. 'content-type': 'multipart/form-data'
  92. },
  93. success: function (res) {
  94. var pic = JSON.parse(res.data);
  95. pics.unshift(pic.data);
  96. let goodsList = _this.data.goodsList;
  97. goodsList[goodsIndex].pics = pics;
  98. _this.setData({
  99. goodsList:goodsList
  100. })
  101. }
  102. })
  103. }
  104. })
  105. },
  106. onLoad: function (options) {
  107. var that = this;
  108. that.setData({
  109. typeId: parseInt(options.typeId),
  110. orderId: parseInt(options.orderId)
  111. });
  112. that.getOrderDetail();
  113. },
  114. onClose() {
  115. wx.navigateBack({
  116. delta: 1
  117. });
  118. },
  119. onPost() {
  120. let that = this;
  121. util.request(api.CommentPost, {
  122. typeId: that.data.typeId,
  123. orderId: that.data.orderId,
  124. mannerScore: that.data.mannerScore,
  125. speedScore: that.data.speedScore,
  126. goodsList: that.data.goodsList
  127. }, 'POST').then(function (res) {
  128. if (res.errno === 0 && res.data.coupon) {
  129. that.setData({
  130. coupon: res.data.coupon
  131. });
  132. } else if (res.errno === 0) {
  133. wx.showToast({
  134. title: '评论成功',
  135. duration: 2000
  136. });
  137. setTimeout(function () {
  138. wx.navigateBack({
  139. delta: 2
  140. });
  141. }, 2000);
  142. }
  143. console.log(res)
  144. });
  145. },
  146. couponClickBack: function () {
  147. wx.navigateBack({
  148. delta: 2
  149. });
  150. },
  151. onReady: function () {
  152. },
  153. onShow: function () {
  154. // 页面显示
  155. },
  156. onHide: function () {
  157. // 页面隐藏
  158. },
  159. onUnload: function () {
  160. // 页面关闭
  161. } ,
  162. getOrderDetail() {
  163. let that = this;
  164. util.request(api.OrderDetail, {
  165. orderId: that.data.orderId
  166. }).then(function (res) {
  167. if (res.errno === 0) {
  168. console.log(res.data);
  169. that.setData({
  170. orderInfo: res.data.orderInfo,
  171. orderGoods: res.data.orderGoods,
  172. });
  173. var goodsList = new Array();
  174. for(var i=0;i<res.data.orderGoods.length;i++) {
  175. let goodVo = {};
  176. goodVo.goods_id = res.data.orderGoods[i].goods_id;
  177. goodVo.goods_name = res.data.orderGoods[i].goods_name;
  178. goodVo.product_id = res.data.orderGoods[i].product_id;
  179. goodVo.list_pic_url = res.data.orderGoods[i].list_pic_url;
  180. goodVo.goods_specification_name_value = null!=res.data.orderGoods[i].goods_specification_name_value?res.data.orderGoods[i].goods_specification_name_value:"";
  181. goodVo.score = 5;
  182. goodVo.pics = [];
  183. goodVo.comment = '';
  184. goodsList.push(goodVo);
  185. }
  186. that.setData({goodsList:goodsList
  187. });
  188. }
  189. });
  190. }
  191. })