index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. var app = getApp();
  2. Component({
  3. properties: {
  4. iSplus: {
  5. type: Boolean,
  6. value: true
  7. },
  8. iSbnt: {
  9. type: Number,
  10. value: 0
  11. },
  12. limitNum: {
  13. type: Number,
  14. value: 0
  15. },
  16. attribute: {
  17. type: Object,
  18. value: {}
  19. },
  20. attrList: {
  21. type: Object,
  22. value: [],
  23. },
  24. productAttr: {
  25. type: Object,
  26. value: [],
  27. },
  28. productSelect: {
  29. type: Object,
  30. value: {
  31. image: '',
  32. store_name: '',
  33. price: 0,
  34. unique: '',
  35. stock: 0,
  36. }
  37. },
  38. },
  39. data: {
  40. attrValue: [],
  41. attrIndex: 0,
  42. isShow: false
  43. },
  44. attached: function () {
  45. let pages = getCurrentPages();
  46. let currPage = null;
  47. if (pages.length) {
  48. currPage = pages[pages.length - 1];
  49. }
  50. let route = currPage.route
  51. this.setData({
  52. isShow: route.indexOf("goods_details") !== -1
  53. });
  54. },
  55. methods: {
  56. /**
  57. * 购物车手动输入数量
  58. */
  59. bindCode: function (e) {
  60. this.triggerEvent('iptCartNum', e.detail.value);
  61. },
  62. close: function () {
  63. this.triggerEvent('myevent', {
  64. 'window': false
  65. });
  66. },
  67. goCat: function () {
  68. this.triggerEvent('goCat');
  69. },
  70. CartNumDes: function () {
  71. this.triggerEvent('ChangeCartNum', false);
  72. },
  73. CartNumInt: function () {
  74. this.triggerEvent('ChangeCartNum', true);
  75. },
  76. tapAttr: function (e) {
  77. //父级index
  78. var indexw = e.currentTarget.dataset.indexw;
  79. //子集index
  80. var indexn = e.currentTarget.dataset.indexn;
  81. //每次点击获得的属性
  82. var attr = this.data.productAttr[indexw].attr_value[indexn];
  83. //设置当前点击属性
  84. this.data.productAttr[indexw].checked = attr['attr'];
  85. this.setData({
  86. productAttr: this.data.productAttr,
  87. });
  88. var value = this.getCheckedValue().sort().join(',');
  89. this.triggerEvent('ChangeAttr', value);
  90. },
  91. getCheckedValue: function () {
  92. return this.data.productAttr.map(function (attr) {
  93. return attr.checked;
  94. });
  95. },
  96. ResetAttr: function () {
  97. for (var k in this.data.productAttr) this.data.productAttr[k].checked = '';
  98. this.setData({
  99. productAttr: this.data.productAttr
  100. });
  101. },
  102. }
  103. })