123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- // pages/components/blockItem/blockItem.js
- 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).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}`);
- 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;
- }
- default: {
- console.log(type+'类型找不到');
- }
- }
- },
- load(e){
- this.setData({
- imgShow:true
- });
- }
- }
- })
|