blockItem.js 4.1 KB

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