var app = new Vue({
  el: "#app",
  data: function () {
    return {
      btnloading: false,
      uploadLoading: null,
      showAudit: false,
      showTag : "view",
      auditLoading: false,
      search: {
        list: [],
        currentPage: 1,
        pageSize: 20,
        total : 0,
        legalName:'',
        auditStatus:'',
      },
      auditItem: {},
      auditReason: "",
      auditStatusList: [
        {value:"0", label:"待审核"},
        {value:"1", label:"审核通过"},
        {value:"2", label:"审核驳回"},
      ]
    }
  },
  created: function () {
  },
  mounted: function () {
    $("#loading").fadeOut();
    this.opSearch();
  },

  methods: {
    postReq(path, data) {
      return axios.post(path, data).then(function (r) {
        return r.data ? r.data : null;
      })
    },
    resetSearch() {
      this.search = this.getEmptySearch();
      this.getList();
    },
    getEmptySearch() {
      return {
        list: [],
        currentPage: 1,
        pageSize: 20,
        total : 0,
        legalName:'',
        auditStatus: ''
      }
    },
    getParams() {
      var params = {};
      for(var f in this.search) {
        if(f == "list") {
          continue;
        }
        params[f] = this.search[f];
      }
      return params;
    },
    opSearch() {
      this.search.currentPage = 1;
      this.search.total = 0;
      this.getList();
    },
    getList() {
      var self = this;
      var params = this.getParams();
      this.$root.postReq("/applet/xggApplet/auditPage", {
        search: params
      }).then(function (d) {
        if (d.code == 1) {
          self.search.list = d.data.rows || [];
          self.search.total = d.data.count || 0;
          for(let item of self.search.list) {
            if (item.audit_status == 0) {
              item.audit_status_name = "待审核";
            } else if (item.audit_status == 1) {
              item.audit_status_name = "审核通过";
            } else {
              item.audit_status_name = "审核驳回";
            }
          }
        } else {
        }
      });
    },
    btnclick (pfm, code) {
    },
    openAudit(item, tag) {
      console.log(item);
      this.showTag = tag;
      this.auditItem = item;

      if (item.companyId == 1) {
        item.companyName = "汇财"
      } else if(item.companyId == 2) {
        item.companyName = "张舟怡帆---北京"
      } else {
        item.companyName = "网众共创---北京"
      }
      item.companyNames = item.companyNames.split("#com#").join("，");

      this.auditReason = "";
      this.auditLoading = false;
      this.showAudit = true;
    },
    saveAudit(auditStatus) {
      var self = this;
      self.auditLoading = true;
      if (auditStatus == 2 && (!this.auditReason || !this.auditReason.trim())) {
        self.auditLoading = false;
        self.$message.warning("请输入驳回原因");
        return;
      }
      var auditParam = {
        auditStatus: auditStatus,
        auditReason: this.auditReason,
        id: this.auditItem.orderId
      };
      // 处理审核
      self.$root.postReq("/applet/xggApplet/auditBiz", auditParam).then(function(d){
        console.log(d);
        if (d.code == 1) {
          self.showAudit = false;
          self.getList();
          self.$message.success("审核成功");
          self.auditItem = {};
        } else {
          self.$message.warning(d.msg || "审核成功, 请稍候重试");
        }
        self.auditLoading = false;
      });
    },
    exportAll(){
      console.log('export all');
      window.open("/applet/xggApplet/exportAll");

    },
    topic_preview(filed) {
      let url = this.auditItem[filed || ""];
      if(url) {
        window.open(url);
      } else {
        this.$message.warning("未上传");
      }
    },
    onColFormater(row, column, cellValue, index) {
      return cellValue || "---";
    },
    handleSizeChange(val) {
      this.search.pageSize = val;
      this.resetSearch();
    },
    handleCurrentChange(val) {
      this.search.currentPage = val;
      this.getList();
    },
    demofunction() {
    },
  },
});