refund.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. // pages/groupmeallist/refund/refund.js
  2. import order from '../../../api/order'
  3. const cache = require('../../../utils/cache.js');
  4. import base from "../../../utils/base";
  5. import Upload from '../../../api/upload'
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. orderGoodList: [{}, {}, {}, {}],
  12. showAllSku: false,
  13. orderInfo: {},
  14. orderSn: '',
  15. chooseViewShowBanner: true,
  16. orderGoodList: [], //spu-sku商品信息
  17. isShowPannel: false,
  18. reasonValue: '请选择退款原因',
  19. reasonDetailValue: '',
  20. avatarUrlShow: [],
  21. t_length: 0,
  22. avatarUrl: [],
  23. reasonListChecked: false,
  24. reasonList: [{
  25. text: '不想要了/临时有事',
  26. checked: false
  27. }, {
  28. text: '点错了/点多了/点少了',
  29. checked: false
  30. }, {
  31. text: '地址/电话填错了',
  32. checked: false
  33. }, {
  34. text: '忘记用红包/优惠券',
  35. checked: false
  36. }, {
  37. text: '菜品质量问题',
  38. checked: false
  39. }, {
  40. text: '出餐/送餐速度过慢',
  41. checked: false
  42. }, {
  43. text: '没有按承诺的优惠',
  44. checked: false
  45. }, {
  46. text: '其他',
  47. checked: false
  48. }, ]
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad: function (options) {
  54. if (options.sn) {
  55. this.reloadPage(options.sn)
  56. }
  57. },
  58. reloadPage(orderSn) {
  59. this.setData({
  60. orderSn
  61. })
  62. this.getOrderdetail();
  63. },
  64. listenInput(e) {
  65. let value = e.detail.value;
  66. this.setData({
  67. reasonDetailValue: value
  68. })
  69. },
  70. callStorePerson() {
  71. let phone = this.data.orderInfo.store.liaisonPhone;
  72. wx.makePhoneCall({
  73. phoneNumber: phone
  74. })
  75. },
  76. /** 图片选择 */
  77. bindViewTap: function () {
  78. var that = this;
  79. if (this.data.avatarUrlShow.length < 4) {
  80. wx.chooseImage({
  81. // 设置最多可以选择的图片张数,默认9,如果我们设置了多张,那么接收时//就不在是单个变量了,
  82. count: 1,
  83. sizeType: ['original', 'compressed'], // original 原图,compressed 压缩图,默认二者都有
  84. sourceType: ['album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
  85. success: function (res) {
  86. // 获取成功,将获取到的地址赋值给临时变量
  87. console.log(res);
  88. if (res.tempFilePaths.count == 0) {
  89. return;
  90. }
  91. //图片上传到金山云
  92. var tempFilePaths = res.tempFilePaths
  93. wx.uploadFile({
  94. url: Upload.uploadPic(),
  95. filePath: tempFilePaths[0],
  96. name: 'file',
  97. formData: {
  98. 'basePath': 'welfareMall',
  99. },
  100. success: function (res) {
  101. //提交路径
  102. var urlImg = JSON.parse(res.data).data.url;
  103. //展示路径
  104. var destPath = JSON.parse(res.data).data.destPath;
  105. var imgArrNow = that.data.avatarUrl;
  106. var imgArrNowShow = that.data.avatarUrlShow;
  107. imgArrNow.push(urlImg);
  108. imgArrNowShow.push(destPath);
  109. if (that.data.avatarUrlShow.length > 4) {
  110. wx.showToast({
  111. title: '最多添加4张图片',
  112. icon: 'none',
  113. duration: 1500
  114. })
  115. return
  116. }
  117. that.setData({
  118. //将临时变量赋值给已经在data中定义好的变量
  119. avatarUrl: imgArrNow,
  120. avatarUrlShow: imgArrNowShow
  121. })
  122. that.chooseViewShowBanner();
  123. },
  124. fail: function (err) {
  125. console.log(err);
  126. },
  127. })
  128. },
  129. fail: function (res) {
  130. // fail
  131. },
  132. complete: function (res) {
  133. // complete
  134. }
  135. })
  136. } else {
  137. wx.showToast({
  138. title: '最多添加4张图片',
  139. icon: 'none',
  140. duration: 1500
  141. })
  142. }
  143. },
  144. /** 删除图片Banner */
  145. deleteImvBanner: function (e) {
  146. var avatarUrlShow = this.data.avatarUrlShow;
  147. var avatarUrl = this.data.avatarUrl;
  148. var itemIndex = e.currentTarget.dataset.id;
  149. avatarUrlShow.splice(itemIndex, 1);
  150. avatarUrl.splice(itemIndex, 1);
  151. this.setData({
  152. avatarUrlShow: avatarUrlShow
  153. })
  154. //判断是否隐藏选择图片
  155. this.chooseViewShowBanner();
  156. },
  157. /** 是否隐藏图片选择Banner*/
  158. chooseViewShowBanner: function () {
  159. if (this.data.avatarUrlShow.length > 3) {
  160. this.setData({
  161. chooseViewShowBanner: false
  162. })
  163. } else {
  164. this.setData({
  165. chooseViewShowBanner: true
  166. })
  167. }
  168. },
  169. // 选中改变
  170. changeChecked(e) {
  171. let index = e.currentTarget.dataset.id;
  172. let value = '';
  173. this.data.reasonList.forEach((item, id) => {
  174. if (id == index) {
  175. item.checked = true
  176. value = item.text
  177. } else {
  178. item.checked = false
  179. }
  180. })
  181. this.setData({
  182. reasonList: this.data.reasonList,
  183. reasonValue: value,
  184. reasonListChecked: true
  185. // isShowPannel: false
  186. })
  187. },
  188. /**
  189. * 获取订单详情
  190. */
  191. async getOrderdetail() {
  192. let _self = this;
  193. try {
  194. let orderRes = await order.getOrderDetail({
  195. orderSn: _self.data.orderSn,
  196. mobile: cache.getMobile()
  197. });
  198. if (orderRes.code == 200 && orderRes.msg == "success") {
  199. let orderInfo = orderRes.data;
  200. orderInfo.originPrice = (parseFloat(orderInfo.payPrice) / 100).toFixed(2)
  201. _self.setData({
  202. orderInfo: orderInfo,
  203. })
  204. //组建spu sku
  205. _self.createOrderGoodList(orderInfo.orderGoodsList)
  206. }
  207. } catch (error) {
  208. console.log(error);
  209. }
  210. },
  211. closeCartPannel: function () {
  212. this.setData({
  213. isShowPannel: false
  214. })
  215. },
  216. //显示对话框
  217. showCartPannel: function () {
  218. // 显示遮罩层
  219. var animation = wx.createAnimation({
  220. duration: 100,
  221. timingFunction: "linear",
  222. delay: 0
  223. })
  224. this.animation = animation
  225. animation.translateY(300).step()
  226. this.setData({
  227. animationData: animation.export(),
  228. isShowPannel: true
  229. })
  230. setTimeout(function () {
  231. animation.translateY(0).step()
  232. this.setData({
  233. animationData: animation.export()
  234. })
  235. }.bind(this), 100)
  236. },
  237. submit() {
  238. if (this.data.reasonListChecked) {
  239. order.refund({
  240. mobile: cache.getMobile(),
  241. orderSn: this.data.orderSn,
  242. reason: this.data.reasonValue + this.data.reasonDetailValue,
  243. photoList: this.data.avatarUrl
  244. }).then(res => {
  245. wx.redirectTo({
  246. url: '../../welfareMall/historical/historical',
  247. })
  248. })
  249. }else{
  250. wx.showToast({
  251. title: '请选择退款理由',
  252. icon: 'none',
  253. duration: 1000
  254. })
  255. }
  256. },
  257. /**
  258. * 组建spu sku
  259. * @param {*} list
  260. */
  261. createOrderGoodList(list) {
  262. console.log("进入详情")
  263. console.log(list)
  264. let _self = this;
  265. if (list.length == 0) {
  266. return;
  267. }
  268. let orderGoodList = [];
  269. for (let a = 0; a < list.length; a++) { //最外层
  270. //某一个商品种类
  271. let goodList = list[a];
  272. //sku-list
  273. let orderGoodsSkuList = goodList.orderGoodsSkuList;
  274. let fullFigure = list[a].fullFigure;
  275. for (let b = 0; b < orderGoodsSkuList.length; b++) {
  276. let orderGood = {};
  277. orderGood.productName = goodList.productName;
  278. let orderGoodsSku = orderGoodsSkuList[b];
  279. let text = '';
  280. if (orderGoodsSku.comboSkuList != null && orderGoodsSku.comboSkuList.length > 0) {
  281. console.log("进入套餐拼接")
  282. text = "套餐:"
  283. let productName = ''
  284. let specValue = []
  285. let num = ''
  286. orderGoodsSku.comboSkuList.forEach(function (comboSkuList, index) {
  287. comboSkuList.skuList.forEach(function (skuList, skuindex) {
  288. productName = skuList.productName
  289. num = skuList.num
  290. if (skuList.specList != null) {
  291. let specList = JSON.parse(skuList.specList);
  292. if (base.isArray(specList)) {
  293. specList.forEach(function (specList, skuindex) {
  294. specValue.push(specList.specValue + " X" + num)
  295. })
  296. }
  297. } else {
  298. specValue.push(productName + " X" + num)
  299. }
  300. })
  301. })
  302. specValue = specValue.join('、') || ""
  303. text = text + "(" + specValue + ")"
  304. }
  305. orderGood.num = orderGoodsSkuList[b].num;
  306. orderGood.allFee = base.fenToYuan(orderGoodsSkuList[b].price * orderGoodsSkuList[b].num)
  307. orderGood.skuText = text
  308. orderGood.fullFigure = fullFigure
  309. orderGoodList.push(orderGood)
  310. }
  311. }
  312. _self.setData({
  313. orderGoodList: orderGoodList
  314. })
  315. console.log(this.data.orderGoodList)
  316. },
  317. /**
  318. * 生命周期函数--监听页面初次渲染完成
  319. */
  320. onReady: function () {
  321. },
  322. /**
  323. * 生命周期函数--监听页面显示
  324. */
  325. onShow: function () {
  326. },
  327. /**
  328. * 生命周期函数--监听页面隐藏
  329. */
  330. onHide: function () {
  331. },
  332. /**
  333. * 生命周期函数--监听页面卸载
  334. */
  335. onUnload: function () {
  336. },
  337. /**
  338. * 页面相关事件处理函数--监听用户下拉动作
  339. */
  340. onPullDownRefresh: function () {
  341. },
  342. /**
  343. * 页面上拉触底事件的处理函数
  344. */
  345. onReachBottom: function () {
  346. },
  347. /**
  348. * 用户点击右上角分享
  349. */
  350. onShareAppMessage: function () {
  351. },
  352. showlable() {
  353. }
  354. })