blockItem.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // pages/components/blockItem/blockItem.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. item_data: {
  8. type:Object
  9. },
  10. summery:{
  11. type:Array
  12. },
  13. special_datas:{
  14. type:Object,
  15. value:{}
  16. }
  17. },
  18. ready() {
  19. if (!(this.properties.special_datas).hasOwnProperty('fcodes')){
  20. return;
  21. }
  22. const fcodes = this.properties.special_datas.fcodes;
  23. const goods_id = this.properties.item_data.data;
  24. const summery = this.properties.summery;
  25. let fcode = {};
  26. for (let item of summery) {
  27. if (item.goods_id == goods_id){
  28. this.setData({
  29. goods:item
  30. })
  31. break;
  32. }
  33. }
  34. for (let item of fcodes){
  35. if (item.goods_id == goods_id) {
  36. fcode = item;
  37. break;
  38. }
  39. }
  40. fcode.usable_time = (function(time){
  41. let date = new Date(time * 1000);
  42. let year = date.getFullYear();
  43. let month = date.getMonth() + 1;
  44. let day = date.getDate();
  45. return `${year}.${month}.${day}`;
  46. })(fcode.usable_time);
  47. fcode.state = (function(state){
  48. let bgColor = '';
  49. let title = '';
  50. switch (state) {
  51. case 0:
  52. bgColor = "#ffa82d";
  53. title = "可使用";
  54. break;
  55. case 1:
  56. bgColor = "#bfbfbf";
  57. title = "已用完";
  58. break;
  59. case 2:
  60. bgColor = "#bfbfbf";
  61. title = "已过期";
  62. break;
  63. case 3:
  64. bgColor = "#7e7e7e";
  65. title = '已锁定';
  66. break;
  67. }
  68. return {
  69. bgColor: bgColor,
  70. title: title
  71. }
  72. })(fcode.state);
  73. this.setData({
  74. fcode:fcode
  75. })
  76. },
  77. /**
  78. * 组件的初始数据
  79. */
  80. data: {
  81. imgShow:false,
  82. goods: {},
  83. fcode: {}
  84. },
  85. /**
  86. * 组件的方法列表
  87. */
  88. methods: {
  89. navigator(e){
  90. const type = e.target.dataset.type || e.currentTarget.dataset.type;
  91. const target_data = e.target.dataset.target || e.currentTarget.dataset.target;
  92. const title = e.target.dataset.title || e.currentTarget.dataset.title;
  93. if(!type)return;
  94. switch(type){
  95. case "url":{
  96. let attr = encodeURIComponent(`${target_data}`);
  97. wx.navigateTo({
  98. url: '/pages/webView/webView?url='+attr
  99. })
  100. break;
  101. }
  102. case "special":{
  103. wx.navigateTo({
  104. url: `/pages/special/special?special_id=${target_data}&title=${title}`
  105. })
  106. break;
  107. }
  108. case "goods":{
  109. wx.navigateTo({
  110. url: `/pages/details/details?goods_id=${target_data}&title=商品详情`
  111. })
  112. break;
  113. }
  114. case "brand":{
  115. wx.navigateTo({
  116. url: `/pages/brand/brand?brand_id=${target_data}&title=${title}`
  117. })
  118. break;
  119. }
  120. default: {
  121. console.log(type+'类型找不到');
  122. }
  123. }
  124. },
  125. load(e){
  126. this.setData({
  127. imgShow:true
  128. });
  129. }
  130. }
  131. })