<template>
  <div>
    <el-button  size="mini" type="primary"  @click="onShow(dialogVisible = true)">编 辑</el-button>
    <el-drawer
        title="编辑业务员"
        :visible.sync="dialogVisible"
        size="30%"
        direction="rtl"
        append-to-body
        :show-close="false"
        @close="dialogVisible = false">
      <div class="drawer__panel">
        <el-row>
          <el-form :model="form"  :rules="rules" ref="form" label-position="right" label-width="75px" size="small" disabled>
            <el-col :span="12" >
              <el-form-item label="业务员:" prop="hrid" >
                <selectMenber ref="salerName"  @selectMenber="selectMenbers" ></selectMenber>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="手机号:"  prop="phonenumber">
                <el-input   v-model="form.phonenumber" placeholder="手机号" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item  label="汇报对象:" prop="reporthrname">
                <el-input   v-model="form.reporthrname" placeholder="汇报对象" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item  label="编号:" prop="hrcode">
                <el-input   v-model="form.hrcode" placeholder="编号" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item  label="邮箱:" prop="email">
                <el-input   v-model="form.email" placeholder="邮箱" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item  label="部门:" prop="depname">
                <el-input   v-model="form.depname" placeholder="部门" disabled></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item  label="区域:" prop="areaname">
                <el-input  v-model="form.areaname" placeholder="区域" disabled></el-input>
              </el-form-item>
            </el-col>
          </el-form>
          <el-form :model="form"   :rules="rules" ref="form" label-position="right" label-width="132px" size="small">
            <el-col :span="15">
              <el-form-item  label="最低授权折扣(%):" prop="discountrate">
                <el-input  v-model="form.discountrate" placeholder="请输入最低授权折扣" @change="discountrateChange(form.discountrate)"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item  prop="discountrate" label-width="132px">
                <el-checkbox :true-label="1" :false-label="0" v-model="form.iseditprice">是否可编辑订单价格</el-checkbox>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </div>
      <div class="fixed__btn__panel">
        <el-button size="small" @click="dialogVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="onSubmit" class="normal-btn-width">确 定</el-button>
      </div>
    </el-drawer>
  </div>
</template>

<script>
import selectMenber from '@/components/selectMenber/index.vue'
export default {
  name: "edit",
  props:["data"],
  components:{
    selectMenber
  },
  data(){
    return {
      dialogVisible:false,
      form:{
        "sa_saleareaid":'',
        "hrid":''
      },
      rules:{
        discountrate:[
          {required: true, message: '请选择业务员', trigger: 'blur' }
        ]
      }
    }
  },
  methods:{
    onShow(){
      this.form = Object.assign({},this.form,this.data)
      this.form.discountrate = this.form.discountrate * 100
      this.$nextTick(() => {
        console.log(this.$refs)
        this.$refs.salerName.value.name = this.data.name
      });
      
    },
    selectMenbers (data) {
      console.log(data)
      this.form = Object.assign({},this.form,data)
    },
    onSubmit(){
      this.form.discountrate = (this.form.discountrate/100).toFixed(4)
      console.log(this.form)
      this.$refs.form.validate(async(valid) =>{
        if (!valid) return false
        const res = await this.$api.requested({
          "id": 20221011144703,
          "content": this.form
        })
        this.tool.showMessage(res,()=>{
          this.dialogVisible = false
          this.$emit('onSuccess')
        })
      })
    },
    discountrateChange(val){
      if (val < 0){
        this.form.discountrate = 1
      }else if(val > 100){
        this.form.discountrate = 100
      }else {
        this.form.discountrate = Math.round(val * 100)/100
      }
    }
  }
}

</script>
<style>
</style>