<template>
  <div class="page">
    <block-header title="资方配置列表"/>
    <div class="b-table">
      <el-table size="small" border :data="baseConfigList" stripe style="width: 100%;">

        <el-table-column align="center" prop="content" label="内容"></el-table-column>
        <el-table-column align="center" prop="valueContent" label="当前配置"></el-table-column>
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="updateQue(scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="b-pagination">
      <el-pagination
          background
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
          :current-page.sync="page.current"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="page.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import * as moment from "moment";

export default {
  name: "Controlswitch",
  data() {
    return {
      value: true,
      page: {
        current: 1,
        size: 10,
        total: 0
      },
      baseConfigList: [],
    }
  },
  filters: {

    dateFilter: function (row) {
      var date = row
      if (typeof (date) == undefined || typeof (date) == null) {
        return ''
      }
      return moment(date).format("YYYY-MM-DD")
    },

  },
  created() {
    this.getRiaseOrPut();
  },
  methods: {
    getRiaseOrPut() {
      this.$$post("/raise/getRiaseOrPut", {
        size: this.page.size,
        current: this.page.current
      }).then(res => {
        if (res.data.code != 200) {
          // this.isShow = false;
          this.$message.error(res.data.message);
        } else {
          if (res.data.result.records == null) {
            this.baseConfigList = [];
          } else {
            this.baseConfigList = res.data.result.records ? res.data.result.records : '';
            this.page.total = res.data.result.total;
          }
        }
      });
    },

    /** 处理分页操作*/
    handleCurrentChange() {
      this.baseConfigList = this.getRiaseOrPut();
    },

    handleSizeChange(row) {
      this.page.size = row
      this.page.current = 1;
      this.getRiaseOrPut();
    },

    updateQue(record) {
      this.$prompt('请输入内容', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        center: true
      }).then(({value}) => {

        if (value == null || value == '') {
          this.$message.error("请输入后再提交");
          return
        }

        this.$$post('/raise/riaseOrPut', {
          keyContent: record.keyContent,
          valueContent: value
        }).then(res => {
          if (res.data.code != 200) {
            this.$message.error(res.data.message);
            return
          }
          this.$message({
            type: 'success',
            message: '你输入的内容是: ' + value
          });
          window.location.reload();

        }).catch(error => {
          this.$message.error("修改资方配置信息失败");
        })

      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消输入'
        });
      });
    }
  }
}
</script>

