123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- import {
- get,
- post
- } from '../../../utils/http'
- const app = getApp()
- Page({
-
- data: {
- store_id: '',
- storeInfo: '',
- giftInfo: "",
- goodsDetailsList: '',
- showMoneyGood: '',
- payNow: false,
- inserllAmount: '',
- pay_methon: 1,
- orderId: '',
- exchangeCondition: '',
- exchangeList: [],
- exchangeSum: 0,
- exchangeSelect: false,
- toExchangePrice: '',
- exchangePop: true,
- exchangeCountDown: 5,
- timer: null,
- },
-
- onLoad(options) {
-
- this.countDown()
-
- let sum = 0
- if (options.productList) {
- let list = JSON.parse(options.productList)
- list.forEach(item => {
- sum = item.num + sum
- })
- }
- this.setData({
- store_id: options.store_id || wx.getStorageSync('store_id'),
- goodsDetailsList: JSON.parse(options.productList),
- giftID: options.giftID,
- total: sum
- })
- console.log(JSON.parse(options.productList));
-
- this.getStoreInfo()
-
- this.getGiftBagDetail()
- },
-
- countDown: function () {
- let that = this;
- let exchangeCountDown = that.data.exchangeCountDown;
- that.setData({
- timer: setInterval(function () {
- exchangeCountDown--;
- that.setData({
- exchangeCountDown: exchangeCountDown
- })
- if (exchangeCountDown == 0) {
- clearInterval(that.data.timer);
- that.setData({
- exchangePop: false
- })
- }
- }, 1000)
- })
- },
-
- onCloseLandscape() {
- clearInterval(this.data.timer);
- this.setData({
- exchangePop: false
- })
- },
-
- onReady() {
- },
-
- onShow() {
- },
-
- onHide() {
- },
-
- onUnload() {
- },
-
- onPullDownRefresh() {
- },
-
- onReachBottom() {
- },
-
- onShareAppMessage() {
- },
-
- onNewPay() {
-
- if (this.data.exchangeSelect) {
- if (this.data.exchangeSum < this.data.exchangeCondition.time) {
- wx.showToast({
- title: '您还有剩余次数未选',
- icon: 'none'
- })
- return
- }
- }
-
- let item_data = []
- this.data.goodsDetailsList.forEach(item => {
- let list = {}
- list.item_id = item.item_id
- list.goods_id = item.goods_id
- list.num = item.num
- item_data.push(list)
- })
-
- let plus = []
- this.data.exchangeList.list.forEach(item => {
- if (item.num != 0) {
- plus.push(item.id)
- }
- })
- let params = {
- store_id: this.data.store_id || wx.getStorageSync('store_id'),
- id: this.data.giftID,
- item_data: JSON.stringify(item_data),
- plus_ids: plus.toString()
- }
- post('v2/api/package/add', params, res => {
- if (res.code == 200) {
- if (res.data.pay_status == 1) {
- wx.showToast({
- title: '支付成功',
- icon: 'success'
- })
-
- wx.reLaunch({
- url: `/pages/paySuccess/paySuccess?current=1&source=goods&order_id=${res.data.order_id}`
- })
- } else {
- this.setData({
- payNow: true,
- orderId: res.data.order_id
- })
- this.getAmount()
- }
- }
- })
- },
-
- payOrder() {
- let that = this
- post(
- 'v2/api/order/goods/pay', {
- pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
- order_id: this.data.orderId
- },
- (res) => {
- that.setData({
- payNow: false
- })
- if (that.data.pay_methon == 2) {
- that.goToOrder('支付成功')
- return
- }
- wx.requestPayment({
- timeStamp: res.data.pay_data.timeStamp,
- nonceStr: res.data.pay_data.nonceStr,
- package: res.data.pay_data.package,
- signType: res.data.pay_data.signType,
- paySign: res.data.pay_data.paySign,
- success(res) {
- if (res.errMsg == 'requestPayment:ok') {
- that.goToOrder('支付成功')
- }
- },
- fail(res) {
- that.goToOrder('支付失败')
- }
- })
- }
- )
- },
-
- goToOrder(text) {
- let that = this
- wx.showToast({
- title: text,
- icon: text == '支付成功' ? 'success' : 'error'
- })
- if (text == '支付成功') {
-
- wx.reLaunch({
- url: `/pages/paySuccess/paySuccess?current=1&source=goods&order_id=${that.data.orderId}`
- })
-
- wx.requestSubscribeMessage({
- tmplIds: ['RNife3ZhTYYpUuT26ylGQj8W0v07IPo2TGe941iR3y8'],
- success(res) {
- let status = ''
- if (res['RNife3ZhTYYpUuT26ylGQj8W0v07IPo2TGe941iR3y8'] == 'reject') {
- status = 2
- } else {
- status = 1
- }
- get('/v2/api/activity/push', {
- type: 2,
- status,
- }, res => {})
- },
- })
- return
- } else {
- let failUrl = `/pages/goods/orderList/orderList?current=0`
- setTimeout(() => {
- wx.reLaunch({
- url: failUrl
- })
- }, 1000)
- }
- },
-
- onClosePay() {
- this.setData({
- payNow: false
- })
- },
-
- pay_methonw() {
- this.setData({
- pay_methon: 1
- })
- },
-
- pay_methonc() {
- this.setData({
- pay_methon: 2
- })
- },
-
- getAmount() {
- get('api/user/amount', {}, (res) => {
- if (res.data) {
- this.setData({
- inserllAmount: res.data.amount
- })
- }
- })
- },
-
- getStoreInfo() {
- get('api/store/info', {
- store_id: this.data.store_id
- }, (res => {
- this.setData({
- storeInfo: res.data
- })
- }))
- },
-
- getGiftBagDetail() {
- get('v2/api/package/info', {
- id: this.data.giftID
- }, (res => {
- this.setData({
- giftInfo: res.data,
- showMoneyGood: res.data.price
- })
-
- this.getNewPlus()
- }))
- },
-
- getNewPlus() {
- post('v2/api/car/plus', {}, (res => {
- if (res.code == 200) {
- let flag = true
- res.data.time = res.data.time.reverse()
- res.data.time.forEach(item => {
- if (Number(this.data.showMoneyGood) >= item.price && flag) {
- flag = false
- this.setData({
- exchangeCondition: item
- })
- }
- })
- res.data.list.forEach(item => {
- item.num = 0
- })
- this.setData({
- exchangeList: res.data,
- })
- }
- }))
- },
-
- add(e) {
- let index = e.currentTarget.dataset.index
-
- if (this.data.exchangeSum + 1 > this.data.exchangeCondition.time) {
- return
- }
- let exchangeList = `exchangeList.list[${index}].num`
- this.setData({
- [exchangeList]: this.data.exchangeList.list[index].num + 1
- })
-
- let sum = 0
- this.data.exchangeList.list.forEach(item => {
- sum = item.num + sum
- })
- this.setData({
- exchangeSum: sum
- })
-
- if (sum >= 1) {
- this.setData({
- exchangeSelect: true,
- toExchangePrice: 99,
- toExchangePrice: (Number(this.data.showMoneyGood) + 99).toFixed(2)
- })
- }
- },
-
- reduce(e) {
- let index = e.currentTarget.dataset.index
- if (this.data.exchangeList.list[index].num == 0) {
- return
- }
- let exchangeList = `exchangeList.list[${index}].num`
- this.setData({
- [exchangeList]: this.data.exchangeList.list[index].num - 1
- })
-
- let sum = 0
- this.data.exchangeList.list.forEach(item => {
- sum = item.num + sum
- })
- this.setData({
- exchangeSum: sum
- })
-
- if (sum < 1) {
- this.setData({
- exchangeSelect: false,
- toExchangePrice: 0,
- })
- }
- },
- })
|