<!-- <template> -->
<!-- <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    @close="close">
    <el-form ref="form" label-width="80px" :model="form" :rules="rules">
      <el-form-item label="产品编码" prop="prodCode">
        <el-input v-model.trim="form.prodCode" style="width:150px;"/>
      </el-form-item>
      <el-form-item label="产品名称" prop="prodName">
        <el-input v-model.trim="form.prodName" />
      </el-form-item>
      <el-form-item label="产品分类" prop="prodClass">
        <el-input v-model.trim="form.prodClass" />
      </el-form-item>
      <el-form-item label="成交价" prop="guidPrice">
        <el-input v-model.trim="form.guidPrice" />
      </el-form-item>
      <el-form-item label="经销商价" prop="distPrice">
        <el-input v-model.trim="form.distPrice" />
      </el-form-item>
      <el-form-item label="签约代理价" prop="agentPrice">
        <el-input v-model.trim="form.agentPrice" />
      </el-form-item>
      <el-form-item label="市场报价" prop="marketPrice">
        <el-input v-model.trim="form.marketPrice" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model.trim="form.remark" type="textarea" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </template>
  </el-dialog>
</template> -->
<template>
  <el-dialog append-to-body :title="title" :visible.sync="dialogFormVisible" @close="handleClose">
    <el-form ref="form" :model="form" :rules="rules">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="产品名称" prop="prodName">
            <el-input v-model="form.prodName" placeholder="请输入产品名称" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="产品分类" prop="prodClass">
            <el-input v-model="form.prodClass" placeholder="请输入产品分类" />
            <!-- <el-select v-model="form.prodClass" placeholder="请选择客户行业" style="width: 100%">
                        <el-option v-for="item in industryOptions" :key="item.value" :label="item.value" :value="item.value" />
                      </el-select> -->
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="成交价" prop="distPrice">
            <el-input v-model.trim="form.distPrice" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="经销商价" prop="guidPrice">
            <el-input v-model.trim="form.guidPrice" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="签约代理价" prop="agentPrice">
            <el-input v-model.trim="form.agentPrice" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="市场报价" prop="marketPrice">
            <el-input v-model.trim="form.marketPrice" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item label="备注" prop="remark">
        <el-input
          v-model="form.remark"
          maxlength="500"
          placeholder="请输入备注"
          resize="none"
          :rows="5"
          show-word-limit
          type="textarea" />
      </el-form-item>
    </el-form>
    <span slot="footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
  import productApi from '@/api/product'

  export default {
    //name: 'UserEdit',
    data() {
      return {
        form: {
          roles: [],
        },
        rules: {
          prodName: [{ required: true, trigger: 'blur', message: '请输入名称' }],
          prodClass: [{ required: true, trigger: 'blur', message: '请输入分类' }],
          guidPrice: [{ required: true, trigger: 'blur', message: '请输入建议成交价' }],
          distPrice: [{ required: true, trigger: 'blur', message: '请输入经销商价' }],
        },
        title: '',
        dialogFormVisible: false,
      }
    },
    methods: {
      showEdit(row) {
        if (!row) {
          this.title = '添加'
        } else {
          this.title = '编辑'
          this.form = Object.assign({}, row)
        }
        this.dialogFormVisible = true
      },
      close() {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
        this.dialogFormVisible = false
      },
      handleClose() {
        this.Form = {
          prodCode: '', //
          prodClass: '', //
          guidPrice: '', //
          distPrice: '', //
          custStatus: '', //
          agentPrice: '', //
          marketPrice: '', //
          remark: '', //
        }
        this.$refs.editForm.resetFields()
      },

      save() {
        this.$refs['form'].validate(async (valid) => {
          if (valid) {
            if (this.form.id) {
              this.form.guidPrice = parseFloat(this.form.guidPrice).toFixed(2)
              this.form.distPrice = parseFloat(this.form.distPrice).toFixed(2)
              this.form.agentPrice = parseFloat(this.form.agentPrice).toFixed(2)
              this.form.marketPrice = parseFloat(this.form.marketPrice).toFixed(2)
              console.log(this.form)
              const { msg } = await productApi.doEdit(this.form)
              this.$baseMessage(msg, 'success', 'vab-hey-message-success')
            } else {
              this.form.guidPrice = parseFloat(this.form.guidPrice).toFixed(2)
              console.log(this.form)
              const { msg } = await productApi.doAdd(this.form)
              this.$baseMessage(msg, 'success', 'vab-hey-message-success')
            }
            this.$emit('fetch-data')
            this.close()
          }
        })
      },
    },
  }
</script>
