index.js 8.38 KB
Newer Older
程智春 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
// static/nativeComponents/SharePicture/index.js
const app = getApp()
const { indexApi } = app;
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    datas: {
      type: Object
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    tabIndex : 0,
    waterfallLeftList:[],
    waterfallRightList:[],
    loaded : true,
    pageNum : 1,
    tabId : 1,
程智春 committed
24 25 26 27 28 29 30 31 32 33
    iconStyleList: [
      {
        name: "common-iconqinziAPPtubiao-",
        value: 0,
        toggle: "common-icondianzan"
      },
      { name: "common-iconaixin1", value: 1, toggle: "common-iconaixin" }
    ],
    praiseState : false,
    getListFinish : false
程智春 committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
  },
  ready(){
    this.queryBuyingShowList(0);
  },

  /**
   * 组件的方法列表
   */
  methods: {
    tabHandle(e){
      let index = e.currentTarget.dataset.index
      let item = e.currentTarget.dataset.item
      console.log(index, item, this.data.tabIndex)
      if(this.data.tabIndex != index){
        this.setData({
          tabIndex: index,
程智春 committed
50 51
          tabId: item.id,
          getListFinish :false
程智春 committed
52 53 54
        })
        this.queryBuyingShowList(0)
      }
侯体倬 committed
55
      app.trackCpn(e, this.data.datas.componentName, e.currentTarget.dataset)
程智春 committed
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    },
    queryBuyingShowList(type){
      if (this.data.datas.componentData["activityFlag"][0]["id"] == "" || !this.data.loaded){

        return;
      }
      this.setData({
        loaded : false
      })
      if(type == 0){
        this.setData({
          pageNum : 1
        })
      }else{
        this.setData({
          pageNum : this.data.pageNum + 1
        })
      }
      let query = {
        activityId: this.data.datas.componentData.activityFlag[0].id || 4,
        sortType: this.data.tabId,
        pageNum: this.data.pageNum,
        startTime: Array.isArray(this.data.datas.componentData.publishTime)
          ? this.data.datas.componentData.publishTime[0]
          : "",
        endTime: Array.isArray(this.data.datas.componentData.publishTime)
          ? this.data.datas.componentData.publishTime[1]
          : "",
        pageSize: +this.data.datas.componentData["quantity"]
      }

      indexApi.queryBuyingShowList(query).then(res => {
        this.setData({
          loaded :true
        })
        if(res.data.code == '200'){
          let data = res.data.data
程智春 committed
93 94 95 96 97 98

          if(res.data.pages <= res.data.current){
            this.setData({
              getListFinish : true
            })
          }
程智春 committed
99
          if(type == 0){
程智春 committed
100 101 102 103 104 105 106 107

            this.setData({
              waterfallLeftList : [],
              waterfallRightList:[]
            })

            let { waterfallLeftList, waterfallRightList } = this.data

程智春 committed
108 109 110
            data.forEach((item,index) => {
              item.customerHandImage = app.DFSImg(item.customerHandImage)
              item.checkMP4Status = this.checkMP4(item.urls)
程智春 committed
111 112 113 114 115 116
              item.custname = this.clientInfoName(item)
              if (item.praiseFlag == 'false'){
                item.nameIcon = this.data.iconStyleList[this.data.datas.componentData['iconStyle']].name
              }else{
                item.nameIcon = this.data.iconStyleList[this.data.datas.componentData['iconStyle']].toggle
              }
侯体倬 committed
117

程智春 committed
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
              if (this.getFileType(item.urls[0]) == 'video'){
                item.coverImg = app.DFSImg(`${item.urls[0]}?x-oss-process=video/snapshot,t_1,m_fast`)
              }else{
                item.coverImg = app.DFSImg(item.urls[0], 400, null, 1)
              }

              if(index % 2 == 0){
                waterfallLeftList.push(item)
              }else{
                waterfallRightList.push(item)
              }
            })

            this.setData({
              waterfallLeftList,
              waterfallRightList
            })

            console.log(this.data.waterfallLeftList, this.data.waterfallRightList,' this.data.waterfallRightList')
          }else{
侯体倬 committed
138

程智春 committed
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
            let { waterfallLeftList, waterfallRightList } = this.data
            data.forEach((item, index) => {
              item.customerHandImage = app.DFSImg(item.customerHandImage)
              item.checkMP4Status = this.checkMP4(item.urls)
              item.custname = this.clientInfoName(item)
              if (item.praiseFlag == 'false') {
                item.nameIcon = this.data.iconStyleList[this.data.datas.componentData['iconStyle']].name
              } else {
                item.nameIcon = this.data.iconStyleList[this.data.datas.componentData['iconStyle']].toggle
              }

              if (this.getFileType(item.urls[0]) == 'video') {
                item.coverImg = app.DFSImg(`${item.urls[0]}?x-oss-process=video/snapshot,t_1,m_fast`)
              } else {
                item.coverImg = app.DFSImg(item.urls[0], 400, null, 1)
              }

              if (index % 2 == 0) {
                waterfallLeftList.push(item)
              } else {
                waterfallRightList.push(item)
              }
            })

            this.setData({
              waterfallLeftList,
              waterfallRightList
            })
程智春 committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214

          }
        }
      })
      .catch(err => {
        this.setData({
          loaded: true
        })
      })


    },
    getFileType(name) {
      if (!name) return false;
      var imgType = ["gif", "jpeg", "jpg", "bmp", "png"];
      var videoType = [
        "avi",
        "wmv",
        "mkv",
        "mp4",
        "mov",
        "rm",
        "3gp",
        "flv",
        "mpg",
        "rmvb"
      ];
      if (
        RegExp(".(" + imgType.join("|") + ")$", "i").test(name.toLowerCase())
      ) {
        return "image";
      } else if (
        RegExp(".(" + videoType.join("|") + ")$", "i").test(name.toLowerCase())
      ) {
        return "video";
      } else {
        return false;
      }
    },
    checkMP4(data) {
      for (let index = 0; index < data.length; index++) {
        if (this.getFileType(data[index]) == "video") {
          return true;
        } else {
          return false;
        }
      }
    },
程智春 committed
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
    clientInfoName(item){
      if (item.customerName.length > 0 || item.customerNickname.length > 0) {
        if (this.data.datas.componentData["clientInfoEncryption"]) {
          return this.noPassByName(item.customerName || item.customerNickname);
        } else {
          return item.customerName || item.customerNickname;
        }
      } else {
        if (this.data.datas.componentData["clientInfoEncryption"]) {
          return "****";
        } else {
          return "匿名用户";
        }
      }
    },
    noPassByName(str) {
      if (null != str && str != undefined) {
        if (str.length <= 3) {
          return str.substring(0, 1) + "****";
        } else {
          return `${str.substr(0, 1)}****${str.charAt(str.length - 1)}`;
        }
      } else {
        return "****";
      }
    },
    addBuyingShowPraise(e){
      let item = e.currentTarget.dataset.item
      let index = e.currentTarget.dataset.index
      let type = e.currentTarget.dataset.type

      let list = type == 'left' ? 'waterfallLeftList' : 'waterfallRightList'
      if (this.data.praiseState) return;
      this.setData({
        praiseState : true
      })
      let query = {
        buyingShowId: item.id
      };
      indexApi.addBuyingShowPraise(query).then(res => {
        this.setData({
          praiseState : false
        })
        if(res.data.code == '200'){
          if(res.data.data == 'true'){
            let praiseFlag = `${list}[${index}].praiseFlag`
            let praisePoints = `${list}[${index}].praisePoints`
            this.setData({
              [praiseFlag] : 'true',
              [praisePoints]: Number(this.data[list][index].praisePoints )+ 1
            })

          }else if(res.data.data == 'false'){

            let praiseFlag = `${list}[${index}].praiseFlag`
            let praisePoints = `${list}[${index}].praisePoints`
            this.setData({
              [praiseFlag]: 'false',
              [praisePoints]: Number(this.data[list][index].praisePoints) - 1
            })

          }
        }
      })
      .catch(err => {
        this.setData({
          praiseState: false
        })
      })

    },
    buyingShowHandle(e){
      let id = e.currentTarget.dataset.id
      console.log(id)
侯体倬 committed
289
      app.trackCpn(e, this.data.datas.componentName, e.currentTarget.dataset)
程智春 committed
290 291 292 293 294
      app.$themeToLink({
        type: 1,
        link: '/buyerShow/showDetail?buyingShowId=' + id
      })
    },
侯体倬 committed
295 296
    viewMore(e){
      app.trackCpn(e, this.data.datas.componentName, 'ViewMore')
程智春 committed
297 298
      this.queryBuyingShowList(1);
    }
程智春 committed
299 300
  }
})