<!-- 系统配置 - 权限配置 -->
<template>
  <div class="page">
    <topBar v-if="topList.length > 0" :top-list="topList" :moren="moren" />
    <div v-if="topList[5].changed == true" class="contain">
      <div class="thetopbox">
        <el-form ref="form" :model="select" label-width="110px">
          <el-row>
            <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="'会员姓名'" prop="teamCode">
                <el-input v-model="select.memberName" clearable />
              </el-form-item>
            </el-col>
            <el-col :span="4" style="margin-left: 0px">
              <el-form-item :label="'荣誉奖衔'" prop="status">
                <el-select v-model="select.realAwards" clearable>
                  <el-option
                    v-for="item in awardsList"
                    :key="item.pkId"
                    :label="item.awardsName"
                    :value="item.pkId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'隶属体系'">
                <el-select v-model="select.pkVertex" clearable>
                  <el-option
                    v-for="item in vertexList"
                    :key="item.value"
                    :label="item.vertexName"
                    :value="item.pkId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'辅导奖衔'" prop="teamCode">
                <el-select v-model="select.mentoringAward" clearable>
                  <el-option
                    v-for="item in awardsList"
                    :key="item.pkId"
                    :label="item.awardsName"
                    :value="item.pkId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4" style="margin-left: -10px">
              <el-form-item :label="'分红奖衔'" prop="status">
                <el-select v-model="select.dividendAward" clearable>
                  <el-option
                    v-for="item in awardsList"
                    :key="item.pkId"
                    :label="item.awardsName"
                    :value="item.pkId"
                  />
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="4" style="margin-left: 0px">
              <el-form-item :label="'荣誉奖衔'" prop="status">
                <el-select v-model="select.extremeAwards" clearable>
                  <el-option
                    v-for="item in awardsList"
                    :key="item.pkId"
                    :label="item.awardsName"
                    :value="item.pkId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'复购考核奖衔'" prop="status">
                <el-select v-model="select.replyExamAward" clearable>
                  <el-option
                    v-for="item in awardsList"
                    :key="item.pkId"
                    :label="item.awardsName"
                    :value="item.pkId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <el-form-item :label="'分红考核奖衔'" prop="status">
                <el-select v-model="select.divvyExamAwards" clearable>
                  <el-option
                    v-for="item in awardsList"
                    :key="item.pkId"
                    :label="item.awardsName"
                    :value="item.pkId"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item :label="'创建时间'">
                <el-date-picker
                  v-model="creationTime"
                  type="daterange"
                  range-separator="——"
                  :start-placeholder="'开始时间'"
                  :end-placeholder="'结束日期'"
                  value-format="yyyy-MM-dd"
                  :unlink-panels="true"
                  @change="changeTime"
                />
              </el-form-item>
            </el-col>
            <el-col :span="4">
              <div class="searchbox">
                <el-button class="searchbtn" @click="getData">
                  {{ '搜索' }}</el-button>
                <el-button @click="reset"> {{ '重置' }}</el-button>
              </div>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="maintop">
        <div class="mainbtn">
          <el-button
            v-hasButtons="['AwardControlAdd']"
            size="small"
            class="thebtn1"
            @click="openDig"
          >{{ '添加' }}</el-button>
          <el-button
            v-hasButtons="['AwardControlExport']"
            size="small"
            style="background-color: #ffad41"
            class="thebtn1"
            @click="handleExport"
          >
            {{ '导出' }}</el-button>
          <!-- <el-button size="small"
                     class="thebtn1">{{'修改'}}</el-button> -->
          <el-button
            v-hasButtons="['AwardControlDelete']"
            size="small"
            :disabled="selTable.length == 0"
            style="background-color: #ffad41"
            class="thebtn1"
            @click="updateShow(selTable)"
          >{{ '修改' }}</el-button>
          <el-button
            v-hasButtons="['AwardControlDelete']"
            size="small"
            :disabled="selTable.length == 0"
            style="background-color: #c8161d"
            class="thebtn1"
            @click="delRole(selTable)"
          >
            {{ '删除' }}</el-button>
        </div>
      </div>
      <div class="main">
        <div class="maintable">
          <el-table
            v-loading="loading"
            :data="tableData"
            style="width: 100%"
            height="630px"
            :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="memberCode"
              :label="'会员编号'"
            />
            <el-table-column
              align="center"
              prop="memberName"
              :label="'会员姓名'"
            />
            <el-table-column
              align="center"
              prop="vertexName"
              :label="'隶属体系'"
            />
            <el-table-column
              align="center"
              prop="realAwardsKeyVal"
              :label="'荣誉奖衔'"
            />
            <el-table-column
              align="center"
              prop="mentoringAwardKeyVal"
              :label="'辅导奖衔'"
            />
            <el-table-column
              align="center"
              prop="dividendAwardKeyVal"
              :label="'分红奖衔'"
            />
            <el-table-column
              align="center"
              prop="extremeAwardsKeyVal"
              :label="'荣誉奖衔'"
            />
            <el-table-column
              align="center"
              prop="replyExamAwardKeyVal"
              :label="'复购考核奖衔'"
            />
            <el-table-column
              align="center"
              prop="divvyExamAwardsKeyVal"
              :label="'分红考核奖衔'"
            />
            <el-table-column
              align="center"
              prop="creationTime"
              :label="'创建时间'"
            />
            <el-table-column
              align="center"
              prop=""
              :label="'操作'"
              fixed="right"
              width="200"
            >
              <template slot-scope="scope">
                <el-button
                  v-hasButtons="['AwardControlUpdate']"
                  class="button-s"
                  type="text"
                  size="small"
                  style="color: #f3a900"
                  @click="updateShow([scope.row])"
                >
                  {{ '修改' }}
                </el-button>
                <el-button
                  v-hasButtons="['AwardControlDelete']"
                  type="text"
                  size="small"
                  class="button-s"
                  style="color: #c8161d"
                  @click="delRole([scope.row])"
                >
                  {{ '删除' }}
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getData"
      />
      <awardDetails
        ref="awardDetails"
        :sign-type="signType"
        :is-award="isAward"
        @handleClose="handleClose"
      />
    </div>
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import { getvertexValue } from '@/api/member'
import awardDetails from '@/views/information/specialBusiness/awardDetails'
import * as api from '@/api/specialBusiness'
import { getRouters } from '@/api/settle'
export default {
  name: 'Qxpz',
  components: {
    topBar,
    awardDetails
  },
  data() {
    return {
      selTable: [],
      creationTime: [],
      signType: '',
      isAward: false,
      value: '',
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      select: {},
      total: 0,
      moren: 'awardControl',
      awardsList: [],
      vertexList: [],
      tableData: [],
      loading: false,
      topList: [
        {
          name: '空单注册',
          path: 'emptyOrder',
          changed: false
        },
        {
          name: '修改直推',
          path: 'modifyDirectpush',
          changed: false
        },
        {
          name: '修改安置',
          path: 'modifyPlacement',
          changed: false
        },
        {
          name: '注水业绩',
          path: 'waterPv',
          changed: false
        },
        {
          name: '修改编号',
          path: 'modifyCode',
          changed: false
        },
        {
          name: '荣誉奖衔控制',
          path: 'awardControl',
          changed: false
        },
        {
          name: '修改结算国家',
          path: 'modifySettleCountry',
          changed: false
        },
        {
          name: '政策币业务',
          path: 'policyMoney',
          changed: false
        }
      ]
    }
  },
  created() {
    this.getData()
    this.getSelect()
    this.getUserRoute()
  },
  methods: {
    changeTime(val) {
      this.select.startDate = val ? val[0] : ''
      this.select.endDate = val ? val[1] : ''
    },
    getUserRoute() {
      getRouters().then((res) => {
        res.data.forEach((item) => {
          this.topList.forEach((items) => {
            if (item.path == items.url) {
              items.changed = true
            }
          })
        })
      })
    },
    handleClose() {
      this.isAward = false
      this.getData()
    },
    getSelect() {
      api.awardsList().then((res) => {
        this.awardsList = res.rows
      })
      getvertexValue().then((res) => {
        this.vertexList = res.data
      })
    },
    getData() {
      this.loading = true
      api
        .awardsControlList(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.loading = false
          this.tableData = res.rows
          this.total = res.total
        })
    },
    reset() {
      this.creationTime = []
      this.select = {}
    },
    openDig() {
      this.$refs.awardDetails.getAllData(0)
      this.signType = 128
      this.isAward = true

      // this.$router.push({
      //   path: "awardDetails",
      //   query: {
      //     addAwards: 0,
      //   },
      // });
    },
    updateShow(item) {
      this.$refs.awardDetails.getAllData(1, JSON.stringify(item))
      this.signType = 129
      this.isAward = true

      // this.$router.push({
      //   path: "awardDetails",
      //   query: {
      //     addAwards: 1,
      //     tableData: JSON.stringify([item]),
      //   },
      // });
    },
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((_) => {
        this.download(
          '/member/manage/awards-control/export',
          Object.assign({}, this.queryParams, this.select),
          `荣誉奖衔控制${new Date().getTime()}.xlsx`
        )
      })
    },
    delRole(item) {
      console.log(
        '%c [ item ]-356',
        'font-size:13px; background:#493acb; color:#8d7eff;',
        item
      )
      // 130
      this.$refs.awardDetails.getAllData(2, JSON.stringify(item))
      this.signType = 130
      this.isAward = true
      // this.$router.push({
      //   path: "awardDetails",
      //   query: {
      //     addAwards: 2,
      //     tableData: JSON.stringify([item]),
      //   },
      // });
    },
    handleSelectionChange(val) {
      this.selTable = val
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return 'warning-row'
      } else if (rowIndex % 2 == 0) {
        return 'success-row'
      }
      return ''
    }
  }
}
</script>
<style lang="scss" scoped>
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
.openClose {
  margin-top: 10px;
  margin-right: 10px;
  color: #666666;
  text-align: center;
}
.page {
  padding: 10px 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    background: #ffffff;
    border-radius: 8px;
    padding-top: 20px;
    .searchbox {
      display: flex;
      align-items: center;
      .searchtitle {
        margin-right: 10px;
      }
      .searchbtn {
        background: #c8161d;
        color: #ffffff;
      }
    }
  }
  .main {
    flex: 1;
    // margin-top: 20px;
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
  }
  .maintop {
    display: flex;
    padding: 0px 0;
    justify-content: space-between;
    align-items: center;
    .mainbtn {
      .thebtn1 {
        color: #ffffff;
        background: rgba(67, 145, 253, 1);
      }
    }
  }
}
.contain {
  height: 100%;
  display: flex;
  flex-direction: column;
}
</style>
