writeReturnLogistics.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. // pages/writeReturnLogistics/writeReturnLogistics.js
  2. var http = require('../../utils/http.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. // 物流公司选择
  9. deliveryList:[],
  10. expressId: 0, //物流公司id
  11. expressName: '', //物流公司名称
  12. expressNo: '', //物流单号
  13. imgs: [], //图片凭证
  14. mobile: '', //手机号码
  15. refundSn: '', //退款编号名称
  16. shopId: '', //店铺id
  17. senderRemarks: '', //备注信息
  18. type:'',//编辑模式
  19. editData:null
  20. },
  21. /**
  22. * 选择物流公司
  23. */
  24. chooseLogisticsCompany: function (e) {
  25. console.log('快递公司',e.detail.value)
  26. this.setData({
  27. expressId: e.detail.value
  28. })
  29. },
  30. onExpressNoInput:function(e){
  31. this.setData({
  32. expressNo:e.detail.value
  33. });
  34. },
  35. onSenderRemarksInput: function (e) {
  36. this.setData({
  37. senderRemarks: e.detail.value
  38. });
  39. },
  40. /**
  41. * 填写&提交物流信息
  42. */
  43. writeLogisticsMsg: function (e) {
  44. wx.showLoading();
  45. if (this.data.expressNo.length == 0) {
  46. wx.showToast({
  47. icon: 'none',
  48. title: '请填写物流单号',
  49. })
  50. } else {
  51. var pics = '';
  52. this.data.imgs.forEach(function (item) {
  53. // pics += item.path + ',';
  54. pics += item.url + ',';
  55. });
  56. if (pics != '') {
  57. pics = pics.substring(0, pics.length - 1)
  58. }
  59. var parmas = {
  60. url:this.data.type == 'edit'?"/refund/delivery/update": "/refund/delivery/save",
  61. method: this.data.type == 'edit'?"PUT":"POST",
  62. data: {
  63. shopId:this.data.shopId,
  64. deyId: this.data.deliveryList[this.data.expressId].dvyId, //物流公司id
  65. deyName: this.data.deliveryList[this.data.expressId].dvyName, //物流公司名称
  66. deyNu: this.data.expressNo, //物流单号
  67. imgs: pics, //图片凭证
  68. senderMobile: this.data.mobile, //手机号码
  69. refundSn: this.data.refundSn, //退款编号名称
  70. senderRemarks: this.data.senderRemarks, //备注信息
  71. userId:wx.getStorageSync("loginResult").userId
  72. },
  73. callBack: (res) => {
  74. wx.hideLoading();
  75. // 物流填写跳转页面
  76. wx.navigateTo({
  77. url: '/pages/DetailsOfRefund/DetailsOfRefund?refundSn=' + this.data.refundSn,
  78. })
  79. }
  80. };
  81. http.request(parmas);
  82. }
  83. },
  84. /**
  85. * 上传图片
  86. */
  87. getUploadImg: function (e) {
  88. const idx = e.target.dataset.idx
  89. console.log(idx);
  90. var ths = this;
  91. wx.chooseImage({
  92. count: 1, // 默认9
  93. sizeType: ['compressed'],
  94. sourceType: ['album', 'camera'],
  95. success: function (res) {
  96. // 图片的本地临时文件路径列表
  97. var tempFilePaths = res.tempFilePaths;
  98. wx.showLoading({
  99. mask: true
  100. })
  101. var params = {
  102. url: "/p/file/upload",
  103. filePath: tempFilePaths[0],
  104. name: 'file',
  105. callBack: function (res2) {
  106. wx.hideLoading();
  107. var img = {};
  108. img.path = JSON.parse(res2).filePath;
  109. img.url = JSON.parse(res2).resourcesUrl + JSON.parse(res2).filePath;
  110. var imgs = ths.data.imgs;
  111. imgs.push(img);
  112. ths.setData({
  113. imgs: imgs
  114. })
  115. }
  116. };
  117. http.upload(params);
  118. }
  119. })
  120. },
  121. /**
  122. * 删除图片
  123. */
  124. removeImage: function (e) {
  125. // const index = e.target.dataset.index
  126. // const idx = e.target.dataset.idx;
  127. var idx = e.currentTarget.dataset.idx;
  128. var imgs = this.data.imgs;
  129. imgs.splice(idx, 1)
  130. this.setData({
  131. imgs: imgs
  132. });
  133. console.log('删除图片')
  134. },
  135. /**
  136. * 生命周期函数--监听页面加载
  137. */
  138. onLoad: function (options) {
  139. this.setData({
  140. refundSn: options.refundSn,
  141. shopId: options.shopId,
  142. type:options.type,
  143. });
  144. this.loadDeliveryData();
  145. },
  146. //获取物流公司列表
  147. loadDeliveryData(){
  148. wx.showLoading();
  149. http.request({
  150. url:"/p/delivery/list",
  151. method: "get",
  152. data: {},
  153. callBack: (res) => {
  154. wx.hideLoading();
  155. this.setData({
  156. deliveryList:res
  157. });
  158. console.log(res)
  159. if(this.data.type == 'edit'){
  160. this.getByRefundSn()
  161. }
  162. }
  163. });
  164. console.log(this.data.deliveryList)
  165. },
  166. /**
  167. *
  168. * 获取退货物流信息
  169. */
  170. getByRefundSn(){
  171. var parmas = {
  172. url: `/refund/delivery/getByRefundSn/${this.data.refundSn}`,
  173. method: "GET",
  174. data: {},
  175. callBack: (r) => {
  176. let res = r.data
  177. let imgs = []
  178. if(res.imgs){
  179. imgs = res.imgs.split(',').map(i=>{
  180. return {url:i,path:i}
  181. })
  182. }
  183. let expressId = 0
  184. this.data.deliveryList.forEach((i,d)=>{
  185. if(i.dvyId == res.deyId){
  186. expressId = d
  187. }
  188. })
  189. this.setData({
  190. expressId,
  191. expressNo:res.deyNu,
  192. imgs,
  193. senderRemarks:res.senderRemarks,
  194. })
  195. }
  196. };
  197. http.request(parmas);
  198. },
  199. /**
  200. * 生命周期函数--监听页面初次渲染完成
  201. */
  202. onReady: function () {
  203. },
  204. /**
  205. * 生命周期函数--监听页面显示
  206. */
  207. onShow: function () {
  208. },
  209. /**
  210. * 生命周期函数--监听页面隐藏
  211. */
  212. onHide: function () {
  213. },
  214. /**
  215. * 生命周期函数--监听页面卸载
  216. */
  217. onUnload: function () {
  218. },
  219. /**
  220. * 页面相关事件处理函数--监听用户下拉动作
  221. */
  222. onPullDownRefresh: function () {
  223. },
  224. /**
  225. * 页面上拉触底事件的处理函数
  226. */
  227. onReachBottom: function () {
  228. },
  229. /**
  230. * 用户点击右上角分享
  231. */
  232. onShareAppMessage: function () {
  233. }
  234. })