<template>
  <div class="page">
    <easy-form
      ref="formRef"
      v-model="formData"
      :form-config="formConfig"
      :fields="fields"
      :buttons="buttons"
    />
  </div>
</template>

<script>
import { annualFillAssetEntTempGet, annualFillAssetEntTempSave } from '@/api/年报填报相关'
import { createGlobalLoading } from '@/utils'
export default {
  data() {
    return {
      formData: {},
      fields: [
        // 主营业务收入
        {
          type: 'number',
          prop: 'maibusinc',
          label: '主营业务收入（万元）',
          span: 24,
          required: true
        },
        {
          type: 'radio',
          prop: 'maibusincdis',
          label: '主营业务收入公示',
          options: [
            { label: '公示', value: '1' },
            { label: '不公示', value: '2' }
          ],
          required: true
        },
        // 纳税总额
        {
          type: 'number',
          prop: 'ratgro',
          label: '纳税总额（万元）',
          span: 24,
          required: true
        },
        {
          type: 'radio',
          prop: 'ratgrodis',
          label: '纳税总额公示',
          options: [
            { label: '公示', value: '1' },
            { label: '不公示', value: '2' }
          ],
          required: true
        },
        // 净利润
        {
          type: 'number',
          prop: 'netinc',
          label: '净利润（万元）',
          span: 24,
          required: true
        },
        {
          type: 'radio',
          prop: 'netincdis',
          label: '净利润公示',
          options: [
            { label: '公示', value: '1' },
            { label: '不公示', value: '2' }
          ],
          required: true
        }
      ],
      buttons: [
        {
          type: 'primary',
          label: '保存',
          show: () => {
            return this.$route.query.isView !== '1'
          },
          handler: (scope) => {
            return scope.formInstance.submitForm().then((formData) => {
              return annualFillAssetEntTempSave({
                info: formData,
                year: formData.year
              }).then(() => {
                this.$message.success('保存成功')
                this.$router.push({
                  path: '/report/public/index',
                  query: {
                    year: this.$route.query.year
                  }
                })
              })
            })
          }
        }
      ]
    }
  },
  computed: {
    formConfig() {
      return {
        labelPosition: 'top',
        isView: this.$route.query.isView === '1'
      }
    }
  },
  created() {
    this.load()
  },
  methods: {
    load() {
      return createGlobalLoading(() => {
        return annualFillAssetEntTempGet({
          year: this.$route.query.year
        }).then((data) => {
          this.formData = data || {
            year: this.$route.query.year
          }
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import "@/styles/bus-page.scss";
.page{
  margin: 24px;
}
</style>
