index.vue 3.57 KB
<template>
  <div class="container">
    <div class="config-card">
      <h2 class="config-title">上传证件配置</h2>
      <p class="config-desc">此开关用于配置用户提现时是否要上传身份证正反面</p>

      <div class="table-container">
        <GLTable :tableData="tableData" :tableParams="tableParams" :hasPage="false" :hasNum="false">
          <template slot="switchSlot" slot-scope="scope">
            <!-- <el-switch v-model="scope.scope.enabled" active-text="启用" inactive-text="停用"></el-switch> -->
            <el-switch v-model="scope.scope.enabled"></el-switch>
            <div class="switch-txt">{{ scope.scope.enabled ? '启用' : '停用' }}</div>
          </template>
        </GLTable>
      </div>

      <div class="form-actions">
        <el-button type="primary" size="small" @click="handleConfirm">保存</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import url from '@/assets/empty.png'

export default {
  props: {},
  data() {
    return {
      url: url,
      tableData: [
        { channelCode: 2, channelName: '续保用户', enabled: false },
        { channelCode: 1, channelName: '阳光激励用户', enabled: false },
        { channelCode: 3, channelName: '管理层', enabled: false }
      ],
      tableParams: {
        listName: 'list',
        tableOption: false,
        tableColumns: [
          {
            label: '渠道名称',
            prop: 'channelName'
          },
          {
            label: '上传身份证',
            prop: 'enabled',
            addHtml: 'switchSlot'
          }
        ]
      }
    }
  },
  mounted() {
    this.getConfig()
  },
  methods: {
    getConfig() {
      this.$apis.ruleConfig.getUpDocConfig({}).then(res => {
        res.forEach(item => {
          let idx = this.tableData.findIndex(i => i.channelCode == item.channelCode)
          this.tableData[idx].id = item.id
          // isEnabled 是否打开:0-关闭,1-打开
          this.tableData[idx].enabled = !!item.isEnabled
        })
      })
    },
    handleConfirm() {
      let params = {
        uploadDocumentConfigRequestList: []
      }
      this.tableData.forEach(item => {
        params.uploadDocumentConfigRequestList.push({
          channelCode: item.channelCode,
          id: item.id,
          isEnabled: item.enabled ? 1 : 0
        })
      })
      this.$apis.ruleConfig.updateUpDocConfig(params).then(res => {
        let { code, message } = res
        code == 0 ? this.$message.success('配置成功!') : this.$message.error(message)
      })
    }
  }
}
</script>
<style scoped lang='scss'>
.container {
  padding: 20px;

  .switch-txt {
    display: inline-block;
    margin-left: 8px;
  }
  .config-card {
    background: #fff;
    border-radius: 4px;
    padding: 20px;
    position: relative;

    .config-title {
      font-size: 18px;
      font-weight: bold;
      margin-bottom: 8px;
    }

    .config-desc {
      color: #909399;
      font-size: 14px;
      margin-bottom: 20px;
    }

    .table-container {
      width: 580px;
      margin-bottom: 20px;
    }

    .config-table {
      width: 100%;
      border-collapse: collapse;

      th,
      td {
        padding: 12px 15px;
        text-align: left;
        border-bottom: 1px solid #ebeef5;
      }

      th {
        background-color: #f5f7fa;
        color: #606266;
        font-weight: 500;
      }

      tr:last-child td {
        border-bottom: none;
      }

      td:first-child {
        color: #606266;
        width: 150px;
      }
    }

    .form-actions {
      margin-top: 30px;
      text-align: left;
    }
  }
}
</style>