<template>
  <div>
    <div>
      <el-form :inline="true">
        <el-form-item>
          <el-input
              v-model="search.entName"
              clearable
              prefix-icon="el-icon-search"
              placeholder="请输入企业名称"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-input
              v-model="search.entTaxId"
              clearable
              prefix-icon="el-icon-search"
              placeholder="请输入企业税号"
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-select
              v-model="search.serviceStatus"
              placeholder="请选择企业服务状态"
          >
            <el-option
                v-for="item in serviceStatusOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
              v-model="status"
              placeholder="请选择企业签约状态"
          >
            <el-option
                v-for="item in statusList"
                :key="item.value"
                :label="item.label"
                :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="handleSearch" type="primary"
          >搜 索
          </el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <div style="margin-bottom: 5px">
      <el-button @click="setCompanyContractInfo" type="primary">绑定签约企业</el-button>
    </div>
    <div>
      <el-container>
        <el-table
            :data="search.resultList"
            border
            style="width: 100%"
            :reserve-selection="true"
            @selection-change="selectChange"
        >
          <el-table-column
              type="selection"
              width="45">
          </el-table-column>
          <el-table-column
              prop="entName"
              label="企业名称"
              width="180"
              show-overflow-tooltip
          ></el-table-column>
          <el-table-column
              prop="entTaxId"
              label="企业税号"
              width="180"
              show-overflow-tooltip
          ></el-table-column>
          <el-table-column
              prop="entShortName"
              label="企业简称"
              width="120"
              show-overflow-tooltip
          ></el-table-column>
          <el-table-column
              prop="entAddress"
              label="企业开票地址"
              width="180"
              show-overflow-tooltip
          ></el-table-column>
          <el-table-column
              prop="entContactPerson"
              label="企业联系人"
              width="180"
              show-overflow-tooltip
          ></el-table-column>
          <el-table-column
              prop="entPhone"
              label="企业电话"
              width="180"
              show-overflow-tooltip
          ></el-table-column>
          <el-table-column
              prop="entTaxOfficeCode"
              label="企业税局"
              width="180"
              show-overflow-tooltip
          ></el-table-column>
          <el-table-column
              prop="availableTaxes"
              label="可用税率"
              width="180"
              show-overflow-tooltip
          ></el-table-column>
          <el-table-column
              prop="bankName"
              label="企业开户银行"
              width="180"
              show-overflow-tooltip
          ></el-table-column>
          <el-table-column
              prop="bankAccountNumber"
              label="企业银行账号"
              width="180"
              show-overflow-tooltip
          ></el-table-column>
          <el-table-column
              prop="payees"
              label="收款人"
              width="120"
              show-overflow-tooltip
          ></el-table-column>
          <el-table-column
              prop="reviewers"
              label="审核者"
              width="120"
              show-overflow-tooltip
          ></el-table-column>
          <el-table-column
              prop="defaultInvoiceDevice"
              label="默认开票设备"
              width="120"
              show-overflow-tooltip
              :formatter="fmtDefaultInvoiceDevice"
          ></el-table-column>
          <el-table-column
              prop="defaultTaxCode"
              label="默认开票税收编码"
              width="180"
              show-overflow-tooltip
              :formatter="fmtDefaultTaxCode"
          ></el-table-column>
          <el-table-column
              prop="defaultItemName"
              label="默认开票商品项目名"
              width="180"
              show-overflow-tooltip
              :formatter="fmtDefaultItemName"
          ></el-table-column>
          <el-table-column
              prop="entType"
              label="企业类型"
              width="120"
              fixed="right"
              align="center"
              show-overflow-tooltip
              :formatter="fmtEntType"
          ></el-table-column>
          <el-table-column
              prop="serviceStatus"
              label="企业服务状态"
              width="120"
              fixed="right"
              align="center"
              show-overflow-tooltip
              :formatter="fmtServiceStatus"
          ></el-table-column>
          <el-table-column
              label="操作"
              align="center"
              fixed="right"
              width="670"
          >
            <template slot-scope="scope">
              <el-button v-if="scope.row.signInfoId !== null"
                  @click="getPayCompany(scope.row.signInfoId)"
                  type="primary">
                查看支付绑定企业
              </el-button>
              <el-button
                  @click="
                                    handleShowAccountUnbindDialog(scope.row)
                                "
                  type="primary"
              >
                账户关联/解绑
              </el-button>
              <el-button
                  @click="
                                    handleShowModifyEntManagerDialog(scope.row)
                                "
                  type="primary"
              >
                修改企业管理者手机号码
              </el-button>
              <el-button
                  @click="
                                    handleShowModifyEntInfoDialog(scope.row)
                                "
                  type="primary"
              >
                修改企业信息
              </el-button>
              <el-button
                  @click="handleShowInvoiceDevice(scope.row)"
                  type="primary"
              >
                上架设备查询
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-container>
      <br/>
      <el-row type="flex" :gutter="20">
        <el-col :span="12"></el-col>
        <el-col :span="12">
          <div style="text-align: right">
            <el-pagination
                @size-change="handleSearchResultSizeChange"
                @current-change="handleSearchResultCurrentChange"
                :current-page="search.resultPagination.currentPage"
                :page-sizes="search.resultPagination.pageSizes"
                :page-size="search.resultPagination.pageSize"
                layout="total, sizes, prev, pager, next"
                :total="search.resultPagination.total"
            >
            </el-pagination>
          </div>
        </el-col>
      </el-row>
    </div>
    <el-dialog
        title="账户关联/解绑"
        :visible.sync="accountUnbind.visible"
        width="60%"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
        @opened="handleAccountUnbindDialogOpened"
        @close="handleAccountUnbindDialogClose"
    >
      <div
          v-loading="accountUnbind.loading"
          element-loading-text="拼命加载中......请稍等"
      >
        <div>
          <el-button
              @click="handleShowSelectEntRoleDialog()"
              type="primary"
          >添加账户关联
          </el-button>
        </div>
        <br/>
        <el-container>
          <el-table
              :data="accountUnbind.result"
              border
              stripe
              style="width: 100%"
              height="400"
          >
            <el-table-column
                type="index"
                :index="pageIndexAccountUnbind"
                align="center"
                label="序号"
                width="50"
            ></el-table-column>
            <el-table-column
                prop="userName"
                label="用户名称"
            ></el-table-column>
            <el-table-column
                prop="userMobile"
                label="用户手机号"
            ></el-table-column>
            <el-table-column
                prop="userEmail"
                label="用户邮箱"
            ></el-table-column>
            <el-table-column
                prop="roleMemo"
                label="用户角色"
            ></el-table-column>
            <el-table-column
                prop="defaultChoose"
                label="默认选择"
            ></el-table-column>
            <el-table-column
                label="操作"
                align="center"
                width="160"
            >
              <template slot-scope="scope">
                <el-button
                    @click="handleSubmitUnbind(scope.row)"
                    type="primary"
                >解绑
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-container>
        <br/>
        <el-row type="flex" :gutter="20">
          <el-col :span="12"></el-col>
          <el-col :span="12">
            <div style="text-align: right">
              <el-pagination
                  @size-change="
                                    handleAccountUnbindResultSizeChange
                                "
                  @current-change="
                                    handleAccountUnbindResultCurrentChange
                                "
                  :current-page="
                                    accountUnbind.resultPagination.currentPage
                                "
                  :page-sizes="
                                    accountUnbind.resultPagination.pageSizes
                                "
                  :page-size="
                                    accountUnbind.resultPagination.pageSize
                                "
                  layout="total, sizes, prev, pager, next"
                  :total="accountUnbind.resultPagination.total"
              ></el-pagination>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-dialog>
    <el-dialog
        title="选择关联企业角色"
        :visible.sync="selectEntRole.visible"
        width="30%"
        append-to-body
        :close-on-press-escape="false"
        :close-on-click-modal="false"
        @opened="handleSelectEntRoleDialogOpened"
        @close="handleSelectEntRoleDialogClose"
    >
      <div
          v-loading="selectEntRole.loading"
          element-loading-text="拼命加载中......请稍等"
      >
        <el-form
            :model="selectEntRole.form"
            :rules="selectEntRole.rules"
            ref="selectEntRoleForm"
            label-position="top"
        >
          <el-form-item label="关联账户" prop="entUserMobile">
            <el-input
                v-model="selectEntRole.form.entUserMobile"
                placeholder="请输入手机号码"
            ></el-input>
          </el-form-item>
          <el-form-item label="关联角色" prop="entRole">
            <el-radio-group v-model="selectEntRole.form.entRole">
              <el-radio
                  v-for="item in selectEntRole.entCategoryRoles"
                  :key="item.id"
                  :label="item.id"
              >{{ item.remark }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <br/>
          <el-form-item>
            <el-button @click="handleSubmitBind" type="primary"
            >确定关联
            </el-button>
            <el-button @click="selectEntRole.visible = false"
            >取 消
            </el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
    <el-dialog
        title="修改企业管理者手机号码"
        :visible.sync="modifyEntManager.visible"
        width="30%"
        append-to-body
        :close-on-press-escape="false"
        :close-on-click-modal="false"
        @close="handleModifyEntManagerDialogClose"
    >
      <div
          v-loading="modifyEntManager.loading"
          element-loading-text="拼命加载中......请稍等"
      >
        <el-form
            :model="modifyEntManager.form"
            :rules="modifyEntManager.rules"
            ref="modifyEntManagerForm"
            label-position="top"
        >
          <el-form-item
              label="新的企业管理者手机号码"
              prop="cusMobile"
          >
            <el-input
                v-model="modifyEntManager.form.cusMobile"
            ></el-input>
          </el-form-item>
          <el-form-item
              label="确认新的企业管理者手机号码"
              prop="cusConfirmMobile"
          >
            <el-input
                v-model="modifyEntManager.form.cusConfirmMobile"
            ></el-input>
          </el-form-item>
          <br/>
          <el-form-item
              label="当前登录服务商用户密码"
              prop="password"
          >
            <el-input
                v-model="modifyEntManager.form.password"
            ></el-input>
          </el-form-item>
          <br/>
          <el-form-item>
            <el-button
                type="primary"
                @click="handleSubmitModifyEntManager"
            >立即修改
            </el-button
            >
            <el-button @click="modifyEntManager.visible = false"
            >取 消
            </el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
    <el-dialog
        title="修改企业信息"
        :visible.sync="modifyEntInfo.visible"
        width="30%"
        append-to-body
        :close-on-press-escape="false"
        :close-on-click-modal="false"
        @close="handleModifyEntInfoDialogClose"
    >
      <div
          v-loading="modifyEntInfo.loading"
          element-loading-text="拼命加载中......请稍等"
      >
        <el-form
            :model="modifyEntInfo.form"
            :rules="modifyEntInfo.rules"
            ref="modifyEntInfoForm"
            label-position="top"
        >
          <el-form-item label="企业名称" prop="entName">
            <el-input
                v-model="modifyEntInfo.form.entName"
                placeholder="请输入企业名称"
                class="ent_input"
            ></el-input>
          </el-form-item>
          <el-form-item label="企业税号" prop="entTaxId">
            <el-input
                v-model="modifyEntInfo.form.entTaxId"
                disabled="disabled"
                placeholder="请输入企业税号"
                class="ent_input"
            ></el-input>
          </el-form-item>
          <br/>
          <el-form-item label="企业类型" prop="entType">
            <el-select
                v-model="modifyEntInfo.form.entType"
                placeholder="请选择"
            >
              <el-option
                  v-for="item in modifyEntInfo.entTypes"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <br/>
          <el-form-item>
            <el-button
                type="primary"
                @click="handleSubmitModifyEntInfo"
            >立即修改
            </el-button
            >
            <el-button @click="modifyEntInfo.visible = false"
            >取 消
            </el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </el-dialog>
    <el-dialog
        title="签约企业信息"
        :visible.sync="isShowCompany"
        width="50%"
        :before-close="enterprisesClose">
      <div>
        <div style="display: flex; margin-bottom: 10px">
          <el-input style="width: 300px" prefix-icon="el-icon-search" v-model="taxName" clearable
                    placeholder="请输入企业名称"></el-input>
          <el-input style="width: 300px; margin-left: 10px" prefix-icon="el-icon-search" v-model="taxId" clearable
                    placeholder="请输入企业税号"></el-input>
          <el-button style="margin-left: 10px" type="primary" v-on:click="getSearchEnterprises">搜索</el-button>
        </div>
        <div>
          <el-table
              :data="enterprisesList"
              :height="350"
              border>
            <el-table-column
                prop="entName"
                label="企业名称"
                width="180">
            </el-table-column>
            <el-table-column
                prop="entTaxId"
                label="企业税号"
                width="180">
            </el-table-column>
            <el-table-column
                prop="dockType"
                label="支付平台"
                width="120">
            </el-table-column>
            <el-table-column
                prop="signType"
                label="支付平台加密类型"
                width="120">
            </el-table-column>
            <el-table-column
                prop="version"
                label="支付平台版本号"
                width="120">
            </el-table-column>
            <el-table-column
                prop="createTime"
                label="创建时间"
                width="160">
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                fixed="right"
                width="120"
            >
              <template slot-scope="scope">
                <el-button @click="selectCompany(scope.row)" type="primary">选择</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div style="display: flex; justify-content: flex-end; margin-top: 10px">
          <el-pagination
              @size-change="getNumberPage"
              @current-change="getPageNumber"
              :current-page.sync="pageNumber"
              :page-sizes="[10, 30, 50, 100]"
              :page-size="numberPage"
              layout="total, sizes, prev, pager, next"
              :total="totalPage">
          </el-pagination>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {EntInfoByMobile} from "@/api/ent_init";
import USER_MANAGEMENT from "@/api/user-management";
import ENT_INFO from "@/api/ent-info";
import {AxiosRequestData} from "@/data/axios_request";
import cache from "@/utils/cache";

// 企业服务状态选项列表
const serviceStatusOptions = [
  {
    value: 1,
    label: "待初始化",
  },
  {
    value: 2,
    label: "初始化成功",
  },
  {
    value: 3,
    label: "服务状态有效",
  },
  {
    value: 4,
    label: "欠费",
  },
];

// 上架设备类型列表
const initDeviceTypes = [
  {
    value: 1,
    label: "软证书",
  },
  {
    value: 2,
    label: "税控盘",
  },
  {
    value: 3,
    label: "金税盘",
  },
  {
    value: 4,
    label: "税控UKey",
  },
  {
    value: 5,
    label: "税控服务器",
  },
];

// 企业类型
const entTypes = [
  {
    value: 1,
    label: "一般纳税人",
  },
  {
    value: 2,
    label: "小规模纳税人",
  },
  {
    value: 3,
    label: "起征点以下纳税人",
  },
];

export default {
  name: "EntInitManage",
  data() {
    return {
      serviceStatusOptions: serviceStatusOptions,
      search: {
        entName: null,
        entTaxId: null,
        serviceStatus: "", // 企业服务状态
        resultList: [],
        resultMultipleSelection: [],
        resultPagination: {
          currentPage: 1,
          pageSizes: [10, 30, 50, 100],
          pageSize: 10,
          total: 0,
        },
      },
      accountUnbind: {
        visible: false,
        loading: false,
        originalRow: null,
        searchText: "",
        serachTimer: "",
        resultList: [],
        resultPagination: {
          currentPage: 1,
          pageSizes: [10, 30],
          pageSize: 10,
          total: 0,
        },
      },
      selectEntRole: {
        visible: false,
        loading: false,
        entCategoryRoles: [],
        entTaxId: "",
        form: {
          entUserMobile: "",
          entRole: "",
        },
        rules: {
          entUserMobile: [
            {
              required: true,
              message: "请输入关联账户手机号码",
              trigger: "change",
            },
          ],
          entRole: [
            {
              required: true,
              message: "请选择账户关联角色",
              trigger: "change",
            },
          ],
        },
      },
      modifyEntManager: {
        visible: false,
        loading: false,
        originalRow: null,
        form: {
          cusMobile: "",
          cusConfirmMobile: "",
          password: "",
        },
        rules: {
          cusMobile: [
            {
              required: true,
              message: "请输入新的企业管理者手机号码",
              trigger: "change",
            },
          ],
          cusConfirmMobile: [
            {
              required: true,
              message: "请输入确认新的企业管理者手机号码",
              trigger: "change",
            },
          ],
          password: [
            {
              required: true,
              message: "请输入当前登录服务商用户密码",
              trigger: "change",
            },
          ],
        },
      },
      modifyEntInfo: {
        visible: false,
        loading: false,
        entTypes: entTypes,
        form: {
          entName: "",
          entTaxId: "",
          entType: "",
        },
        rules: {
          entName: [
            {
              required: true,
              message: "请输入企业名称",
              trigger: "change",
            },
          ],
          entTaxId: [
            {
              required: true,
              message: "请输入企业税号",
              trigger: "change",
            },
          ],
          entType: [
            {
              required: true,
              message: "请选择企业类型",
              trigger: "change",
            },
          ],
        },
      },
      isShowCompany: false,
      selectCompanyList: [],
      pageNumber: 1,
      enterprisesList: [],
      taxName: '',
      taxId: '',
      numberPage: 10,
      totalPage: 0,
      ispId: '',
      token: '',
      companyList: [],
      status: null,
      statusList: [
        {
          value: null,
          label: '全部'
        },
        {
          value: true,
          label: '已签约'
        },
        {
          value: false,
          label: '未签约'
        }
      ]
    }
  },
  created() {
    this.token = cache.getToken()
    let company = JSON.parse(cache.getLocal('ISP'))
    this.ispId = company.ispId
    this.callEntInfoByMobile(
        this.search.resultPagination.currentPage,
        this.search.resultPagination.pageSize
    );
  },
  methods: {
    fmtEntType(row, column, cellValue) {
      if (cellValue == 1) {
        return "一般纳税人";
      } else if (cellValue == 2) {
        return "小规模纳税人";
      } else if (cellValue == 3) {
        return "起征点以下纳税人";
      } else {
        return cellValue;
      }
    },
    fmtServiceStatus(row, column, cellValue) {
      let result = cellValue;
      if (cellValue == 1) {
        result = "待初始化";
      } else if (cellValue == 2) {
        result = "初始化成功";
      } else if (cellValue == 3) {
        result = "服务状态有效";
      } else if (cellValue == 4) {
        result = "欠费";
      }
      return result;
    },
    fmtDefaultInvoiceDevice(row, column, cellValue) {
      let result = cellValue;
      for (const item of initDeviceTypes) {
        if (item.value === cellValue) {
          result = item.label;
          break;
        }
      }
      return result;
    },
    fmtDefaultTaxCode(row, column, cellValue) {
      let result = cellValue;
      if (cellValue == null || cellValue == "null") result = "";
      return result;
    },
    fmtDefaultItemName(row, column, cellValue) {
      let result = cellValue;
      if (cellValue == null || cellValue == "null") result = "";
      return result;
    },
    handleSearch() {
      this.callEntInfoByMobile(1, this.search.resultPagination.pageSize);
    },
    handleSearchResultSizeChange(val) {
      this.callEntInfoByMobile(1, val);
    },
    handleSearchResultCurrentChange(val) {
      this.callEntInfoByMobile(
          val,
          this.search.resultPagination.pageSize
      );
    },
    handleShowInvoiceDevice(row) {
      this.$router.push({
        name: "EntInitDevice",
        params: {key: row.entTaxId.toString()},
      });
    },
    /**
     * 用户手机号查询企业列表
     * @param {Number} pageNum : 当前页码
     * @param {Number} pageSize : 每页数量
     */
    callEntInfoByMobile(pageNum, pageSize) {
      EntInfoByMobile({
        entTaxId: this.search.entTaxId,
        entName: this.search.entName,
        serviceStatus: this.search.serviceStatus,
        hasSigned: this.status,
        pageNum: pageNum,
        pageSize: pageSize,
      })
          .then((val) => {
            this.search.resultPagination.total = val.data.total;
            this.search.resultPagination.pageSize = val.data.size;
            this.search.resultPagination.currentPage = val.data.current;
            this.search.resultList = val.data.records;
          })
          .catch((err) => {
            this.$message.error(err);
          });
    },
    handleShowAccountUnbindDialog(row) {
      this.accountUnbind.originalRow = row;
      this.accountUnbind.visible = true;
    },
    handleAccountUnbindDialogOpened() {
      this.callGetEntUserRoleInfo(
          this.accountUnbind.originalRow.entTaxId,
          this.accountUnbind.resultPagination.currentPage,
          this.accountUnbind.resultPagination.pageSize
      );
    },
    handleAccountUnbindDialogClose() {
      this.accountUnbind.originalRow = null;
    },
    pageIndexAccountUnbind(index) {
      let currentPage = this.accountUnbind.resultPagination.currentPage; // 当前页码，具体看组件取值
      let pageSize = this.accountUnbind.resultPagination.pageSize; // 每页条数，具体是组件取值
      return index + 1 + (currentPage - 1) * pageSize;
    },
    handleAccountUnbindResultSizeChange(val) {
      this.callGetEntUserRoleInfo(
          this.accountUnbind.originalRow.entTaxId,
          1,
          val
      );
    },
    handleAccountUnbindResultCurrentChange(val) {
      this.callGetEntUserRoleInfo(
          this.accountUnbind.originalRow.entTaxId,
          val,
          this.accountUnbind.resultPagination.pageSize
      );
    },
    // 提交解绑操作
    handleSubmitUnbind(row) {
      let _this = this;
      _this.accountUnbind.loading = true;
      USER_MANAGEMENT.entUserDelOnEnt(
          row.userMobile,
          this.accountUnbind.originalRow.entTaxId
      )
          .then((val) => {
            _this.accountUnbind.loading = false;
            _this.$message.success(val.msg);

            this.callGetEntUserRoleInfo(
                this.accountUnbind.originalRow.entTaxId,
                this.accountUnbind.resultPagination.currentPage,
                this.accountUnbind.resultPagination.pageSize
            );
          })
          .catch((err) => {
            _this.accountUnbind.loading = false;
            _this.$message.error(err);
          });
    },
    /**
     * 搜索当前登陆用户管理的用户列表
     * @param {Number} pageNum : 当前页码
     * @param {Number} pageSize : 每页数量
     */
    callGetEntUserRoleInfo(entTaxId, pageNum, pageSize) {
      let _this = this;
      _this.accountUnbind.loading = true;
      USER_MANAGEMENT.getEntUserRoleInfo(
          entTaxId,
          this.accountUnbind.searchText,
          pageNum,
          pageSize
      )
          .then((val) => {
            _this.accountUnbind.loading = false;
            _this.accountUnbind.resultPagination.total = val.data.total;
            _this.accountUnbind.resultPagination.pageSize =
                val.data.size;
            _this.accountUnbind.resultPagination.currentPage =
                val.data.current;
            _this.accountUnbind.result = val.data.records;
          })
          .catch((err) => {
            _this.accountUnbind.loading = false;
            _this.$message.error(err);
          });
    },
    handleShowSelectEntRoleDialog() {
      this.selectEntRole.entTaxId = this.accountUnbind.originalRow.entTaxId;

      this.selectEntRole.visible = true;
    },
    handleSelectEntRoleDialogOpened() {
      this.callGetEntCategoryRoles();
    },
    handleSelectEntRoleDialogClose() {
      this.selectEntRole.entCategoryRoles = [];
      this.selectEntRole.form.entUserMobile = "";
      this.selectEntRole.form.entRole = "";

      this.$refs["selectEntRoleForm"].resetFields();
    },
    // 获取企业用户角色
    callGetEntCategoryRoles() {
      let _this = this;
      _this.selectEntRole.loading = true;
      USER_MANAGEMENT.getEntCategoryRoles()
          .then((val) => {
            let roles = val.data;
            for (let i = 0; i < roles.length; i++) {
              // 移除 企业管理者
              if (roles[i].remark === "企业管理者") {
                roles.splice(i, 1);
              }
              roles[i].checked = false;
            }

            _this.selectEntRole.entCategoryRoles = roles;
            _this.selectEntRole.loading = false;
          })
          .catch((err) => {
            _this.selectEntRole.loading = false;
            _this.$alert(
                "数据获取失败窗口将关闭！请尝试重新操作。",
                "提示",
                {
                  confirmButtonText: "确定",
                  callback: (action) => {
                    _this.selectEntRole.visible = false;
                  },
                }
            );
          });
    },
    // 提交关联操作
    handleSubmitBind() {
      let _this = this;
      this.$refs["selectEntRoleForm"].validate((valid) => {
        if (valid) {
          _this.selectEntRole.loading = true;
          USER_MANAGEMENT.entUserSaveOnEnt({
            entTaxId: this.selectEntRole.entTaxId,
            roleId: this.selectEntRole.form.entRole,
            entUserMobile: this.selectEntRole.form.entUserMobile,
          })
              .then((val) => {
                _this.selectEntRole.loading = false;
                _this.selectEntRole.visible = false;
                _this.$message.success(val.msg);

                _this.callGetEntUserRoleInfo(
                    _this.accountUnbind.originalRow.entTaxId,
                    _this.accountUnbind.resultPagination
                        .currentPage,
                    _this.accountUnbind.resultPagination.pageSize
                );
              })
              .catch((err) => {
                _this.selectEntRole.loading = false;
                _this.$message.error(err);
              });
        } else {
          _this.$message.error(
              "输入信息不合法，请检查您的输入信息！"
          );
          return false;
        }
      });
    },
    handleShowModifyEntManagerDialog(row) {
      this.modifyEntManager.originalRow = row;
      this.modifyEntManager.visible = true;
    },
    handleModifyEntManagerDialogClose() {
      this.modifyEntManager.originalRow = null;
      this.modifyEntManager.form.cusMobile = "";
      this.modifyEntManager.form.cusConfirmMobile = "";
      this.modifyEntManager.form.password = "";
    },
    handleSubmitModifyEntManager() {
      let _this = this;
      this.$refs["modifyEntManagerForm"].validate((valid) => {
        if (valid) {
          _this.modifyEntManager.loading = true;
          USER_MANAGEMENT.modifyEntManager({
            entTaxId: this.modifyEntManager.originalRow.entTaxId,
            cusMobile: this.modifyEntManager.form.cusMobile,
            cusConfirmMobile: this.modifyEntManager.form
                .cusConfirmMobile,
            password: this.modifyEntManager.form.password,
          })
              .then((val) => {
                _this.modifyEntManager.loading = false;
                _this.modifyEntManager.visible = false;
                _this.$message.success(val.msg);
              })
              .catch((error) => {
                _this.modifyEntManager.loading = false;
                _this.$message.error(error);
              });
        } else {
          _this.$message.error(
              "输入信息不合法，请检查您的输入信息！"
          );
          return false;
        }
      });
    },
    handleShowModifyEntInfoDialog(row) {
      this.modifyEntInfo.originalRow = row;
      this.modifyEntInfo.form.entName = row.entName;
      this.modifyEntInfo.form.entTaxId = row.entTaxId;
      this.modifyEntInfo.form.entType = row.entType;

      this.modifyEntInfo.visible = true;
    },
    handleModifyEntInfoDialogClose() {
      this.modifyEntInfo.originalRow = null;
      this.modifyEntInfo.form.entName = "";
      this.modifyEntInfo.form.entTaxId = "";
      this.modifyEntInfo.form.entType = "";

      this.$refs["modifyEntInfoForm"].resetFields();
    },
    handleSubmitModifyEntInfo() {
      let _this = this;
      this.$refs["modifyEntInfoForm"].validate((valid) => {
        if (valid) {
          _this.modifyEntInfo.loading = true;
          ENT_INFO.modifyEntBriefInfo({
            entTaxId: this.modifyEntInfo.form.entTaxId,
            entName: this.modifyEntInfo.form.entName,
            entType: this.modifyEntInfo.form.entType,
          })
              .then((val) => {
                _this.modifyEntInfo.loading = false;
                _this.modifyEntInfo.visible = false;
                _this.$message.success(val.msg);

                _this.callEntInfoByMobile(
                    _this.search.resultPagination.currentPage,
                    _this.search.resultPagination.pageSize
                );
              })
              .catch((error) => {
                _this.modifyEntInfo.loading = false;
                _this.$message.error(error);
              });
        } else {
          _this.$message.error(
              "输入信息不合法，请检查您的输入信息！"
          );
          return false;
        }
      });
    },
    // table选择触发事件
    selectChange(list) {
      this.selectCompanyList = list
      let listInfo = []
      list.forEach((item, index) => {
        let info = {
          cusEntTaxId: item.entTaxId,
          ownEntTaxId: ''
        }
        listInfo = listInfo.concat(info)
      })
      this.companyList = listInfo
    },
    // 绑定签约企业信息
    setCompanyContractInfo() {
      if (this.selectCompanyList && this.selectCompanyList.length > 0) {
        this.getEnterprises()
        this.isShowCompany = true
      } else {
        this.$message({
          message: '请选择需要签约的企业信息！',
          type: 'warning'
        })
      }
    },
    // 查询企业信息
    getSearchEnterprises() {
      this.pageNumber = 1
      this.numberPage = 10
      this.getEnterprises()
    },
    // 获取企业信息
    getEnterprises: async function () {
      if (this.token) {
        const url = '/marketing/isp/signPay/info/findPage'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              ispId: this.ispId,
              entName: this.taxName,
              entTaxId: this.taxId,
              pageNum: this.pageNumber,
              pageSize: this.numberPage
            },
            false,
            2
        )
        if (response) {
          if (response.code === 0) {
            this.enterprisesList = response.data.records
            this.totalPage = response.data.total
          }
        }
      }
    },
    // 获取当前页码
    getPageNumber(num) {
      this.pageNumber = num
      this.getEnterprises()
    },
    // 获取每页显示数据的数量
    getNumberPage(numPage) {
      this.numberPage = numPage
      this.getEnterprises()
    },
    // 企业信息页面关闭
    enterprisesClose() {
      this.isShowCompany = false
    },
    // 选择对应的签约企业
    async selectCompany(row) {
      if (this.token) {
        this.companyList.forEach((item, index) => {
          item.ownEntTaxId = row.entTaxId
        })
        const url = '/marketing/isp/signPay/entSign/update'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              ispId: this.ispId,
              signInfos: this.companyList,
              reqChannel: 4
            },
            false,
            1
        )
        if (response) {
          if (response.code === 0) {
            this.isShowCompany = false
            this.$message({
              message: '保存成功！',
              type: 'success'
            })
            this.callEntInfoByMobile(
                this.search.resultPagination.currentPage,
                this.search.resultPagination.pageSize
            )
          } else {
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 获取支付绑定企业信息
    async getPayCompany(id) {
      if (this.token) {
        const url = '/marketing/isp/signPay/info/findById'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              infoId: id
            },
            false,
            2
        )
        if (response) {
          if (response.code === 0) {
            this.$message({
              message: response.data.entName,
              type: 'success'
            })
          } else {
            this.$message.error(response.msg)
          }
        }
      }
    }
  }
}
</script>

<style scoped>
</style>
