index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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({ isShow: route.indexOf("goods_details")!==-1});
  52. },
  53. methods: {
  54. /**
  55. * 购物车手动输入数量
  56. *
  57. */
  58. bindCode: function (e) {
  59. this.triggerEvent('iptCartNum', e.detail.value);
  60. },
  61. close: function () {
  62. this.triggerEvent('myevent', {'window': false});
  63. },
  64. goCat:function(){
  65. this.triggerEvent('goCat');
  66. },
  67. CartNumDes:function(){
  68. this.triggerEvent('ChangeCartNum', false);
  69. },
  70. CartNumInt:function(){
  71. this.triggerEvent('ChangeCartNum', true);
  72. },
  73. tapAttr:function(e){
  74. //父级index
  75. var indexw = e.currentTarget.dataset.indexw;
  76. //子集index
  77. var indexn = e.currentTarget.dataset.indexn;
  78. //每次点击获得的属性
  79. var attr = this.data.productAttr[indexw].attr_value[indexn];
  80. //设置当前点击属性
  81. this.data.productAttr[indexw].checked = attr['attr'];
  82. this.setData({
  83. productAttr: this.data.productAttr,
  84. });
  85. var value = this.getCheckedValue().sort().join(',');
  86. this.triggerEvent('ChangeAttr',value);
  87. },
  88. getCheckedValue: function () {
  89. return this.data.productAttr.map(function (attr) {
  90. return attr.checked;
  91. });
  92. },
  93. ResetAttr:function(){
  94. for (var k in this.data.productAttr) this.data.productAttr[k].checked='';
  95. this.setData({ productAttr: this.data.productAttr});
  96. },
  97. }
  98. })