details.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // page/component/details/details.js
  2. Page({
  3. data:{
  4. goods: {
  5. id: 1,
  6. image: '/image/goods1.png',
  7. title: '新鲜梨花带雨',
  8. price: 0.01,
  9. stock: '有货',
  10. detail: '这里是梨花带雨详情。',
  11. parameter: '125g/个',
  12. service: '不支持退货'
  13. },
  14. num: 1,
  15. totalNum: 0,
  16. hasCarts: false,
  17. curIndex: 0,
  18. show: false,
  19. scaleCart: false
  20. },
  21. addCount() {
  22. let num = this.data.num;
  23. num++;
  24. this.setData({
  25. num : num
  26. })
  27. },
  28. addToCart() {
  29. const self = this;
  30. const num = this.data.num;
  31. let total = this.data.totalNum;
  32. self.setData({
  33. show: true
  34. })
  35. setTimeout( function() {
  36. self.setData({
  37. show: false,
  38. scaleCart : true
  39. })
  40. setTimeout( function() {
  41. self.setData({
  42. scaleCart: false,
  43. hasCarts : true,
  44. totalNum: num + total
  45. })
  46. }, 200)
  47. }, 300)
  48. },
  49. bindTap(e) {
  50. const index = parseInt(e.currentTarget.dataset.index);
  51. this.setData({
  52. curIndex: index
  53. })
  54. }
  55. })