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.

268 lines
6.9 KiB

  1. // pages/couponRecord/index.js
  2. const config = require('../../config/config.js')
  3. const Http = require('../../utils/HttpBasics.js')
  4. const util = require('../../utils/util.js')
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. date: util.formatTime(new Date(), 'yyyy-MM-dddd'), //默认起始时间
  12. date2: util.formatTime(new Date(), 'yyyy-MM-dddd'), //默认结束时间
  13. endDate: util.formatTime(new Date(), 'yyyy-MM-dddd'),
  14. time: new Date(),
  15. list: [],
  16. showNocontent: false,
  17. todayDate: null,
  18. pageNum: 1,
  19. length: 0,
  20. userInfo: null,
  21. listData: [],
  22. loading: false,
  23. content: '正在加载中',
  24. content1: '正在加载中',
  25. couList:[],
  26. dataH:[],
  27. pages:null,
  28. },
  29. /**
  30. * 生命周期函数--监听页面加载
  31. */
  32. onLoad: function (options) {
  33. this.getUser();
  34. this.setData({
  35. pageNumH: 2,
  36. flag: "coupons",
  37. loading:false
  38. });
  39. },
  40. bindDateChange(e) {
  41. let that = this;
  42. that.setData({
  43. date: e.detail.value,
  44. })
  45. console.log(that.data.date)
  46. },
  47. bindDateChange2(e) {
  48. let that = this;
  49. that.setData({
  50. date2: e.detail.value,
  51. })
  52. console.log(that.data.date2)
  53. },
  54. search() {
  55. this.getList(this.data.pageNum)
  56. },
  57. getUser() {
  58. let _this = this;
  59. app.globalData.userInfo().then(res => {
  60. this.setData({
  61. userInfo: res
  62. })
  63. _this.getMerchentCoupon(1);
  64. console.log(res);
  65. })
  66. },
  67. formatData(data) {
  68. let tempAtt = data
  69. let arr = [];
  70. tempAtt.map(item => {
  71. let a = {};
  72. a.value = [item];
  73. a.dateR = item.createDate01;
  74. let indexSt = 0;
  75. let haveIf = false;
  76. arr.map((item01, index01) => {
  77. if (item.createDate01 == item01.dateR) {
  78. indexSt = index01;
  79. haveIf = true;
  80. }
  81. })
  82. // console.log((new Date(item.createDate)).valueOf())
  83. // console.log((new Date((this.data.date + ' 00:00:00'))).getTime())
  84. // console.log((new Date((this.data.date2 + ' 23:59:59').replace(/-/g, "/"))))
  85. // console.log(this.data.date, this.data.date2)
  86. if (haveIf && (new Date(item.createDate)).valueOf() >= (new Date((this.data.date + ' 00:00:00').replace(/-/g, "/"))).getTime() && (new Date(item.createDate)).valueOf() <= (new Date((this.data.date2 + ' 23:59:59').replace(/-/g, "/"))).getTime()) {
  87. arr[indexSt].value.push(item)
  88. } else if ((new Date(item.createDate)).valueOf() >= (new Date((this.data.date + ' 00:00:00').replace(/-/g, "/"))).getTime() && (new Date(item.createDate)).valueOf() <= (new Date((this.data.date2 + ' 23:59:59').replace(/-/g, "/"))).getTime()) {
  89. arr.push(a)
  90. }
  91. })
  92. this.setData({
  93. list: arr
  94. })
  95. console.log(arr,888888888888)
  96. },
  97. getList(page) {
  98. let _this = this;
  99. Http.get({
  100. url: config.api.wxMerchantcouponStory,
  101. data: {
  102. token: app.globalData.token,
  103. pageNum: page,
  104. pageSize: 10,
  105. channelType:7,
  106. beginDate: this.data.date ,
  107. endDate: this.data.date2
  108. }
  109. })
  110. .then(res => {
  111. wx.stopPullDownRefresh();
  112. let data = res.data.list;
  113. let listData = [];
  114. if (page == 1) {
  115. listData = res.data.list;
  116. } else {
  117. listData = _this.data.listData;
  118. }
  119. data.map(item => {
  120. let haveIf = false;
  121. item.createDate01 = util.formatTime(item.createDate, 'yyyy-MM-dddd hh:mm:ss')
  122. listData.map((item02, index02) => {
  123. if (item02.actionId == item.actionId) {
  124. haveIf = true;
  125. }
  126. })
  127. if (!haveIf) {
  128. listData.push(item)
  129. }
  130. })
  131. _this.formatData(listData)
  132. if (res.data.pages <= page) {
  133. _this.setData({
  134. listData,
  135. pageNum: res.data.pages - 1,
  136. content: '已经加载全部数据!'
  137. })
  138. } else {
  139. _this.setData({
  140. listData,
  141. loading: false,
  142. content: '小主,我在玩命加载中...'
  143. })
  144. }
  145. })
  146. .catch(err => {
  147. wx.stopPullDownRefresh();
  148. wx.showToast({
  149. title: err.message,
  150. icon: 'none',
  151. duration: 2000,
  152. mask: false
  153. });
  154. });
  155. },
  156. //赠券库存
  157. getMerchentCoupon(pageNumH) {
  158. let that = this;
  159. let postData = {
  160. token: app.globalData.token,
  161. pageNum: pageNumH,
  162. pageSize: 10,
  163. sendType: 7,
  164. expired:'',
  165. status:'',
  166. }
  167. Http.get({
  168. url: config.api.wxMerchantcouponSend,
  169. data: postData,
  170. })
  171. .then(res => {
  172. res.data.list.map((item, index) => {
  173. // item = Object.assign(item, { yxStauts: true })
  174. // if (item.validDays) {
  175. // item = Object.assign(item, { yxStauts: false })
  176. // }
  177. // if (item.validEndDate < Date.now()) {
  178. // item = Object.assign(item, { yxStauts: true })
  179. // } else {
  180. // item = Object.assign(item, { yxStauts: false })
  181. // }
  182. item.validEndDate = util.formatTime(item.validEndDate, 'yyyy-MM-dddd')
  183. item.validStartDate = util.formatTime(item.validStartDate, 'yyyy-MM-dddd')
  184. });
  185. if (pageNumH == 1) {
  186. console.log("我进来了!")
  187. var tmpArr = [];
  188. } else {
  189. console.log("我赋值了")
  190. var tmpArr = that.data.couList;
  191. }
  192. tmpArr.push.apply(tmpArr, res.data.list);
  193. that.setData({
  194. couList: tmpArr,
  195. })
  196. if (tmpArr.length >= res.data.total) {
  197. that.setData({
  198. content1: '没有更多数据'
  199. })
  200. return false;
  201. } else {
  202. that.setData({
  203. loading: false,
  204. content1: '小主,我在玩命加载中...'
  205. })
  206. }
  207. })
  208. .catch(err => {
  209. wx.showToast({
  210. title: err.message,
  211. icon: 'none',
  212. duration: 2000,
  213. mask: false
  214. });
  215. });
  216. },
  217. //切换库存
  218. getCoupons() {
  219. this.setData({
  220. flag: "coupons",
  221. pageNumH: 1,
  222. loading:false
  223. })
  224. this.getMerchentCoupon(1, "coupons"),
  225. wx.setNavigationBarTitle({
  226. title: '赠券库存'
  227. })
  228. },
  229. //切换记录
  230. getRecord() {
  231. this.setData({
  232. flag: "record",
  233. page: 1,
  234. loading:false
  235. })
  236. this.getList(1, "record"),
  237. wx.setNavigationBarTitle({
  238. title: '注券记录'
  239. })
  240. },
  241. /**
  242. * 刷新
  243. */
  244. onPullDownRefresh: function (e) {
  245. let that = this;
  246. that.setData({
  247. pageNum: 1,
  248. });
  249. that.getList(1);
  250. that.getMerchentCoupon(1);
  251. },
  252. onReachBottom: function () {
  253. let that = this;
  254. that.data.pageNum++;
  255. that.setData({
  256. pageNum: that.data.pageNum,
  257. loading: true
  258. });
  259. that.getList(that.data.pageNum);
  260. let pageNumH = that.data.pageNumH++;
  261. that.getMerchentCoupon(pageNumH);
  262. }
  263. })