C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

373 linhas
8.2 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. console.log(this.data.shippingtype)
  173. if (this.data.area == "" && this.data.shippingtype==2) {
  174. wx.showToast({
  175. title: "请选择地址",
  176. icon: 'none',
  177. duration: 2000,
  178. });
  179. return
  180. }
  181. let data = []
  182. let tempObj = {
  183. signleOrder: {
  184. couponChannelId: this.data.couponChannelId,
  185. couponId: this.data.couponId,
  186. formId: ""
  187. },
  188. count: this.data.num,
  189. shippingType: this.data.shippingtype, //1自提 2配送
  190. }
  191. if (this.data.shippingtype==2){
  192. tempObj.address = this.data.thenArr
  193. }
  194. data.push(tempObj)
  195. Http.post({
  196. url: config.api.goodsShopCartSave,
  197. data: JSON.stringify(data)
  198. }).then(res => {
  199. let {mainOrderId,composeOrderType} = { ...res.data}
  200. console.log(mainOrderId, composeOrderType)
  201. Http.post({
  202. url: config.api.payOrderCreate,
  203. data: {
  204. orderId: mainOrderId,
  205. composeOrderType: composeOrderType
  206. }
  207. }).then(res => {
  208. var payOrderId = "" + res.data.payOrderId;
  209. let that = this
  210. wx.requestPayment({
  211. timeStamp: res.data.timeStamp,
  212. nonceStr: res.data.nonceStr,
  213. package: res.data.package,
  214. signType: (res.data.signType) ? res.data.signType : "MD5",
  215. paySign: res.data.paySign,
  216. success: res => {
  217. wx.showLoading({
  218. title: '订单正在处理中...',
  219. })
  220. that.payOrderUpdate(mainOrderId, payOrderId, 1, "", "", that, composeOrderType)
  221. },
  222. fail: res => {
  223. wx.showToast({
  224. title: '支付已取消',
  225. icon: 'none',
  226. duration: 2000,
  227. })
  228. }
  229. })
  230. }).catch(err => {
  231. wx.showToast({
  232. title: err.message ? err.message : err.data,
  233. icon: 'none',
  234. duration: 2000,
  235. });
  236. })
  237. }).catch(err => {
  238. wx.showToast({
  239. title: err.message ? err.message : err.data,
  240. icon: 'none',
  241. duration: 2000,
  242. });
  243. })
  244. },
  245. /**
  246. * 生命周期函数--监听页面加载
  247. */
  248. onLoad: function(options) {
  249. this.setData({
  250. couponChannelId: options.couponChannelId,
  251. couponId: options.couponId,
  252. shippingtype: options.shippingtype
  253. })
  254. Http.get({
  255. url: config.api.checkUserStatus,
  256. data: {
  257. token: app.globalData.token
  258. }
  259. }).then(res => {
  260. Http.get({
  261. url: config.api.checkPhoneStatus,
  262. data: {}
  263. }).then(res => {
  264. //授权完成 开始支付
  265. }).catch(err => {
  266. wx.redirectTo({
  267. url: `/pages/getphoneInfo/index?path=fi&fillIndentId=${this.data.couponChannelId}&couponId${this.data.couponId}`
  268. });
  269. })
  270. }).catch(err => {
  271. wx.navigateTo({
  272. url: `/pages/getuserinfo/index?fromflag=fillIndent&fillIndentId=${this.data.couponChannelId}&couponId${this.data.couponId}`,
  273. })
  274. })
  275. },
  276. getCouponDetail() {
  277. Http.get({
  278. url: config.api.couponDetail,
  279. data: {
  280. couponChannelId: this.data.couponChannelId
  281. }
  282. }).then(res => {
  283. let temp = res.data
  284. this.setData({
  285. coverImg: temp.coverImg,
  286. title: temp.title,
  287. salePriceStr: temp.salePriceStr,
  288. freightPriceStr: temp.freightPriceStr,
  289. remainInventory: temp.remainInventory,
  290. contentType: res.data.contentType
  291. })
  292. this.setTotal()
  293. }).catch(err => {
  294. wx.showToast({
  295. title: err.message ? err.message : err.data,
  296. icon: 'none',
  297. duration: 2000,
  298. });
  299. })
  300. },
  301. /**
  302. * 生命周期函数--监听页面初次渲染完成
  303. */
  304. onReady: function() {
  305. },
  306. /**
  307. * 生命周期函数--监听页面显示
  308. */
  309. onShow: function() {
  310. this.getCouponDetail()
  311. this.getSetiLsit()
  312. },
  313. /**
  314. * 生命周期函数--监听页面隐藏
  315. */
  316. onHide: function() {
  317. },
  318. /**
  319. * 生命周期函数--监听页面卸载
  320. */
  321. onUnload: function() {
  322. },
  323. /**
  324. * 页面相关事件处理函数--监听用户下拉动作
  325. */
  326. onPullDownRefresh: function() {
  327. },
  328. /**
  329. * 页面上拉触底事件的处理函数
  330. */
  331. onReachBottom: function() {
  332. },
  333. // /**
  334. // * 用户点击右上角分享
  335. // */
  336. // onShareAppMessage: function() {
  337. // }
  338. })