card.js 1.45 KB
// components/2.0/pinglun/card.js
import util from '../../../utils/util'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    post:Object,
    hasSeller:Boolean,//显示商户信息
    hasStatus:Boolean,//显示审核状态
    cla:String,
  },

  /**
   * 组件的初始数据
   */
  data: {

  },
  attached(){
    // this.setData({
    //   enclosure:JSON.parse(this.data.post.enclosure||null)
    // })
  },
  observers: {
    'post': function(post) {
      this.setData({
        enclosure:this.isJSON(post.enclosure)
      })
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    isJSON(str) {
      try {
        let data=JSON.parse(str);
        return data;
      } catch (e) {
        return str;
      }
    },
    displayImage(e){
      let index=util.attr(e,'index')
      if(this.data.enclosure[index].avinfo){//video
        let attr=this.data.enclosure[index]
        wx.navigateTo({
          url:util.http_build_query({
            url:attr.url,
            title:this.data.post.sellerinfo?this.data.post.sellerinfo.sellername:''
          },'/pages/pinglun/video'),
        })
      }else {
        let urls=[],current=''
        this.data.enclosure.some((attr,i)=>{
            if(i==index){
              current=attr.url
            }
            if(!attr.avinfo){
              urls.push(attr.url)
            }
        })
        wx.previewImage({
          urls: urls,
          current: current
        })
      }
    },
  }
})