{
  template: '${tmpl}',
  data: function () {
    return {
      multipleSelection: [],
      isSingleSelect: false,
      showBind: false,
      companyUserId: 0,
      companysForm: {
        bpoCompanyList: [{
          companyName: '',
          key: Date.now(),
          rules: {required: true, message: '公司名称不能为空', trigger: 'blur'},
        }]
      },
    }
  },
  mounted: function () {
    console.log(this.item," aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
  },
  created: function () {},
  methods: {
    onColFormater(row, column, cellvalue, index) {
      if (column.property == "isEnabled") {
        if (row["isEnabled"]) {
          return "正常";
        } else {
          return "停用";
        }
      }
      if (column.property == "Roles") {
        var tmp = [];
        var ids = [];
        row["Roles"].forEach(s => {
          tmp.push(s.name);
          ids.push(s.id);
        });
        row.roles = ids;
        return tmp.join(",");
      }
      return cellvalue;
    },
    handleSelectionChange: function (val) {
      this.multipleSelection = val;
      console.log(val);
    },
    fetchData: function () {

    },
    onRowClick(row, key, e) {
      var self = this;
      console.log(key, "................////////////////////////////");
      if (key == "stopUser") {
        this.modelName = "user";
        var url = this.getUrl("update");
        row.isEnabled = !row.isEnabled;
        this.$root.postReq(url, row).then(rd => {
          if (rd.status == 0) {
            this.$refs.userGrid.fetchData();
          }
        });
      }

      if (key == "bindCompany") {
        console.log("................////////////////////////////");
        this.companyUserId = row.id;

        this.$root.postReq("/web/userbpocompanyCtl/userCompanys", {
          uid: this.companyUserId
        }).then(function (d) {
          if (d.status == 0) {
            self.showBind = true;
            self.companysForm.bpoCompanyList = [];
            if(d.data && d.data.length > 0) {
              for(var item of d.data) {
                self.companysForm.bpoCompanyList.push({
                  companyName: item.companyName,
                  key: item.id,
                  rules: {required: true, message: '公司名称不能为空', trigger: 'blur'},
                });
              }
            } else {
              self.companysForm.bpoCompanyList = [{
                companyName: '',
                key: Date.now(),
                rules: {required: true, message: '公司名称不能为空', trigger: 'blur'},
              }];
            }
          } else {
            self.companysForm.bpoCompanyList = [{
              companyName: '',
              key: Date.now(),
              rules: {required: true, message: '公司名称不能为空', trigger: 'blur'},
            }];
          }
        });
        return;
      }
      console.log($(e.target).text());
    },

    removeCompany(item) {
      var index = this.companysForm.bpoCompanyList.indexOf(item);
      if (index !== -1) {
        this.companysForm.bpoCompanyList.splice(index, 1);
      }
    },

    addCompany() {
      this.companysForm.bpoCompanyList.push({
        companyName: '',
        key: Date.now(),
        rules: {required: true, message: '公司名称不能为空', trigger: 'blur'},
      });
    },
    saveBpoCompany() {
      var self = this;
      var names = [];
      for(var item of self.companysForm.bpoCompanyList) {
        var companyName = (item.companyName || "").trim();
        if(item.companyName && names.indexOf(companyName) == -1) {
          names.push(companyName);
        }
      }

      if(names.length == 0) {
        self.$message.warning("请填写公司名称");
        return;
      }

      self.$root.postReq("/web/userbpocompanyCtl/save", {
        uid: this.companyUserId,
        names: names,
      }).then(function (d) {
        if (d.status == 0) {
            self.$message.success(`保存成功`);
            self.$refs.userGrid.fetchData();
            self.showBind = false;
        } else {
            self.$message.warning(d.msg || `保存失败，请刷新页面后重新操作`);
        }
      });
    },
  },
  computed: Vuex.mapState({
    count: state => state.count,
    headStyle: function () {
      return {
        "background-color": "white"
      };
    }
  }),
  vname: "gsb-users"
}