<template>
  <div>


    <el-row>
      <el-col :span="24">
        <el-link type="danger" disabled>绿色时为开启积累 红色时为关闭积累</el-link>
      </el-col>
      <el-col :span="24">
        <el-switch
                v-model="value"
                active-color="#13ce66"
                @change="change()"
                inactive-color="#ff4949">
        </el-switch>
      </el-col>
    </el-row>

  </div>
</template>

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

export default {
  name: "Controlswitch",
  data() {
    return {
      value: true
    }
  },
  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: {
    change(){
      this.$confirm('此操作将影响是否积累放款, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if(this.value === true){
          this.$$get("/raise/riaseOrPut?type=ON",null).then(res=>{
            if (res.data.code==="200"){
              this.$message({
                message: '设置成功',
                type: 'success'
              });
              this.getRiaseOrPut();
            }
          });
        }else {
          this.$$get("/raise/riaseOrPut?type=OFF",null).then(res=>{
            if (res.data.code==="200"){
              this.$message({
                message: '设置成功',
                type: 'success'
              });
              this.getRiaseOrPut();
            }
          });
        }

      }).catch(() => {
        this.$message({
          message: '已取消',
          type: 'warning'
        });
        this.getRiaseOrPut();
      });


    },
    getRiaseOrPut(){
      this.$$get("/raise/getRiaseOrPut",null).then(res=>{
        if (res.data.result==="OFF"){
          this.value = false
        }else {
          this.value = true
        }
      });
    }
  }
}


</script>

<style scoped>

</style>
