<template>
  <div v-loading="loading" class="addplate">
    <div class="head-title">
      <span @click="CommonJump('plateList')" class="blue point">板块管理</span> / 编辑板块管理
    </div>
    <div class="content">
      <el-form :model="addMsg" :rules="rules" ref="addMsg" label-width="150px" style="width:50%">
        <el-form-item label="商品名称" prop="Name" class="is-required" size="small">
          <el-input v-model="addMsg.Name" placeholder="请输入商品名称" class="w400"/>
        </el-form-item>
        <el-form-item label="图片" prop="Icon" class="is-required">
          <el-button @click="openChangeDig(1)" size="small">选择文件</el-button>
          <div class="app-gallery-item" style="position: relative;width: 100px;margin-top: 10px;border:none;">
            <img v-if="!addMsg.Icon || addMsg.Icon==''" src="../../assets/img/default.png"
                 style="width:80px;height:80px" alt="">
            <img v-else style="width:80px;height:80px" :src="addMsg.Icon" alt="">
          </div>
        </el-form-item>
        <el-form-item label="排序" prop="Sort" class="is-required" size="small">
          <el-input v-model="addMsg.Sort" placeholder="请输入排序" class="w400"/>
        </el-form-item>
        <el-form-item label="是否显示" class="is-required">
          <el-radio v-model="addMsg.IsShow" :label="1" >是</el-radio>
          <el-radio v-model="addMsg.IsShow" :label="2" >否</el-radio>
        </el-form-item>
      </el-form>
    </div>
    <div style="margin-top:20px">
      <el-button size="small" type="primary" @click="Save('addMsg')">保存</el-button>
    </div>
    <!-- 选择文件 -->
    <el-dialog title="选择文件" :visible.sync="changeState" width="1240px">
      <ChooseImg @SelectId="SelectId"></ChooseImg>
    </el-dialog>
  </div>

</template>
<script>
  import ChooseImg from "@/components/global/ChooseImg.vue";
  export default {
    components: {
      ChooseImg
    },
    data() {
      return {
        addMsg: {
          ID: 0,
          Name:'',
          Icon:'',
          Sort:0,
          IsShow:1,
        },
        changeState:false,
        imgType: 0,
        rules: {
          Name: [{
            required: true,
            message: '请输入商品名称',
            trigger: 'blur'
          }],
          Sort: [{
            required: true,
            message: '请输入排序',
            trigger: 'blur'
          }],
          Icon: [{
            required: true,
            message: '请选择图片',
            trigger: 'blur'
          }],

        },
        loading: false,
      };
    },
    created() {

      if(this.$route.query.arr){
        this.addMsg=JSON.parse(decodeURIComponent(this.$route.query.arr))
      }
    },
    methods: {
      Save(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.apipost("/api/Miai/SetForumInfo", this.addMsg, res => {
              if (res.data.resultCode == 1) {
                this.CommonJump('plateList');
                this.Success(res.data.message);
              } else {
                this.Error(res.data.message);
              }
            })
          } else {
            return false;
          }
        });
      },
      openChangeDig(num) {
        this.changeState = true;
        this.imgType = num;
      },
      SelectId(msg) {
        if (this.imgType == 1) {
          let url = this.getIconLink(msg.url)
          this.addMsg.Icon = url
        }
        this.changeState = false;
      },
      getData(ID) {
        this.loading = true;
        this.apipost("/api/Point/GetPointGoodsModel", {
          ID: ID
        }, res => {
          this.loading = false;
          var tempDate = res.data.data;
          this.addMsg = tempDate;

        })
      },
    },
    mounted() {
    }
  };
</script>
<style>
  .app-add-cat .el-checkbox-group {
    font-size: 14px !important;
  }

  .app-add-cat .el-checkbox {
    margin-right: 0;
  }

  .app-add-cat .el-dialog__body {
    padding: 10px 20px !important;
  }

  .app-add-cat .tag-box .tag-item {
    margin-right: 5px;
  }

  .app-add-cat .tag-box {
    margin: 20px 0;
  }

  .app-add-cat .app-goods-cat-list .active {
    background: #FAFAFA;
  }

  .app-add-cat .app-goods-cat-list .cat-item {
    cursor: pointer;
    padding: 5px 10px;
  }

  .app-add-cat .app-goods-cat-list {
    border: 1px solid #E8EAEE;
    border-radius: 5px;
    margin-top: -5px;
    padding: 10px 0;
    overflow: scroll;
    height: 400px;
  }



  .addplate .blue {
    color: #409EFF;

  }

  .addplate .content {
    background: #fff;
    margin-top: 10px;
    padding: 20px;
    box-sizing: border-box;
  }
  .addplate .gez_list{
    /*width: 650px;*/
    margin-bottom: 12px;
    padding: 20px;
    border: 1px solid #EBEEF5;
    background-color: #FFF;
    color: #303133;

  }
  .addplate .quyu{
    background-color: #f4f4f5;
    color: #909399;
    padding: 10px;
    line-height: 30px;
    height: 30px;
    font-size: 12px;
    border-radius: 4px;
    white-space: nowrap;
    margin: 5px;
  }
  .addplate .el-tag + .el-tag {
    margin-left: 10px;
  }
  .addplate .button-new-tag {
    margin-left: 10px;
    height: 32px;
    line-height: 30px;
    padding-top: 0;
    padding-bottom: 0;
  }
  .addplate .input-new-tag {
    width: 90px;
    margin-left: 10px;
    vertical-align: bottom;
  }

</style>
