<template>
  <div class="app-container">
    <el-tabs v-model="activeName">
      <el-tab-pane label="公司小程序配置" name="companyConfig">
        <el-form ref="sysConfig" :model="sysConfig" label-width="120px">
          <el-form-item label="主要小程序" prop="mainMiniAppId">
            <el-select
              v-model="queryParams.mainMiniAppId"
              placeholder="请选择主要小程序"
              clearable
              size="small"
            >
              <el-option
                v-for="item in companyMiniAppList"
                :key="item.id"
                :label="item.name"
                :value="item.appid"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="备用小程序" prop="backupMiniAppId">
            <el-select
              v-model="queryParams.backupMiniAppId"
              placeholder="请选择备用小程序"
              clearable
              size="small"
            >
              <el-option
                v-for="item in companyMiniAppList"
                :key="item.id"
                :label="item.name"
                :value="item.appid"
              />
            </el-select>
          </el-form-item>
          <div class="line"></div>
          <div style="float: right; margin-right: 20px">
            <el-button type="primary" @click="onSubmit1">提交</el-button>
          </div>
        </el-form>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import {
    getCompanyMiniAppList,
    saveCompanyMiniApp
} from "@/api/company/companyConfig";

export default {
  name: "miniappConfig",
  data() {
    return {
     activeName: "companyConfig",
     queryParams:{
        mainMiniAppId:null,
        backupMiniAppId:null
     },
     companyMiniAppList:[],
     sysConfig:{}
    };
  },
  created() {
    this.initMimiAppList();
  },
  mounted() {},
  methods: {
    initMimiAppList(){
        getCompanyMiniAppList().then(res=>{
        console.log(res.data);
        this.companyMiniAppList = res.data;
        let current = res.current;
        if(!!current){
            this.queryParams.mainMiniAppId =  current.mainMiniAppId;
            this.queryParams.backupMiniAppId =  current.backupMiniAppId;
        }
        }).catch(res=>{
          console.log(res);
        })
    },
    //保存配置
    onSubmit1() {
        console.log(this.queryParams);
        saveCompanyMiniApp(this.queryParams).then(res=>{
            this.msgSuccess("修改成功");
        }).catch(res=>{

        })
    },
  },
};
</script>
<style scoped lang="scss">
.tip {
  color: indianred;
}
.line {
  margin: 10px 0;
  background-color: gainsboro;
  height: 1px;
}
.el-row {
  margin-bottom: 0px;
  &:last-child {
    margin-bottom: 0;
  }
}
</style>

