<template>
  <div class="yqrange-index-wrapper">
    <!--<bread-crumb :curmbFirst="curmbFirst"></bread-crumb>-->
    <div class="yqrange-index-content" id="screenSet">
      <!--<div class="header-title">云鹊小圈</div>-->

      <el-form ref="settingForm" :model="settingForm"
               label-width="150px"
               label-suffix="："
               class="basic-form">


        <div v-for="(item, index) in settingForm.settingData" :key="index">

          <el-form-item :label="item.appTagName">
            <el-radio-group size="small" v-model="item.showOff">
              <el-radio :label="1">开启</el-radio>
              <el-radio :label="0">关闭</el-radio>
            </el-radio-group>
          </el-form-item>
        </div>

      </el-form>


      <div style="margin-top: 60px;margin-left: 150px;">
        <el-button type="primary" @click="save()" center>保存</el-button>
        <!--<el-button @click="cancle()">取 消</el-button>-->
      </div>

      </div>

    </div>



</template>
<script>
  import { openLoading, closeLoading } from "../../utils/utils";
import BreadCrumb from "@/components/breadcrumb.vue";
import { getRangeList,updateRangeStatus, getCircleSettingList, saveCircleSetting} from "../../utils/yqrange/yqrangeApi";
export default {
  components: {
    BreadCrumb
  },
  data(){
    return{
      curmbFirst: '云鹊小圈',
      showAllFlag: false,
      showNewFlag: false,
      searchForm: {
        name: '',
        createdTime: '',
        // endTime: '',
        userType: "", // 用户标识 1：内部用户 2：外部用户,
        status: "",
        pageNo: 1,
        pageSize: 10,
      },
      totalRows: 0,
      tableData: [],
      dialogSettingVisible: false,
      settingForm:{
        circleId: null,
        settingData: []
      }
    }
  },
  created() {
    this.circleId = this.$route.query.id;
    this.setting();

  },
  methods: {

    // 应用配置
    setting(){

      let params = {
        circleId: this.circleId
        // circleId: 22
      }

      getCircleSettingList(params).then((res) => {
        closeLoading(this);
        if(res.code == "000000") {
          this.settingForm.settingData = res.data;


        } else {
          // this.$message.error(res.data.message);
          this.settingForm.settingData = [];
        }
        if(this.settingForm.settingData == [] || this.settingForm.settingData.length == 0){

          this.settingForm.settingData = [{
            appTag: 1,
            showOff: 1
          },
            {
              appTag: 2,
              showOff: 1
            },
            {
              appTag: 3,
              showOff: 1
            },
            {
              appTag: 4,
              showOff: 1
            },
            {
              appTag: 5,
              showOff: 0
            }];
        }


        for(let i = 0; i < this.settingForm.settingData.length; i++){
          if(this.settingForm.settingData[i].appTag == 1){
            this.settingForm.settingData[i].appTagName = "教培"
          }
          else if(this.settingForm.settingData[i].appTag == 2){
            this.settingForm.settingData[i].appTagName = "直播"
          }
          else if(this.settingForm.settingData[i].appTag == 3){
            this.settingForm.settingData[i].appTagName = "继教课程"
          }
          else if(this.settingForm.settingData[i].appTag == 4){
            this.settingForm.settingData[i].appTagName = "职称培训"
          }
          else if(this.settingForm.settingData[i].appTag == 5){
            this.settingForm.settingData[i].appTagName = "云鹊豆商城"
          }
        }

      }).catch((error) => {
        this.$message.error("请重试");
      })

    },

    // 保存
    save(){

      let params = {
        apps: this.settingForm.settingData,
        circleId: this.circleId
      }


      saveCircleSetting(params).then((res) => {
        closeLoading(this);
        if(res.code == "000000") {
          this.$message.success("保存成功！");
          // this.$router.go(-1);
        }
    }).catch((error) => {
    this.$message.error("请重试");
    })

    },

    cancle(){
      this.$router.go(-1);
    }


  },
}
</script>
<style lang="scss">
  .yqrange-index-wrapper{
    .yqrange-index-content{
      background: #fff;
      padding: 10px;
      .header-title{
        padding: 10px 12px;
        font-size: 12px;
        color: #449284;
        border-bottom: 1px solid #efefef;
      }
    }
    .el-button--text{
      color: #449284;
      font-size: 14px;
      &::after{
        content: '';
        position: relative;
        height: 14px;
        /*border-right: 1px solid #EBEEF5;*/
        border-right: 1px solid #aaaaaa;
        padding-right: 10px;
      }
      &:last-of-type{
        &::after{
          content: '';
          position: relative;
          width: 1px;
          height: 14px;
          border-right: none;
        }
      }
    }
  }
  /*.range-make-box{*/
    /*.el-message-box__btns{*/
      /*margin-top: 30px;*/
    /*}*/
  /*}*/
</style>
