<template>
  <div>
    <el-card>
      <el-form :model="form" :rules="rules" ref="formRef" label-width="100px">
        <el-form-item label="产品编码" prop="product_code">
          <el-input v-model="form.product_code"></el-input>
        </el-form-item>
        <el-form-item label="充值账号" prop="card_no">
          <el-input v-model="form.card_no"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('formRef')">提交</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { postEquityMsg } from '@/api';
import context from '../../main';
export default {
  data(){
    return {
      form:{
        product_code:'',
        card_no:''
      },
      rules:{
        product_code: [
          { required: true, message: '请输入产品编码', trigger: 'blur' }
        ],
        card_no: [
          { required: true, message: '请输入充值账号', trigger: 'blur' }
        ],
      }
    }
  },
  methods:{
    submitForm(formName) {
        const _self = this;
        _self.$refs[formName].validate( async (valid) => {
          if (valid) {
            console.log('valid', this.form);

            let param = new URLSearchParams()
            param.append('product_code', _self.form.product_code)
            param.append('card_no', _self.form.card_no)
            const res = await postEquityMsg(param)
            if(res && res.code == 200) {
                context.$message({
                  message: '提交成功',
                  type: 'success'
                });
                _self.$refs[formName].resetFields();
            }
            // postEquityMsg(_self.form).then(res=>{
            //   console.log(res);
            //   if(res && res.code == 200) {
            //     context.$message({
            //       message: '提交成功',
            //       type: 'success'
            //     });
            //     _self.$refs[formName].resetFields();
            //   }
            // })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
  }
}
</script>