<template>
  <div>
    <el-button size="small" :disabled="isEdit()" type="primary" @click="btn">调 价 助 手</el-button>
    <el-dialog title="产品调价助手" append-to-body :visible.sync="dialogFormVisible" width="30%">
      <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="manner">
              <el-radio-group v-model="form.manner">
                <el-radio :label="1">按金额</el-radio>
                <el-radio :label="0">按百分比</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="调价规则" prop="cardinality">
              <el-radio-group v-model="form.cardinality">
                <el-radio :label="1">上浮</el-radio>
                <el-radio :label="0">下调</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="值" prop="coefficient">
              <el-input size="mini" v-model="form.coefficient" placeholder="上浮或下调数据"></el-input>
            </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','isEdit'],
  data(){
    return {
      dialogFormVisible:false,
      form:{
        "sa_itempriceadjustid":"",
        "manner":"", // 调价方式 0 按百分比 1 定额
        "cardinality":"", //调价规则 0 下调 1上浮
        "coefficient":""  //下调或上浮  的 金额或百分比
      },
      rules:{
        manner:[
          { required: true, message: '请选择调价方式', trigger: 'blur'},
        ],
        cardinality:[
          { required: true, message: '请选择调价规则', trigger: 'blur'},
        ],
        coefficient:[
          { required: true, message: '请输入上浮或下浮金额', trigger: 'blur'},
        ],
      }
    }
  },
  methods:{
    btn () {
      this.dialogFormVisible = true
    },
    onSubmit(){
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        this.form.sa_itempriceadjustid = this.$route.query.id
        const res = await this.$api.requested({
          "id": "20221027095504",
          "version":1,
          "content": this.form
        })
        this.tool.showMessage(res,()=>{
          this.$emit('onSuccess')
          this.$refs['form'].resetFields();
          this.dialogFormVisible = false
        })
      })
    }
  }
}
</script>

<style scoped>
/deep/.el-select {
  width: 100%;
}
</style>