|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
- const util = require("../../utils/util.js");
- const Http = require("../../utils/HttpBasics");
- const config = require("../../config/config");
- const imgurl = require("../../utils/imgurl");
- const {
- alipay
- } = require("../../utils/imgurl");
- let app = getApp();
- Page({
- data: {
- navLineHeight: ((app.statusBarHeight + app.statusBarHeight) + 50) + "px",
- navigationBarHeight,
- noDataFlag: false,
- businePageNum: 1,
- businessData: null,
- Lsit: [],
- },
- goOrder() {
- tt.navigateTo({
- url: '/pages/order/index/index',
- success: (res) => {
-
- },
- fail: (res) => {
-
- },
- });
- },
- getCouponChannelList(key) {
- if (app.globalData.token) {
- if (this.data.noDataFlag) {
- return
- }
- tt.showLoading({
- title: "加载中"
- });
- let param = {}
- if (key == 0) {
- param = {
- pageNum: this.data.businePageNum,
- pageSize: 6,
- targetAd: 101
- }
- } else {
- param = {
- pageNum: this.data.businePageNum,
- pageSize: 6,
- business: key,
- targetAd: 101
-
- }
- }
- Http.get({
- url: config.api.couponChannelDouyinLiveList,
- data: param
- }).then(res => {
-
- if (res.data.list && res.data.list.length != 0) {
- let tempArr = []
- let tempLsit = this.data.businessData
- let data = res.data.list
- data.map(item => {
- tempArr.push(item.id)
-
- item.discount = (((item.salePriceStr * 1) / (item.priceStr * 1)) * 10).toFixed(1)
- })
- if (this.data.businePageNum > 1) {
- this.setData({
- businessData: [...tempLsit, ...data]
- })
- } else {
- this.setData({
- businessData: data
- })
- }
- this.getPriceAndStock(tempArr.join())
-
- } else {
- this.setData({
- noDataFlag: true
- })
- }
- tt.hideLoading();
- }).catch(err => {
- tt.hideLoading();
- tt.showModal({
- title: '提示',
- content: err.message ? err.message : err.data,
- showCancel: false
- })
- })
- } else {
- app.tokenCallback = token => {
- if (this.data.noDataFlag) {
- return
- }
- tt.showLoading({
- title: "加载中"
- });
- let param = {}
- if (key == 0) {
- param = {
- pageNum: this.data.businePageNum,
- pageSize: 6,
- targetAd: 101
- }
- } else {
- param = {
- pageNum: this.data.businePageNum,
- pageSize: 6,
- business: key,
- targetAd: 101
-
- }
- }
- Http.get({
- url: config.api.couponChannelDouyinLiveList,
- data: param
- }).then(res => {
- if (res.data.list && res.data.list.length != 0) {
- let tempArr = []
- let tempLsit = this.data.businessData
- let data = res.data.list
- data.map(item => {
- tempArr.push(item.id)
- item.discount = (((item.salePriceStr * 1) / (item.priceStr * 1)) * 10).toFixed(1)
- })
- if (this.data.businePageNum > 1) {
- this.setData({
- businessData: [...tempLsit, ...data]
- })
- } else {
- this.setData({
- businessData: data
- })
- }
- this.getPriceAndStock(tempArr.join())
-
- } else {
- this.setData({
- noDataFlag: true
- })
- }
- tt.hideLoading();
- }).catch(err => {
- tt.hideLoading();
- tt.showModal({
- title: '提示',
- content: err.message ? err.message : err.data,
- showCancel: false
- })
- })
- }
- }
-
-
-
- },
-
- upDataLsit() {
- this.setData({
- businePageNum: 1,
- noDataFlag: false,
- businessData: []
-
- });
- this.getCouponChannelList(0)
- },
-
- //获取券列表的价格和库存(列表接口有缓存通过这个来获取) str 列表数组里面的所有id
- getPriceAndStock(str) {
- console.log(str);
- Http.get({
- url: config.api.batchCouponPriceAndStock,
- data: {
- couponChannelIds: str
- }
- }).then(res => {
- console.log(JSON.parse(res.data));
- let tempObj = JSON.parse(res.data)
- let tempData = this.data.businessData
- tempData.map(item1 => {
- tempObj.map(item2 => {
- if (item2.id == item1.id) {
- item1.sale = item2.inventory - item2.remainInventory
- item1.percent = ((item1.sale / item2.inventory).toFixed(3)) * 100 + '%'
- item1.salePriceStr = item2.salePrice / 100
- item1.priceStr = item2.price / 100
- }
- })
- })
- this.setData({
- Lsit: tempData
- })
-
- }).catch(err => {
- tt.hideLoading();
- tt.showModal({
- title: '提示',
- content: err.message ? err.message : err.data,
- showCancel: false
- })
- })
- },
- goDetail(e) {
- let couponChannelId = e.currentTarget.dataset.id
- let couponId = e.currentTarget.dataset.couponid
- tt.navigateTo({
- url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`,
- })
- },
- onLoad: function (options) {
- //固定写法 放在指定要手机号授权框出现
- // app.globalData.ifCongPh = 1
- this.getCouponChannelList()
- },
- onReachBottom: function () {
- console.log("我到底了")
- let that = this;
- that.setData({
- businePageNum: that.data.businePageNum + 1
- });
- console.log("加载更多页数" + that.data.page, );
- console.log("加载更多key" + that.data.code);
- this.getCouponChannelList(0)
- },
- })
|