C端小程序
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.

359 regels
7.8 KiB

  1. var app = getApp();
  2. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  3. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  4. const Http = require("../../utils/HttpBasics");
  5. const config = require("../../config/config.js");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. navigationBarHeight,
  12. num: 1,
  13. showShade: false,
  14. coverImg: "",
  15. title: "",
  16. salePriceStr: "", //单价
  17. freightPriceStr: "", //运费
  18. remainInventory: "", //库存
  19. seti: [],
  20. area: "",
  21. address: "",
  22. consignee: "",
  23. mobile: "",
  24. couponChannelId: "",
  25. thenArr: {}, //选中的地址对象
  26. contentType:0,
  27. shippingtype:1,//1是自提 2配送
  28. },
  29. goAddStie() {
  30. wx.navigateTo({
  31. url: '/pages/siteAdd/siteAdd?url=/pages/fillIndent/fillIndent',
  32. })
  33. },
  34. setSite(e) {
  35. let id = e.currentTarget.dataset.id
  36. let arr = []
  37. arr = this.data.seti.filter(item => {
  38. return item.id == id
  39. })[0]
  40. this.setData({
  41. thenArr: arr,
  42. area: arr.regionStr,
  43. address: arr.address,
  44. consignee: arr.consignee,
  45. mobile: arr.mobile,
  46. })
  47. },
  48. getSetiLsit() {
  49. Http.get({
  50. url: config.api.siteList,
  51. data: {
  52. pageNum: 1,
  53. pageSize: 1000
  54. }
  55. }).then(res => {
  56. let temp = res.data.list
  57. if (temp.length > 0) {
  58. temp.map(item => {
  59. // let regionStr = ""
  60. let tempstr = ""
  61. JSON.parse(item.region).map(item2 => {
  62. tempstr += item2
  63. })
  64. item.regionStr = tempstr
  65. })
  66. console.log(temp, "temp")
  67. this.setData({
  68. seti: temp,
  69. })
  70. let tempRegion = JSON.parse(temp[0].region)
  71. let str = ""
  72. tempRegion.map(item => {
  73. str += item
  74. })
  75. this.setData({
  76. thenArr: temp[0],
  77. area: str,
  78. address: temp[0].address,
  79. consignee: temp[0].consignee,
  80. mobile: temp[0].mobile
  81. })
  82. }
  83. }).catch(err => {
  84. wx.showToast({
  85. title: err.message ? err.message : err.data,
  86. icon: 'none',
  87. duration: 2000,
  88. });
  89. })
  90. },
  91. addNum() {
  92. let num = this.data.num
  93. if (this.data.num >= this.data.remainInventory) {
  94. wx.showToast({
  95. title: '购买总数超库存',
  96. icon: 'none',
  97. duration: 2000,
  98. })
  99. } else {
  100. num = num + 1
  101. this.setData({
  102. num: num
  103. })
  104. }
  105. },
  106. dleNum() {
  107. let num = this.data.num
  108. if (this.data.num <= 1) {
  109. wx.showToast({
  110. title: '购买总数不能为0',
  111. icon: 'none',
  112. duration: 2000,
  113. })
  114. } else {
  115. num = num - 1
  116. this.setData({
  117. num: num
  118. })
  119. }
  120. },
  121. hieShade() {
  122. this.setData({
  123. showShade: false
  124. })
  125. },
  126. showTShade() {
  127. this.setData({
  128. showShade: true
  129. })
  130. },
  131. /**
  132. * 支付订单更新
  133. */
  134. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this, composeOrderType) => {
  135. // 支付成功
  136. Http.post({
  137. url: config.api.payOrderUpdate,
  138. data: {
  139. payOrderId: payOrderId,
  140. composeOrderId: orderId,
  141. status: status,
  142. reason: reason
  143. }
  144. }).then(res => {
  145. //订单详情
  146. wx.hideLoading()
  147. wx.navigateTo({
  148. url: `/pages/order/detail/index?orderId=${orderId}&contentType=${_this.data.contentType}&composeOrderType=${composeOrderType}&dingdan=order`
  149. });
  150. })
  151. .catch(err => {
  152. console.log(err);
  153. if (!type) {
  154. setTimeout(function () {
  155. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType);
  156. }, 2000)
  157. }
  158. })
  159. },
  160. pay() {
  161. if (this.data.area == "") {
  162. wx.showToast({
  163. title: "请选择地址",
  164. icon: 'none',
  165. duration: 2000,
  166. });
  167. return
  168. }
  169. let data = []
  170. let tempObj = {
  171. signleOrder: {
  172. couponChannelId: this.data.couponChannelId,
  173. couponId: this.data.couponId,
  174. formId: ""
  175. },
  176. count: this.data.num,
  177. shippingType: this.data.shippingtype, //1自提 2配送
  178. }
  179. if (this.data.shippingtype==2){
  180. tempObj.address = this.data.thenArr
  181. }
  182. data.push(tempObj)
  183. Http.post({
  184. url: config.api.goodsShopCartSave,
  185. data: JSON.stringify(data)
  186. }).then(res => {
  187. let {mainOrderId,composeOrderType} = { ...res.data}
  188. console.log(mainOrderId, composeOrderType)
  189. Http.post({
  190. url: config.api.payOrderCreate,
  191. data: {
  192. orderId: mainOrderId,
  193. composeOrderType: composeOrderType
  194. }
  195. }).then(res => {
  196. var payOrderId = "" + res.data.payOrderId;
  197. let that = this
  198. wx.requestPayment({
  199. timeStamp: res.data.timeStamp,
  200. nonceStr: res.data.nonceStr,
  201. package: res.data.package,
  202. signType: (res.data.signType) ? res.data.signType : "MD5",
  203. paySign: res.data.paySign,
  204. success: res => {
  205. wx.showLoading({
  206. title: '订单正在处理中...',
  207. })
  208. that.payOrderUpdate(mainOrderId, payOrderId, 1, "", "", that, composeOrderType)
  209. },
  210. fail: res => {
  211. wx.showToast({
  212. title: '支付已取消',
  213. icon: 'none',
  214. duration: 2000,
  215. })
  216. }
  217. })
  218. }).catch(err => {
  219. wx.showToast({
  220. title: err.message ? err.message : err.data,
  221. icon: 'none',
  222. duration: 2000,
  223. });
  224. })
  225. }).catch(err => {
  226. wx.showToast({
  227. title: err.message ? err.message : err.data,
  228. icon: 'none',
  229. duration: 2000,
  230. });
  231. })
  232. },
  233. /**
  234. * 生命周期函数--监听页面加载
  235. */
  236. onLoad: function(options) {
  237. this.setData({
  238. couponChannelId: options.couponChannelId,
  239. couponId: options.couponId,
  240. shippingtype: options.shippingtype
  241. })
  242. Http.get({
  243. url: config.api.checkUserStatus,
  244. data: {
  245. token: app.globalData.token
  246. }
  247. }).then(res => {
  248. Http.get({
  249. url: config.api.checkPhoneStatus,
  250. data: {}
  251. }).then(res => {
  252. //授权完成 开始支付
  253. }).catch(err => {
  254. wx.redirectTo({
  255. url: `/pages/getphoneInfo/index?path=fi&fillIndentId=${this.data.couponChannelId}&couponId${this.data.couponId}`
  256. });
  257. })
  258. }).catch(err => {
  259. wx.navigateTo({
  260. url: `/pages/getuserinfo/index?fromflag=fillIndent&fillIndentId=${this.data.couponChannelId}&couponId${this.data.couponId}`,
  261. })
  262. })
  263. },
  264. getCouponDetail() {
  265. Http.get({
  266. url: config.api.couponDetail,
  267. data: {
  268. couponChannelId: this.data.couponChannelId
  269. }
  270. }).then(res => {
  271. let temp = res.data
  272. this.setData({
  273. coverImg: temp.coverImg,
  274. title: temp.title,
  275. salePriceStr: temp.salePriceStr,
  276. freightPriceStr: temp.freightPriceStr,
  277. remainInventory: temp.remainInventory,
  278. contentType: res.data.contentType
  279. })
  280. }).catch(err => {
  281. wx.showToast({
  282. title: err.message ? err.message : err.data,
  283. icon: 'none',
  284. duration: 2000,
  285. });
  286. })
  287. },
  288. /**
  289. * 生命周期函数--监听页面初次渲染完成
  290. */
  291. onReady: function() {
  292. },
  293. /**
  294. * 生命周期函数--监听页面显示
  295. */
  296. onShow: function() {
  297. this.getCouponDetail()
  298. this.getSetiLsit()
  299. },
  300. /**
  301. * 生命周期函数--监听页面隐藏
  302. */
  303. onHide: function() {
  304. },
  305. /**
  306. * 生命周期函数--监听页面卸载
  307. */
  308. onUnload: function() {
  309. },
  310. /**
  311. * 页面相关事件处理函数--监听用户下拉动作
  312. */
  313. onPullDownRefresh: function() {
  314. },
  315. /**
  316. * 页面上拉触底事件的处理函数
  317. */
  318. onReachBottom: function() {
  319. },
  320. /**
  321. * 用户点击右上角分享
  322. */
  323. onShareAppMessage: function() {
  324. }
  325. })