index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. // nova-tourism/pages/my/my-order/my-refund/refund-good/index.js
  2. let Parse = getApp().Parse;
  3. const company = getApp().globalData.company
  4. const uid = Parse.User.current()?.id
  5. const dateF = require("../../../../../../utils/date")
  6. const qiniuUploader = require("../../../../../../utils/qiniuUploader");
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. order: null, //订单
  13. way: '退货退款', //退换方式
  14. wayList: [{
  15. name: '退货退款'
  16. },
  17. {
  18. name: '退款(无需退货)'
  19. },
  20. {
  21. name: '换货'
  22. },
  23. ], //可选退换方式
  24. cause: '不想要了', //原因
  25. causeList: [{
  26. name: '不想要了'
  27. },
  28. {
  29. name: '商品瑕疵'
  30. },
  31. {
  32. name: '少件漏发'
  33. },
  34. {
  35. name: '商家发错货'
  36. },
  37. {
  38. name: '其他原因'
  39. },
  40. ], //可选原因
  41. content: '', //描述
  42. tempFiles: [], //图片-本地
  43. refundImgs: [], //图片
  44. isShowWay: false, //选择退货方式弹框
  45. isShowCause: false, //选择原因弹框
  46. },
  47. /**
  48. * 生命周期函数--监听页面加载
  49. */
  50. onLoad(options) {
  51. this.getToken()
  52. let {
  53. oid
  54. } = options
  55. console.log(options)
  56. this.setData({
  57. oid
  58. })
  59. this.getOrder()
  60. },
  61. /**上传图片 */
  62. getTemp() {
  63. let {
  64. tempFiles
  65. } = this.data
  66. let that = this
  67. wx.chooseMedia({
  68. count: 9,
  69. mediaType: 'image',
  70. success: (res) => {
  71. console.log(res)
  72. let tempPathList = res.tempFiles?.map(item => item.tempFilePath)
  73. that.setData({
  74. tempFiles: [...tempFiles, ...(tempPathList || [])]
  75. })
  76. }
  77. })
  78. },
  79. /**删除图片 */
  80. del(e) {
  81. let {
  82. index
  83. } = e.currentTarget.dataset
  84. let {
  85. tempFiles
  86. } = this.data
  87. tempFiles.splice(index, 1)
  88. this.setData({
  89. tempFiles
  90. })
  91. },
  92. /** 获取token 上传图片所需*/
  93. async getToken() {
  94. let res = await Parse.Cloud.run('qiniu_uptoken', {
  95. company: company
  96. })
  97. this.setData({
  98. uptokenURL: res.uptoken,
  99. domain: res.domain,
  100. uploadURL: res.zoneUrl
  101. })
  102. },
  103. /**转换图片链接 */
  104. async upFileCall() {
  105. let {
  106. tempFiles
  107. } = this.data
  108. console.log(tempFiles)
  109. let that = this
  110. for (let i in tempFiles) {
  111. let item = tempFiles[i]
  112. await qiniuUploader.upload(
  113. item,
  114. async (res) => {
  115. let {
  116. refundImgs
  117. } = that.data
  118. console.log(res)
  119. refundImgs.push(res?.imageURL)
  120. that.setData({
  121. refundImgs
  122. })
  123. },
  124. (error) => {
  125. console.log("error: " + error);
  126. }, {
  127. region: "SCN",
  128. uploadURL: that.data.uploadURL,
  129. domain: that.data.domain,
  130. uptoken: that.data.uptokenURL,
  131. }
  132. );
  133. }
  134. },
  135. /**提交 */
  136. async submit() {
  137. let {
  138. content
  139. } = this.data
  140. if (!content) {
  141. wx.showToast({
  142. title: '请描述退款原因',
  143. icon: 'none'
  144. })
  145. return
  146. }
  147. wx.showLoading()
  148. let that = this
  149. await this.upFileCall()
  150. let interval = setInterval(async () => {
  151. if (that.data.refundImgs?.length == that.data.tempFiles?.length) {
  152. await that.saveOrder()
  153. clearInterval(interval)
  154. }
  155. }, 1000);
  156. },
  157. async saveOrder() {
  158. let {
  159. way,
  160. cause,
  161. content,
  162. refundImgs,
  163. orderParse
  164. } = this.data
  165. orderParse.set('status', '500')
  166. orderParse.set('content', `退换方式:${way}。原因:${cause}。描述:${content}`)
  167. orderParse.set('refundImgs', refundImgs || [])
  168. wx.hideLoading()
  169. try {
  170. await orderParse.save()
  171. await wx.showToast({
  172. title: '已提交退款申请',
  173. icon: 'none'
  174. })
  175. setTimeout(() => {
  176. wx.navigateBack({
  177. delta: 2,
  178. })
  179. }, 900);
  180. } catch (error) {
  181. wx.showToast({
  182. title: '出错了请检查后重试',
  183. icon: 'error'
  184. })
  185. }
  186. },
  187. /**获取订单 */
  188. async getOrder() {
  189. let {
  190. oid
  191. } = this.data
  192. let query = new Parse.Query('Order')
  193. query.include('targetObject')
  194. let d = await query.get(oid)
  195. let order = d?.toJSON()
  196. console.log(order)
  197. this.setData({
  198. order,
  199. orderParse: d
  200. })
  201. },
  202. closeWay() {
  203. this.setData({
  204. isShowWay: false
  205. });
  206. },
  207. openWay() {
  208. this.setData({
  209. isShowWay: true
  210. });
  211. },
  212. selectWay(event) {
  213. this.setData({
  214. way: event?.detail?.name || '退货退款'
  215. })
  216. },
  217. closeCause() {
  218. this.setData({
  219. isShowCause: false
  220. });
  221. },
  222. openCause() {
  223. this.setData({
  224. isShowCause: true
  225. });
  226. },
  227. selectCause(event) {
  228. this.setData({
  229. cause: event?.detail?.name || '不想要了'
  230. })
  231. },
  232. /**
  233. * 生命周期函数--监听页面初次渲染完成
  234. */
  235. onReady() {
  236. },
  237. /**
  238. * 生命周期函数--监听页面显示
  239. */
  240. onShow() {
  241. },
  242. /**
  243. * 生命周期函数--监听页面隐藏
  244. */
  245. onHide() {
  246. },
  247. /**
  248. * 生命周期函数--监听页面卸载
  249. */
  250. onUnload() {
  251. },
  252. /**
  253. * 页面相关事件处理函数--监听用户下拉动作
  254. */
  255. onPullDownRefresh() {
  256. },
  257. /**
  258. * 页面上拉触底事件的处理函数
  259. */
  260. onReachBottom() {
  261. },
  262. /**
  263. * 用户点击右上角分享
  264. */
  265. onShareAppMessage() {
  266. }
  267. })