抖音小程序C端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

210 wiersze
5.2 KiB

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