index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. var app = getApp();
  2. Component({
  3. properties: {
  4. attribute: {
  5. type: Object,
  6. value:{}
  7. },
  8. attrList:{
  9. type: Object,
  10. value:[],
  11. },
  12. productAttr:{
  13. type: Object,
  14. value: [],
  15. },
  16. productSelect:{
  17. type: Object,
  18. value: {
  19. image: '',
  20. store_name: '',
  21. price: 0,
  22. unique: '',
  23. stock:0,
  24. }
  25. },
  26. },
  27. data: {
  28. attrValue:[],
  29. attrIndex:0,
  30. },
  31. attached: function () {
  32. },
  33. methods: {
  34. close: function () {
  35. this.triggerEvent('myevent', {'window': false});
  36. },
  37. CartNumDes:function(){
  38. this.triggerEvent('ChangeCartNum', false);
  39. },
  40. CartNumInt:function(){
  41. this.triggerEvent('ChangeCartNum', true);
  42. },
  43. tapAttr:function(e){
  44. //父级index
  45. var indexw = e.currentTarget.dataset.indexw;
  46. //子集index
  47. var indexn = e.currentTarget.dataset.indexn;
  48. //每次点击获得的属性
  49. var attr = this.data.productAttr[indexw].attr_value[indexn];
  50. //设置当前点击属性
  51. this.data.productAttr[indexw].checked = attr['attr'];
  52. this.setData({
  53. productAttr: this.data.productAttr,
  54. });
  55. var value = this.getCheckedValue().sort().join(',');
  56. this.triggerEvent('ChangeAttr',value);
  57. },
  58. getCheckedValue: function () {
  59. return this.data.productAttr.map(function (attr) {
  60. return attr.checked;
  61. });
  62. },
  63. ResetAttr:function(){
  64. for (var k in this.data.productAttr) this.data.productAttr[k].checked='';
  65. this.setData({ productAttr: this.data.productAttr});
  66. },
  67. }
  68. })