{
    template:'${tmpl}',
    data:function(){
        return {
          id: 0,
          auditRemark : "",
          show : false,
          isDisabled : false,
          btnloading : false,
          showbind: true,
          activeName : "bind",
          d : [],
          action : "",
          company:{
            account:"",
            passwd : "",
            passwdConfirm : "",
            contact : "",
            useCount : 5,
            name :"",
            payVoucher : "http://gsb-zc.oss-cn-beijing.aliyuncs.com/empty2018082212365411225525855.jpg",
          },
          binddata:{
          },
          useCountList:[
            {label:"5人",value : 5},
            {label:"10人",value : 10},
            {label:"20人",value : 20},
            {label:"50人",value : 50},
            {label:"100人",value : 100},
            {label:"500人",value : 500},
            {label:"1000人",value : 1000}
          ],
        }
    },
    computed: Vuex.mapState({
      count:state=>state.count,
      headStyle:function(){
        return {"background-color":"white"};
      },

    }),
    created:function(){
    },
    mounted:function(){
      var that=this;

      this.id = this.$router.currentRoute.query.id || 0;
      if(this.id) {
        this.getCompany();
      }
      this.$root.postReq("/web/uploadCtl/getOssConfig","").then(function(d){
          that.d["key"]="key";
          that.d["Bucket"]=d.Bucket;
          that.d["OSSAccessKeyId"]=d.OSSAccessKeyId;
          that.d["Signature"]=d.Signature;
          that.d["policy"]=d.policy;
          that.d["success_action_status"]=d.success_action_status;
          that.action=d.url;
      });
    },
    methods:{
      handleClick(tab, event) {
        this.showbind = this.activeName == 'bind';
      },
      changeTab(obj) {
        this.showbind = obj;
      },
      error(err){
        this.$message.warning(`上传失败，请重新上传`);
      },
      getCompany() {
        var self = this;
        if(!self.id) {
          return;
        }
        self.$root.postReq("/web/tmcompanyCtl/findOne", {id:self.id}).then(function(d) {
          self.isDisabled = true;
          self.showbind = false;
          this.activeName == 'apply';
          d.data.passwd = "";
          self.company = d.data;

          if(d.status==0) {
            var c = d.data;
            if(c.auditStatus == "0") {
              self.isDisabled = true;
              self.auditRemark = "您的申请正在审核中, 请耐心等候";
            }
            else if(c.auditStatus == "1") {
              self.auditRemark = "";
              self.$router.push("/bycquerytm");
            }
            else if(c.auditStatus == "2") {
              self.isDisabled = false;
              self.auditRemark = c.audit_reason || "审核驳回";
            }
            else if(c.auditStatus == "3") {
              self.isDisabled = false;
              self.auditRemark = "您的企业帐号已过期, 请续费并重新提交申请";
            } else {
              self.isDisabled = false;
              self.auditRemark = "";
            }
          }
        });
      },
      setKey(name,flag){
        name=name.substring(name.length - 5);
        var myDate = new Date();
        var key = "zc_"+Math.round(Math.random()*500)+myDate.getMonth()+myDate.getTime()+myDate.getFullYear()+myDate.getDate()+myDate.getHours()+myDate.getMinutes()+myDate.getSeconds()+myDate.getMilliseconds()+name.replace(" ","");
        this.d.key = key;
      },
      uploadsuccess(obj){
        obj = obj || {};
        this.company.payVoucher = obj.result;
      },
      error(err){
        this.$message.warning(`上传失败，请重新上传`);
      },
      applyCompany() {
        var self = this;
        if(!self.company.account) {
          self.$message.warning(`请填写帐号`);
          return;
        }
        if(!self.company.passwd) {
          self.$message.warning(`请填写密码`);
          return;
        }
        if(self.company.passwdConfirm != self.company.passwd) {
          self.$message.warning(`两次密码不一致`);
          return;
        }
        if(!self.company.useCount) {
          self.$message.warning(`请选择使用人数`);
          return;
        }
        if(!self.company.contact) {
          self.$message.warning(`请填写联系方式`);
          return;
        }
        if(!self.company.payVoucher || self.company.payVoucher == "http://gsb-zc.oss-cn-beijing.aliyuncs.com/empty2018082212365411225525855.jpg") {
          self.$message.warning(`请上传付款凭证`);
          return;
        }
        self.btnloading=true;
        self.$root.postReq("/web/tmcompanyCtl/validAccount", {id: self.id || 0,account:self.company.account}).then(function(d) {
          if(d.status==0){
            self.$root.postReq("/web/tmcompanyCtl/saveApply", self.company).then(function(d2) {
              if(d2.status==0){
                self.id = d2.data.id;
                self.getCompany();
              } else {
                self.$message.warning(d2.msg || "申请失败,请稍后重试");
              }
              setTimeout(()=>{
                  self.btnloading=false;
              },3000);
            });
          } else {
            self.$message.warning(d.msg || "帐号冲突");
            setTimeout(()=>{
                self.btnloading=false;
            },3000);
          }
        });
      },
      bindCompany() {
        var self = this;
        if(!self.binddata.account) {
          self.$message.warning(`请填写帐号`);
          return;
        }

        if(!self.binddata.passwd) {
          self.$message.warning(`请填写密码`);
          return;
        }
        self.btnloading=true;
        self.$root.postReq("/web/tmcompanyCtl/bind", self.binddata).then(function(d2) {
          if(d2.status==0){
            self.$message.success( "绑定成功");
            self.$router.push("/bycquerytm");
          } else {
            self.$message.warning(d2.msg || "绑定失败, 请稍后重试");
          }
          setTimeout(()=>{
              self.btnloading=false;
          },3000);
        });
      },
    },

    vname:"gsb-tmcompanyapply"
}
