抖音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.

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