// component/selectRelatedGoods/selectRelatedGoods.js
var app = getApp()
const wxService = require('../../utils/wxService')
const utils = require('../../utils/util')
const envInfo = require('../../config/index').envInfo

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    showSelectTabModal: { // 显示标识
      type: Boolean,
      value: false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    tabList: [],
    proData: [],
    productName: '',
    pageNum: '1',
    pageSize: '10000',
    currentTab:'',
    currentTabName:''
  },

  observers: {
    proGoods(val) {
      for (var i in this.data.proList) {
        for (var j in val) {
          if (this.data.proList[i].productId == val[j].productId) {
            this.data.proList[i].isSelect = true
          }
          this.setData({
            proList: this.data.proList
          })
        }
      }
    },
    showSelectTabModal() {
      const { showSelectTabModal } = this.data
      if (showSelectTabModal) {
        wxService.nextTick(() => {
          this.geTabList();
        })
      }
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    hidePopup: function () { // 隐藏弹出框
      this.setData({
        showSelectTabModal: false
      })
    },
   
    confirm() {
      if(!this.data.currentTab){
        wx.showToast({
          title: '请选择标签',
          icon: 'none'
        })
        return false;
      }
      let params = {
        id: this.data.currentTab,
        name: this.data.currentTabName
      }
      this.setData({
        showSelectTabModal: false
      },()=>{
        wxService.nextTick(() => {
          this.triggerEvent('_selectTab', params)
        })
      })
    
    },

    // 点击键盘完成时触发
    onTapConfirm(e) {
      this.setData({
        productName: e.detail.value
      })
    },

    geTabList(){
      wxService.post(`/merchant/contentTags/getTagsGroupedListC?pageNum=${this.data.pageNum}&pageSize=${this.data.pageSize}`, {
      }).then(res => {
        const { result, data } = res.data
        if (result == 0) {
         this.setData({
           tabList: data
         })
        }
      }).finally(() => {
      })
    },

    // 点击更多
    getMoreTab(e){
      let index = e.currentTarget.dataset.index
      if (!this.data.tabList[index].flag){
        this.data.tabList[index].flag = true
      }else{
        this.data.tabList[index].flag = false
      }
      this.setData({
        tabList: this.data.tabList
      })
    },

    selectTab(e) {
      this.setData({
        currentTab: e.currentTarget.dataset.id,
        currentTabName: e.currentTarget.dataset.name
      })
    }

  },

 

})
