comment.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. datas: {},
  6. imgUrl: [],
  7. uploadImg: [],
  8. star: 0,
  9. cusStar: 0,// 客服
  10. leaderStar: 0,// 领队
  11. pgStar: 0, // 摄影师
  12. aid: '',
  13. title: '',
  14. orderid: '',
  15. type: '',
  16. act: '',
  17. content: '', //评价
  18. wordsLength: 0,//评价字数
  19. cid: '',
  20. one: [{
  21. txt: '带队技能欠佳',
  22. cet: false
  23. }, {
  24. txt: '与宣传有差距',
  25. cet: false
  26. }, {
  27. txt: '活动不合理',
  28. cet: false
  29. }, {
  30. txt: '孩子体验一般',
  31. cet: false
  32. }, {
  33. txt: '吃住有待升级',
  34. cet: false
  35. }, {
  36. txt: '性价比一般',
  37. cet: false
  38. }],
  39. two: [{
  40. txt: '正能量的小黄人',
  41. cet: false
  42. }, {
  43. txt: '领队专业细心',
  44. cet: false
  45. }, {
  46. txt: '教育意义明显',
  47. cet: false
  48. }, {
  49. txt: '活动安排有序',
  50. cet: false
  51. }, {
  52. txt: '安全措施到位',
  53. cet: false
  54. }, {
  55. txt: '性价比超值',
  56. cet: false
  57. }],
  58. chooseIndex: [],
  59. option: [],
  60. recommendArr: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], //推荐值数组
  61. recomLevel: 0, //推荐值
  62. },
  63. onLoad(options) {
  64. let orderid = options.orderid,
  65. type = options.otype,
  66. act = options.act || '';
  67. this.setData({
  68. orderid,
  69. type,
  70. act
  71. });
  72. this.getData(orderid, type, act);
  73. },
  74. getData(orderid, type, act) {
  75. let that = this;
  76. util.ajax({
  77. func: "v2/order/detail",
  78. data: {
  79. "orderid": orderid,
  80. "type": (type != undefined ? type : "")
  81. }
  82. }, function (res) {
  83. if (res.code == 0) {
  84. let datas = res.data,
  85. star = 5,
  86. uploadImg = [],
  87. content = '',
  88. wordsLength = 0,
  89. option = [],
  90. options = that.data.two,
  91. cid = '',
  92. recomLevel = 0;
  93. if (!util.isObjEmpty(datas.comment)) {
  94. cid = datas.comment.cid;
  95. that.updateCommentData(datas.comment)
  96. }
  97. if (that.data.act != 'edit') {
  98. that.getlocalData();
  99. }
  100. that.setData({
  101. aid: datas.aid,
  102. cid,
  103. datas,
  104. title: datas.title,
  105. })
  106. } else
  107. util.showTips(res.reason);
  108. })
  109. },
  110. chooseImg() {
  111. let that = this,
  112. uploadImg = that.data.uploadImg,
  113. count = 8 - uploadImg.length,
  114. img = [];
  115. wx.chooseMedia({
  116. count: count,
  117. mediaType: ['image'],
  118. sizeType: ['compressed', 'compressed'], //可以指定是原图还是压缩图
  119. sourceType: ['album', 'camera'], //从相册选择
  120. success: (res) => {
  121. let imgUrl = res.tempFiles
  122. if ((imgUrl.length + that.data.uploadImg.length) > 8) {
  123. util.showTips("最多只能上传8张照片");
  124. return false;
  125. }
  126. res.tempFiles.forEach(item => {
  127. let avatarUrl = item.tempFilePath
  128. wx.showLoading({
  129. title: '上传中…'
  130. });
  131. util.uploadFile("oss/policy", avatarUrl, {
  132. type: 'baoBeiEvaluate'
  133. }, true).then((res) => {
  134. if (res.code == 0) {
  135. uploadImg.push(res.url);
  136. img.push(res.url);
  137. if (img.length == imgUrl.length) {
  138. that.setData({
  139. uploadImg: that.data.uploadImg
  140. });
  141. wx.hideLoading();
  142. }
  143. }
  144. });
  145. })
  146. }
  147. })
  148. },
  149. delImg(e) {
  150. let index = e.currentTarget.dataset.index,
  151. uploadImg = this.data.uploadImg;
  152. uploadImg.splice(index, 1);
  153. this.setData({
  154. uploadImg
  155. })
  156. },
  157. submit() {
  158. let that = this,
  159. data = {},
  160. uploadImg = this.data.uploadImg,
  161. act = this.data.act,
  162. userInfo = app.globalData.userInfo,
  163. star = this.data.star,
  164. content = this.data.content.replace(/\n/g, '<br/>'),
  165. option = this.data.two;
  166. if (star == 1 || star == 2) {
  167. option = this.data.one;
  168. }
  169. for (let i in option) {
  170. if (option[i].cet) {
  171. content = content + '#' + option[i].txt + '#'
  172. }
  173. }
  174. let pages = getCurrentPages(),
  175. prevPage = pages[pages.length - 2];
  176. if (prevPage.route == "pages/order/detail/index") {
  177. prevPage.data.query.otype = 0;
  178. }
  179. data['aid'] = this.data.aid;
  180. data['orderid'] = this.data.orderid;
  181. data['arating'] = star; //整体活动评分
  182. data['crating'] = this.data.cusStar; //客服评分
  183. data['ratingLeader'] = this.data.leaderStar; //领队评分
  184. data['ratingPhoto'] = this.data.pgStar; //摄影师评分
  185. data['outTradeNo'] = this.data.datas.outTradeNo; // 商户订单号
  186. data['content'] = content;
  187. data['cid'] = this.data.cid;
  188. data['image'] = uploadImg ? uploadImg.join(',') : '';
  189. data['rid'] = userInfo ? userInfo['rid'] : "";
  190. data['recomLevel'] = this.data.recomLevel;
  191. if (data.arating == 0 && this.data.datas.atype == 0) {
  192. util.showTips("尚未填写活动评分,请填写后再进行提交~");
  193. return false;
  194. }
  195. if (data.crating == 0 && this.data.datas.atype == 0) {
  196. util.showTips("请对于客服这次的服务打分。");
  197. return false;
  198. }
  199. if (data.ratingLeader == 0 && this.data.datas.atype == 0) {
  200. util.showTips("请对于领队这次的服务打分。");
  201. return false;
  202. }
  203. if (data.ratingPhoto == 0 && this.data.datas.atype == 0) {
  204. util.showTips("请对于摄影师这次的服务打分。");
  205. return false;
  206. }
  207. if (data.recomLevel <= 0 && this.data.datas.atype == 0) {
  208. util.showTips("请点击数字对本次活动体验进行打分。");
  209. return false;
  210. }
  211. if (util.isEmpty(data.content)) {
  212. util.showTips(this.data.datas.atype == 0 ? "请填写本次活动体验后的评价。" : '请填写对此商品的评价。');
  213. return false;
  214. }
  215. util.ajax({
  216. func: (act == 'edit' ? "v2/comments/order/update" : "v2/comments/order/addcomment"),
  217. data: data,
  218. method: "POST",
  219. load: true,
  220. title: '提交中'
  221. }, function (res) {
  222. if (res.code == 0) {
  223. if (act == 'edit' || that.data.datas.atype == 1) {
  224. wx.navigateBack();
  225. } else {
  226. wx.redirectTo({
  227. url: '/pages/order/scratch/scratch?orderid=' + that.data.orderid + '&coin=' + res.data || 0
  228. })
  229. }
  230. } else {
  231. util.showTips(res.reason);
  232. }
  233. });
  234. },
  235. // 获取的评论数据整理公共方法
  236. updateCommentData(commentData) {
  237. let star = 5,
  238. cusStar = 5,
  239. leaderStar = 5,
  240. pgStar = 5,
  241. uploadImg = [],
  242. content = '',
  243. wordsLength = 0,
  244. option = [],
  245. options = this.data.two,
  246. recomLevel = 0;
  247. star = commentData.arating;
  248. cusStar = commentData.crating;
  249. leaderStar = commentData.leaderStar;
  250. pgStar = commentData.pgStar;
  251. recomLevel = commentData.recomLevel;
  252. uploadImg = commentData.images || [];
  253. content = commentData.content.replace(/#([^#]+)#/g, "").replace(/<br\/>/g, '\n');
  254. option = commentData.content.match(/#([^#]+)#/g);
  255. star >= 3 || star == 0 ? options = this.data.two : options = this.data.one;
  256. for (let i in option) {
  257. option[i] = option[i].replace(/#/g, "");
  258. for (let k in options) {
  259. if (option[i] == options[k].txt) {
  260. options[k].cet = true
  261. }
  262. }
  263. }
  264. if (star >= 3 || star == 0) {
  265. this.setData({
  266. two: options
  267. })
  268. } else {
  269. this.setData({
  270. one: options
  271. })
  272. }
  273. this.setData({
  274. star,
  275. cusStar,
  276. leaderStar,
  277. pgStar,
  278. uploadImg,
  279. content,
  280. wordsLength: content.length,
  281. recomLevel
  282. })
  283. },
  284. // 获取本地草稿数据
  285. getlocalData() {
  286. if (!util.isObjEmpty(wx.getStorageSync("orderComment"))) {
  287. let localData = wx.getStorageSync("orderComment");
  288. if (localData.orderid == this.data.orderid) {
  289. this.updateCommentData(localData)
  290. }
  291. }
  292. },
  293. // 保存草稿至本地
  294. saveDataToLocal() {
  295. let that = this,
  296. commentData = {},
  297. option = this.data.two;
  298. if (!util.isEmpty(this.data.content) || this.data.uploadImg.length > 0) {
  299. commentData.orderid = this.data.orderid;
  300. commentData.saveDate = util.getNowFormatDate('yyyy-MM-dd hh:mm:ss');
  301. commentData.arating = this.data.star;
  302. commentData.crating = this.data.cusStar;
  303. commentData.leaderStar = this.data.leaderStar;
  304. commentData.pgStar = this.data.pgStar;
  305. commentData.recomLevel = this.data.recomLevel;
  306. commentData.images = this.data.uploadImg || '';
  307. let content = this.data.content.replace(/\n/g, '<br/>');
  308. if (this.data.star == 1 || this.data.star == 2) {
  309. option = this.data.one;
  310. }
  311. for (let i in option) {
  312. if (option[i].cet) {
  313. content = content + '#' + option[i].txt + '#'
  314. }
  315. }
  316. commentData.content = content;
  317. wx.setStorageSync("orderComment", commentData);
  318. }
  319. },
  320. chooseOpt: function (e) {
  321. var star = this.data.star,
  322. chooseIndex = this.data.chooseIndex,
  323. index = e.currentTarget.dataset.index,
  324. option = this.data.two;
  325. if (star == 1 || star == 2) {
  326. option = this.data.one;
  327. }
  328. if (option[index].cet) {
  329. option[index].cet = false;
  330. } else {
  331. option[index].cet = true;
  332. }
  333. if (star == 1 || star == 2) {
  334. this.setData({
  335. one: option
  336. });
  337. } else {
  338. this.setData({
  339. two: option
  340. });
  341. }
  342. },
  343. bindblur: function (e) {
  344. this.setData({
  345. content: e.detail.value,
  346. wordsLength: e.detail.value.length
  347. });
  348. },
  349. bindstar: function (e) {
  350. if (e.currentTarget.dataset.type == 'star') {
  351. if (this.data.star == 0 || !this.data.star) {
  352. this.setData({
  353. cusStar: e.target.dataset.index,
  354. leaderStar: e.target.dataset.index,
  355. pgStar: e.target.dataset.index,
  356. });
  357. }
  358. this.setData({
  359. star: e.target.dataset.index
  360. });
  361. } else if (e.currentTarget.dataset.type == 'leaderStar') {
  362. this.setData({
  363. leaderStar: e.target.dataset.index
  364. });
  365. } else if (e.currentTarget.dataset.type == 'pgStar') {
  366. this.setData({
  367. pgStar: e.target.dataset.index
  368. });
  369. } else {
  370. this.setData({
  371. cusStar: e.target.dataset.index
  372. });
  373. }
  374. },
  375. recommend(e) {
  376. this.setData({
  377. recomLevel: e.target.dataset.number
  378. })
  379. },
  380. onUnload: function () {
  381. if (this.data.datas.atype == '0') {
  382. this.saveDataToLocal()
  383. }
  384. },
  385. onHide() {
  386. if (this.data.datas.atype == '0') {
  387. this.saveDataToLocal()
  388. }
  389. }
  390. })