writeOff.js 4.4 KB

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