writeOff.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. },
  59. /**
  60. * 用户点击右上角分享
  61. */
  62. onShareAppMessage: function () {
  63. },
  64. // 获取核销记录
  65. getHexiaoList: function() {
  66. WelfareMall.getHexiaoList({
  67. page: this.data.page,
  68. pageSize: this.data.pageSize,
  69. mobile: getMobileCache(),
  70. storeNo: this.data.storeNo,
  71. date: this.data.date,
  72. }).then(res => {
  73. if (res.code == 200) {
  74. this.userHexiaoListView(res.data)
  75. }
  76. this.data.lock = false
  77. }).catch(_ => {
  78. console.log(_)
  79. this.data.lock = false
  80. })
  81. },
  82. userHexiaoListView: function(data) {
  83. if (!Array.isArray(data) || data.length == 0) {
  84. console.log("核销列表数据为空");
  85. if (this.data.page == 1) {
  86. this.setData({
  87. mobileTop:getMobileCache(),
  88. noResult: true
  89. })
  90. } else {
  91. this.setData({
  92. mobileTop:getMobileCache(),
  93. noMore: true
  94. })
  95. }
  96. return
  97. }
  98. data.forEach(v => {
  99. let usedTime = v.usedTime
  100. v.usedTime = parseTime(usedTime, "{y}.{m}.{d} {h}:{i}:{s}")
  101. })
  102. this.data.hexiaoList = this.data.hexiaoList.concat(...data)
  103. this.setData({
  104. mobileTop:getMobileCache(),
  105. hexiaoList: this.data.hexiaoList
  106. })
  107. },
  108. // 根据职员获取门店列表
  109. getStoreListByStaff: function() {
  110. WelfareMall.getStoreListByStaff({
  111. mobile: getMobileCache(),
  112. }).then(res => {
  113. if (res.code == 200) {
  114. this.userstoreListView(res.data)
  115. }
  116. this.data.lock = false
  117. }).catch(_ => {
  118. console.log(_)
  119. this.data.lock = false
  120. })
  121. },
  122. userstoreListView: function(data) {
  123. if (!Array.isArray(data) || data.length == 0) {
  124. console.log("门店列表数据为空");
  125. if (this.data.page == 1) {
  126. this.setData({
  127. mobileTop:getMobileCache(),
  128. noResult: true
  129. })
  130. } else {
  131. this.setData({
  132. mobileTop:getMobileCache(),
  133. noMore: true
  134. })
  135. }
  136. return
  137. }
  138. //增加全部门店空数据
  139. data.unshift({storeNo:"",storeName:"全部门店"})
  140. this.data.storeList = data
  141. this.setData({
  142. mobileTop:getMobileCache(),
  143. storeList: this.data.storeList
  144. })
  145. },
  146. //选择门店
  147. bindPickerChange: function (e) {
  148. console.log(e)
  149. this.setData({
  150. index: e.detail.value,
  151. hexiaoList: [],
  152. })
  153. let storeList = this.data.storeList
  154. if(storeList != null && storeList.length > 0){
  155. for(var i=0; i<storeList.length;i++){
  156. if(e.detail.value == i){
  157. // console.log(e.detail.value+'?'+i+'====='+storeList[i].storeNo)
  158. this.setData({
  159. storeNo: storeList[i].storeNo
  160. })
  161. break;
  162. }
  163. }
  164. }
  165. this.getHexiaoList();
  166. },
  167. //选择日期
  168. bindDateChange: function (e) {
  169. this.setData({
  170. date: e.detail.value,
  171. hexiaoList: [],
  172. })
  173. this.getHexiaoList();
  174. },
  175. //清除日期
  176. toCloseDet: function (e) {
  177. this.setData({
  178. hexiaoList: [],
  179. date: '',
  180. })
  181. this.getHexiaoList();
  182. },
  183. })