blockItem.js 4.6 KB

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