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. },
  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. page: 1,
  159. pageSize: 10,
  160. lock: false,
  161. noResult: false,
  162. noMore: false,
  163. mobileTop: 'TONY WU',
  164. })
  165. let storeList = this.data.storeList
  166. if(storeList != null && storeList.length > 0){
  167. for(var i=0; i<storeList.length;i++){
  168. if(e.detail.value == i){
  169. // console.log(e.detail.value+'?'+i+'====='+storeList[i].storeNo)
  170. this.setData({
  171. storeNo: storeList[i].storeNo
  172. })
  173. break;
  174. }
  175. }
  176. }
  177. this.getHexiaoList();
  178. },
  179. //选择日期
  180. bindDateChange: function (e) {
  181. this.setData({
  182. date: e.detail.value,
  183. hexiaoList: [],
  184. page: 1,
  185. pageSize: 10,
  186. lock: false,
  187. noResult: false,
  188. noMore: false,
  189. mobileTop: 'TONY WU',
  190. })
  191. this.getHexiaoList();
  192. },
  193. //清除日期
  194. toCloseDet: function (e) {
  195. this.setData({
  196. hexiaoList: [],
  197. date: '',
  198. page: 1,
  199. pageSize: 10,
  200. lock: false,
  201. noResult: false,
  202. noMore: false,
  203. mobileTop: 'TONY WU',
  204. })
  205. this.getHexiaoList();
  206. },
  207. })