goodsManage.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. isIpx: false,
  9. goods: [{
  10. name: '大苹果',
  11. image: 'https://shiziyu.liofis.com/attachment/images/3/2019/03/S3sWb8he8w9ujHJ70bI8JUh2wuJjbS.jpg?imageView2/2/w/240/h/240/ignore-error/1',
  12. status_name: '上架',
  13. checked: false
  14. },
  15. {
  16. name: '大苹果',
  17. image: 'https://shiziyu.liofis.com/attachment/images/3/2019/03/S3sWb8he8w9ujHJ70bI8JUh2wuJjbS.jpg?imageView2/2/w/240/h/240/ignore-error/1',
  18. status_name: '上架',
  19. checked: true
  20. }],
  21. checkedAll: false,
  22. checkedCount: 0
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function(options) {
  28. if (!util.check_login()) {
  29. wx.redirectTo({
  30. url: '/lionfish_comshop/pages/user/me',
  31. })
  32. }
  33. app.globalData.isIpx && this.setData({
  34. isIpx: true
  35. });
  36. },
  37. /**
  38. * 生命周期函数--监听页面显示
  39. */
  40. onShow: function() {
  41. },
  42. /**
  43. * 勾选
  44. */
  45. checkboxChange: function(e) {
  46. var type = e.currentTarget.dataset.type,
  47. idx = e.currentTarget.dataset.index,
  48. goods = this.data.goods,
  49. checkedAll = this.data.checkedAll;
  50. if ("all" === type) {
  51. let ck = 0;
  52. if (checkedAll) {
  53. goods.forEach(function(item) {
  54. item.checked = 0;
  55. })
  56. } else {
  57. goods.forEach(function (item) {
  58. item.checked = 1;
  59. })
  60. ck = goods.length;
  61. }
  62. this.setData({
  63. checkedCount: ck,
  64. goods: goods,
  65. checkedAll: !checkedAll
  66. })
  67. } else if ("item" === type) {
  68. goods.forEach(function (item, t) {
  69. if (idx == t) {
  70. if (item.checked) {
  71. item.checked = 0
  72. } else {
  73. item.checked = 1
  74. }
  75. }
  76. })
  77. var ck = 0;
  78. goods.forEach(function (item) {
  79. if (item.checked) {
  80. ck++;
  81. }
  82. })
  83. this.setData({
  84. checkedCount: ck,
  85. goods: goods,
  86. checkedAll: ck == goods.length ? true : false
  87. })
  88. }
  89. },
  90. /**
  91. * 页面相关事件处理函数--监听用户下拉动作
  92. */
  93. onPullDownRefresh: function() {
  94. },
  95. /**
  96. * 页面上拉触底事件的处理函数
  97. */
  98. onReachBottom: function() {
  99. }
  100. })