<template>
  <div id="agent_account_claim" v-loading="loading"  element-loading-text="文件导出中，请稍后！">
    <div style="display: flex; margin-bottom: 10px">
      <el-input style="width: 300px" prefix-icon="el-icon-search" v-model="searchEntTaxId" clearable
                placeholder="请输入代账机构企业税号"></el-input>
      <el-input style="width: 300px; margin-left: 10px" prefix-icon="el-icon-search" v-model="searchEntTaxName" clearable
                placeholder="请输入代账机构企业名称"></el-input>
      <el-button style="margin-left: 10px" type="primary" v-on:click="getSearchAgentCompany">搜索</el-button>
    </div>
    <div>
      <el-table
          :data="userList"
          border
          :height="tableHeight">
        <el-table-column
            prop="entTaxId"
            label="代账机构企业税号"
            width="160">
        </el-table-column>
        <el-table-column
            prop="entName"
            label="代账机构企业名称"
            width="200"
            show-overflow-tooltip>
        </el-table-column>
        <el-table-column
            prop="address"
            label="代账机构企业地址"
            width="200"
            show-overflow-tooltip>
        </el-table-column>
        <el-table-column
            prop="roleRemark"
            label="当前用户在该机构的角色"
            width="200">
        </el-table-column>
        <el-table-column
            label="操作"
            align="center"
            width="380"
        >
          <template slot-scope="scope">
            <el-button @click="getCompanyShow(scope.row)" type="primary">绑定</el-button>
            <el-button type="primary" v-on:click="cancelCompanyShow(scope.row)">撤销</el-button>
            <el-button type="primary" v-on:click="openBusinessUserPage(scope.row)">设置业务人员</el-button>
            <el-button type="primary" v-on:click="bindHistoryShow(scope.row)">绑定记录查询</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>
    <el-dialog
        title="企业信息绑定"
        :visible.sync="companyShow"
        width="50%"
        :before-close="companyInfoClose">
      <div>
        <div style="display: flex; margin-bottom: 10px">
          <el-input style="width: 260px; margin-left: 10px" prefix-icon="el-icon-search" v-model="entTaxId" clearable
                    placeholder="请输入企业税号或企业名称"></el-input>
<!--          <el-input style="width: 260px; margin-left: 10px" prefix-icon="el-icon-search" v-model="entName" clearable-->
<!--                    placeholder="请输入企业名称"></el-input>-->
          <el-button style="margin-left: 10px" type="primary" v-on:click="getSearchCompany">搜索</el-button>
        </div>
        <el-table
            :data="companyList"
            border
            height="400"
            style="width: 100%">
          <el-table-column
              prop="entName"
              label="企业名称"
              width="230">
          </el-table-column>
          <el-table-column
              prop="entTaxId"
              label="企业税号"
              width="180">
          </el-table-column>
          <el-table-column
              prop="entType"
              label="企业类型"
              width="120"
              :formatter="getCompanyType">
          </el-table-column>
          <el-table-column
              prop="serviceStatus"
              label="企业服务状态"
              width="120"
              :formatter="getCompanyStatus">
          </el-table-column>
          <el-table-column
              fixed="right"
              label="操作"
              align="center"
              width="100"
          >
            <template slot-scope="scope">
              <el-button @click="bindCompany(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="getCompanyNumberPage"-->
