<!-- 配置管理 - 钱包配置 - 提现手续费 -->
<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"> {{ '导出' }}</el-button>
        </div>
      </div>
      <div class="maintable">
        <el-table
          v-loading="loading"
          :data="tableData"
          height="760px"
          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="pkCountry"
            :label="'国家'"
            width="180"
          >
            <template slot-scope="scope">
              <div class="tem">
                <template v-if="renderCountryName(scope.row.pkCountry)">
                  <img :src="renderCountryName(scope.row.pkCountry).icon" alt="">
                  <div>{{ renderCountryName(scope.row.pkCountry).name }}</div>
                </template>
                <template v-else>
                  -
                </template>
              </div>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="serviceType" label="手续费类型">
            <template slot-scope="scope">
              {{ renderCellType(scope.row.serviceType) }}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="serviceRatio"
            :label="'手续费数值'"
          />
          <el-table-column
            align="center"
            prop="effectiveDate"
            :label="'生效日期'"
          />
          <el-table-column
            align="center"
            prop="creationTime"
            :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
                type="text"
                size="small"
                class="button-s"
                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="getWithdrawalProcessList"
    />

    <el-dialog
      :title="updateTitle"
      :visible.sync="updateShow"
      width="37%"
      center
      :before-close="handleClose"
    >
      <el-form
        ref="form"
        :rules="rules"
        :model="form"
        label-width="120px"
        style="padding-bottom: 130px"
      >
        <el-row style="display: flex; justify-content: space-between">
          <el-col :span="11" style="margin-left: -10px">
            <el-form-item :label="'手续费类型'" prop="serviceType">
              <el-select v-model="form.serviceType" clearable placeholder="">
                <el-option
                  v-for="item in cellTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item :label="'手续费数值'" prop="serviceRatio">
              <el-input
                v-model="form.serviceRatio"
                clearable
                placeholder=""
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="23" style="margin-left: 5px">
            <el-form-item :label="'生效日期'" prop="effectiveDate">
              <el-date-picker
                v-model="form.effectiveDate"
                type="datetime"
                :placeholder="'请选择'"
                value-format="yyyy-MM-dd HH:mm:ss"
              />
            </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"
          type="primary"
          @click="onSubmit('form')"
        >{{ '确定' }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import { userCountryList } from '@/api/user'
import { getcellTypeList } from '@/api/bonus'
import {
  getWithdrawalProcessList,
  deleteWithdrawalProcess,
  saveWithdrawalProcess,
  updateWithdrawalProcess,
  getOneWithdrawalProcessList
} from '@/api/configManage'
export default {
  name: 'Txsxf',
  components: {
    topBar
  },
  filters: {
    isAgree(val) {
      if (!val) {
        return '允许'
      } else {
        return '禁止'
      }
    }
  },
  data() {
    return {
      moren: 'txsxf',
      topList: [
        {
          name: '币种配置',
          path: 'bzpz'
        },
        {
          name: '消费配置',
          path: 'xfpz'
        },
        {
          name: '转账配置',
          path: 'zzpz'
        },
        {
          name: '提现配置',
          path: 'txpz'
        },
        {
          name: '提现个税',
          path: 'txgs'
        },
        {
          name: '提现手续费',
          path: 'txsxf'
        },
        {
          name: '特殊消费',
          path: 'specialMoney'
        }
      ],
      countryList: [], // 国家列表
      tableData: [],
      loading: false,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 50
      },
      cellTypeList: [], // 扣除类型
      updateShow: false,
      addOrEdit: '', // 添加还是修改 true添加 false修改
      updateTitle: '',
      form: {
        serviceType: '', // 手续费类型
        serviceRatio: '', // 手续费值
        effectiveDate: '' // 生效时间
      },
      rules: {
        serviceRatio: [
          { required: true, message: '请输入手续费值', trigger: 'blur' }
        ],
        serviceType: [
          { required: true, message: '请选择', trigger: 'change' }
        ],
        effectiveDate: [
          { required: true, message: '请选择生效时间', trigger: 'change' }
        ]
      }
    }
  },
  created() {
    this.getWithdrawalProcessList()
    this.userCountryList()
    this.getcellTypeList()
  },
  methods: {
    // 计算类型枚举值
    getcellTypeList() {
      getcellTypeList().then((res) => {
        this.cellTypeList = res.data
      })
    },
    renderCellType(serviceType) {
      return this.cellTypeList.find((item) => item.value === serviceType)?.label
    },
    renderCountryName(country) {
      const countryInfo = this.countryList.find((item) => item.pkCountry === country)
      return countryInfo ? {
        name: countryInfo.name,
        icon: countryInfo.nationalFlag2
      } : null
    },
    handleClose() {
      this.updateShow = false
      this.$refs['form'].clearValidate()
      this.$refs['form'].resetFields()
    },
    // 点击保存
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = ''
          if (this.addOrEdit == true) {
            url = saveWithdrawalProcess
          } else {
            url = updateWithdrawalProcess
          }
          url(this.form).then((res) => {
            if (res.code == 200) {
              this.updateShow = false
              this.$message({
                message: res.msg,
                type: 'success'
              })
              this.getWithdrawalProcessList()
            } else {
              this.$message({
                message: res.msg,
                type: 'warning'
              })
            }
          })
        }
      })
    },

    // 获取提现个税配置列表
    getWithdrawalProcessList() {
      this.loading = true
      getWithdrawalProcessList(this.queryParams).then((res) => {
        this.tableData = res.rows
        this.total = res.total
        this.loading = false
      })
    },
    // 添加
    adddate() {
      this.updateShow = true
      this.updateTitle = '添加'
      this.addOrEdit = true

      if (this.$refs.form) {
        this.form.pkId = null
        this.$refs.form.clearValidate()
        this.$refs.form.resetFields()
      }
    },
    // 获取国家
    userCountryList() {
      userCountryList().then((res) => {
        this.countryList = res.data
      })
    },
    // 修改
    update(row) {
      this.updateTitle = '修改'
      this.addOrEdit = false
      this.updateShow = true
      getOneWithdrawalProcessList(row.pkId).then((res) => {
        this.form = res.data
      })
    },
    // 删除
    deleteRow(row) {
      this.$confirm('确定删除?').then((_) => {
        deleteWithdrawalProcess(row.pkId).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: 'success'
            })
            this.getWithdrawalProcessList()
          }
        })
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = 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-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}
::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;
}
.tem {
  display: flex;
  align-items: center;
  justify-content: center;
  img {
    width: 28px;
    height: 20px;
    margin-right: 3px;
  }
}
.button-s {
  padding: 0 3px;
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    .maintop {
      display: flex;
      // padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: #3181e5;
        }
        .thebtn2 {
          color: #ffffff;
          background: #ffad41;
        }
      }
      .maintitle {
        font-size: 10px;
        font-family: MicrosoftYaHei;
        color: #999999;
      }
    }
  }
  .isRed {
    color: #ed1d25;
  }
  .isGreen {
    color: #1ab62b;
  }
}
</style>
