<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        <el-col :span="12">
            <el-form-item label="工程年度" prop="projectYear"
                :rules="[
                  {required: true, message:'工程年度不能为空', trigger:'blur'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.projectYear"
                      type="year"
                      value-format="yyyy"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="项目编码" prop="itemCode"
                :rules="[
                  {required: true, message:'项目编码不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.itemCode" placeholder="请填写项目编码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="项目类型" prop="projectType"
                :rules="[
                  {required: true, message:'项目类型不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.projectType" placeholder="请填写项目类型"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="项目名称" prop="entryName"
                :rules="[
                  {required: true, message:'项目名称不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.entryName" placeholder="请填写项目名称"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="施工单位" prop="constructionUnit"
                :rules="[
                  {required: true, message:'施工单位不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.constructionUnit" placeholder="请填写施工单位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="合同金额" prop="contractAmount"
                :rules="[
                  {required: true, message:'合同金额不能为空', trigger:'blur'},
                  {validator: validator.isNumber, trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.contractAmount" placeholder="请填写合同金额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="完工日期" prop="completionDate"
                :rules="[
                  {required: true, message:'完工日期不能为空', trigger:'blur'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.completionDate"
                      type="date"
                      value-format="yyyy-MM-dd"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="时限" prop="timeLimit"
                :rules="[
                  {required: true, message:'时限不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.timeLimit" placeholder="请填写时限"     ></el-input>
           </el-form-item>
        </el-col>
<!--        <el-col :span="12">-->
<!--            <el-form-item label="实际资料提交日期" prop="submissionDate"-->
<!--                :rules="[-->
<!--                 ]">-->
<!--              <el-input v-model="inputForm.submissionDate" placeholder="请填写实际资料提交日期"     ></el-input>-->
<!--           </el-form-item>-->
<!--        </el-col>-->
<!--        <el-col :span="12">-->
<!--            <el-form-item label="备注信息" prop="remarks"-->
<!--                :rules="[-->
<!--                 ]">-->
<!--          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>-->
<!--           </el-form-item>-->
<!--        </el-col>-->
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          projectYear: '',
          itemCode: '',
          projectType: '',
          entryName: '',
          constructionUnit: '',
          contractAmount: '',
          completionDate: '',
          timeLimit: '',
          submissionDate: '',
          remarks: ''
        }
      }
    },
    components: {
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建项目信息`
        } else if (method === 'edit') {
          this.title = '修改项目信息'
        } else if (method === 'view') {
          this.title = '查看项目信息'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/sys/completionInformation/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.completionInformation)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/sys/completionInformation/update`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
              this.loading = false
            })
          }
        })
      }
    }
  }
</script>
