/**
* @Author: kk
*
*/

<template>
  <div>
    <div align="left" style="margin-top:50px;margin-left:80px">
      <h3>点击切换是否脱敏：</h3>
      <br />
      <br />
      <el-form
        :model="ruleForm"
        ref="ruleForm"
        :rules="rules"
        label-width="120px"
        class="demo-ruleForm"
      >
        <el-switch
          v-model="ruleForm.status"
          active-color="#13ce66"
          inactive-color="#ff4949"
          @change="updateStatus"
        ></el-switch>
      </el-form>
      <br />
      <br />
      <el-divider></el-divider>

      <!--  添加分组 -->

      <h2>添加新的分组</h2>
      <br />
      <br />

      <el-form
        :model="ruleFormGroup"
        ref="ruleForm"
        :rules="rules"
        label-width="150px"
        class="demo-ruleForm"
        style="width:60%"
      >
        <el-form-item label="请输入新分组key" prop="groupNo">
          <el-col :span="20">
            <el-input v-model="ruleFormGroup.groupNo" placeholder="请输入新分组key"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="请输入新分组value" prop="groupName">
          <el-col :span="20">
            <el-input v-model="ruleFormGroup.groupName" placeholder="请输入新分组value"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="请选择类型" prop="bizType">
          <el-select v-model="ruleFormGroup.bizType" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>

      <div slot="footer" style="margin-left:45%">
        <el-button type="primary" @click="submitForm('ruleFormGroup')">确定添加</el-button>
      </div>
    </div>
    <br />
    <br />
    <br />
    <h4 style="color:red;maring-top:80px" align="center">以上操作修改会立即生效，请谨慎操作！！！</h4>
  </div>
</template>


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

export default {
  name: "PassMoneyMarket",
  components: {},
  data() {
    return {
      queryModel: {
        type: Object
      },
      ruleForm: {
        status: false,
        code:''
      },
      ruleFormGroup: {
        bizType :'',
        groupName : "",
        groupNo :''
      },
      operat: [],
      page: {
        current: 1,
        size: 10,
        total: 0
      },
      options:[
        {
          value: 'YINGXIAO',
          label: '营销'
        }, {
          value: 'KEFU',
          label: '客服'
        }, {
          value: 'TIXING',
          label: '提醒'
        }, {
          value: 'CUISHOU',
          label: '催收'
        }
      ],
      rules: {
        loginName: [
          { required: true, message: "请输入用户名", trigger: "blur" }
        ]
      }
    };
  },

  methods: {
    
    /** 提交点击 */
    submitForm() {
      if(!this.ruleFormGroup.groupName){
          this.$message({ message: "参数不能为空", type: "error" });
          return;
      }

      if(!this.ruleFormGroup.groupNo){
          this.$message({ message: "参数不能为空", type: "error" });
          return;
      }
      if(!this.ruleFormGroup.bizType){
          this.$message({ message: "类型不能为空", type: "error" });
          return;
      }
      this.$$post("/group/insertGroup", {
        bizType : this.ruleFormGroup.bizType ,
        groupName : this.ruleFormGroup.groupName ,
        groupNo  : this.ruleFormGroup.groupNo ,
      })
        .then(res => {
          if (res.data.code != 1) {
            this.$message.error(res.data.msg);
            return;
          }
          this.handleClose();
          this.$message({ message: "新增分组成功", type: "success" });
          window.location.reload();
        })
        .catch(err => {
          this.$message.error("新增分组失败");
        });
    },

    // 查询当前是否为脱敏状态
    loadOperate() {
      this.$$post(`/config/getSysConfigList`, {
        channel: "WITHDRAW"
      }).then(res => {
        if (res.data.code == 1) {
              this.operat = res.data.data.records;
              this.operat.forEach((item, index) => {
                  console.log(item,index);
                  if(item.code=='HIDEPHONE'){
                    if(item.value == 1){
                      this.ruleForm.status = true;
                    }
                    this.ruleForm.code = item.code;
                  }
              })
        } else {
          this.$message({ message: res.data.msg, type: "error" });
        }
      });
    },
    updateStatus(item) {
      if(this.ruleForm.status){
        this.ruleForm.status = 1
      }else{
        this.ruleForm.status = 0
      }
      this.$$post(`/config/updateConfig`, {
        code: this.ruleForm.code,
        value: this.ruleForm.status 
      }).then(res => {
        if (res.data.code == 1) {
              this.$message({ message: res.data.msg, type: "success" });
              setTimeout(() => {
                  window.location.reload()
              }, 600)
        } else {
          this.$message({ message: res.data.msg, type: "error" });
        }
      });
    },

    onRadioChange(val) {
      // 当radio已被选中时，这个事件不会被触发
     
    },
    dateFormat: function(row, column) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return moment(date).format("YYYY-MM-DD HH:mm:ss");
    },
    /** 关闭处理 */
    handleClose() {
      this.visible = false;
      setTimeout(() => {
        this.$emit("update:dialogVisible", false);
      }, 300);
    }
  },
  mounted: function() {
    this.loadOperate();
  }
};
</script>

