const util = require("../../../../utils/util.js");
const app = getApp();
Page({
  data: {
    id:"",
    childs:[]
  },
  onLoad: function () {
    this.getChilds();
  },
  getChilds() {
    let that = this;
    util.ajax({
      func: "user/idcardinfo_list",
      data: { "type": "0" }
    }, function (res) {
      if (res.code == 0) {
        res.data = util.defaultIdcard(res.data);;
        that.setData({ childs: res.data });
      } else {
        util.showTips(res.reason);
      }
    });
  },
  selectChild(e) {
    let id = e.detail.value, childs = this.data.childs;
    for (let i = 0; i < childs.length; i++) {
      childs[i].status = 0;
      if (childs[i].id == id) {
        childs[i].status = 1;
      }
    }
    this.setData({ id, childs: childs });
  },
  pay() {
    if (util.isEmpty(this.data.id)){
      util.showTips("请先点击选择要绑定的儿童。");
      return false;
    }
    util.ajax({
      func: "score/bind",
      data: { "cid": this.data.id }
    }, function (res) {
      if (res.code == 0) {
        wx.navigateBack();
      } else{
        util.showTips(res.reason);
      }
    });
  }
})