<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="userName">
              <a-input v-model="model.userName" placeholder="请输入老板名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工人名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workName">
              <a-input v-model="model.workName" placeholder="请输入工人名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作标题" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="title">
              <a-input v-model="model.title" placeholder="请输入工作标题"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="公司名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="companyName">
              <a-input v-model="model.companyName" placeholder="请输入公司名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工人出发地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workerAddress">
              <a-input v-model="model.workerAddress" placeholder="请输入工人出发地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出行方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="travelType">
              <j-dict-select-tag type="list" v-model="model.travelType" dictCode="travel_type" placeholder="请选择出行方式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="上班地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workAddress">
              <a-input v-model="model.workAddress" placeholder="请输入上班地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="行业/工种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="industryName">
              <a-input v-model="model.industryName" placeholder="请输入行业/工种"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工人个人简介" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="detail">
              <j-editor v-model="model.detail" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工作内容" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workDetail">
              <j-editor v-model="model.workDetail" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="图片上传" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workPic">
              <j-image-upload isMultiple  v-model="model.workPic" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="工人联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="phone">
              <a-input v-model="model.phone" placeholder="请输入工人联系方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="招聘方联系方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bossPhone">
              <a-input v-model="model.bossPhone" placeholder="请输入招聘方联系方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="年龄" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="age">
              <a-input-number v-model="model.age" placeholder="请输入年龄" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gender">
              <j-dict-select-tag type="list" v-model="model.gender" dictCode="sex" placeholder="请选择性别" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="时间范围" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startTime">
              <j-date placeholder="请选择时间范围"  v-model="model.startTime" :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="时间范围" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="endTime">
              <j-date placeholder="请选择时间范围"  v-model="model.endTime" :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="支付时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payTime">
              <j-date placeholder="请选择支付时间"  v-model="model.payTime" :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="工作时长" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workTime">
              <a-input v-model="model.workTime" placeholder="请输入工作时长"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderStatus">
              <j-dict-select-tag type="list" v-model="model.orderStatus" dictCode="order_status" placeholder="请选择订单状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结算方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payType">
              <j-dict-select-tag type="list" v-model="model.payType" dictCode="pay_type" placeholder="请选择结算方式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="付款金额（元）、" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payMoney">
              <a-input-number v-model="model.payMoney" placeholder="请输入付款金额（元）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="moneyType">
              <j-dict-select-tag type="list" v-model="model.moneyType" dictCode="money_type" placeholder="请选择支付方式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="保险费（元）、" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="premium">
              <a-input-number v-model="model.premium" placeholder="请输入保险费（元）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="交通费用金额（元）、" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="travelMoney">
              <a-input-number v-model="model.travelMoney" placeholder="请输入交通费用金额（元）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="试工费用金额（元）、" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="workMoney">
              <a-input-number v-model="model.workMoney" placeholder="请输入试工费用金额（元）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总金额（元）、" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amount">
              <a-input-number v-model="model.amount" placeholder="请输入总金额（元）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="平台手续费（元）、" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rateMoney">
              <a-input-number v-model="model.rateMoney" placeholder="请输入平台手续费（元）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="平台手续费率）、" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rate">
              <a-input-number v-model="model.rate" placeholder="请输入平台手续费率）" style="width: 100%" />
            </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: 'TbOrderForm',
    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 },
        },
        confirmLoading: false,
        validatorRules: {
           payMoney: [
              { required: true, message: '请输入付款金额（元）、!'},
           ],
           premium: [
              { required: true, message: '请输入保险费（元）、!'},
           ],
           travelMoney: [
              { required: true, message: '请输入交通费用金额（元）、!'},
           ],
           workMoney: [
              { required: true, message: '请输入试工费用金额（元）、!'},
           ],
           amount: [
              { required: true, message: '请输入总金额（元）、!'},
           ],
           rateMoney: [
              { required: true, message: '请输入平台手续费（元）、!'},
           ],
           rate: [
              { required: true, message: '请输入平台手续费率）、!'},
           ],
        },
        url: {
          add: "/tbOrder/tbOrder/add",
          edit: "/tbOrder/tbOrder/edit",
          queryById: "/tbOrder/tbOrder/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>