<template lang="html">
  <div class="">
    <el-dialog :title="pageEditRowIndex > -1 ? '修改页面布局' : '新增页面布局'" v-model="p_editFormVisible" size="tiny">
      <el-form ref="pageLayoutData" :model="pageCustomLayoutData" :rules="rules" label-width="100px">
        <el-form-item label="布局编码" prop="code">
          <el-input v-model="pageCustomLayoutData.code"></el-input>
        </el-form-item>
        <el-form-item label="布局名称" prop="name">
          <el-input v-model="pageCustomLayoutData.name"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="pageLayoutSubmit">完成</el-button>
          <el-button @click="pageCustomLayoutCancel">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

  </div>

</template>

<script>
export default {
  name:'pageCustomLayout',
  data() {
    return {
      // pageCustomFormData: [],
      rules:{
        name: [{required: true, message: '请输入页面布局名称', trigger: 'blur' }],
        code: [{required: true, message: '请输入页面布局编码', trigger: 'blur' }]
      },
      p_editFormVisible:false

    };
  },
  props: ['pageCustomLayoutData', 'pageEditRowIndex', 'pageEditFormVisible', 'pageTreeCode'],
  methods: {
    pageLayoutSubmit() {
      this.$refs.pageLayoutData.validate((valid) => {
        if(valid) {
          this.p_editFormVisible = false;
          var url = '/ifbp-app-sm-infoset-web/page_layout/create';
          if(this.pageCustomLayoutData.id) {
            url = '/ifbp-app-sm-infoset-web/page_layout/update';
          }
          var data = {
            "busitype":this.pageTreeCode,
            "name":this.pageCustomLayoutData.name,
            "code":this.pageCustomLayoutData.code,
            "id":this.pageCustomLayoutData.id,
          };
          this.$http({
            url: url,
            method: 'post',
            data: data,
            dataType: 'json'
          }).then( (res) => {
            if(res.data.success === true){
              // this.pageCustomLayoutData = res.data.data;
              this.$emit('pageLayoutSubmit', res.data.data);
            }

          }).catch(() => {
            this.$message({
              message: '保存失败',
              type: 'error'
            });
          });
        }
      })
    },
    pageCustomLayoutCancel() {
      this.p_editFormVisible = false;
    }

  },
  mounted() {

  },
  watch: {
    pageEditFormVisible: function(value) {
      this.p_editFormVisible = value;
    },
    p_editFormVisible: function(value) {
      this.$emit('changeVisible', value);
    },
  },
}
</script>

<style lang="css">
</style>
