123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- // pages/components/blockItem/blockItem.js
- const getTypeSn = require('../../../utils/util.js').getTypeSn;
- const parseAppjump = require('../../../utils/util.js').parseAppjump;
- const buyVGoods = require('../../../config.js').buyVGoods;
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- item_data: {
- type: Object
- },
- summery: {
- type: Array
- },
- special_datas: {
- type: Object,
- value: {}
- },
- block_type: {
- type: String,
- value: ""
- }
- },
- ready() {
- if (!this.properties.special_datas || !(this.properties.special_datas).hasOwnProperty('fcodes')) {
- return;
- }
- const fcodes = this.properties.special_datas.fcodes;
- const goods_id = this.properties.item_data.data;
- const summery = this.properties.summery;
- let fcode = {};
- for (let item of summery) {
- if (item.goods_id == goods_id) {
- this.setData({
- goods: item
- })
- break;
- }
- }
- for (let item of fcodes) {
- if (item.goods_id == goods_id) {
- fcode = item;
- break;
- }
- }
- fcode.usable_time = (function (time) {
- let date = new Date(time * 1000);
- let year = date.getFullYear();
- let month = date.getMonth() + 1;
- let day = date.getDate();
- return `${year}.${month}.${day}`;
- })(fcode.usable_time);
- fcode.state = (function (state) {
- let bgColor = '';
- let title = '';
- switch (state) {
- case 0:
- bgColor = "#ffa82d";
- title = "可使用";
- break;
- case 1:
- bgColor = "#bfbfbf";
- title = "已用完";
- break;
- case 2:
- bgColor = "#bfbfbf";
- title = "已过期";
- break;
- case 3:
- bgColor = "#7e7e7e";
- title = '已锁定';
- break;
- }
- return {
- bgColor: bgColor,
- title: title
- }
- })(fcode.state);
- this.setData({
- fcode: fcode
- })
- },
- /**
- * 组件的初始数据
- */
- data: {
- imgShow: false,
- goods: {},
- fcode: {}
- },
- /**
- * 组件的方法列表
- */
- methods: {
- navigator(e) {
- const type = e.target.dataset.type || e.currentTarget.dataset.type;
- const target_data = e.target.dataset.target || e.currentTarget.dataset.target;
- const title = e.target.dataset.title || e.currentTarget.dataset.title;
- if (!type) return;
- switch (type) {
- case "url": {
- let attr = encodeURIComponent(`${target_data}`);
- // let type_sn = ''
- // if (target_data.indexOf('type_sn') != -1) {
- // let arr = target_data.split('&')
- // arr.some(item => {
- // if (item.indexOf('type_sn') != -1) {
- // type_sn = item.split('=')[1]
- // return true
- // }
- // })
- // if (type_sn) {
- // wx.navigateTo({
- // url: `/pages/shareBonus/shareBonus?type_sn=${type_sn}`
- // })
- // break;
- // }
- // }
- let type_sn = getTypeSn(target_data)
- if (type_sn) {
- wx.navigateTo({
- url: `/pages/shareBonus/shareBonus?type_sn=${type_sn}`
- })
- break;
- }
- wx.navigateTo({
- url: '/pages/webView/webView?url=' + attr
- })
- break;
- }
- case "special": {
- wx.navigateTo({
- url: `/pages/special/special?special_id=${target_data}&title=${title}`
- })
- break;
- }
- case "goods": {
- wx.navigateTo({
- url: `/pages/details/details?goods_id=${target_data}&title=商品详情`
- })
- break;
- }
- case "brand": {
- wx.navigateTo({
- url: `/pages/brand/brand?brand_id=${target_data}&title=${title}`
- })
- break;
- }
- case "keyword": {
- wx.navigateTo({
- url: `/pages/brand/brand?keyword=${target_data}&title=${title}`
- })
- break;
- }
- case "appjump": {
- //let url = 'xyzshop://www.xyzshops.com/DirectBuy?goods_id=6217&num=1';
- let url = target_data;
- const [prefix, params] = parseAppjump(url);
- if(prefix == 'xyzshop://www.xyzshops.com/DirectBuyVGoods') {
- let goods_id = params['goods_id'];
- let num = params['num'];
- buyVGoods(goods_id,num);
- }
- }
- default: {
- console.log(type + '类型找不到');
- }
- }
- },
- load(e) {
- this.setData({
- imgShow: true
- });
- }
- }
- })
|