<template>
  <div class="setting app-container">
    <el-form
      :model="setQuery"
      ref="setQuery"
      :rules="rules"
      label-width="130px"
    >
      <el-form-item label="姓名：" prop="bannerName">
        <el-input
          v-model="setQuery.bannerName"
          class="item-width-300"
        ></el-input>
      </el-form-item>
      <el-form-item label="手机号：" prop="bannerName">
        <el-input
          v-model="setQuery.bannerName"
          class="item-width-300"
        ></el-input>
      </el-form-item>
     <el-form-item label="头像：" prop="bannerImg">
        <Upload
          type="bannerImg"
          id="bannerImg"
          width="300px"
          height="200px"
          uploadType="SHOP_INFO"
          :imgUrl="setQuery.bannerImg"
          @uploadEnd="uploadEnd"
        ></Upload>
      </el-form-item>
      
    </el-form>

    <div class="btn-group">
       <el-button>取 消</el-button>
     <el-button type="primary" :loading="loading"  @click="save">确 定</el-button>
    </div>
  </div>
</template>

<script>
import Upload from '@/components/Upload'
import {addOrUpdateBanner,getMenuName} from '@/api/appConfig'
export default {
    components: {
        Upload,
    },
  data() {
    return {
        loading:false,
        setQuery: {
          "bannerImg": "",
          "bannerName": "",
          "id": 0,
        },
        rules:{
            bannerName: [{ required: true, message: "请输入banner名称", trigger: "blur" }],
            bannerImg: [{ required: true, message: "请输入banner名称", trigger: "blur" }]
        },
        options:[]
    };
  },
  methods: {
    uploadEnd(val){
      this.setQuery.bannerImg = val.url
    },
    getMenuName(){
      getMenuName({}).then(res=>{
        if(res.state == 'Success'){
          for (const key in res.content) {
            if (res.content.hasOwnProperty.call(res.content, key)) {
                this.options.push({
                  label:res.content[key],
                  value:Number(key) 
                })              
            }
          }
          
        }
      })
    },
   save() {
      this.$refs.setQuery.validate((v) => {
        if (v) {
          this.loading = true
          addOrUpdateBanner(this.setQuery).then(res=>{
            this.loading = false

            if(res.state == 'Success'){

              this.$notify({
                  title: '成功',
                  message: '操作成功',
                  type: 'success'
                });
               
            }
          })
              
        }
      });
    },
  },
  created () {
    this.getMenuName()
  },
};
</script>

<style lang="scss" scoped>
.setting {
  padding-bottom: 40px;
  .btn-group{
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>