// pages/micro_shop_add_category/micro_shop_add_category.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    active2: true,
    active: 9999,
    list: [],
    shop_id: '',
    contentlist: {},
    state: {
      adv_img: '',
      adv_url: ''
    },
    formCard: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.shop_id) {
      this.setData({
        shop_id: options.shop_id
      });
    }
    if (options.formCard) {
      this.setData({
        formCard: options.formCard
      });
    }
    this.getList();
    this.getContentlist2();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  getList() {
    let that = this;
    let urlStr = app.getNetAddresss('goods.category.get-category');
    urlStr += '&shop_id=' + that.data.shop_id;
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          // var myData = res.data;
          that.setData({
            list: res.data.data
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  getContentlist2() {
    let that = this;
    let urlStr = app.getNetAddresss('shop.index.get-default-index');
    urlStr += '&shop_id=' + that.data.shop_id;
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that.setData({
            'contentlist.category': res.data.category,
            err: false
          });
          that.setData({
            'contentlist.goo': true,
            'contentlist.tjfl': true,
            'contentlist.set': res.data.set
          });
        } else {
          that.setData({
            err: true
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  tabsa(e) {
    let index = e.currentTarget.dataset.index;
    let item = e.currentTarget.dataset.item;
    this.tabsaData(index, item);
  },
  tabsaData(n, i) {
    this.setData({
      'state.adv_img': i.adv_img,
      'state.adv_url': i.adv_url
    });
    this.setData({
      active: n,
      active2: false
    });
    this.getContentlist(i.id);
  },
  getContentlist(id) {
    let that = this;
    let urlStr = app.getNetAddresss('goods.category.get-children-category');
    urlStr += '&parent_id=' + id;
    urlStr += '&shop_id=' + that.data.shop_id;
    app._getNetWork({
      url: urlStr,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that.setData({
            err: false,
            contentlist: res.data
          });
          that.setData({
            'contentlist.tjfl': false,
            'contentlist.set': res.data.set
          });
        } else {
          that.setData({
            err: true
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  allList() {
    this.setData({
      active2: true,
      active: 9999
    });
    this.getContentlist2();
  }
});
