<template>
  <div>
    <el-form :inline="true" :model="searchForm">
      <el-form-item>
        <el-input
          v-model.trim="searchForm.search"
          @keyup.enter.native="FetchList"
          placeholder="学生编号"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-select
          v-model.trim="searchForm.subjectId"
          style="width: 180px"
          clearable
          filterable
          placeholder="请选择声部"
        >
          <el-option
            v-for="(item, index) in storeState.sounds"
            :key="index"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="FetchList" type="danger">搜索</el-button>
        <el-button @click="onReSet" type="primary">重置</el-button>
        <!-- <el-button
          type="primary"
          :disabled="!activeChiose.length"
          @click="deleteUser"
          v-permission="'musicGroupPaymentCalenderDetail/batchDel'"
        >删除学员</el-button> -->
      </el-form-item>
    </el-form>
    <el-table
      :data="list"
      @selection-change="handleSelectionChange"
      :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
    >
      <!-- <el-table-column type="selection" width="55"> </el-table-column> -->
      <el-table-column
        align="center"
        prop="userId"
        label="学员编号"
        width="100"
      >
        <template slot-scope="scope">
          <copy-text>{{ scope.row.userId }}</copy-text>
        </template>
      </el-table-column>
      <el-table-column
        width="100"
        align="center"
        prop="studentId"
        label="学员姓名"
      >
        <template slot-scope="scope">
          <div v-if="scope.row.sysUser">
            <copy-text>{{ scope.row.sysUser.username }}</copy-text>
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="学员声部">
        <template slot-scope="scope">
          <overflow-text
            width="100%"
            :text="
              scope.row.studentRegistration &&
              scope.row.studentRegistration.subjectName
            "
          ></overflow-text>
        </template>
      </el-table-column>
      <el-table-column align="center" label="学员状态">
        <template slot-scope="scope">
          <div v-if="scope.row.studentRegistration">
            {{
              scope.row.studentRegistration.musicGroupStatus | studentTeamStatus
            }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        width="130"
        align="center"
        prop="studentId"
        label="手机号"
      >
        <template slot-scope="scope">
          <div v-if="scope.row.sysUser">
            <copy-text>{{ scope.row.sysUser.phone }}</copy-text>
          </div>
        </template>
      </el-table-column>
      <el-table-column width="110" align="center" label="是否开启缴费">
        <template slot-scope="scope">
          <div>
            {{ scope.row.open ? "是" : "否" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="缴费状态">
        <template slot-scope="scope">
          <div>
            {{ scope.row.paymentStatus | paymentStatusDetall }}
          </div>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :total="rules.total"
      :page.sync="rules.page"
      :limit.sync="rules.limit"
      :page-sizes="rules.page_size"
      @pagination="FetchList"
    />
  </div>
</template>
<script>
import store from '../store'

const initSearchForm = {
  search: '',
  subjectId: ''
}
import pagination from "@/components/Pagination/index";
import { getmusicGroupPaymentCalenderDetail, delMusicGroupPaymentCalenderStudent } from "@/api/buildTeam";
export default {
  props: ['detail'],
  components: {
    pagination,
  },
  data() {
    return {
      searchForm: {
        ...initSearchForm
      },
      list: [],
      activeChiose: [],
      rules: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50], // 选择限制显示条数
      },
    };
  },
  computed: {
    storeState() {
      return store.state
    }
  },
  mounted() {
    if (this.detail) {
      store.dispatch('getFindSound', {
        data: {
          musicGroupId: this.detail.musicGroupId
        }
      })
      this.FetchList();
    }
  },
  methods: {
    handleSelectionChange(val) {
      this.activeChiose = val;
    },
    onReSet() {
      this.searchForm = {
        ...initSearchForm
      }
      this.FetchList()
    },
    async deleteUser() {
      try {
        await this.$confirm('是否删除选中学员?', '提示', {
          type: 'warning'
        })
        await delMusicGroupPaymentCalenderStudent({
          musicGroupPaymentCalenderDetailIds: this.activeChiose.map(item => item.id).join(',')
        })
        this.$message.success('删除成功')
        this.FetchList()
      } catch (error) {}
    },
    async FetchList() {
      try {
        const res = await getmusicGroupPaymentCalenderDetail({
          id: this.detail.id,
          page: this.rules.page,
          rows: this.rules.limit,
          ...this.searchForm,
        });
        this.rules.total = res.data.total;
        this.list = res.data.rows;
      } catch (error) {}
    },
  },
};
</script>
<style lang="less" scoped>
</style>
