writeOff.js 5.5 KB

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