<template>
  <div class="block">
    <div class="head">
      <div class="go-back" @click="goBack"><i class="el-icon-back"></i>返回上一页</div>
    </div>

    <div class="body">
      <custom-form
        :formData="formObject"
        @submitFunc="updateFunc"
        @reset="goBack"
        ></custom-form>
    </div>
  </div>
</template>

<script>
import CustomForm from "@/components/CustomForm"

import { satelliteIntroduction } from "@/utils/formDatas.js"//表单数据
import { update } from "@/api/website/satelliteIntroduction"

export default {
  components: {
    CustomForm
  },
  data() {
    return {
      formObject: {
        formVal: satelliteIntroduction.init(),//提交的表单参数
        rules: satelliteIntroduction.rules,//表单规则
        formItem: satelliteIntroduction.formInfo,//表单项。
      },
    }
  },
  mounted() {
    this.$bus.$on('satelliteIntroduction-edit-renderData', this.renderData)
  },
  methods: {
    renderData(val) {
      this.formObject.formVal = val
      // console.log('bus end', this.formObject.formVal)
    },
    goBack() {
      this.$emit('change', 'List')
    },
    filterParams(obj) {
      let p = {}
      let b = ['isDel', 'status', 'updTime', 'crtTime']
      for (let key in obj) {
        if (!b.includes(key)) {
          p[key] = obj[key]
        }
      }
      return p;
    },
    //更新方法
    updateFunc(params) {
      params.rank = ~~params.rank;
      let datas = this.filterParams(params);

      update(datas).then(res => {
        if (res.status ==  200) {
          //返回上一页，更新列表
          this.goBack();

        } else {
          this.$message.error(res.message);
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  width: 100%;
  border-bottom: 1px solid #e6e6e6;
  .go-back {
    height: 30px;
    line-height: 30px;
    font-size: 16px;
    color: #1989fa;
    cursor: pointer;
    i {
      margin-right: 10px;
    }
  }
}
.body {
  padding: 20px 50px 40px
}
</style>
