blockItem.js 3.0 KB

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