<!--            @current-change="getCompanyPageNumber"-->
<!--            :current-page.sync="companyPageNumber"-->
<!--            :page-sizes="[10, 30, 50, 100, 300, 500]"-->
<!--            :page-size="companyNumberPage"-->
<!--            layout="total, sizes, prev, pager, next"-->
<!--            :total="companyTotalPage">-->
<!--        </el-pagination>-->
<!--      </div>-->
      <div style="display: flex; justify-content: flex-end; margin-top: 10px">
        <el-button @click="companyInfoClose">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
        title="企业信息解绑"
        :visible.sync="isCancelCompany"
        width="50%"
        v-on:before-close="closeCancelCompanyPage">
      <div>
        <el-table
            :data="cancelCompanyList"
            border
            height="400"
            style="width: 100%"
            @selection-change="cancelCompanySelectChange">
          <el-table-column
              type="selection"
              width="55">
          </el-table-column>
          <el-table-column
              prop="entName"
              label="企业名称"
              width="230">
          </el-table-column>
          <el-table-column
              prop="entTaxId"
              label="企业税号"
              width="180">
          </el-table-column>
          <el-table-column
              prop="claimedTime"
              label="认领的时间"
              width="150">
          </el-table-column>
          <el-table-column
              prop="claimedUser"
              label="认领用户"
              width="120">
          </el-table-column>
        </el-table>
      </div>
      <div style="display: flex; justify-content: flex-end; margin-top: 10px">
        <el-pagination
            @size-change="getCancelCompanyNumberPage"
            @current-change="getCancelCompanyPageNumber"
            :current-page.sync="cancelCompanyPageNumber"
            :page-sizes="[10, 30, 50, 100, 300, 500]"
            :page-size="cancelCompanyNumberPage"
            layout="total, sizes, prev, pager, next"
            :total="cancelCompanyTotalPage">
        </el-pagination>
      </div>
      <div style="display: flex; justify-content: flex-end; margin-top: 10px">
        <el-button @click="closeCancelCompanyPage">取 消</el-button>
        <el-button type="primary" @click="cancelCompanyBind">确 认</el-button>
      </div>
    </el-dialog>
    <el-dialog
        title="绑定记录查询"
        :visible.sync="isBindHistory"
        width="50%"
        v-on:before-close="closeBindHistoryPage">
      <div>
        <div style="display: flex; margin-bottom: 10px; flex-wrap: wrap">
          <el-input style="width: 260px; margin-right: 10px; margin-top: 5px" prefix-icon="el-icon-search" v-model="searchEntTaxIdHistory" clearable
                    placeholder="请输入企业税号"></el-input>
          <el-input style="width: 260px; margin-right: 10px; margin-top: 5px" prefix-icon="el-icon-search" v-model="searchEntTaxNameHistory" clearable
                    placeholder="请输入企业名称"></el-input>
          <el-select style="margin-right: 10px; margin-top: 5px" 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-date-picker
              style="margin-right: 10px; margin-top: 5px"
              v-model="beginTime"
              type="datetime"
              placeholder="选择认领开始时间"
              value-format="yyyy-MM-dd HH:mm:ss"
              :default-time="'00:00:00'">
          </el-date-picker>
          <el-date-picker
              style="margin-right: 10px; margin-top: 5px"
              v-model="endTime"
              type="datetime"
              placeholder="选择认领结束时间"
              value-format="yyyy-MM-dd HH:mm:ss"
              :default-time="'23:59:59'">
          </el-date-picker>
          <el-button style="margin-left: 5px; margin-top: 5px" type="primary" v-on:click="getBindHistory">搜索</el-button>
          <el-button style="margin-left: 10px; margin-top: 5px" type="primary" v-on:click="exportBindHistory">导出</el-button>
        </div>
        <el-table
            :data="cancelCompanyList"
            border
            height="400"
            style="width: 100%"
            @selection-change="cancelCompanySelectChange">
          <el-table-column
              prop="entName"
              label="企业名称"
              width="230">
          </el-table-column>
          <el-table-column
              prop="entTaxId"
              label="企业税号"
              width="180">
          </el-table-column>
          <el-table-column
              prop="claimedTime"
              label="认领的时间"
              width="150">
          </el-table-column>
          <el-table-column
              prop="cancelClaimedTime"
              label="撤销认领时间"
              width="150">
          </el-table-column>
          <el-table-column
              prop="claimedUser"
              label="认领用户"
              width="120">
          </el-table-column>
          <el-table-column
              prop="cancelClaimedUser"
              label="撤销认领用户"
              width="120">
          </el-table-column>
          <el-table-column
              prop="claimedStatus"
              label="认领状态"
              width="70"
              :formatter="getClaimedStatus">
          </el-table-column>
          <el-table-column
              prop="deviceType"
              label="设备类型"
              width="90"
              :formatter="getDeviceStatus">
          </el-table-column>
          <el-table-column
              prop="initStatus"
              label="上架状态"
              width="100"
              :formatter="getCompanyStatus">
          </el-table-column>
          <el-table-column
              prop="initStatusMemo"
              label="上架状态说明"
              width="120">
          </el-table-column>
          <el-table-column
              prop="latestPutTime"
              label="最近一次上架时间"
              width="150">
          </el-table-column>
          <el-table-column
              prop="latestUnshelveTime"
              label="最近一次下架时间"
              width="150">
          </el-table-column>
        </el-table>
      </div>
      <div style="display: flex; justify-content: flex-end; margin-top: 10px">
        <el-pagination
            @size-change="getCancelCompanyNumberPage"
            @current-change="getCancelCompanyPageNumber"
            :current-page.sync="cancelCompanyPageNumber"
            :page-sizes="[10, 30, 50, 100, 300, 500]"
            :page-size="cancelCompanyNumberPage"
            layout="total, sizes, prev, pager, next"
            :total="cancelCompanyTotalPage">
        </el-pagination>
      </div>
      <div style="display: flex; justify-content: flex-end; margin-top: 10px">
        <el-button @click="closeBindHistoryPage">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
        title="业务人员信息"
        :visible.sync="isBusinessUserShow"
        width="50%"
        v-on:opened="getBusinessUserPage"
        :before-close="closeBusinessUserPage">
      <div>
        <div style="display: flex; margin-bottom: 10px">
          <el-input style="width: 260px" prefix-icon="el-icon-search" v-model="searchUserName" clearable
                    placeholder="请输入用户名"></el-input>
          <el-input style="width: 260px; margin-left: 10px" prefix-icon="el-icon-search" v-model="searchUserPhone" clearable
                    placeholder="请输入用户手机号"></el-input>
          <el-button style="margin-left: 10px" type="primary" v-on:click="getBusinessUserPage">搜索</el-button>
          <el-button style="margin-left: 10px" type="primary" v-on:click="isBusinessUser = true">新增</el-button>
          <el-button style="margin-left: 10px" type="primary" v-on:click="deleteUser">删除</el-button>
        </div>
        <el-table
            :data="businessUserList"
            border
            height="400"
            style="width: 100%"
            @selection-change="userSelectChange">
          <el-table-column
              type="selection"
              width="55">
          </el-table-column>
          <el-table-column
              prop="userName"
              label="用户名"
              width="230"
              show-overflow-tooltip>
          </el-table-column>
          <el-table-column
              prop="userMobile"
              label="用户手机号"
              width="110">
          </el-table-column>
          <el-table-column
              prop="roleRemark"
              label="角色"
              width="130">
          </el-table-column>
          <el-table-column
              prop="createTime"
              label="创建时间"
              width="150">
          </el-table-column>
        </el-table>
      </div>
      <div style="display: flex; justify-content: flex-end; margin-top: 10px">
        <el-pagination
            @size-change="getBusinessUserNumberPage"
            @current-change="getBusinessUserPageNumber"
            :current-page.sync="businessUserPageNumber"
            :page-sizes="[10, 30, 50, 100, 300, 500]"
            :page-size="businessUserNumberPage"
            layout="total, sizes, prev, pager, next"
            :total="businessUserTotalPage">
        </el-pagination>
      </div>
      <div style="display: flex; justify-content: flex-end; margin-top: 10px">
        <el-button @click="closeBusinessUserPage">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
        title="添加业务人员"
        :visible.sync="isBusinessUser"
        width="30%"
        :before-close="closeUserPhonePage">
      <div>
        <div style="display: flex; justify-content: center; align-items: center">
          <span><span style="color: red">*</span>业务人员手机号码：</span>
          <el-input style="width: 200px" v-model="userPhone" clearable placeholder="请输入业务人员手机号码"></el-input>
        </div>
      </div>
      <div style="display: flex; justify-content: flex-end; margin-top: 10px">
        <el-button @click="closeUserPhonePage">取 消</el-button>
        <el-button type="primary" @click="setUserPhone">确认</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import cache from '@/utils/cache'
