index.js 5.4 KB

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