<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="msgCityId">
  	          <j-tree-select
                ref="treeSelect"
                placeholder="请选择关联城市"
                v-model="model.msgCityId"
                dict="msg_city,name,id"
                pidValue="0"
                >
              </j-tree-select>
            </a-form-model-item>
          </a-col>
          <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="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="icon">
              <j-image-upload isMultiple  v-model="model.icon" ></j-image-upload>
            </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,phone,id"  />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="级别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="level">
              <a-input-number v-model="model.level" placeholder="请输入级别" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="评分" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="score">
              <a-input-number v-model="model.score" placeholder="请输入评分" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="个人介绍" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="notes">
              <a-textarea v-model="model.notes" rows="4" placeholder="请输入个人介绍" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="官方认证" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isVip">
              <a-input v-model="model.isVip" placeholder="请输入官方认证"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="体重" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="kg">
              <a-input v-model="model.kg" placeholder="请输入体重"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="身高" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cm">
              <a-input v-model="model.cm" placeholder="请输入身高"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="地区" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="area">
              <a-input v-model="model.area" placeholder="请输入地区"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="城市" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="city">
              <a-input v-model="model.city" placeholder="请输入城市"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="区县" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="county">
              <a-input v-model="model.county" placeholder="请输入区县"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="实名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="realOk">
              <j-switch v-model="model.realOk"  ></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="sex">
              <a-input v-model="model.sex" placeholder="请输入性别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="经验" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="experience">
              <a-input v-model="model.experience" placeholder="请输入经验"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="识别度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isSb">
              <a-input-number v-model="model.isSb" placeholder="请输入识别度" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="服务次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isFw">
              <a-input-number v-model="model.isFw" placeholder="请输入服务次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收藏次数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="collectNum">
              <a-input-number v-model="model.collectNum" placeholder="请输入收藏次数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="个人相册" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="images">
              <j-image-upload isMultiple  v-model="model.images" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="评价条数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pinNum">
              <a-input-number v-model="model.pinNum" placeholder="请输入评价条数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最早可预约时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="useTime">
              <a-input v-model="model.useTime" placeholder="请输入最早可预约时间"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="经度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="longitude">
              <a-input v-model="model.longitude" placeholder="请输入经度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="多少公里内免费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isKm">
              <a-input-number v-model="model.isKm" placeholder="请输入多少公里内免费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="纬度" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="latitude">
              <a-input v-model="model.latitude" placeholder="请输入纬度"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否可预约" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bookable">
              <j-switch v-model="model.bookable"  ></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="免费出行" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isCx">
              <j-switch v-model="model.isCx"  ></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="显示距离" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="setKm">
              <a-input-number v-model="model.setKm" placeholder="请输入显示距离" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="运营号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isTest">
              <a-input-number v-model="model.isTest" placeholder="请输入运营号" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="距离显示开启" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="setKmOpen">
              <j-switch v-model="model.setKmOpen"  ></j-switch>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="健康证" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="healthCertificate">
              <j-image-upload isMultiple  v-model="model.healthCertificate" ></j-image-upload>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="营业证" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="businessLicense">
              <j-image-upload isMultiple  v-model="model.businessLicense" ></j-image-upload>
            </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: 'MsgTechnicianForm',
    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: "/msgTechnician/msgTechnician/add",
          edit: "/msgTechnician/msgTechnician/edit",
          queryById: "/msgTechnician/msgTechnician/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>