<template>
  <div id="policy">
    <el-row>
      <el-col :span="24" class="main">
        <div class="w_1200">
          <el-col :span="24" class="one">
            <el-col :span="24" class="btn">
              <el-button type="primary" size="mini" @click="back">返回</el-button>
            </el-col>
            <el-col :span="24" class="text">环南湖科创先导区双创服务平台-高企政策服务</el-col>
            <el-col :span="24" class="dwon">
              <el-form :model="form" :rules="rules" ref="form" label-width="100px">
                <el-form-item label="服务类型">
                  <el-radio-group v-model="form.type">
                    <el-radio label="研发补贴"></el-radio>
                    <el-radio label="奖励兑现"></el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item label="申请单位" prop="company">
                  <el-input v-model="form.company" placeholder="请输入申请单位"></el-input>
                </el-form-item>
                <el-form-item label="申请人" prop="apply_personal">
                  <el-input v-model="form.apply_personal" placeholder="请输入申请人"></el-input>
                </el-form-item>
                <el-form-item label="联系电话" prop="phone">
                  <el-input v-model="form.phone" placeholder="请输入联系电话"></el-input>
                </el-form-item>
                <el-form-item label="法人复印件" prop="qyfr">
                  <e-upload url="/files/cysci/qyfr_file/upload" :limit="1" v-model="form.qyfr" type="text"></e-upload>
                </el-form-item>
                <el-form-item label="企业营业执照" prop="yyzz">
                  <e-upload url="/files/cysci/yyzz_file/upload" :limit="1" v-model="form.yyzz" type="text"></e-upload>
                </el-form-item>
                <el-form-item label="企业利润表" prop="qylr">
                  <e-upload url="/files/cysci/qylr_file/upload" :limit="1" v-model="form.qylr" type="text"></e-upload>
                </el-form-item>
                <el-col :span="24" class="formBtn">
                  <el-button type="danger" size="mini" @click="back">取消注册</el-button>
                  <el-button type="primary" size="mini" @click="onSubmit('form')">提交注册</el-button>
                </el-col>
              </el-form>
            </el-col>
          </el-col>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: mapPolicy } = createNamespacedHelpers('policy');
export default {
  name: 'policy',
  props: {},
  components: {},
  data: function () {
    return {
      form: {
        user_id: '607e70354de4e23e840f4ef6',
        qyfr: [],
        yyzz: [],
        qylr: [],
        status: '0',
      },
      rules: {
        type: [{ required: true, message: '请选择服务类型', trigger: 'change' }],
        company: [{ required: true, message: '请输入申请单位', trigger: 'blur' }],
        apply_personal: [{ required: true, message: '请输入申请人', trigger: 'blur' }],
        phone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
      },
    };
  },
  created() {},
  methods: {
    ...mapPolicy(['create']),
    onSubmit(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          let data = this.form;
          let res = await this.create(data);
          if (this.$checkRes(res)) {
            this.$message({
              message: '政策服务申报成功，请耐心等待结果',
              type: 'success',
            });
            this.$router.push({ path: '/service/index' });
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    back() {
      this.$router.push({ path: '/service/index' });
    },
  },
  computed: {
    ...mapState(['user']),
    type() {
      return this.$route.query.type;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  min-height: 500px;
  margin: 10px 0;
  .one {
    min-height: 500px;
    border-radius: 5px;
    border: 1px solid #ccc;
    padding: 0 10px;
    .btn {
      padding: 10px;
      text-align: right;
    }
    .text {
      font-size: 30px;
      text-align: center;
      margin: 0 0 10px 0;
    }
    .dwon {
      padding: 10px;
      border: 1px dashed #ccc;
      border-radius: 5px;
      .formBtn {
        text-align: center;
      }
    }
  }
}
</style>
