refund.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. // pages/order/refund.js
  2. var util = require('../../utils/util.js');
  3. var app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. xarray: ['点击选择退款理由', '商品有质量问题', '没有收到货', '商品少发漏发发错', '商品与描述不一致', '收到商品时有划痕或破损', '质疑假货', '其他'],
  10. index: 0,
  11. refund_type: 1,
  12. refund_money: 0,
  13. refund_imgs: [],
  14. mobile: '',
  15. refund_thumb_imgs: [],
  16. refund_miaoshu: '',
  17. order_id: 0,
  18. order_status_id: -1
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. //get_order_money
  25. var order_id = options.id;
  26. var order_goods_id = options.order_goods_id;
  27. this.setData({
  28. order_id: order_id,
  29. order_goods_id: order_goods_id
  30. })
  31. var token = wx.getStorageSync('token');
  32. var that = this;
  33. app.util.request({
  34. 'url': 'entry/wxapp/index',
  35. 'data': {
  36. controller: 'user.get_order_money',
  37. token: token,
  38. order_id: order_id,
  39. order_goods_id: order_goods_id
  40. },
  41. dataType: 'json',
  42. success: function (res) {
  43. if (res.data.code == 3) {
  44. //un login
  45. } else if (res.data.code == 1) {
  46. //code goods_image
  47. that.setData({
  48. total_money: res.data.total,
  49. order_status_id: res.data.order_status_id
  50. })
  51. }
  52. }
  53. })
  54. },
  55. bindPickerChange: function (e) {
  56. //console.log('picker发送选择改变,携带值为', e.detail.value)
  57. this.setData({
  58. index: e.detail.value
  59. })
  60. },
  61. choseImg: function () {
  62. var self = this;
  63. var refund_imgs = this.data.refund_imgs;
  64. if (refund_imgs.length >= 3) {
  65. wx.showToast({
  66. title: '最多三张图片',
  67. icon: 'success',
  68. duration: 1000
  69. })
  70. return false;
  71. }
  72. wx.chooseImage({
  73. count: 1, // 默认9
  74. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  75. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  76. success: function (res) {
  77. // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
  78. var tempFilePaths = res.tempFilePaths;
  79. wx.showLoading({
  80. title: '上传中',
  81. })
  82. wx.uploadFile({
  83. url: app.util.url('entry/wxapp/index', {'m':'lionfish_comshop','controller':'goods.doPageUpload'}), //仅为示例,非真实的接口地址
  84. filePath: tempFilePaths[0],
  85. name: 'upfile',
  86. formData: {
  87. 'name': tempFilePaths[0]
  88. },
  89. header: {
  90. 'content-type': 'multipart/form-data'
  91. },
  92. success: function (res) {
  93. wx.hideLoading();
  94. var data = JSON.parse(res.data);
  95. var image_thumb = data.image_thumb;
  96. var orign_image = data.image_o;
  97. var new_img = self.data.refund_imgs;
  98. var new_thumb_img = self.data.refund_thumb_imgs;
  99. new_img.push(orign_image);
  100. new_thumb_img.push(image_thumb);
  101. self.setData({
  102. refund_thumb_imgs: new_thumb_img,
  103. refund_imgs: new_img
  104. })
  105. //https://mall.shiziyu888.com/Uploads/image/cache/goods/2017-11-28/5a1d30ca7c627-300x300.png
  106. // https://mall.shiziyu888.com/Uploads/image/goods/2017-11-28/5a1d30ca7c627.png
  107. //do something
  108. }
  109. })
  110. }
  111. })
  112. },
  113. chose_type: function (event) {
  114. let stype = event.currentTarget.dataset.rel;
  115. this.setData({
  116. refund_type: stype
  117. })
  118. },
  119. cancle_img: function (event) {
  120. let sr = event.currentTarget.dataset.sr;
  121. var j = 0;
  122. var refund_imgs = this.data.refund_imgs;
  123. var refund_thumb_imgs = this.data.refund_thumb_imgs;
  124. var new_refund_imgs = [];
  125. var new_refund_thumb_imgs = [];
  126. for (var i in refund_thumb_imgs) {
  127. if (refund_thumb_imgs[i] == sr) {
  128. console.log('find');
  129. j = i;
  130. } else {
  131. new_refund_thumb_imgs.push(refund_thumb_imgs[i]);
  132. }
  133. }
  134. for (var i in refund_imgs) {
  135. if (i != j) {
  136. new_refund_imgs.push(refund_imgs[i]);
  137. }
  138. }
  139. this.setData({
  140. refund_thumb_imgs: new_refund_thumb_imgs,
  141. refund_imgs: new_refund_imgs
  142. })
  143. console.log(new_refund_thumb_imgs.length);
  144. console.log(new_refund_imgs.length);
  145. },
  146. refund_money_input: function (event) {
  147. var content = event.detail.value;
  148. //pinjia_text
  149. this.setData({
  150. refund_money: content
  151. })
  152. },
  153. wenti_input: function (event) {
  154. var content = event.detail.value;
  155. //pinjia_text
  156. this.setData({
  157. refund_miaoshu: content
  158. })
  159. },
  160. mobile_input: function (event) {
  161. var content = event.detail.value;
  162. //pinjia_text
  163. this.setData({
  164. mobile: content
  165. })
  166. },
  167. sub_refund: function () {
  168. /**
  169. xarray: ['请选择退款理由', '商品有质量问题', '没有收到货', '商品少发漏发发错', '商品与描述不一致', '收到商品时有划痕或破损', '质疑假货', '其他'],
  170. index: 0,
  171. refund_type:0,
  172. refund_money:0,
  173. refund_imgs:[],
  174. refund_thumb_imgs:[],
  175. refund_miaoshu:'',
  176. */
  177. if (this.data.refund_type == 0) {
  178. wx.showToast({
  179. title: '请选择退款类型',
  180. icon: 'success',
  181. duration: 1000
  182. })
  183. return false;
  184. }
  185. console.log(this.data.refund_money)
  186. if (this.data.refund_money <= 0) {
  187. wx.showToast({
  188. title: '请填写退款金额',
  189. icon: 'success',
  190. duration: 1000
  191. })
  192. return false;
  193. }
  194. if (this.data.index == 0) {
  195. wx.showToast({
  196. title: '请选择退款原因',
  197. icon: 'success',
  198. duration: 1000
  199. })
  200. return false;
  201. }
  202. var rfund_name = this.data.xarray[this.data.index];
  203. if (this.data.refund_miaoshu == '') {
  204. wx.showToast({
  205. title: '请填写问题描述',
  206. icon: 'success',
  207. duration: 1000
  208. })
  209. return false;
  210. }
  211. // if (this.data.refund_imgs <= 0) {
  212. // wx.showToast({
  213. // title: '请上传图片',
  214. // icon: 'success',
  215. // duration: 1000
  216. // })
  217. // return false;
  218. // }
  219. if (this.data.mobile == '') {
  220. wx.showToast({
  221. title: '请填写手机号',
  222. icon: 'success',
  223. duration: 1000
  224. })
  225. return false;
  226. }
  227. var that = this;
  228. var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
  229. if (!myreg.test(this.data.mobile)) {
  230. wx.showToast({
  231. title: '请填写正确手机号',
  232. icon: 'success',
  233. duration: 1000
  234. })
  235. return false;
  236. }
  237. var token = wx.getStorageSync('token');
  238. app.util.request({
  239. 'url': 'entry/wxapp/index',
  240. 'data': {
  241. controller: 'user.refund_sub',
  242. token:token,
  243. order_id: that.data.order_id,
  244. order_goods_id: that.data.order_goods_id,
  245. complaint_type: that.data.refund_type,
  246. complaint_images: that.data.refund_imgs,
  247. complaint_desc: that.data.refund_miaoshu,
  248. complaint_mobile: that.data.mobile,
  249. complaint_reason: rfund_name,
  250. complaint_money: that.data.refund_money
  251. },
  252. method: 'POST',
  253. dataType: 'json',
  254. success: function (msg) {
  255. wx.hideLoading();
  256. if (msg.data.code == 3) {
  257. wx.showToast({
  258. title: '未登录',
  259. icon: 'loading',
  260. duration: 1000
  261. })
  262. }
  263. else if (msg.data.code == 0) {
  264. wx.showToast({
  265. title: msg.data.msg,
  266. icon: 'success',
  267. duration: 1000
  268. })
  269. return;
  270. }
  271. else {
  272. wx.showToast({
  273. title: '申请成功',
  274. icon: 'success',
  275. duration: 4000,
  276. success: function (res) {
  277. wx.redirectTo({
  278. url: "/lionfish_comshop/pages/order/order?id=" + that.data.order_id
  279. })
  280. }
  281. })
  282. }
  283. }
  284. })
  285. },
  286. /**
  287. * 生命周期函数--监听页面初次渲染完成
  288. */
  289. onReady: function () {
  290. },
  291. /**
  292. * 生命周期函数--监听页面显示
  293. */
  294. onShow: function () {
  295. },
  296. /**
  297. * 生命周期函数--监听页面隐藏
  298. */
  299. onHide: function () {
  300. },
  301. /**
  302. * 生命周期函数--监听页面卸载
  303. */
  304. onUnload: function () {
  305. },
  306. /**
  307. * 页面相关事件处理函数--监听用户下拉动作
  308. */
  309. onPullDownRefresh: function () {
  310. },
  311. /**
  312. * 页面上拉触底事件的处理函数
  313. */
  314. onReachBottom: function () {
  315. },
  316. /**
  317. * 用户点击右上角分享
  318. */
  319. onShareAppMessage: function () {
  320. }
  321. })