writeOff.js 6.0 KB

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