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

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