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.

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