<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <div class="main">
      <div class="form_all">
        <el-form ref="select" :model="select" label-width="auto">
          <el-row :gutter="40">
            <el-col :span="4">
              <el-form-item label="会员编号">
                <el-input v-model="select.memberCode" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="会员姓名">
                <el-input v-model="select.memberName" clearable />
              </el-form-item>
            </el-col>

            <el-col :span="4">
              <el-form-item label="活动名称">
                <el-input v-model="select.actName" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="订单编号">
                <el-input v-model="select.orderCode" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="姓名">
                <el-input v-model="select.buyName" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item label="手机号">
                <el-input v-model="select.phone" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="隶属体系">
                <el-select
                  v-model="select.pkTeamListStr"
                  multiple
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in options"
                    :key="item.pkId"
                    :label="item.vertexName"
                    :value="item.pkId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="隶属团队">
                <el-select
                  v-model="select.pkTeamCodeListStr"
                  multiple
                  placeholder="请选择"
                >
                  <el-option
                    v-for="item in teamNameList"
                    :key="item.pkId"
                    :label="`${item.vertexName}--${item.teamName} `"
                    :value="item.pkId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-button type="primary" size="small" @click="getDataList">
                {{ '搜索' }}</el-button>
              <el-button size="small" class="resetBtn" @click="reset">
                {{ '重置' }}</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="main_a">
        <div class="mainbtn">
          <el-button
            v-hasButtons="['TicketQueryExport']"
            size="small"
            class="addBtn"
            @click="handleExport"
          >导出</el-button>
        </div>
        <div class="maintable">
          <el-table
            v-loading="loading"
            :data="tableData"
            style="width: 100%"
            height="710px"
            :header-cell-style="{ background: '#EEEEEE' }"
            :row-class-name="tableRowClassName"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="55" />
            <el-table-column
              align="center"
              prop="actName"
              width="150"
              :label="'活动名称'"
            />
            <el-table-column
              align="center"
              prop="actStartDate"
              width="150"
              :label="$t('门票开始日期')"
            />
            <el-table-column
              align="center"
              prop="actEndDate"
              width="150"
              :label="$t('门票结束日期')"
            />
            <el-table-column
              align="center"
              prop="memberCode"
              :label="$t('会员编号')"
              min-width="120"
            />
            <el-table-column
              align="center"
              prop="memberName"
              :label="$t('会员姓名')"
            />
            <el-table-column
              align="center"
              prop="orderCode"
              :label="$t('订单编号')"
              min-width="170"
            />
            <el-table-column
              align="center"
              prop="orderAmount"
              :label="$t('订单金额')"
              min-width="150"
            />
            <el-table-column align="center" prop="price" :label="$t('单价')" />
            <!-- <el-table-column align="center" prop="quantity" :label="$t('数量')">
            </el-table-column> -->
            <el-table-column align="center" prop="buyName" :label="$t('姓名')" />
            <el-table-column
              align="center"
              prop="phone"
              width="150"
              :label="$t('手机号')"
            />
            <el-table-column
              align="center"
              prop="idCard"
              width="190"
              :label="$t('身份证号')"
            />
            <el-table-column align="center" prop="sexVal" :label="$t('性别')" />
            <el-table-column
              align="center"
              prop="clothSize"
              :label="$t('尺码')"
            />
            <el-table-column
              align="center"
              prop="cohabitant"
              :label="$t('同住人')"
              min-width="150"
            />
            <el-table-column
              align="center"
              prop="emergencyPhone"
              width="150"
              :label="$t('紧急联系人')"
            />
            <el-table-column align="center" prop="vertexName" label="隶属体系" width="120" />
            <el-table-column align="center" prop="teamName" label="隶属团队" />
            <el-table-column
              align="center"
              prop="creationTime"
              label="支付时间"
              width="160"
            />
          </el-table>
        </div>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import * as api from '@/api/ticket.js'
import { vertexList, memberTeam } from '@/api/settle.js'
export default {
  name: 'Bzpz',
  components: {
    topBar
  },
  data() {
    return {
      creationTime: [],
      creationTime1: [],
      creationTime2: [],
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      addOrEdit: '',
      total: 0,
      dialogVisible: false,
      tableData: [],
      loading: false,
      moren: 'ticketQueryList',
      topList: [
        {
          name: '自助购票',
          path: 'ticketQueryList'
        }
      ],
      form: {
        name: ''
      },
      actStatus: [],
      teamNameList: [],
      options: []
    }
  },
  mounted() {
    // 获取下拉
    this.getData()
    // 获取列表
    this.getDataList()
  },
  methods: {
    // 重置
    reset() {
      this.select = {}
      this.creationTime = []
      this.creationTime1 = []
      this.creationTime2 = []
      this.getDataList()
    },
    getData() {
      vertexList().then((res) => {
        this.options = res.data
      })
      memberTeam().then((res) => {
        this.teamNameList = res.rows
      })
    },
    changeTime(val) {
      this.select.actStartDate = val ? val[0] : ''
      this.select.actEndDate = val ? val[1] : ''
    },
    handleClose() {
      this.dialogVisible = false
      this.$refs['form'].clearValidate()
      this.$refs['form'].resetFields()
    },
    // 获取列表
    getDataList() {
      this.loading = true
      api
        .ticketQuery(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.tableData = res.rows
          this.total = res.total
          this.loading = false
        })
    },
    handleSelectionChange(val) {},
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((_) => {
        this.download(
          '/sale/manage/ticket/export',
          Object.assign(
            {},
            {
              actType: 22
            },
            this.queryParams,
            this.select
          ),
          `自助购票${new Date().getTime()}.xlsx`
        )
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return 'warning-row'
      } else if (rowIndex % 2 == 0) {
        return 'success-row'
      }
      return ''
    }
  }
}
</script>
<style scoped lang="scss">
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}

::v-deep .el-table thead {
  color: #000000;
}

::v-deep .el-select {
  width: 100%;
}

.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;

  .main {
    // background: #ffffff;
    border-radius: 8px;
    display: flex;
    flex-direction: column;

    .main_a {
      background: #fff;
      border-radius: 8px;
      justify-content: space-between;
      align-items: center;
      box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    }

    .mainbtn {
      padding: 0;
    }

    .maintable {
      flex: 1;
    }
  }
}

::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}

.form_all {
  padding: 0 20px;
  margin-bottom: 10px;
  background: #fff;
}
</style>
