<template>
  <div id="detail">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <el-col :span="24" class="top">
            <el-button type="primary" size="mini" @click="back">返回</el-button>
          </el-col>
          <el-col :span="24" class="down">
            <el-form :model="form" :rules="rules" ref="form" label-width="100px">
              <el-col :span="12" class="text">
                <el-form-item label="服务类型">
                  <el-radio-group v-model="form.type">
                    <el-radio v-for="(i, index) in typeList" :key="index" :label="i">{{ i }}</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="12" class="text">
                <el-form-item label="申请单位" prop="company">
                  <el-input v-model="form.company" placeholder="请输入申请单位"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12" class="text">
                <el-form-item label="申请人" prop="apply_personal">
                  <el-input v-model="form.apply_personal" placeholder="请输入申请人"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12" class="text">
                <el-form-item label="联系电话" prop="phone">
                  <el-input v-model="form.phone" placeholder="请输入联系电话"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="text">
                <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-col>
              <el-col :span="24" class="text">
                <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-col>
              <el-col :span="24" class="text">
                <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>
              <el-col :span="24" class="text">
                <el-form-item label="申领状态" prop="status">
                  <el-radio-group v-model="form.status" disabled>
                    <el-radio v-for="(i, index) in statusList" :key="index" :label="i.value">{{ i.label }}</el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="text">
                <el-form-item label="申领意见" prop="desc">
                  <el-input v-model="form.desc" type="textarea" :autosize="{ minRows: 4, maxRows: 6 }" show-word-limit disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="24" class="formBtn" v-if="form.status == ''">
                <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>
      </el-col>
    </el-row>
  </div>
</template>

<script>
const _ = require('lodash');
const { policyType, policyStatus } = require('@common/dict/index');
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: policy } = createNamespacedHelpers('policy');
export default {
  name: 'detail',
  props: {},
  components: {},
  data: function () {
    return {
      form: {
        qyfr: [],
        yyzz: [],
        qylr: [],
        status: '',
      },
      rules: {},
      typeList: policyType,
      statusList: policyStatus,
    };
  },
  created() {
    if (this.id) this.search();
  },
  methods: {
    ...policy(['fetch', 'create']),
    async search() {
      const res = await this.fetch(this.id);
      if (this.$checkRes(res)) {
        this.$set(this, `form`, res.data);
      }
    },
    onSubmit(formName) {
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          let data = this.form;
          data.status = '0';
          let res = await this.create(data);
          if (this.$checkRes(res)) {
            this.$message({
              message: '政策服务申报成功，请耐心等待结果',
              type: 'success',
            });
            this.back();
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    back() {
      this.$router.push({ path: '/adminCenter/company/policy' });
    },
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  border-radius: 10px;
  box-shadow: 0 0 5px #cccccc;
  padding: 20px;
  .one {
    .top {
      text-align: right;
      margin: 0 0 15px 0;
    }
    .down {
      .text {
        border-bottom: 1px dashed #333;
      }
      /deep/.el-form-item {
        padding: 20px 10px;
        margin: 0;
      }
      /deep/.el-input__inner {
        border: 1px solid #333;
      }
      .formBtn {
        text-align: center;
        padding: 15px 0;
      }
    }
  }
}
.main:hover {
  box-shadow: 0 0 5px #409eff;
}
</style>
