<template>
  <div>
    <el-row v-show="isShow">
      <el-col :span="5">
        <div class="box">
          <el-scrollbar>
            <basic-container>
              <avue-tree :option="treeOption" :data="customTypeData" @node-click="nodeClick">
                <template slot="addBtn">
                  <el-tooltip class="item" effect="dark" content="新建分类" placement="top">
                    <i class="el-icon-setting" style="font-size:18px;line-height: 30px;width: 20px;padding: 0 10px;"
                      @click="corpTypeVisible = true"></i>
                  </el-tooltip>
                </template>
              </avue-tree>
            </basic-container>
          </el-scrollbar>
        </div>
      </el-col>
      <el-col :span="19">
        <basic-container class="page-crad">
          <!-- :on-change="handleChange" -->
          <avue-crud :option="option" :table-loading="loading" :data="data" :page.sync="page" :permission="permissionList"
            id="out-table" :header-cell-class-name="headerClassName" :search.sync="search" :before-open="beforeOpen"
            v-model="form" ref="crud" @row-update="rowUpdate" @row-save="rowSave" @row-del="rowDel"
            @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
            @current-change="currentChange" @size-change="sizeChange" @refresh-change="refreshChange"
            @resetColumn="resetColumnTwo('crud', 'option', 'optionBack', 304)"
            @saveColumn="saveColumnTwo('crud', 'option', 'optionBack', 304)" @on-load="onLoad">



            <template slot="code" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.code" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="uscc" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.uscc" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="cnName" slot-scope="scope">
                <div style="color: #1e9fff;cursor: pointer;" @click.stop="editOpen(scope.row)">
                    <avue-text-ellipsis :text="scope.row.cnName" :height="30" use-tooltip placement="top">
                        <small slot="more">...</small>
                    </avue-text-ellipsis>
                </div>
            </template>
            <template slot="enName" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.enName" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="cnAddr" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.cnAddr" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="shortName" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.shortName" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="tel" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.tel" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="fax" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.fax" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="adminProfiles" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.adminProfiles" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="seaEmail" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.seaEmail" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="airEmail" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.airEmail" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="unCode" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.unCode" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="customsCode" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.customsCode" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="scacCode" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.scacCode" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="email" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.email" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>
            <template slot="enAddr" slot-scope="scope">
              <avue-text-ellipsis :text="scope.row.enAddr" :height="30" use-tooltip placement="top">
                <small slot="more">...</small>
              </avue-text-ellipsis>
            </template>

            <template slot="menuLeft">
              <el-button type="warning" size="small" icon="el-icon-printer" @click="excelBox = true">导入
              </el-button>
              <el-button type="success" size="small" @click="handleExport" icon="el-icon-printer">导出</el-button>
            </template>
            <template slot-scope="{ row, index }" slot="menu">
                <el-button v-if="row.status == 1" type="text" style="color: #85e967" size="small"
                           @click.stop="statusfun(row.id,0)">
                  启用
                </el-button>
                <el-button v-if="row.status == 0" type="text" style="color: #e83c3a" size="small"
                           @click.stop="statusfun(row.id,1)">
                    停用
                </el-button>

              <!--<el-button type="text" size="small" @click.stop="editOpen(row)">-->
              <!--  编辑-->
              <!--</el-button>-->
              <el-button type="text" size="small" @click.stop="rowDel(row, index)" :disabled="row.status > 0">
                删除
              </el-button>
            </template>
          </avue-crud>
        </basic-container>
      </el-col>
    </el-row>
    <detailPage v-if="!isShow" ref="detail" @goBack="goBack" @copyOrder="copyOrder" :detailData="detailData"></detailPage>

    <!--类别弹窗-->
    <el-dialog title="类别" :visible.sync="corpTypeVisible" append-to-body width="60%" :before-close="corpTypeClose">
      <div>
        <bcorpstypedefine></bcorpstypedefine>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="corpTypeVisible = false">取 消</el-button>
        <el-button type="primary" @click="corpTypeVisible = false">确 定</el-button>
      </span>
    </el-dialog>


    <el-dialog title="导入往来单位" append-to-body :visible.sync="excelBox" width="555px" :close-on-click-modal="false"
      v-dialog-drag>
      <avue-form :option="excelOption" v-model="excelForm" :table-loading="excelLoading" :upload-before="uploadBefore"
        :upload-after="onSuccess">
        <template slot="excelTemplate">
          <el-button type="primary" @click="handleGet">
            点击下载<i class="el-icon-download el-icon--right"></i>
          </el-button>
        </template>
      </avue-form>
      <p style="text-align: center;color: #DC0505">
        温馨提示 第一次导入时请先下载模板
      </p>
    </el-dialog>
  </div>
