<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="image">
              <j-image-upload isMultiple  v-model="model.image" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入姓名"  ></a-input>
            </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="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="address">
              <a-input v-model="model.address" placeholder="请输入下单地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地址标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="addressId">
              <j-search-select-tag v-model="model.addressId" dict="msg_address,address_detail,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="总计时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useTime">
              <a-input-number v-model="model.useTime" placeholder="请输入总计时间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="技师名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="terName">
              <a-input v-model="model.terName" placeholder="请输入技师名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="state">
              <j-dict-select-tag type="list" v-model="model.state" dictCode="order_state" placeholder="请选择订单状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="money">
              <a-input-number v-model="model.money" placeholder="请输入订单价格" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="用户标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="userId">
              <j-search-select-tag v-model="model.userId" dict="han_hai_member,nick_name,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="关联技师" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="technicianId">
              <j-search-select-tag v-model="model.technicianId" dict="msg_technician,title,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectId">
              <j-search-select-tag v-model="model.projectId" dict="msg_shop,title,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="项目名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectName">
              <a-input v-model="model.projectName" placeholder="请输入项目名称"  ></a-input>
            </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="order_pay" placeholder="请选择支付方式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-input v-model="model.remark" placeholder="请输入订单备注"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="优惠券标识" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="couponId">
              <j-search-select-tag v-model="model.couponId" dict="msg_coupon,money,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="技师状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenState">
              <j-dict-select-tag type="list" v-model="model.tenState" dictCode="ten_state" placeholder="请选择技师状态" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="技师是否接单" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenOk">
              <j-switch v-model="model.tenOk"  ></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="接单时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="confirmTime">
              <j-date placeholder="请选择接单时间"  v-model="model.confirmTime" :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="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="arriveTime">
              <j-date placeholder="请选择到达时间"  v-model="model.arriveTime" :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="arrivalPicture">
              <j-image-upload isMultiple  v-model="model.arrivalPicture" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="服务时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="startServiceTime">
              <j-date placeholder="请选择服务时间"  v-model="model.startServiceTime" :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="endErviceTime">
              <j-date placeholder="请选择结束服务时间"  v-model="model.endErviceTime" :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="endPicture">
              <j-image-upload isMultiple  v-model="model.endPicture" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="车费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="temp">
              <a-input-number v-model="model.temp" placeholder="请输入车费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="服务下单时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serviceTime">
              <j-date placeholder="请选择服务下单时间"  v-model="model.serviceTime" :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="evaluated">
              <a-input-number v-model="model.evaluated" placeholder="请输入用户评价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="技师评价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jsEvaluated">
              <a-input-number v-model="model.jsEvaluated" placeholder="请输入技师评价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="服务日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="serviceDate">
              <j-date placeholder="请选择服务日期" v-model="model.serviceDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="分销商所得(一级)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shopMoney">
              <a-input-number v-model="model.shopMoney" placeholder="请输入分销商所得(一级)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="技师所得（项目）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenMoney">
              <a-input-number v-model="model.tenMoney" placeholder="请输入技师所得（项目）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="一级所得" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenPrice">
              <a-input-number v-model="model.tenPrice" placeholder="请输入一级所得" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="二级所得" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenMinPrice">
              <a-input-number v-model="model.tenMinPrice" placeholder="请输入二级所得" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="评价所得" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pinPrice">
              <a-input-number v-model="model.pinPrice" 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: 'MsgOrderForm',
    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: {
        },
        url: {
          add: "/msgOrder/msgOrder/add",
          edit: "/msgOrder/msgOrder/edit",
          queryById: "/msgOrder/msgOrder/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>