抖音小程序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.

215 line
5.6 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  2. const util = require("../../utils/util.js");
  3. const Http = require("../../utils/HttpBasics");
  4. const config = require("../../config/config");
  5. const imgurl = require("../../utils/imgurl");
  6. const { alipay } = require("../../utils/imgurl");
  7. let app = getApp();
  8. Page({
  9. data: {
  10. navLineHeight: ((app.statusBarHeight + app.statusBarHeight) + 50) + "px",
  11. navigationBarHeight,
  12. noDataFlag: false,
  13. businePageNum: 1,
  14. businessData: null,
  15. // Lsit:[]
  16. },
  17. getCouponChannelList(key) {
  18. if (app.globalData.token) {
  19. if (this.data.noDataFlag) {
  20. return
  21. }
  22. tt.showLoading({
  23. title: "加载中"
  24. });
  25. let param = {}
  26. if (key == 0) {
  27. param = {
  28. pageNum: this.data.businePageNum,
  29. pageSize: 6,
  30. targetAd: 101
  31. }
  32. } else {
  33. param = {
  34. pageNum: this.data.businePageNum,
  35. pageSize: 6,
  36. business: key,
  37. targetAd: 101
  38. }
  39. }
  40. Http.get({
  41. url: config.api.couponChannelDouyinLiveList,
  42. data: param
  43. }).then(res => {
  44. if (res.data.list && res.data.list.length != 0) {
  45. let tempArr = []
  46. let tempLsit = this.data.businessData
  47. let data = res.data.list
  48. data.map(item => {
  49. tempArr.push(item.id)
  50. item.discount = (((item.salePriceStr*1)/(item.priceStr*1))*10).toFixed(1)
  51. })
  52. if (this.data.businePageNum > 1) {
  53. this.setData({
  54. businessData: [...tempLsit, ...data]
  55. })
  56. } else {
  57. this.setData({
  58. businessData: data
  59. })
  60. }
  61. this.getPriceAndStock(tempArr.join())
  62. } else {
  63. this.setData({
  64. noDataFlag: true
  65. })
  66. }
  67. tt.hideLoading();
  68. }).catch(err => {
  69. tt.hideLoading();
  70. tt.showModal({
  71. title: '提示',
  72. content: err.message ? err.message : err.data,
  73. showCancel: false
  74. })
  75. })
  76. } else {
  77. app.tokenCallback = token => {
  78. if (this.data.noDataFlag) {
  79. return
  80. }
  81. tt.showLoading({
  82. title: "加载中"
  83. });
  84. let param = {}
  85. if (key == 0) {
  86. param = {
  87. pageNum: this.data.businePageNum,
  88. pageSize: 6,
  89. targetAd: 101
  90. }
  91. } else {
  92. param = {
  93. pageNum: this.data.businePageNum,
  94. pageSize: 6,
  95. business: key,
  96. targetAd: 101
  97. }
  98. }
  99. Http.get({
  100. url: config.api.couponChannelDouyinLiveList,
  101. data: param
  102. }).then(res => {
  103. if (res.data.list && res.data.list.length != 0) {
  104. let tempArr = []
  105. let tempLsit = this.data.businessData
  106. let data = res.data.list
  107. data.map(item => {
  108. tempArr.push(item.id)
  109. item.discount = (((item.salePriceStr*1)/(item.priceStr*1))*10).toFixed(1)
  110. })
  111. if (this.data.businePageNum > 1) {
  112. this.setData({
  113. businessData: [...tempLsit, ...data]
  114. })
  115. } else {
  116. this.setData({
  117. businessData: data
  118. })
  119. }
  120. this.getPriceAndStock(tempArr.join())
  121. } else {
  122. this.setData({
  123. noDataFlag: true
  124. })
  125. }
  126. tt.hideLoading();
  127. }).catch(err => {
  128. tt.hideLoading();
  129. tt.showModal({
  130. title: '提示',
  131. content: err.message ? err.message : err.data,
  132. showCancel: false
  133. })
  134. })
  135. }
  136. }
  137. },
  138. upDataLsit() {
  139. this.setData({
  140. businePageNum: 1,
  141. noDataFlag: false,
  142. businessData: []
  143. });
  144. this.getCouponChannelList(0)
  145. },
  146. //获取券列表的价格和库存(列表接口有缓存通过这个来获取) str 列表数组里面的所有id
  147. getPriceAndStock(str) {
  148. return
  149. console.log(str);
  150. Http.get({
  151. url: config.api.batchCouponPriceAndStock,
  152. data: {
  153. couponChannelIds: str
  154. }
  155. }).then(res => {
  156. console.log(JSON.parse(res.data));
  157. let tempObj = JSON.parse(res.data)
  158. let tempData = this.data.businessData
  159. tempData.map(item1 => {
  160. tempObj.map(item2 => {
  161. if (item2.id == item1.id) {
  162. item1.sale = item2.inventory - item2.remainInventory
  163. item1.percent = ((item1.sale / item2.inventory).toFixed(3)) * 100 + '%'
  164. item1.salePriceStr = item2.salePrice / 100
  165. item1.priceStr = item2.price / 100
  166. }
  167. })
  168. })
  169. this.setData({
  170. Lsit: tempData
  171. })
  172. }).catch(err => {
  173. tt.hideLoading();
  174. tt.showModal({
  175. title: '提示',
  176. content: err.message ? err.message : err.data,
  177. showCancel: false
  178. })
  179. })
  180. },
  181. goDetail(e) {
  182. let couponChannelId = e.currentTarget.dataset.id
  183. let couponId = e.currentTarget.dataset.couponid
  184. tt.navigateTo({
  185. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`,
  186. })
  187. },
  188. onLoad: function (options) {
  189. app.globalData.ifCongPh = 1//固定写法 放在指定要手机号授权框出现
  190. this.getCouponChannelList()
  191. },
  192. onReachBottom: function () {
  193. console.log("我到底了")
  194. let that = this;
  195. that.setData({
  196. businePageNum: that.data.businePageNum + 1
  197. });
  198. console.log("加载更多页数" + that.data.page,);
  199. console.log("加载更多key" + that.data.code);
  200. this.getCouponChannelList(0)
  201. },
  202. })