You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

208 lines
4.3 KiB

  1. const config = require('../../config/config.js')
  2. const Http = require('../../utils/HttpBasics.js')
  3. const util = require('../../utils/util.js')
  4. const app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. receiptUrl: "",
  11. obj: {},
  12. courierInput: "",
  13. expressageIdInput: "",
  14. },
  15. setCourierInput(e) {
  16. console.log(e)
  17. this.setData({
  18. courierInput: e.detail.value
  19. })
  20. },
  21. setExpressageIdInput(e) {
  22. console.log(e)
  23. this.setData({
  24. expressageIdInput: e.detail.value
  25. })
  26. },
  27. submit() {
  28. if (this.data.courierInput == "") {
  29. wx.showToast({
  30. title: '请输入快递公司名称',
  31. icon: "none"
  32. })
  33. return
  34. }
  35. if (this.data.expressageIdInput == "") {
  36. wx.showToast({
  37. title: '请输入快递单号',
  38. icon: "none"
  39. })
  40. return
  41. }
  42. if (this.data.receiptUrl == "") {
  43. wx.showToast({
  44. title: '请上传快递照片',
  45. icon: "none"
  46. })
  47. return
  48. }
  49. debugger
  50. if (this.data.expressageIdInput.length>18) {
  51. wx.showToast({
  52. title: '快递单号不能超过18位',
  53. icon: "none"
  54. })
  55. return
  56. }
  57. Http.post({
  58. url: config.api.sendGoods,
  59. data: {
  60. id: this.data.id,
  61. deliveryInfo: JSON.stringify({
  62. courierInput: this.data.courierInput,
  63. expressageIdInput: this.data.expressageIdInput,
  64. receiptUrl: this.data.receiptUrl
  65. })
  66. }
  67. }).then(res=>{
  68. wx.showToast({
  69. title: '提交成功!',
  70. icon:"none"
  71. })
  72. wx.navigateBack({
  73. delta: 1
  74. })
  75. }).catch(err=>{
  76. wx.showToast({
  77. title: err.message?err.message:err.data,
  78. icon: "none"
  79. })
  80. })
  81. },
  82. uploadImg() {
  83. let that = this;
  84. wx.chooseImage({
  85. success(res) {
  86. const tempFilePaths = res.tempFilePaths
  87. wx.uploadFile({
  88. url: config.api.imgUpload, // 仅为示例,非真实的接口地址
  89. filePath: tempFilePaths[0],
  90. name: 'file',
  91. header: {
  92. 'token': app.globalData.token
  93. },
  94. success(res) {
  95. const data = res.data
  96. that.setData({
  97. receiptUrl: JSON.parse(res.data).data.url
  98. })
  99. // do something
  100. },
  101. fail(err) {
  102. wx.showToast({
  103. title: err.message ? err.message : err.data,
  104. icon: "none"
  105. })
  106. }
  107. })
  108. }
  109. })
  110. },
  111. /**
  112. * 生命周期函数--监听页面加载
  113. */
  114. onLoad: function(options) {
  115. this.setData({
  116. id: options.id
  117. })
  118. this.getData()
  119. },
  120. getData() {
  121. Http.get({
  122. url: config.api.ouponOrderId,
  123. data: {
  124. couponOrderId: this.data.id
  125. }
  126. }).then(res => {
  127. let tempObj = res.data
  128. tempObj.createDate = util.formatTime(tempObj.createDate, 'yyyy-MM-dddd hh:mm:ss')
  129. tempObj.couponPriceStr = (tempObj.couponPrice / 100).toFixed(2)
  130. tempObj.shippingAddressObj = JSON.parse(tempObj.shippingAddress)
  131. let tempRegion = JSON.parse(tempObj.shippingAddressObj.region)
  132. if (tempObj.deliveryInfo) {
  133. tempObj.deliveryInfo = JSON.parse(tempObj.deliveryInfo)
  134. this.setData({
  135. receiptUrl: tempObj.deliveryInfo.receiptUrl,
  136. courierInput: tempObj.deliveryInfo.courierInput,
  137. expressageIdInput: tempObj.deliveryInfo.expressageIdInput
  138. })
  139. }
  140. let str = ""
  141. tempRegion.map(item => {
  142. str += item
  143. })
  144. tempObj.regionStr = str
  145. this.setData({
  146. obj: tempObj
  147. })
  148. console.log(this.data.obj)
  149. }).catch(err => {
  150. wx.showToast({
  151. title: err.message ? err.message : err.data,
  152. })
  153. })
  154. },
  155. /**
  156. * 生命周期函数--监听页面初次渲染完成
  157. */
  158. onReady: function() {
  159. },
  160. /**
  161. * 生命周期函数--监听页面显示
  162. */
  163. onShow: function() {
  164. },
  165. /**
  166. * 生命周期函数--监听页面隐藏
  167. */
  168. onHide: function() {
  169. },
  170. /**
  171. * 生命周期函数--监听页面卸载
  172. */
  173. onUnload: function() {
  174. },
  175. /**
  176. * 页面相关事件处理函数--监听用户下拉动作
  177. */
  178. onPullDownRefresh: function() {
  179. },
  180. /**
  181. * 页面上拉触底事件的处理函数
  182. */
  183. onReachBottom: function() {
  184. },
  185. /**
  186. * 用户点击右上角分享
  187. */
  188. onShareAppMessage: function() {
  189. }
  190. })