<!-- 配置管理 - 奖金配置 - 奖项配置 -->
<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <div class="main">
      <div class="maintop">
        <div class="mainbtn">
          <el-button
            size="mini"
            class="thebtn1"
            @click="adddate"
          > {{ '生成' }}</el-button>
          <el-button size="mini" class="thebtn2" @click="handleExport"> {{ '导出' }}</el-button>
        </div>
        <div class="maintitle">{{ '基于报单时间，往后延期天数' }}</div>
      </div>
      <div class="maintable">
        <el-table
          v-loading="loading"
          height="750px"
          :data="tableData"
          style="width: 100%"
          :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="bonusName"
            :label="'奖项名称'"
            width="180"
          />
          <el-table-column
            align="center"
            prop="settleType2"
            :label="'结算周期'"
            width="180"
          />
          <el-table-column align="center" prop="publishTime" :label="'公布时间'" />
          <el-table-column
            align="center"
            prop="publishDate2"
            :label="'公布日期(天)'"
          />
          <el-table-column
            align="center"
            prop="grantDate2"
            :label="'发放日期(天)'"
          />
          <el-table-column
            align="center"
            prop="withdrawalDate2"
            :label="'可提现日期(天)'"
          />
          <el-table-column align="center" prop="time" :label="'操作'" fixed="right">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="small"
                class="button-s"
                style="color:#6962F6"
                @click.native.prevent="update(scope.row)"
              >
                {{ '修改' }}
              </el-button>
              <el-button
                class="button-s"
                type="text"
                size="small"
                style="color: #c73030"
                @click.native.prevent="deleteRow(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="getbonusList"
    />
    <el-dialog
      :title="'修改'"
      :visible.sync="updateShow"
      width="37%"
      center
      :before-close="handleClose"
    >
      <el-form ref="form" :rules="rules" :model="form" label-width="140px" style="padding-bottom: 30px">
        <el-row style="display: flex;justify-content:space-between ">
          <el-col :span="12">
            <el-form-item :label="'奖项名称'" prop="bonusName">
              <el-input
                v-model="form.bonusName"
                clearable
                :placeholder="'请输入奖项名称'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'结算周期'" prop="settleType">
              <el-select v-model="form.settleType" clearable :placeholder="'请选择结算周期'">
                <el-option
                  v-for="item in settleList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="display: flex;justify-content:space-between ">
          <el-col :span="12">
            <el-form-item :label="'公布时间'" prop="publishTime">
              <el-time-picker
                v-model="form.publishTime"
                :placeholder="'请选择公布时间'"
                value-format="HH:mm:ss"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'公布日期(天)'" prop="publishDate">
              <el-select
                v-model="form.publishDate"
                clearable
                :placeholder="'请选择公布日期(天)'"
              >
                <el-option
                  v-for="item in publishDate"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="'发布日期(天)'" prop="grantDate">
              <el-select
                v-model="form.grantDate"
                clearable
                :placeholder="'请选择发布日期(天)'"
              >
                <el-option
                  v-for="item in publishDate"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'可提现日期(天)'" prop="withdrawalDate">
              <el-select
                v-model="form.withdrawalDate"
                clearable
                :placeholder="'请选择可提现日期(天)'"
              >
                <el-option
                  v-for="item in publishDate"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button class="cancels" @click="handleClose"> {{ '取消' }}</el-button>
        <el-button class="submit" style="margin-left: 40px" @click="onSubmit('form')">{{ '确定' }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import {
  getbonusList,
  deletebonusList,
  getOneBounsList,
  scBonusList,
  updateBonus,
  getsettlement,
  getPublishDate
} from '@/api/bonus'
import { mixin } from './mixins'
export default {
  name: 'Bonus',
  components: {
    topBar
  },
  mixins: [mixin],
  data() {
    return {
      moren: 'bonus',
      tableData: [],
      loading: false,
      multipleSelection: [],
      updateShow: false,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      settleList: [], // 结算周期下拉选
      publishDate: [], // 公布日期、发布日期、可提现日期枚举
      form: {
        bonusName: '', // 奖项名称
        settleType: '', // 结算周期
        publishTime: '', // 公布时间
        publishDate: '', // 公布日期(天)
        grantDate: '', // 发布日期(天)
        withdrawalDate: '' // 可提现日期(天)
      },
      rules: {}
    }
  },
  created() {
    this.getbonusList()
    this.getsettlement()
    this.getPublishDate()
  },
  methods: {
    /** 导出按钮操作 */
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((_) => {
        this.download(
          '/system/manage/bd-bonus-items/export',
          Object.assign({}, this.queryParams, this.select),
          `${'奖项配置'}${new Date().getTime()}.xlsx`
        )
      })
    },
    // 查询公布日期、发布日期、可提现日期枚举
    getPublishDate() {
      getPublishDate().then((res) => {
        this.publishDate = res.data
      })
    },
    // 查询结算周期列表
    getsettlement() {
      getsettlement().then((res) => {
        this.settleList = res.data
      })
    },
    // 点击保存
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // 修改
          updateBonus(this.form).then((res) => {
            if (res.code == 200) {
              this.updateShow = false
              this.$message({
                message: res.msg,
                type: 'success'
              })
              this.getbonusList()
            } else {
              this.$message({
                message: res.msg,
                type: 'warning'
              })
            }
          })
        } else {
          return false
        }
      })
    },
    // 生成
    adddate() {
      scBonusList({}).then((res) => {
        if (res.code == 200) {
          this.getbonusList()
        }
      })
    },
    // 点击修改
    update(row) {
      this.updateShow = true
      getOneBounsList(row.pkId).then((res) => {
        this.form = res.data
      })
    },
    // 获取奖项配置列表
    getbonusList() {
      this.loading = true
      getbonusList(this.queryParams).then((res) => {
        res.rows.forEach((element) => {
          this.settleList.forEach((item) => {
            if (element.settleType == item.value) {
              element.settleType2 = item.label
            }
          })
          this.publishDate.forEach((child) => {
            if (element.publishDate == child.value) {
              element.publishDate2 = child.label
            }
            if (element.grantDate == child.value) {
              element.grantDate2 = child.label
            }
            if (element.withdrawalDate == child.value) {
              element.withdrawalDate2 = child.label
            }
          })
        })
        this.tableData = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleClose() {
      this.updateShow = false
      this.$refs['form'].clearValidate()
      this.$refs['form'].resetFields()
    },
    // 删除
    deleteRow(row) {
      this.$confirm('确定删除?').then((_) => {
        deletebonusList(row.pkId).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: 'success'
            })
            this.getbonusList()
          }
        })
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return 'warning-row'
      } else if (rowIndex % 2 == 0) {
        return 'success-row'
      }
      return ''
    }
  }
}
</script>
<style scoped lang="scss">
.el-date-editor.el-input, .el-date-editor.el-input__inner{
  width: 100%;
}
.button-s{
  padding: 3px 0;
}
::v-deep .el-select{
  width: 100%;
}
.submit{
  width: 209px;
  height: 48px;
  background: #c8161d;
  border-radius: 5px;
  color: #fff;
  font-size: 18px;
  border-color: #c8161d;
  margin-left: 20px;
}
.cancels{
  width: 209px;
  height: 48px;
  background: #CCCCCC;
  border-radius: 5px;
  color: #fff;
  font-size: 18px;
  border-color: #ccc;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    //margin-top: 20px;
    //background: #ffffff;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    background: #f9f9f9;
    .maintop {
      display: flex;
      // padding: 0px 10px 0px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
        color: #ffffff;
        background: #3181e5;
      }
      .thebtn2 {
        color: #ffffff;
        background: #ffad41;
      }
      }
    }
  }
}
</style>
