<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="任务名称" prop="taskName" v-bind="labelCol1">
              <a-input v-model="model.taskName" placeholder="请输入任务名称"  ></a-input>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="12">-->
<!--            <a-form-model-item label="任务状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="taskState">-->
<!--              <j-dict-select-tag type="list" v-model="model.taskState" dictCode="sms_check_task_state" placeholder="请选择任务状态" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="12">
            <a-form-model-item label="开始时间" prop="taskStartTime" v-bind="labelCol2">
              <j-date placeholder="请选择任务开始时间"  v-model="model.taskStartTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="结束时间" prop="taskEndTime" v-bind="labelCol2">
              <j-date placeholder="请选择任务结束时间"  v-model="model.taskEndTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="描述" prop="description" v-bind="labelCol1">
              <a-textarea v-model="model.description" rows="4" placeholder="请输入描述" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="文件路径" prop="fileUrl" v-bind="labelCol1">
              <j-upload v-model="model.fileUrl"   ></j-upload>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="12">-->
<!--            <a-form-model-item label="客户总数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerCount">-->
<!--              <a-input v-model="model.customerCount" placeholder="请输入客户总数"  ></a-input>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="12">-->
<!--            <a-form-model-item label="稽核数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="checkCount">-->
<!--              <a-input v-model="model.checkCount" 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 { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'SmsCheckTaskForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        // 1列
        labelCol1 : {
          labelCol: {
            xs: { span: 24 },
            sm: { span: 2 },
          },
          wrapperCol: {
            xs: { span: 24 },
            sm: { span: 21 },
          }
        },
        // 2列
        labelCol2 : {
          labelCol: {
            xs: { span: 24 },
            sm: { span: 4 },
          },
          wrapperCol: {
            xs: { span: 24 },
            sm: { span: 18 },
          }
        },
        confirmLoading: false,
        validatorRules: {
           taskName: [
              { required: true, message: '请输入任务名称!'},
           ],
           taskStartTime: [
              { required: true, message: '请输入任务开始时间!'},
           ],
           taskEndTime: [
              { required: true, message: '请输入任务结束时间!'},
           ],
           fileUrl: [
              { required: true, message: '请输入文件路径!'},
           ],
        },
        url: {
          add: "/smsCheck/task//add",
          edit: "/smsCheck/task//edit",
          queryById: "/smsCheck/task//queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        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';
            }
            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>