</template>

<script>
import { getToken } from "@/util/auth";
import detailPage from "./detailsPage";
import { getBcorpsList, getBcorpsDetail, addBcorps, updateBcorps, removeBcorps, downLoadBcorpsTemplate } from "@/api/iosBasicData/bcorps";
import { mapGetters } from "vuex";
import { bcorpstypedefineList } from "@/api/iosBasicData/bcorpstypedefine"
import bcorpstypedefine from "@/views/iosBasicData/bcorps/bcorpstypedefine.vue";
export default {
  components: {
    detailPage,
    bcorpstypedefine
  },
  data() {
    return {
      headers: { "Blade-Auth": "Bearer " + getToken() },
      // 类别弹窗的开启
      corpTypeVisible: false,
      treeOption: {
        nodeKey: "id",
        lazy: true,
        treeLoad: function (node, resolve) {
          const parentId = node.level === 0 ? 0 : node.data.id;
        },
        addBtn: false,
        menu: false,
        size: "small",
        props: {
          labelText: "标题",
          label: "cnName",
          value: "id",
          children: "children"
        }
      },
      excelForm: {},
      search: {},
      excelLoading: false,
      excelOption: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: "模板下载",
            prop: "excelTemplate",
            formslot: true,
            span: 24
          },
          {
            label: "模板上传",
            prop: "excelFile",
            type: "upload",
            drag: true,
            loadText: "模板上传中，请稍等",
            span: 24,
            propsHttp: {
              res: "data"
            },
            tip: "请上传 .xls,.xlsx 标准格式文件",
            action: "/api/blade-los/bcorps/importBCorps"
          }
        ]
      },
      // 客户类别数据
      customTypeData: [],
      excelBox: false,
      form: {},
      query: {},
      detailData: {},
      isShow: true,
      loading: true,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
        pageSizes: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500]
      },
      selectionList: [],
      option: {},
      optionBack: {
        height: 'auto',
        calcHeight: 30,
        tip: false,
        searchIcon: true,
        searchIndex: 3,
        searchShow: true,
        searchMenuSpan: 6,
          menuWidth:100,
        border: true,
        index: true,
        viewBtn: true,
        selection: true,
        addBtnText: '新建客户',
        dialogClickModal: false,
        column: [
          {
            label: "编码",
            prop: "code",
            width: "180",
            search: true,
            rules: [{
              required: true,
              message: "请输入单位编码",
              trigger: "blur"
            }]
          },
          {
            label: "中文名称",
            prop: "cnName",
            width: "180",
            search: true,
            rules: [{
              required: true,
              message: "请输入中文名称",
              trigger: "blur"
            }]
          },
          {
            label: "英文名称",
            prop: "enName",
            width: "180",
            search: true,
            rules: [{
              required: true,
              message: "请输入英文名称",
              trigger: "blur"
            }]
          },
          {
            label: "统一社会信用代码",
            prop: "uscc",
            width: 160,
            rules: [{
              required: true,
              message: "请输入统一社会信用代码",
              trigger: "blur"
            }]
          },
          {
            label: "首字母",
            prop: "initials",
            rules: [{
              required: true,
              message: "请输入首字母",
              trigger: "blur"
            }]
          },
          {
            label: "简称",
            prop: "shortName",
            width: "180",
            rules: [{
              required: true,
              message: "请输入简称",
              trigger: "blur"
            }]
          },
          {
            label: "国家代码",
            prop: "cntyCode",
            rules: [{
              required: true,
              message: "请输入国家代码",
              trigger: "blur"
            }]
          },
          {
            label: "国家名称",
            prop: "cntyName",
            search: true,
            rules: [{
              required: true,
              message: "请输入国家名称",
              trigger: "blur"
            }]
          },
          {
            label: "省、州",
            prop: "province",
            rules: [{
              required: true,
              message: "请输入省、州",
              trigger: "blur"
            }]
          },
          {
            label: "城市",
            prop: "city",
            rules: [{
              required: true,
              message: "请输入城市",
              trigger: "blur"
            }]
          },
          {
            label: "中文地址",
            prop: "cnAddr",
            search: true,
            rules: [{
              required: true,
              message: "请输入中文地址",
              trigger: "blur"
            }]
          },
          {
            label: "英文地址",
            prop: "enAddr",
            search: true,
            rules: [{
              required: true,
              message: "请输入英文地址",
              trigger: "blur"
            }]
          },
          {
            label: "电话",
            prop: "tel",
            width: "120",
            search: true,
            rules: [{
              required: true,
              message: "请输入电话",
              trigger: "blur"
            }]
          },
          {
            label: "传真",
            prop: "fax",
            width: "120",
            rules: [{
              required: true,
              message: "请输入传真",
              trigger: "blur"
            }]
          },
          {
            label: "电子邮箱",
            prop: "email",
            width: "160",
            rules: [{
              required: true,
              message: "请输入电子邮箱",
              trigger: "blur"
            }]
          },
          {
            label: "负责人姓名",
            prop: "mgrName",
            width: 100,
            rules: [{
              required: true,
              message: "请输入负责人姓名",
              trigger: "blur"
            }]
          },
          {
            label: "联系人姓名",
            prop: "attnName",
            width: 100,
            rules: [{
              required: true,
              message: "请输入联系人姓名",
              trigger: "blur"
            }]
          },
          {
            label: "联系人电话",
            prop: "attnTel",
            width: 100,
            rules: [{
              required: true,
              message: "请输入联系人电话",
              trigger: "blur"
            }]
          },
          {
            label: "客户来源类别",
            prop: "sourceType",
            width: 100,
            rules: [{
              required: true,
              message: "请输入客户来源类别",
              trigger: "blur"
            }]
          },
          {
            label: "部门 Id",
            prop: "deptId",
            hide: true,
            display: false,
          },
          {
            label: "部门名称",
            prop: "deptName",
            rules: [{
              required: true,
              message: "请输入部门名称",
              trigger: "blur"
            }]
          },
          {
            label: "业务员 Id",
            prop: "salesId",
            hide: true,
            display: false,
          },
          {
            label: "业务员姓名",
            prop: "salesName",
            width: 100,
            rules: [{
              required: true,
              message: "请输入业务员姓名",
              trigger: "blur"
            }]
          },
          {
            label: "所属单位 Id",
            prop: "corpId",
            hide: true,
            display: false,
          },
          {
            label: "所属单位名称",
            prop: "corpName",
            width: 100,
            rules: [{
              required: true,
              message: "请输入所属单位名称",
              trigger: "blur"
            }]
          },
          {
            label: "客户类型",
            prop: "corpTypeName",
            rules: [{
              required: true,
              message: "请输入客户类型",
              trigger: "blur"
            }]
          },
          {
            label: "分管员",
            prop: "adminProfiles",
            width: "100",
            rules: [{
              required: true,
              message: "请输入分管员",
              trigger: "blur"
            }]
          },
          {
            label: "海运邮箱",
            prop: "seaEmail",
            width: "160",
            rules: [{
              required: true,
              message: "请输入海运邮箱",
              trigger: "blur"
            }]
          },
          {
            label: "空运邮箱",
            prop: "airEmail",
            width: "160",
            rules: [{
              required: true,
              message: "请输入空运邮箱",
              trigger: "blur"
            }]
          },
          {
            label: "国际编码",
            prop: "unCode",
            width: "160",
            rules: [{
              required: true,
              message: "请输入国际编码",
              trigger: "blur"
            }]
          },
          {
            label: "海关编码",
            prop: "customsCode",
            width: "160",
            rules: [{
              required: true,
              message: "请输入海关编码",
              trigger: "blur"
            }]
          },
          {
            label: "SCAC 代码",
            prop: "scacCode",
            width: "160",
            rules: [{
              required: true,
              message: "请输入SCAC 代码",
              trigger: "blur"
            }]
          },
          {
            label: "iGenZong 代码",
            prop: "igenzongCode",
            width: 120,
            rules: [{
              required: true,
              message: "请输入iGenZong 代码",
              trigger: "blur"
            }]
          },
          {
            label: "美线约号",
            prop: "amLineAgreementno",
            rules: [{
              required: true,
              message: "请输入美线约号",
              trigger: "blur"
            }]
          },
          {
            label: "船公司代码",
            prop: "carrierCode",
            width: 100,
            rules: [{
              required: true,
              message: "请输入船公司代码",
              trigger: "blur"
            }]
          },
          {
            label: "场站三字码",
            prop: "cyCode",
            width: 100,
            rules: [{
              required: true,
              message: "请输入场站三字码",
              trigger: "blur"
            }]
          },
          {
            label: "CMA Laracode",
            prop: "cmaLaracode",
            width: 120,
            rules: [{
              required: true,
              message: "请输入CMA Laracode",
              trigger: "blur"
            }]
          },
          {
            label: "CMA Location",
            prop: "cmaLocation",
            width: 120,
            rules: [{
              required: true,
              message: "请输入CMA Location",
              trigger: "blur"
            }]
          },
          {
            label: "ZIM CUCC",
            prop: "zimCucc",
            width: 120,
            rules: [{
              required: true,
              message: "请输入ZIM CUCC",
              trigger: "blur"
            }]
          },
          {
            label: "关贸云编码",
            prop: "gmyCode",
            width: 100,
            rules: [{
              required: true,
              message: "请输入关贸云编码",
              trigger: "blur"
            }]
          },
          {
            label: "INTRRA ICUA",
            prop: "inttraIcua",
            width: 100,
            rules: [{
              required: true,
              message: "请输入INTRRA ICUA",
              trigger: "blur"
            }]
          },
          {
            label: "INTRRA ICUA 联系人",
            prop: "inttraIcuaAttn",
            width: 160,
            rules: [{
              required: true,
              message: "请输入INTRRA ICUA 联系人",
              trigger: "blur"
            }]
          },
          {
            label: "INTRRA ICUA Email",
            prop: "inttraIcuaEmail",
            width: 140,
            rules: [{
              required: true,
              message: "请输入INTRRA ICUA Email",
              trigger: "blur"
            }]
          },
          {
            label: "EDI 格式名称",
            prop: "ediFmt",
            width: 120,
            rules: [{
              required: true,
              message: "请输入EDI 格式名称",
              trigger: "blur"
            }]
          },
          {
            label: "EDI FTP 地址",
            prop: "ediFtp",
            width: 100,
            rules: [{
              required: true,
              message: "请输入EDI FTP 地址",
              trigger: "blur"
            }]
          },
          {
            label: "EDI 邮箱",
            prop: "ediEmail",
            rules: [{
              required: true,
              message: "请输入EDI 邮箱",
              trigger: "blur"
            }]
          },
          {
            label: "是否 VIP 客户",
            prop: "vip",
            width: 120,
            type: 'select',
            dicData: [{
              label: '否',
              value: 0
            }, {
              label: '是',
              value: 1
            }],
            rules: [{
              required: true,
              message: "请输入是否 VIP 客户，0=否，1=是",
              trigger: "blur"
            }]
          },
          {
            label: "VIP 等级",
            prop: "vipLevel",
            rules: [{
              required: true,
              message: "请输入VIP 等级",
              trigger: "blur"
            }]
          },
          {
            label: "是否已签约",
            prop: "isSigned",
            type: 'select',
            width: 100,
            dicData: [{
              label: '否',
              value: 0
            }, {
              label: '是',
              value: 1
            }],
            rules: [{
              required: true,
              message: "请输入是否已签约，0=否，1=是",
              trigger: "blur"
            }]
          },
          {
            label: "授信状态",
            prop: "creditStatus",
            rules: [{
              required: true,
              message: "请输入授信状态",
              trigger: "blur"
            }]
          },
          {
            label: "授信等级",
            prop: "creditLevel",
            rules: [{
              required: true,
              message: "请输入授信等级,A=A级,B=B级,B+=B+级,B-=B-级,C=C级,D=黑名单",
              trigger: "blur"
            }]
          },
          {
            label: "授信天数",
            prop: "creditDay",
            rules: [{
              required: true,
              message: "请输入授信天数",
              trigger: "blur"
            }]
          },
          {
            label: "授信币种",
            prop: "creditCur",
            rules: [{
              required: true,
              message: "请输入授信币种",
              trigger: "blur"
            }]
          },
          {
            label: "授信额度",
            prop: "creditGrant",
            rules: [{
              required: true,
              message: "请输入授信额度",
              trigger: "blur"
            }]
          },
          {
            label: "授信利率",
            prop: "creditRate",
            rules: [{
              required: true,
              message: "请输入授信利率",
              trigger: "blur"
            }]
          },
          {
            label: "付款方式",
            prop: "paymentType",
            rules: [{
              required: true,
              message: "请输入付款方式",
              trigger: "blur"
            }]
          },
          {
            label: "账期设置",
            prop: "accountPeriodType",
            rules: [{
              required: true,
              message: "请输入账期设置",
              trigger: "blur"
            }]
          },
          {
            label: "最大欠款额",
            prop: "maxArrears",
            width: 100,
            rules: [{
              required: true,
              message: "请输入最大欠款额",
              trigger: "blur"
            }]
          },
          {
            label: "协议号",
            prop: "agreementNo",
            rules: [{
              required: true,
              message: "请输入协议号",
              trigger: "blur"
            }]
          },
          {
            label: "绩效系数",
            prop: "performanceRate",
            rules: [{
              required: true,
              message: "请输入绩效系数",
              trigger: "blur"
            }]
          },
          {
            label: "增值税率",
            prop: "taxRate",
            rules: [{
              required: true,
              message: "请输入增值税率",
              trigger: "blur"
            }]
          },
          {
            label: "存在",
            prop: "isPs",
            type: 'select',
            dicData: [{
              label: '否',
              value: 0
            }, {
              label: '是',
              value: 1
            }],
            rules: [{
              required: true,
              message: "请输入存在 PS 0=否 1=是",
              trigger: "blur"
            }]
          },
          {
            label: "利润分成比例",
            prop: "psRate",
            width: 100,
            rules: [{
              required: true,
              message: "请输入PS(利润分成) 比例",
              trigger: "blur"
            }]
          },
          {
            label: "允许付大于收",
            prop: "psAllowLargeCredit",
            type: 'select',
            width: 100,
            dicData: [{
              label: '否',
              value: 0
            }, {
              label: '是',
              value: 1
            }],
            rules: [{
              required: true,
              message: "请输入PS允许付大于收 0=否 1=是",
              trigger: "blur"
            }]
          },
          // {
          //   label: "详情，主要用于提单信息",
          //   prop: "details",
          //   rules: [{
          //     required: true,
          //     message: "请输入详情，主要用于提单信息",
          //     trigger: "blur"
          //   }]
          // },
          // {
          //   label: "JSON 对象数组，用于不查询的扩展数据, 例如：[{name: "key1", value: "value1"}]",
          //   prop: "extendedData",
          //   rules: [{
          //     required: true,
          //     message: "请输入JSON 对象数组，用于不查询的扩展数据, 例如：[{name: "key1", value: "value1"}]",
          //     trigger: "blur"
          //   }]
          // },
          {
            label: "版本",
            prop: "version",
            hide: true,
            display: false,
          },
          {
            label: "状态",
            prop: "status",
            type: 'select',
            dicData: [{
              label: '启用',
              value: 0
            }, {
              label: '停用',
              value: 1
            }],
            rules: [{
              required: true,
              message: "请输入状态",
              trigger: "blur"
            }]
          },
          {
            label: "主键",
            prop: "id",
            hide: true,
            display: false,
          },
          {
            label: "分公司 Id",
            prop: "branchId",
            hide: true,
            display: false,
          },
          {
            label: "创建人 Id",
            prop: "createUser",
            hide: true,
            display: false,
          },
          {
            label: "创建人",
            prop: "createUserName",
            display: false,
          },
          {
            label: "创建部门 Id",
            prop: "createDept",
            hide: true,
            display: false,
          },
          {
            label: "创建部门",
            prop: "createDeptName",
            display: false,
          },
          {
            label: "创建时间",
            prop: "createTime",
            width: 160,
            display: false,
          },
          {
            label: "修改人 Id",
            prop: "updateUser",
            hide: true,
            display: false,
          },
          {
            label: "修改人",
            prop: "updateUserName",
            display: false,
          },
          {
            label: "修改时间",
            prop: "updateTime",
            width: 160,
            display: false,
          },
          {
            label: "是否已删除（0 否 1是）",
            prop: "isDeleted",
            hide: true,
            display: false,
          },
          {
            label: "备注",
            prop: "remarks",
            span: 24,
            type: 'textarea',
            width: "180",
            slot: true,
            minRows: 3,

          },
        ]
      },
      data: []
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        // addBtn: this.vaildData(this.permission.bcorps_add, false),
        viewBtn: this.vaildData(this.permission.bcorps_view, false),
        delBtn: this.vaildData(this.permission.bcorps_delete, false),
        editBtn: this.vaildData(this.permission.bcorps_edit, false)
      };
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
  },
  async created() {
    this.option = await this.getColumnData(this.getColumnName(304), this.optionBack);
    this.bcorpstypedefineListfun()
  },
  methods: {
      // 禁用启用按钮
      statusfun(id,status){
          this.$confirm("确定将选择数据更改状态?", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
          }).then(()=>{
              getBcorpsDetail(id).then(res => {
                  let obj = res.data.data;
                  obj.status = status
                  updateBcorps(obj).then(res=>{
                      this.onLoad(this.page);
                      this.$message({
                          type: "success",
                          message: "操作成功!"
                      });
                  })
              });
          })

      },
    // 导入
    // handleChange(file, fileLis) {
    //   console.log('daoru');
    //   // this.$Export.xlsx(file.raw)
    //   //   .then(data => {
    //   //     this.data=data.results;
    //   //   })
    // },
    // 导出
    handleExport() {
      var condition = ''
      for (const key in this.search) {
        var value = this.search[key]
        if (value) {
          condition += `&${key}=${this.search[key]}`
        }
      }

      this.$confirm('是否导出客户资料？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        window.open(
          `/api/blade-los/bcorps/exportBCorps?${this.website.tokenHeader
          }=${getToken()}${condition}`
        );
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消' //
        });
      })
    },
    // 下载模板
    handleGet() {
      window.open(
        `/api/blade-los/bcorps/exportBCorps/template?${this.website.tokenHeader
        }=${getToken()}`
      );
    },
    // 上传成功
    onSuccess(res, done, loading, column) {
      this.excelBox = false;
      this.$message.success("导入成功！");
      loading = false;
      this.onLoad(this.page);
      done();
    },
    uploadBefore(file, done, loading) {
      done();
      loading = true;
    },
    onError(err, file, fileList) {
      err += ''
      // console.log(JSON.stringify(err.match(/{(\S*)}/)[1]));
      var data = err.match(/{(\S*)}/)[1]
      this.$message.error(data.split("msg\":")[1]);
    },
    // 左侧点击回调
    nodeClick(data) {
      // var reqiestData = this.search;
      // // console.log(data, 904)
      // reqiestData.corpType = data.id
      // if (this.search.corpType == null) {
      this.search.corpType = data.id
      // } else {
      //   this.search.corpType = null
      // }
      this.onLoad(this.page, this.search);
      // this.onLoad(this.page, reqiestData);
    },
    // 获取客户类别
    bcorpstypedefineListfun() {
      bcorpstypedefineList(1,30).then(res => {
        this.customTypeData = res.data.data.records
      })
    },
    editOpen(row) {
      this.detailData = {
        id: row.id
      };
      this.isShow = false;
    },
    rowSave(row, done, loading) {
      addBcorps(row).then(() => {
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        done();
      }, error => {
        loading();
        window.console.log(error);
      });
    },
    rowUpdate(row, index, done, loading) {
      updateBcorps(row).then(() => {
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        done();
      }, error => {
        loading();
        console.log(error);
      });
    },
    rowDel(row) {
      if (row.status === 1) {
        this.$confirm("确定将选择数据删除?", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            return removeBcorps(row.id);
          })
          .then(() => {
            this.onLoad(this.page);
            this.$message({
              type: "success",
              message: "操作成功!"
            });
          });
      } else {
        this.$message({
          message: '非禁用状态无法删除',
          type: 'warning'
        });
      }
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return removeBcorps(this.ids);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          this.$refs.crud.toggleSelection();
        });
    },
    beforeOpen(done, type) {
      this.detailData = {};
      if (this.search.corpType != null) {
        this.detailData.corpType = this.search.corpType
      }
      this.isShow = false;
      // if (["edit", "view"].includes(type)) {
      //   getBcorpsDetail(this.form.id).then(res => {
      //     this.form = res.data.data;
      //   });
      // }
      // done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getBcorpsList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
    goBack() {
      this.onLoad(this.page);
      this.detailData = {};
      this.isShow = true;
    },
    // 类别弹窗关闭
    corpTypeClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => { });
    },
    //自定义列保存
    async saveColumnTwo(ref, option, optionBack, code) {
      /**
       * 已定义全局方法，直接使用，saveColumnData保存列数据方法,参数传值(表格名称，当前表格的option数据)
       * 已定义全局方法，直接使用，getColumnName方法用来获取枚举值，参数根据自己定义的code值获取中文名
       * 一定要执行异步操作，要等接口成功返回，才能执行下一行代码
       */
      const inSave = await this.saveColumnData(this.getColumnName(code), this[option]);
      if (inSave) {
        this.$message.success("保存成功");
        //关闭窗口
        this.$refs[ref].$refs.dialogColumn.columnBox = false;
      }
    },
    //自定义列重置
    async resetColumnTwo(ref, option, optionBack, code) {
      this[option] = this[optionBack];
      const inSave = await this.delColumnData(this.getColumnName(code), this[optionBack]);
      if (inSave) {
        this.$message.success("重置成功");
        this.$refs[ref].$refs.dialogColumn.columnBox = false;
      }
    },
    // 更改表格颜色
    headerClassName(tab) {
      //颜色间隔
      let back = ""
      if (tab.columnIndex >= 0 && tab.column.level === 1) {
        if (tab.columnIndex % 2 === 0) {
          back = "back-one"
        } else if (tab.columnIndex % 2 === 1) {
          back = "back-two"
        }
      }
      return back;
    },

  }
};
</script>

<style lang="scss" scoped>
::v-deep#out-table .back-one {
  background: #ecf5ff !important;
}

::v-deep#out-table .back-two {
  background: #ecf5ff !important;
}

::v-deep .el-input-group__append {
  padding: 0 0px !important;
}

/deep/ .el-tree-node__content>.el-tree-node__expand-icon {
  visibility: hidden;
}

/deep/ .el-col-md-8 {
  width: 24.33333%;
}
</style>
