<template>
  <div>
    <el-button size="mini" type="text" @click="editBtn">编 辑</el-button>
    <el-dialog title="新 建" append-to-body :visible.sync="dialogFormVisible" width="30%">
      <div slot="title" style="font-size: 15px">
        编辑报价单
      </div>
      <el-row :gutter="20">
        <el-form :model="form" :rules="rules" ref="form" label-width="120px" label-position="right" size="mini">
          <el-col :span="24">
            <el-form-item label="原价" prop="oldprice">
              <el-input v-model="form.oldprice" placeholder="请输入原价"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="折扣率" prop="discountrate">
              <el-input v-model="form.discountrate" placeholder="请输入折扣率"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="产品" prop="itemid">
              <el-select v-model="form.itemid" placeholder="请选择产品" size="small">
                <el-option
                  v-for="item in productList()"
                  :key="item.itemid"
                  :label="item.itemname"
                  :value="item.itemid">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="onSubmit" class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "add",
  inject:['productList'],
  props:['data'],
  components:{},
  data(){
    return {
      dialogFormVisible:false,
      form:{
        "sa_quotedprice_itemsid":0,
        "itemid":"",
        "oldprice":"",
        "discountrate":""
      },
      rules:{
        itemid:[
          { required: true, message: '输入项目名称', trigger: 'blur'},
        ],
        oldprice:[
          { required: true, message: '请选择报价有效期', trigger: 'blur'}
        ],
        discountrate:[
          { required: true, message: '整单折扣率，保留2位小数', trigger: 'blur'}
        ],
      }
    }
  },
  methods:{
    editBtn () {
      this.dialogFormVisible = true
      this.form = Object.assign({},this.form,this.data)
      console.log(this.form);
      
    },
    onSubmit(){
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        const res = await this.$api.requested({
            "id": 20221021095403,
            "version":1,
            "content": {
                "sa_quotedpriceid":this.data.sa_quotedpriceid,
                "items":[this.form]
            }
        })
        this.tool.showMessage(res,()=>{
          this.$emit('onSuccess')
          this.$refs['form'].resetFields();
          this.dialogFormVisible = false
        })
      })
    },
  }
}
</script>

<style scoped>
/deep/.el-select {
  height: 28px !important;
  width: 100%;
}
/deep/.el-input__inner {
  height: 28px !important;
}
</style>