<template>
  <div class="app-container">
    <el-form :model="firminfoForm" >
      <el-form-item label="头像" prop="pass">
        <userAvatar/>
      </el-form-item>
      <el-form-item label="姓名" prop="pass">
        <span>{{firminfoForm.nickName}}</span>
      </el-form-item>
      <el-form-item label="手机号" prop="pass">
        <span>{{firminfoForm.phonenumber}}</span>
      </el-form-item>
      <el-form-item label="企业（团队）名称" prop="pass">
        <span>{{firminfoForm.firmTem}}</span>
      </el-form-item>
      <el-form-item label="姓名" prop="pass">
        <span>{{firminfoForm.names}}</span>
      </el-form-item>
      <el-form-item label="职位" prop="pass">
        <span>{{firminfoForm.position}}</span>
      </el-form-item>
      <el-form-item label="公司所在省市区" prop="pass">
        <span>{{firminfoForm.firmRegion}}</span>
      </el-form-item>
      <el-form-item label="公司详细地址" prop="pass">
        <span>{{firminfoForm.firmFrom}}</span>
      </el-form-item>
      <el-form-item label="统一社会信用代码" prop="pass">
        <span>{{firminfoForm.socialReputation}}</span>
      </el-form-item>
      <el-form-item label="营业执照" prop="pass">
        <span>{{firminfoForm.businessLicense}}</span>
      </el-form-item>
      <el-form-item label="余额" prop="pass">
        <span>{{firminfoForm.firmScore}}</span>
      </el-form-item>
    </el-form>

    <el-button  @click="dialogFormVisible = true">充值</el-button>
    <el-button @click="handleAdd">新增</el-button>

    <el-dialog title="充值" :visible.sync="dialogFormVisible">
      <el-form :model="pay">
        <el-form-item label="金额" >
          <el-input v-model="pay.totalAmount" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <button @click="topup()">充值</button>
      </div>
    </el-dialog>


    <!-- 添加或修改firmList对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="企业名称" prop="firmTem">
          <el-input v-model="form.firmTem" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="姓名" prop="names">
          <el-input v-model="form.names" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="职位" prop="position">
          <el-input v-model="form.position" placeholder="请输入职位" />
        </el-form-item>
        <el-form-item label="公司所在省市区" prop="firmRegion">
          <el-input v-model="form.firmRegion" placeholder="请输入公司所在省市区" />
        </el-form-item>
        <el-form-item label="公司详细地址" prop="firmFrom">
          <el-input v-model="form.firmFrom" placeholder="请输入公司详细地址" />
        </el-form-item>
        <el-form-item label="社会信誉" prop="socialReputation">
          <el-input v-model="form.socialReputation" placeholder="请输入社会信誉" />
        </el-form-item>
        <el-form-item label="营业执照" prop="businessLicense">
          <el-input v-model="form.businessLicense" placeholder="请输入社会信誉" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {listFirminfo, getFirminfo, delFirminfo, addFirminfo, updateFirminfo, edit} from "/src/api/firminfo/firminfo";
import firminfo from "./index.vue";
import userAvatar from "../../system/user/profile/userAvatar.vue";
import {pay} from "../../../api/market/apitype";

export default {
  open: false,
  name: "Firminfo",
  components: {userAvatar},
  computed: {
    firminfo() {
      return firminfo
    }
  },
  data() {
    return {
      title: "",
      dialogFormVisible:false,
      firminfoForm:{},
      pay:{},
      firminfo:{},
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        firmAvatr: null,
        createdName: null,
        phone: null,
        firmTem: null,
        names: null,
        position: null,
        firmRegion: null,
        firmFrom: null,
        socialReputation: null,
        businessLicense: null,
        firmTime: null,
        firmScore: null
      },
      form: {},
      rules: {
      },
      open: false,
    };
  },
  created() {
    this.getFirminfo()
  },
  methods: {
    reset() {
      this.form = {
        firmId: null,
        firmAvatr: null,
        createdName: null,
        phone: null,
        firmTem: null,
        names: null,
        position: null,
        firmRegion: null,
        firmFrom: null,
        socialReputation: null,
        businessLicense: null,
        firmTime: null,
        firmScore: null
      };
      this.resetForm("form");
    },
      cancel() {
      this.open = false;
      this.reset();
    },

    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加firmList";
    },
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.firmId != null) {
            updateFirminfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFirminfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

    getFirminfo() {
      getFirminfo().then(response => {
        this.firminfoForm = response.data;
      });
    },
    async topup(){
      this.pay.subject=this.firminfoForm.firmTem
      const url  = `http://10.0.2.1:8080/market/alipay/pay?subject=${this.pay.subject}&totalAmount=${this.pay.totalAmount}`;
      pay(this.pay).then(res=>{
        console.log(res)
        window.open(url, '_self');
        if(200==res.code){
          this.firminfo.firmId=this.firminfoForm.firmId
          this.firminfo.firmScore=this.pay.totalAmount
          edit(this.firminfo).then(res=>{
            console.log(res)
          })
        }
      })
    }
  }
};
</script>
