writeOff.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. // pages/welfareMall/writeOff/writeOff.js
  2. import WelfareMall from '../../../api/welfareMall'
  3. import { parseTime } from '../../../utils/util'
  4. import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. page: 1,
  11. pageSize: 10,
  12. lock: false,
  13. noResult: false,
  14. noMore: false,
  15. mobileTop: 'TONY WU',
  16. hexiaoList: [],
  17. storeList: [],
  18. index: 0,
  19. storeNo: '',
  20. date: '',
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. wx.hideShareMenu();
  27. },
  28. /**
  29. * 生命周期函数--监听页面初次渲染完成
  30. */
  31. onReady: function () {
  32. },
  33. /**
  34. * 生命周期函数--监听页面显示
  35. */
  36. onShow: function () {
  37. this.getHexiaoList();
  38. this.getStoreListByStaff();
  39. },
  40. /**
  41. * 生命周期函数--监听页面隐藏
  42. */
  43. onHide: function () {
  44. },
  45. /**
  46. * 生命周期函数--监听页面卸载
  47. */
  48. onUnload: function () {
  49. },
  50. /**
  51. * 页面相关事件处理函数--监听用户下拉动作
  52. */
  53. onPullDownRefresh: function () {
  54. },
  55. /**
  56. * 页面上拉触底事件的处理函数
  57. */
  58. onReachBottom: function () {
  59. if (this.data.lock || this.data.noMore) {
  60. return
  61. }
  62. this.data.lock = true
  63. this.data.page++
  64. this.getHexiaoList();
  65. },
  66. /**
  67. * 用户点击右上角分享
  68. */
  69. onShareAppMessage: function () {
  70. },
  71. // 获取核销记录
  72. getHexiaoList: function() {
  73. WelfareMall.getHexiaoList({
  74. page: this.data.page,
  75. pageSize: this.data.pageSize,
  76. mobile: getMobileCache(),
  77. storeNo: this.data.storeNo,
  78. date: this.data.date,
  79. }).then(res => {
  80. if (res.code == 200) {
  81. this.userHexiaoListView(res.data)
  82. }
  83. this.data.lock = false
  84. }).catch(_ => {
  85. console.log(_)
  86. this.data.lock = false
  87. })
  88. },
  89. userHexiaoListView: function(data) {
  90. if (!Array.isArray(data) || data.length == 0) {
  91. console.log("核销列表数据为空");
  92. if (this.data.page == 1) {
  93. this.setData({
  94. mobileTop:getMobileCache(),
  95. noResult: true
  96. })
  97. } else {
  98. this.setData({
  99. mobileTop:getMobileCache(),
  100. noMore: true
  101. })
  102. }
  103. return
  104. }
  105. data.forEach(v => {
  106. let usedTime = v.usedTime
  107. v.usedTime = parseTime(usedTime, "{y}.{m}.{d} {h}:{i}:{s}")
  108. })
  109. this.data.hexiaoList = this.data.hexiaoList.concat(...data)
  110. this.setData({
  111. mobileTop:getMobileCache(),
  112. hexiaoList: this.data.hexiaoList
  113. })
  114. },
  115. // 根据职员获取门店列表
  116. getStoreListByStaff: function() {
  117. WelfareMall.getStoreListByStaff({
  118. mobile: getMobileCache(),
  119. }).then(res => {
  120. if (res.code == 200) {
  121. this.userstoreListView(res.data)
  122. }
  123. this.data.lock = false
  124. }).catch(_ => {
  125. console.log(_)
  126. this.data.lock = false
  127. })
  128. },
  129. userstoreListView: function(data) {
  130. if (!Array.isArray(data) || data.length == 0) {
  131. console.log("门店列表数据为空");
  132. if (this.data.page == 1) {
  133. this.setData({
  134. mobileTop:getMobileCache(),
  135. noResult: true
  136. })
  137. } else {
  138. this.setData({
  139. mobileTop:getMobileCache(),
  140. noMore: true
  141. })
  142. }
  143. return
  144. }
  145. //增加全部门店空数据
  146. data.unshift({storeNo:"",storeName:"全部门店"})
  147. this.data.storeList = data
  148. this.setData({
  149. mobileTop:getMobileCache(),
  150. storeList: this.data.storeList
  151. })
  152. },
  153. //选择门店
  154. bindPickerChange: function (e) {
  155. console.log(e)
  156. this.setData({
  157. index: e.detail.value,
  158. hexiaoList: [],
  159. page: 1,
  160. pageSize: 10,
  161. lock: false,
  162. noResult: false,
  163. noMore: false,
  164. mobileTop: 'TONY WU',
  165. })
  166. let storeList = this.data.storeList
  167. if(storeList != null && storeList.length > 0){
  168. for(var i=0; i<storeList.length;i++){
  169. if(e.detail.value == i){
  170. // console.log(e.detail.value+'?'+i+'====='+storeList[i].storeNo)
  171. this.setData({
  172. storeNo: storeList[i].storeNo
  173. })
  174. break;
  175. }
  176. }
  177. }
  178. this.getHexiaoList();
  179. },
  180. //选择日期
  181. bindDateChange: function (e) {
  182. this.setData({
  183. date: e.detail.value,
  184. hexiaoList: [],
  185. page: 1,
  186. pageSize: 10,
  187. lock: false,
  188. noResult: false,
  189. noMore: false,
  190. mobileTop: 'TONY WU',
  191. })
  192. this.getHexiaoList();
  193. },
  194. //清除日期
  195. toCloseDet: function (e) {
  196. this.setData({
  197. hexiaoList: [],
  198. date: '',
  199. page: 1,
  200. pageSize: 10,
  201. lock: false,
  202. noResult: false,
  203. noMore: false,
  204. mobileTop: 'TONY WU',
  205. })
  206. this.getHexiaoList();
  207. },
  208. })