<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="xmName">
              <a-input v-model="model.xmName" placeholder="请输入项目名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="外协费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wxf">
              <!-- <a-input v-model="model.wxf" placeholder="请输入外协费"  ></a-input> -->
              <!-- <j-upload v-model="model.fileWX" :returnUrl="false" :number="1" :multiple="false" text="上传"></j-upload> -->
              <j-upload v-model="model.wxfurl" :returnUrl="false" :number="1" :multiple="false" text="上传"></j-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="材料费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="clf">
              <!-- <a-input v-model="model.clf" placeholder="请输入材料费"  ></a-input> -->
              <!-- <j-upload v-model="model.fileCL" :returnUrl="false" :number="1" :multiple="false" text="上传"></j-upload> -->
              <j-upload v-model="model.clfurl" :returnUrl="false" :number="1" :multiple="false" text="上传"></j-upload>
            </a-form-model-item>
          </a-col>
          <!-- <a-col :span="24">
            <a-form-model-item label="材料费类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="clfType">
              <a-input v-model="model.clfType" placeholder="请输入材料费类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="事务费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="swf">
              <a-input v-model="model.swf" placeholder="请输入事务费"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="专用费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zyf">
              <a-input v-model="model.zyf" placeholder="请输入专用费"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="固定资产折旧费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gdzczj">
              <a-input v-model="model.gdzczj" placeholder="请输入固定资产折旧费"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="燃料动力费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rldlf">
              <a-input v-model="model.rldlf" placeholder="请输入燃料动力费"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工资及劳务费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gzjlwf">
              <a-input v-model="model.gzjlwf" placeholder="请输入工资及劳务费"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="管理费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="glf">
              <a-input v-model="model.glf" placeholder="请输入管理费"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="totalPrice">
              <a-input v-model="model.totalPrice" placeholder="请输入总价"  ></a-input>
            </a-form-model-item>
          </a-col> -->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { getModalIdList } from '@/api/kzksApi'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'CostModelListForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
          xmName: '',
          fileWX: [],
          fileCL: [],
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           xmName: [
              { required: true, message: '请输入项目名称!'},
           ],
        },
        url: {
          add: "/costModelList/costModelList/add",
          edit: "/costModelList/costModelList/edit",
          queryById: "/costModelList/costModelList/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.visible = true;
        // this.edit(this.modelDefault);
      },
      edit (record) {
        const data = {
          id: record.id
        }
        getModalIdList(data).then((res) => {
          console.log(res)
          this.model = res.result
        })
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            // console.log(111111,this.model)
            // this.model.wxfurl = this.model.fileWX[0].filePath
            // this.model.clfurl = this.model.fileCL[0].filePath
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>