import { __FAIL_FN } from "../../../utils/network";
const baseUrl = require("../../../api/index.js").config;
const member = require("../../../api/member.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    active: "",
    activeNames: "",
    datalist: [],
    explanatlist: [
      {
        id: 1,
        name: "协议/规则",
        childList: [
          {
            id: 1,
            name: "平台资质",
            childList: [
              {
                id: 1,
                name: "平台资质",
                childList: null,
              },
            ],
          },
          {
            id: 11,
            name: "招商规范",
            childList: [
              {
                id: 11,
                name: "招商规范",
                childList: null,
              },
            ],
          },
          {
            id: 21,
            name: "商品规范",
            childList: [
              {
                id: 21,
                name: "商品规范",
                childList: null,
              },
            ],
          },
        ],
      },
      {
        id: 2,
        name: "公告",
        childList: [
          {
            id: 2,
            name: "规则公告",
            childList: [
              {
                id: 2,
                name: "规则公告",
                childList: null,
              },
            ],
          },
        ],
      },
      {
        id: 3,
        name: "普法专栏",
        childList: [
          {
            id: 3,
            name: "法规解读",
            childList: [
              {
                id: 3,
                name: "法规解读",
                childList: null,
              },
            ],
          },
        ],
      },
    ],
    loading: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.takeExplanation();
  },

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

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},
  // 切换面板
  onChangecollapse(event) {
    this.setData({
      activeNames: event.detail,
    });
  },
  // 解释与说明的接口
  takeExplanation: function () {
    var that = this;
    this.setData({
      loading: true,
    });
    member.takeExplanation(
      `${baseUrl.merchantUrl}/client/agreement/categories`,
      {},
      {},
      "加载中",
      function (res) {
        var result = res.results;
        if (result && result.length > 0) {
          const active = result[0] || {};
          const { id = null, childList } = active;
          const activeName =
            childList && childList.length > 0 ? childList[0].id : null;
          that.setData({
            datalist: result,
            active: id,
            activeName,
          });
        }
        that.setData({
          loading: false,
        });
      },
      function (err) {
        that.setData({
          loading: false,
        });
        __FAIL_FN({ res: err });
      }
    );
  },
  // 获取详情
  godetail: function (e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/package/my/details/details?id=${id}`,
    });
  },
});
