writeOff.js 5.1 KB

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