order.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. const util = require('../../utils/util.js');
  2. const app = getApp()
  3. Page({
  4. data: {
  5. openId: wx.getStorageSync("openId"),
  6. id: "",
  7. ccNo: "",
  8. name: "",
  9. phone: "",
  10. content: "",
  11. region: ['江苏省', '南京市', '栖霞区'],
  12. detail: "",
  13. money: "",
  14. showEdit: true,
  15. click: true
  16. },
  17. onLoad: function (option) {
  18. this.setData({
  19. id: option.id,
  20. ccNo: option.ccNo,
  21. showEdit: option.alreadyAppFlag
  22. })
  23. var that = this;
  24. wx.request({
  25. url: app.globalData.serverUrl + "/application/order",
  26. method: "GET",
  27. data: {
  28. openId: that.data.openId,
  29. ccNo: that.data.ccNo
  30. },
  31. header: {
  32. "Content-Type": "application/x-www-form-urlencoded"
  33. },
  34. success: function (res) {
  35. if(res.data.code == "0000"){
  36. var list = res.data.data.ApplicationOrder;
  37. if(list != null){
  38. if(list.appStatus == 'N'){
  39. list.appStatusName = '未支付'
  40. } else if(list.appStatus == 'O'){
  41. list.appStatusName = '已申请'
  42. } else if(list.appStatus == 'S'){
  43. list.appStatusName = '已邮寄'
  44. } else if(list.appStatus == 'D'){
  45. list.appStatusName = '已退款'
  46. }
  47. that.setData({
  48. detail: list,
  49. showEdit: false,
  50. money: res.data.data.totalFee
  51. })
  52. } else {
  53. that.setData({
  54. showEdit: true,
  55. money: res.data.data.totalFee
  56. })
  57. }
  58. } else {
  59. wx.showToast({
  60. title: res.data.msg,
  61. icon: 'none',
  62. duration: 2000
  63. })
  64. }
  65. }
  66. })
  67. },
  68. //姓名
  69. getNameValue: function(e) {
  70. this.setData({
  71. name: e.detail.value
  72. })
  73. },
  74. //手机号
  75. getPhoneValue: function(e) {
  76. this.setData({
  77. phone: e.detail.value
  78. })
  79. },
  80. //详细地址
  81. getContentValue: function(e) {
  82. this.setData({
  83. content: e.detail.value
  84. })
  85. },
  86. //地区
  87. bindRegionChange: function (e) {
  88. this.setData({
  89. region: e.detail.value
  90. })
  91. },
  92. //保存并支付
  93. toPay: function(){
  94. var myreg = /^1[0-9]{10,11}$/;
  95. if (this.data.name == "") {
  96. wx.showToast({
  97. title: '姓名不能为空',
  98. icon: 'none',
  99. duration: 1000
  100. })
  101. return false;
  102. } else if (this.data.phone == "") {
  103. wx.showToast({
  104. title: '手机号不能为空',
  105. icon: 'none',
  106. duration: 1000
  107. })
  108. return false;
  109. } else if (!myreg.test(this.data.phone)) {
  110. wx.showToast({
  111. title: '请输入正确的手机号',
  112. icon: 'none',
  113. duration: 1000
  114. })
  115. return false;
  116. } else if(this.data.content == ""){
  117. wx.showToast({
  118. title: '详细地址不能为空',
  119. icon: 'none',
  120. duration: 1000
  121. })
  122. return false;
  123. } else {
  124. if(this.data.click){
  125. var that = this , str = "";
  126. that.setData({
  127. click:false
  128. })
  129. for(var i in that.data.region){
  130. if(i == that.data.region.length -1){
  131. str += that.data.region[i]
  132. } else {
  133. str += that.data.region[i] + " "
  134. }
  135. }
  136. str += that.data.content
  137. wx.request({
  138. url: app.globalData.serverUrl + "/application/orderSave",
  139. method: "GET",
  140. data: {
  141. openId: that.data.openId,
  142. ccNo: that.data.ccNo,
  143. initiatorName: that.data.name,
  144. initiatorMobile: that.data.phone,
  145. initiatorUserId: wx.getStorageSync("userInfo").id,
  146. address: str
  147. },
  148. header: {
  149. "Content-Type": "application/x-www-form-urlencoded"
  150. },
  151. success: function (res) {
  152. if(res.data.code == "0000"){
  153. wx.showToast({
  154. title: '申请成功!',
  155. icon: 'success',
  156. duration: 2000
  157. })
  158. var item = res.data.data;
  159. wx.requestPayment({
  160. timeStamp: item.timeStamp,
  161. nonceStr: item.nonceStr,
  162. package: item.package,
  163. signType: item.signType,
  164. paySign: item.paySign,
  165. success (res) {
  166. that.setData({
  167. click:true
  168. })
  169. wx.showToast({
  170. title: "支付成功",
  171. icon: 'success',
  172. duration: 2000
  173. })
  174. setTimeout(function() {
  175. wx.reLaunch({
  176. url: '../detail/detail?id='+ that.data.id
  177. })
  178. }, 200)
  179. },
  180. fail (res) {
  181. that.setData({
  182. click:true
  183. })
  184. wx.showToast({
  185. title: "支付失败",
  186. icon: 'none',
  187. duration: 2000
  188. })
  189. }
  190. })
  191. } else {
  192. that.setData({
  193. click:true
  194. })
  195. wx.showToast({
  196. title: res.data.msg,
  197. icon: 'none',
  198. duration: 2000
  199. })
  200. }
  201. },
  202. fail: function (res) {
  203. that.setData({
  204. click:true
  205. })
  206. wx.showToast({
  207. title: '提交失败!',
  208. icon: 'none',
  209. duration: 2000
  210. })
  211. }
  212. })
  213. } else {
  214. wx.showToast({
  215. title: '保存中,请勿重复提交',
  216. icon: 'none',
  217. duration: 1000
  218. })
  219. }
  220. }
  221. }
  222. })