<template>
  <div class="editMenu app-container">
    <el-form
      :model="setQuery"
      ref="setQuery"
      :rules="rules"
      label-width="130px"
    >
      <el-form-item label="菜单名称：" prop="menuName">
        <el-input
          v-model="setQuery.menuName"
          class="item-width-300"
        ></el-input>
      </el-form-item>
    <el-form-item label="菜单编码：" prop="menuCode">
        <el-input
          v-model="setQuery.menuCode"
          class="item-width-300"
        ></el-input>
      </el-form-item>
      <el-form-item label="菜单上方文字：">
        <el-input
          v-model="setQuery.labelAbove"
          class="item-width-300"
        ></el-input>
      </el-form-item>
      <el-form-item label="菜单下方文字：">
        <el-input
          v-model="setQuery.labelBelow"
          class="item-width-300"
        ></el-input>
      </el-form-item>
       <el-form-item label="域名地址：" prop="domainUrl">
        <el-input
          v-model="setQuery.domainUrl"
          class="item-width-300"
        ></el-input>
      </el-form-item>
        <el-form-item label="链接地址：" prop="linkUrl">
        <el-input
          v-model="setQuery.linkUrl"
          class="item-width-300"
        ></el-input>
      </el-form-item>
       <el-form-item label="排序：" prop="sort">
        <el-input
          v-model.number="setQuery.sort"
          class="item-width-300"
        ></el-input>
      </el-form-item>
       <el-form-item label="显示状态：" prop="status">
        
        <el-switch
        v-model="setQuery.status"
        active-text="显示"
        inactive-text="隐藏"
        :active-value="2"
        :inactive-value="1"
        active-color="#13ce66"
        inactive-color="#ff4949">
        </el-switch>
      </el-form-item>

    <el-form-item label="备注：" prop="note">
        <el-input
          v-model="setQuery.note"
          class="item-width-300"
        ></el-input>
      </el-form-item>

      <el-form-item label="图标：" prop="imgUrl">
        <Upload
          type="imgUrl"
          id="imgUrl"
          width="150px"
          height="150px"
          uploadType="SHOP_INFO"
          :imgUrl="setQuery.imgUrl"
          @uploadEnd="uploadEnd"
        ></Upload>
      </el-form-item>
        <el-form-item label="分类顶部图：" prop="secondaryImg">
        <Upload
          type="secondaryImg"
          id="secondaryImg"
          width="150px"
          height="150px"
          uploadType="SHOP_INFO"
          :imgUrl="setQuery.secondaryImg"
          @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 {addOrUpdate} from '@/api/appConfig'

export default {
    components: {
        Upload,
    },
  data() {
    return {
        loading:false,
      setQuery: {
         "domainUrl": "",
        "imgUrl": "",
        "labelAbove": "",
        "labelBelow": "",
        "linkUrl": "",
        "menuCode": "",
        "menuName": "",
        "note": "",
        "secondaryImg": "",
        "sort": 0,
        "status": 0
      },
      rules: {
        menuName: [{ required: true, message: "请输入菜单名称", trigger: "blur" }],
        menuCode: [{ required: true, message: "请输入菜单编码", trigger: "blur" }],
        // domainUrl: [{ required: true, message: "请输入域名地址", trigger: "blur" }],
        linkUrl: [{ required: true, message: "请输入链接地址", trigger: "blur" }],
        imgUrl: [{ required: true, message: "请上传图标", trigger: "change" }],
        // secondaryImg: [{ required: true, message: "请上传分类顶部图", trigger: "change" }],
        sort: [{ required: true, message: "请输入权重", trigger: "blur" }],
        note: [{ required: true, message: "请输入备注", trigger: "blur" }],
        
      },
    };
  },
  methods: {
    uploadEnd(val){
      this.setQuery[val.type] = val.url

    },
    save() {
      this.$refs.setQuery.validate((v) => {
        if (v) {
          this.loading = true
          addOrUpdate(this.setQuery).then(res=>{
            this.loading = false

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

              this.$notify({
                  title: '成功',
                  message: '操作成功',
                  type: 'success'
                });
               
                  this.$router.push('/operationManage/appMenuManage/index')
            }
          })
              
        }
      });
    },
  },
  created () {
    this.setQuery = JSON.parse(sessionStorage.getItem('menuItem')) 
  },
};
</script>

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