const util = require("../../../utils/util.js");
Component({
  properties: {
    show:{
      type: Boolean,
      observer:function(val){
        this.setData({ show: val });
        if (this.data.show) this.getScore();
      }
    },
    info:{
      type:Object,
      observer: function (params){
        params.discount = params.discount != undefined && params.discount < 0 ? params.discount.toString().replace("0.", "") : 1;
        this.setData({ params });
        if (params.idcards && params.idcards.ids.length > 0) this.getStatus();
      }
    },
  },
  data: {
    show: false,
    params:{
      discount: 1,
      aid:'',
      idcards:[],
      sid:''
    },
    explainInfo:[]
  },
  methods: {
    getScore(){
      let that = this;
      util.ajax({
        func:'v2/user/score/detail',
        load:false
      },function(res){
        if(res.code == 0){
          that.setData({ datas: res.data, role: util.userRole(res.data.score)});
        }
      })
    },
    getStatus(){
      let that = this, childIds = [];
      util.ajax({
        func:"v2/user/discount/detail",
        data: { aid: that.data.params.aid, childIds: that.data.params.idcards.ids.join(","), sid: that.data.params.sid },
        load: false
      },function(res){
        if(res.code == 0){
          that.setData({ explainInfo: res.data });
        }
      })
    },
    submit(){
      this.close();
      this.triggerEvent("close", this.data.show);
    },
    close() {
      this.setData({ show: false });
      this.triggerEvent("close", this.data.show);
    }
  }
})