import { AxiosRequestData } from '@/data/axios_request'
import { GetBoolType, GetCompanyServiceStatus, GetCompanyType, GetDeviceType } from '@/utils/enumeration'

export default {
  name: 'agent_account_claim',
  data() {
    return {
      token: '',
      searchEntTaxId: '',
      searchEntTaxName: '',
      userList: [],
      ispId: '',
      entName: '',
      entTaxId: '',
      tableHeight: '',
      totalPage: 0,
      numberPage: 10,
      pageNumber: 1,
      pageNum: 1,
      pageSize: 10,
      companyPageNumber: 1,
      companyPageSize: 10,
      companyNumberPage: 10,
      companyTotalPage: 0,
      isShow: false,
      account: '',
      companyShow: false,
      companyList: [],
      selectCompanyList: [],
      entTaxIdList: [],
      couponId: '',
      couponTitle: '',
      userId: '',
      orgId: '',
      isCancelCompany: false,
      cancelCompanyList: [],
      cancelCompanyPageNumber: 1,
      cancelCompanyPageSize: 10,
      cancelCompanyNumberPage: 10,
      cancelCompanyTotalPage: 0,
      companyIdList: [],
      isBindHistory: false,
      status: null,
      statusList: [
        {
          value: null,
          label: '全部'
        },
        {
          value: 0,
          label: '未认领'
        },
        {
          value: 1,
          label: '已认领'
        }
      ],
      beginTime: null,
      endTime: null,
      searchEntTaxIdHistory: '',
      searchEntTaxNameHistory: '',
      recordId: '',
      timer: null,
      loading: false,
      isBusinessUserShow: false,
      businessUserList: [],
      searchUserName: '',
      searchUserPhone: '',
      businessUserPageNumber: 1,
      businessUserPageSize: 10,
      businessUserNumberPage: 10,
      businessUserTotalPage: 0,
      isBusinessUser: false,
      userPhone: '',
      userIdList: []
    }
  },
  created() {
    this.tableHeight = window.innerHeight - 250
    let company = JSON.parse(cache.getSession('company'))
    let user = JSON.parse(cache.getSession('user'))
    this.ispId = company.ispId
    this.token = cache.getToken()
    this.account = user.account
    this.userId = user.userId
    this.getUserList()
  },
  mounted() {
    this.tableHeight = window.innerHeight - 250
    window.onresize = () => {
      return (() => {
        this.tableHeight = window.innerHeight - 250
      })()
    }
  },
  methods: {
    // 查询代账公司信息
    getSearchAgentCompany() {
      this.pageNumber = 1
      this.numberPage = 10
      this.getUserList()
    },
    // 获取当前用户下关联的企业信息
    getUserList: async function () {
      if (this.token) {
        const url = '/marketing/bagent/user/findAgentOrgPage'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              userId: this.userId,
              entTaxId: this.searchEntTaxId,
              entName: this.searchEntTaxName,
              ispId: this.ispId,
              pageNum: this.pageNumber,
              pageSize: this.numberPage
            },
            false,
            2
        )
        if (response) {
          if (response.code === 0) {
            this.userList = response.data.records
            this.totalPage = response.data.total
          }
        }
      }
    },
    // 获取当前页码
    getPageNumber(num) {
      this.pageNumber = num
      this.getUserList()
    },
    // 获取每页显示数据的数量
    getNumberPage(numPage) {
      this.numberPage = numPage
      this.getUserList()
    },
    // 显示企业信息页面
    getCompanyShow(row) {
      this.orgId = row.orgId
      // this.couponId = row.couponId
      this.companyShow = true
      // this.getCompanyInfo()
    },
    // 获取企业信息
    async getCompanyInfo() {
      if (this.token) {
        const url = '/sys/entInfo/findByEntKey'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              entKey: this.entTaxId,
              // entName: this.entName,
              // userMobile: this.account,
              // pageNum: this.companyPageNumber,
              // pageSize: this.companyNumberPage,
              reqChannel: 4
            },
            false,
            2
        )
        if (response) {
          if (response.code === 0) {
            this.companyList = response.data
            // this.companyTotalPage = response.data.total
          } else {
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 获取企业信息当前页码
    getCompanyPageNumber(num) {
      this.companyPageNumber = num
      this.getCompanyInfo()
    },
    // 获取企业信息每页显示数据的数量
    getCompanyNumberPage(numPage) {
      this.companyNumberPage = numPage
      this.getCompanyInfo()
    },
    // 查询企业信息
    getSearchCompany() {
      if (!this.entTaxId && !this.entName) {
        this.$message({
          message: '请输入需要查询的企业税号或企业名称！',
          type: 'warning'
        })
        return
      }
      this.companyPageNumber = 1
      this.companyNumberPage = 10
      this.getCompanyInfo()
    },
    // 企业信息页面关闭
    companyInfoClose() {
      this.companyShow = false
      this.entName = ''
      this.entTaxId = ''
      this.companyList = []
      this.companyPageNumber = 1
      this.companyNumberPage = 10
    },
    // 获取企业类型状态
    getCompanyType(row, column, cellValue) {
      return GetCompanyType(row, column, cellValue)
    },
    // 获取企业服务类型状态
    getCompanyStatus(row, column, cellValue) {
      return GetCompanyServiceStatus(row, column, cellValue)
    },
    // 获取企业设备类型状态
    getDeviceStatus(row, column, cellValue) {
      return GetDeviceType(row, column, cellValue)
    },
    // 获取企业认领状态
    getClaimedStatus(row, column, cellValue) {
      return GetBoolType(row, column, cellValue)
    },
    // 绑定企业
    async bindCompany(row) {
      if (this.token) {
        const url = '/marketing/bagent/ent/claimed'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              agentOrgId: this.orgId,
              entTaxIds: [row.entTaxId],
              mobile: this.account,
              reqChannel: 4
            },
            false,
            1
        )
        if (response) {
          if (response.code === 0) {
            this.companyShow = false
            this.$message({
              message: '绑定成功！',
              type: 'success'
            })
            await this.getUserList()
          } else {
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 撤销绑定页面显示
    cancelCompanyShow(row) {
      this.orgId = row.orgId
      this.isCancelCompany = true
      this.getCancelCompanyPage()
    },
    // 获取可以撤销记录
    async getCancelCompanyPage() {
      if (this.token) {
        const url = '/marketing/bagent/ent/findPage'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              agentOrgId: this.orgId,
              claimedStatus: 1,
              pageNum: this.companyPageNumber,
              pageSize: this.companyNumberPage,
              reqChannel: 4
            },
            false,
            2
        )
        if (response) {
          if (response.code === 0) {
            this.cancelCompanyList = response.data.records
            this.cancelCompanyTotalPage = response.data.total
          } else {
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 获取解除绑定企业信息当前页码
    getCancelCompanyPageNumber(num) {
      this.cancelCompanyPageNumber = num
      this.getCancelCompanyPage()
    },
    // 获取解除绑定企业信息每页显示数据的数量
    getCancelCompanyNumberPage(numPage) {
      this.cancelCompanyNumberPage = numPage
      this.getCancelCompanyPage()
    },
    // 撤销企业选择
    cancelCompanySelectChange(list) {
      let listInfo = []
      list.forEach((item, index) => {
        listInfo = listInfo.concat(item.entTaxId)
      })
      this.companyIdList = listInfo
    },
    // 撤销企业绑定信息
    async cancelCompanyBind() {
      if (this.companyIdList.length === 0) {
        this.$message({
          message: '请选择需要撤销的企业信息！',
          type: 'warning'
        })
        return
      }
      if (this.token) {
        const url = '/marketing/bagent/ent/cancelClaimed'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              agentOrgId: this.orgId,
              entTaxIds: this.companyIdList,
              mobile: this.account,
              reqChannel: 4
            },
            false,
            1
        )
        if (response) {
          if (response.code === 0) {
            this.isCancelCompany = false
            this.$message({
              message: '解绑成功！',
              type: 'success'
            })
            await this.getUserList()
          } else {
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 撤销页面关闭
    closeCancelCompanyPage() {
      this.isCancelCompany = false
      this.cancelCompanyList = []
      this.companyIdList = []
      this.cancelCompanyPageNumber = 1
      this.cancelCompanyNumberPage = 10
    },
    // 显示绑定企业信息历史记录
    bindHistoryShow(row) {
      this.orgId = row.orgId
      this.isBindHistory = true
      this.getBindHistory()
    },
    // 获取绑定企业记录信息
    async getBindHistory() {
      if (this.token) {
        const url = '/marketing/bagent/ent/findPage'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              agentOrgId: this.orgId,
              entTaxId: this.searchEntTaxIdHistory,
              entName: this.searchEntTaxNameHistory,
              claimedStatus: this.status,
              claimedTimeBegin: this.beginTime,
              claimedTimeEnd: this.endTime,
              pageNum: this.cancelCompanyPageNumber,
              pageSize: this.cancelCompanyNumberPage,
              reqChannel: 4
            },
            false,
            2
        )
        if (response) {
          if (response.code === 0) {
            this.cancelCompanyList = response.data.records
            this.cancelCompanyTotalPage = response.data.total
          } else {
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 绑定企业记录信息导出
    async exportBindHistory() {
      if (this.token) {
        const url = '/marketing/bagent/ent/exportRpt'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              agentOrgId: this.orgId,
              mobile: this.account,
              entName: this.searchEntTaxNameHistory,
              claimedTimeBegin: this.beginTime,
              claimedTimeEnd: this.endTime,
              reqChannel: 4
            },
            false,
            1
        )
        if (response) {
          console.log(response)
          if (response.code === 0) {
            this.isBindHistory = false
            this.loading = true
            this.recordId = response.data.recordId
            this.timer = await setInterval(() => {
              this.exportFile()
            }, 3000)
          } else {
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 获取导出的文件
    async exportFile() {
      if (this.token) {
        const url = '/marketing/rpt/findById'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              recordId: this.recordId,
              reqChannel: 4
            },
            false,
            2
        )
        if (response) {
          if (response.code === 0) {
            if (response.data) {
              if (response.data.status === 2) {
                clearInterval(this.timer)
                this.loading = false
                if (response.data.fileUrl) {
                  window.open(response.data.fileUrl)
                } else {
                  this.$message.error(response.data.statusMemo)
                }
              }
            }
          } else {
            this.loading = false
            clearInterval(this.timer)
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 绑定记录页面关闭
    closeBindHistoryPage() {
      this.isBindHistory = false
      this.searchEntTaxIdHistory = ''
      this.searchEntTaxNameHistory = ''
      this.status = null
      this.beginTime = null
      this.endTime = null
      this.cancelCompanyPageNumber = 1
      this.cancelCompanyNumberPage = 10
    },
    // 设置业务人员页面显示
    openBusinessUserPage(row) {
      this.orgId = row.orgId
      this.isBusinessUserShow = true
    },
    // 获取业务人员分页列表信息
    async getBusinessUserPage() {
      if (this.token) {
        const url = '/marketing/bagent/user/findAgentUserPage'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              orgId: this.orgId,
              userMobile: this.searchUserPhone,
              userName: this.searchUserName,
              pageNum: this.businessUserPageNumber,
              pageSize: this.businessUserNumberPage,
              reqChannel: 4
            },
            false,
            2
        )
        if (response) {
          if (response.code === 0) {
            this.businessUserList = response.data.records
            this.businessUserTotalPage = response.data.total
          } else {
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 获取业务人员信息当前页码
    getBusinessUserPageNumber(num) {
      this.businessUserPageNumber = num
      this.getBusinessUserPage()
    },
    // 获取业务人员信息每页显示数据的数量
    getBusinessUserNumberPage(numPage) {
      this.businessUserNumberPage = numPage
      this.getBusinessUserPage()
    },
    // 业务人员添加页面关闭
    closeUserPhonePage() {
      this.isBusinessUser = false
      this.userPhone = ''
    },
    // 保存业务人员信息
    async setUserPhone() {
      if (!this.userPhone) {
        this.$message({
          message: '业务人员手机号码不能为空！',
          type: 'warning'
        })
        return
      }
      if (this.token) {
        const url = '/marketing/bagent/user/save'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              agentOrgId: this.orgId,
              addUserMobile: this.userPhone,
              reqChannel: 4
            },
            false,
            1
        )
        if (response) {
          if (response.code === 0) {
            this.isBusinessUser = false
            this.$message({
              message: '保存成功！',
              type: 'success'
            })
            await this.getBusinessUserPage()
          } else {
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 业务人员选择触发事件
    userSelectChange(list) {
      let listInfo = []
      list.forEach((item, index) => {
        listInfo = listInfo.concat(item.agentUserRoleId)
      })
      this.userIdList = listInfo
    },
    // 删除业务人员信息
    async deleteUser() {
      if (this.userIdList.length === 0) {
        this.$message({
          message: '请选择要删除的数据！',
          type: 'warning'
        })
        return
      }
      if (this.token) {
        const url = '/marketing/bagent/user/delete'
        let response = await AxiosRequestData(
            url,
            this.token,
            {
              agentOrgId: this.orgId,
              mobile: this.account,
              agentUserRoleIds: this.userIdList,
              reqChannel: 4
            },
            false,
            1
        )
        if (response) {
          if (response.code === 0) {
            this.$message({
              message: '删除成功！',
              type: 'success'
            })
            await this.getBusinessUserPage()
          } else {
            this.$message.error(response.msg)
          }
        }
      }
    },
    // 设置业务人员页面关闭
    closeBusinessUserPage() {
      this.orgId = ''
      this.searchUserName = ''
      this.searchUserPhone = ''
      this.businessUserList = []
      this.isBusinessUserShow = false
    },
  }
}
</script>

<style scoped>

</style>
