<template>
  <div class="app-container">
    <div class="titleList">
      <div v-for="(item, index) in userTypeList" :key="index" @click="getListType(item.userType)"
        :class="{ active: queryParams.userType == item.userType }">
        {{ item.name }}
      </div>
    </div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"
      v-if="queryParams.userType == '1'">
      <el-form-item label="单位名称" prop="registerCompanyName">
        <el-input v-model="queryParams.registerCompanyName" placeholder="请输入单位名称" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="单位类别" prop="companyClassId">
        <el-input v-model="queryParams.companyClassId" placeholder="请输入单位类别" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="用户来源" prop="memberSourceId">
        <el-input v-model="queryParams.memberSourceId" placeholder="请输入用户来源" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="用户姓名" prop="realName">
        <el-input v-model="queryParams.realName" placeholder="请输入用户姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入手机号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="标签" prop="memberTag">
        <el-input v-model="queryParams.memberTag" placeholder="请输入标签" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="状态" prop="memberTag">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
          <el-option label="正常" value="0"></el-option>
          <el-option label="禁用" value="1"></el-option>
          <el-option label="未激活" value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="注册时间" prop="createAt">
        <el-date-picker clearable v-model="queryParams.createAt" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择注册时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px"
      v-if="queryParams.userType == '2'">

      <el-form-item label="用户类别" prop="userClassId">
        <el-input v-model="queryParams.userClassId" placeholder="请输入用户类别" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="队列类型ID" prop="queueTypeId">
        <el-input v-model="queryParams.queueTypeId" placeholder="请输入队列类型ID" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="主题" prop="theme">
        <el-input v-model="queryParams.theme" placeholder="请输入主题" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="分配日期" prop="allocationTime">
        <el-date-picker clearable v-model="queryParams.allocationTime" type="date" value-format="yyyy-MM-dd"
          placeholder="请选择分配日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="单位名(注册信息)" prop="registerCompanyName">
        <el-input v-model="queryParams.registerCompanyName" placeholder="请输入单位名(注册信息)" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="使用单位联系人" prop="useContacts">
        <el-input v-model="queryParams.useContacts" placeholder="请输入使用单位联系人" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="中心对接人" prop="centerLiaison">
        <el-input v-model="queryParams.centerLiaison" placeholder="请输入中心对接人" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['cs:csOrderMemberUser:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['cs:csOrderMemberUser:edit']">修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['cs:csOrderMemberUser:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['cs:csOrderMemberUser:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="csOrderMemberUserList" @selection-change="handleSelectionChange"
      v-if="queryParams.userType == '1'">
      <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序号" align="center" prop="sort">
        <template slot-scope="scope">
          {{ ((queryParams.pageNum - 1) * queryParams.pageSize) + (scope.$index + 1) }}
        </template>
      </el-table-column>
      <el-table-column label="单位名(注册信息)" align="center" prop="registerCompanyName" />
      <el-table-column label="部门/院系名称" align="center" prop="deptName" />
      <el-table-column label="单位类别" align="center" prop="companyClass" />
      <el-table-column label="用户来源" align="center" prop="memberSource" />
      <el-table-column label="真实姓名" align="center" prop="realName" />
      <el-table-column label="是否付费" align="center" prop="isPay">
        <template slot-scope="scope">
          <span>{{ scope.row.isPay == 0 ? '否' : '是' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="职称/职务" align="center" prop="professionalTitle" />
      <el-table-column label="职业" align="center" prop="occupation" />
      <el-table-column label="用户账号/AC账户" align="center" prop="userAccount" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="邮箱(登录账号)" align="center" prop="email" />
      <el-table-column label="创建时间" align="center" prop="createAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="当前余额" align="center" prop="nowBalance" >
        <template slot-scope="scope">
          <span>{{ scope.row.nowBalance }}</span>
        </template>
      </el-table-column>
      <el-table-column label="服务状态" align="center" prop="serviceStatus">
        <template slot-scope="scope">
          <span>{{ scope.row.serviceStatus == 0 ? '服务中' : '服务结束' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row, 1)"
            v-hasPermi="['cs:csOrderMemberUser:edit']">用户画像</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row, 2)"
            v-hasPermi="['cs:csOrderMemberUser:edit']">资源使用情况</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['cs:csOrderMemberUser:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-table v-loading="loading" :data="csOrderMemberUserList" @selection-change="handleSelectionChange"
      v-if="queryParams.userType == '2'">
      <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="序号" align="center" prop="sort">
        <template slot-scope="scope">
          {{ ((queryParams.pageNum - 1) * queryParams.pageSize) + (scope.$index + 1) }}
        </template>
      </el-table-column>
      <el-table-column label="用户类别" align="center" prop="userClass" />
      <el-table-column label="队列类型" align="center" prop="queueType" />
      <el-table-column label="主题" align="center" prop="theme" />
      <el-table-column label="节点数量" align="center" prop="nodeNum" />
      <el-table-column label="分配日期" align="center" prop="allocationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.allocationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际使用时间区间" align="center" prop="useTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.useTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="工作单位名称" align="center" prop="companyName" />
      <el-table-column label="使用单位联系人" align="center" prop="useContacts" />
      <el-table-column label="使用人电话" align="center" prop="phone" />
      <el-table-column label="使用人邮箱" align="center" prop="email" />
      <el-table-column label="备注信息" align="center" prop="remarks" />
      <el-table-column label="回收记录" align="center" prop="recoveryRecord" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['cs:csOrderMemberUser:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['cs:csOrderMemberUser:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
      <resourceUsersDialog ref="resourceUsersDialog" :title="title"></resourceUsersDialog>
  </div>
</template>

<script>
import { listCsOrderMemberUser, getCsOrderMemberUser, delCsOrderMemberUser, addCsOrderMemberUser, updateCsOrderMemberUser } from "@/api/cs/csOrderMemberUser";
export default {
  name: "CsOrderMemberUser",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工单用户信息表格数据
      csOrderMemberUserList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        password: null,
        name: null,
        realName: null,
        phone: null,
        concatPhone: null,
        email: null,
        registerCompanyName: null,
        companyId: null,
        companyName: null,
        companyClassId: null,
        companyClass: null,
        deptId: null,
        deptName: null,
        professionalTitle: null,
        occupation: null,
        jobNumber: null,
        status: null,
        sort: null,
        acUid: null,
        guideStatus: null,
        loginTime: null,
        lastLoginTime: null,
        loginToken: null,
        memberSourceId: null,
        memberSource: null,
        memberType: null,
        openStatus: null,
        userType: '1',
        userAccount: null,
        userClassId: null,
        userClass: null,
        isPay: null,
        nowBalance: null,
        centerLiaisonId: null,
        centerLiaison: null,
        serviceStatus: null,
        queueTypeId: null,
        queueType: null,
        theme: null,
        nodeNum: null,
        allocationTime: null,
        useTime: null,
        useContacts: null,
        recoveryRecord: null,
        memberTag: null,
        remarks: null,
        invitePeople: null,
        inviteCode: null,
        createAt: null,
        updateAt: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      userTypeList: [{
        name: '资源用户管理',
        userType: '1'
      }, {
        name: '特殊资源用户',
        userType: '2'
      },],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询工单用户信息列表 */
    getList() {
      this.loading = true;
      listCsOrderMemberUser(this.queryParams).then(response => {
        
       this.csOrderMemberUserList =[]
        this.csOrderMemberUserList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getListType(status) {
      this.queryParams.userType = status
      this.getList()
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        memberUserId: null,
        password: null,
        name: null,
        realName: null,
        phone: null,
        concatPhone: null,
        email: null,
        registerCompanyName: null,
        companyId: null,
        companyName: null,
        companyClassId: null,
        companyClass: null,
        deptId: null,
        deptName: null,
        professionalTitle: null,
        occupation: null,
        jobNumber: null,
        status: "0",
        sort: null,
        acUid: null,
        guideStatus: "0",
        loginTime: null,
        lastLoginTime: null,
        loginToken: null,
        memberSourceId: null,
        memberSource: null,
        memberType: null,
        openStatus: "0",
        userType: null,
        userAccount: null,
        userClassId: null,
        userClass: null,
        isPay: null,
        nowBalance: null,
        centerLiaisonId: null,
        centerLiaison: null,
        serviceStatus: "0",
        queueTypeId: null,
        queueType: null,
        theme: null,
        nodeNum: null,
        allocationTime: null,
        useTime: null,
        useContacts: null,
        recoveryRecord: null,
        memberTag: null,
        remarks: null,
        invitePeople: null,
        inviteCode: null,
        createAt: null,
        updateAt: null,
        delFlag: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      let str = this.queryParams.userType
      this.resetForm("queryForm");
      this.queryParams.userType = str
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.memberUserId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加工单用户信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row, type) {
      if (type == 1) {
        this.$router.push({ name: 'resourceUserDetail', params: { id: row.memberUserId } })
      } else if (type == 2) {
        this.$router.push({ name: 'operateResourceDetail', params: { id: row.memberUserId } })
      }
      return
      this.reset();
      const memberUserId = row.memberUserId || this.ids
      getCsOrderMemberUser(memberUserId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改工单用户信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.memberUserId != null) {
            updateCsOrderMemberUser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCsOrderMemberUser(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const memberUserIds = row.memberUserId || this.ids;
      this.$modal.confirm('是否确认删除工单用户信息编号为"' + memberUserIds + '"的数据项？').then(function () {
        return delCsOrderMemberUser(memberUserIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('cs/csOrderMemberUser/export', {
        ...this.queryParams
      }, `资源用户管理_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
.titleList {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.titleList>div {
  cursor: pointer;
  padding: 10px;
}

.active {
  color: #1890ff;
  border-bottom: 4px solid #1890ff;
}
</style>
