<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="userId">
              <j-select-user-by-dep v-model="model.userId" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="排序" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sort">
              <a-input-number v-model="model.sort" placeholder="请输入排序" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="身高（厘米）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="height">
              <a-input-number v-model="model.height" placeholder="请输入身高（厘米）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="体重（千克）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="weight">
              <a-input-number v-model="model.weight" placeholder="请输入体重（千克）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="下摆（厘米）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hem">
              <a-input-number v-model="model.hem" placeholder="请输入下摆（厘米）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="袖口（厘米）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cuff">
              <a-input-number v-model="model.cuff" placeholder="请输入袖口（厘米）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="袖长（厘米）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sleeveLength">
              <a-input-number v-model="model.sleeveLength" placeholder="请输入袖长（厘米）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="胸围（厘米）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bust">
              <a-input-number v-model="model.bust" placeholder="请输入胸围（厘米）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="腰围（厘米）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="theWaist">
              <a-input-number v-model="model.theWaist" placeholder="请输入腰围（厘米）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="肩宽（厘米）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shoulderWidth">
              <a-input-number v-model="model.shoulderWidth" placeholder="请输入肩宽（厘米）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="前身长（厘米）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="forebodyLength">
              <a-input-number v-model="model.forebodyLength" placeholder="请输入前身长（厘米）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="领围（厘米）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="neck">
              <a-input-number v-model="model.neck" placeholder="请输入领围（厘米）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="臀围（厘米）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hipline">
              <a-input-number v-model="model.hipline" placeholder="请输入臀围（厘米）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="衣长" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="length">
              <a-input-number v-model="model.length" placeholder="请输入衣长" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="胸距" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sternalDistance">
              <a-input-number v-model="model.sternalDistance" placeholder="请输入胸距" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="量体方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="measurementMethod">
              <j-dict-select-tag type="list" v-model="model.measurementMethod" dictCode="ctfs" placeholder="请选择量体方式" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="量体店铺" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="storeId">
              <j-select-depart v-model="model.storeId" multi  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="量体设备" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviceId">
              <j-search-select-tag v-model="model.deviceId" dict="se_equipmenttype,name,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="量体师" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="measurerId">
              <j-select-user-by-dep v-model="model.measurerId" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="量体时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="measurementTime">
              <j-date placeholder="请选择量体时间"  v-model="model.measurementTime" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" 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: 'CustomerMeasureForm',
    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: "/customermeasure/customerMeasure/add",
          edit: "/customermeasure/customerMeasure/edit",
          queryById: "/customermeasure/customerMeasure/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>