<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="团队名称" prop="teamName">
        <el-input v-model="queryParams.teamName" 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>
        <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="csTeamUserList" @selection-change="handleSelectionChange">
      <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="teamName" />
      <el-table-column label="团队类型" align="center" prop="companyClass" />
      <el-table-column label="用户来源" align="center" prop="memberSource" />
      <el-table-column label="用户类型" align="center" prop="memberType" />
      <el-table-column label="负责人姓名" align="center" prop="realName" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="邮箱" align="center" prop="email" />
      <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="memberTag" />
      <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="status">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.status" active-color="#13ce66" inactive-color="#ff4949" @change="switchStatus(scope.row,$event)">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <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" />
  </div>
</template>

<script>
import { selectTeamUserList } from "@/api/cs/csTeamManagement";

export default {
  name: "CsOrderMemberUser",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工单用户信息表格数据
      csTeamUserList: [],
      // 弹出层标题
      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: {
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询工单用户信息列表 */
    getList() {
      this.loading = true;
      selectTeamUserList(this.queryParams).then(response => {
        this.csTeamUserList = response.rows.length==0?[{memberUserId:1}]:response.rows
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    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");
    },
    switchStatus(row,value){

    },
    /** 搜索按钮操作 */
    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) {
      this.$router.push({ name: 'teamDetail', params: { id: row.memberUserId } })
      return
      this.reset();
      const memberUserId = row.memberUserId || this.ids

    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
        }
      });
    },
    /** 删除按钮操作 */
    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/exportTeamUserList', {
        ...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>
