<template>
  <div id="columnDetail">
    <el-row>
      <el-col :span="24" class="top">
        <topInfo :topTitle="topTitle"></topInfo>
      </el-col>
      <el-col :span="24" class="main">
        <detail :form="form" @submitDate="onSubmit"></detail>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import topInfo from '@/layout/public/top.vue';
import detail from '@/layout/enterpriseTrans/detail.vue';
import { createNamespacedHelpers, mapState } from 'vuex';

const { mapActions: tranaudit } = createNamespacedHelpers('tranaudit');
const { mapActions: transaction } = createNamespacedHelpers('transaction');

export default {
  name: 'columnDetail',
  props: {},
  components: {
    detail,
    topInfo,
  },
  data: () => ({
    topTitle: '审核',
    form: {},
    acc: {},
    xinxi: {},
  }),
  created() {
    this.search();
  },
  computed: {
    ...mapState(['user']),

    id() {
      return this.$route.query.id;
    },
    oneid() {
      return this.$route.query.oneid;
    },
    twoid() {
      return this.$route.query.twoid;
    },
    name() {
      return this.$route.query.name;
    },
    keyWord() {
      let meta = this.$route.meta;
      let main = meta.title || '';
      return main;
    },
  },
  methods: {
    ...tranaudit(['fetch', 'create', 'update', 'query']),
    ...transaction({ transactionsfetch: 'fetch', transactionslist: 'query', transactionupdate: 'update' }),
    async search() {
      console.log(this.id);
      console.log(this.oneid);
      console.log(this.twoid);
      console.log(this.name);
      let transaction_id = this.id;
      const ress = await this.transactionsfetch(transaction_id);
      console.log(ress.data);
      this.$set(this, `form`, ress.data);
      this.$set(this, `xinxi`, ress.data);
    },
    async onSubmit() {
      let acc = {};
      acc.username = this.oneid;
      acc.market_username = this.twoid;
      acc.product_name = this.name;
      acc.transaction_id = this.id;
      acc.id = this.id;
      acc.userid = this.user.uid;
      acc.result = this.form.result;
      acc.description = this.form.description;
      console.log(acc);
      if (this.form.result == '1') {
        this.xinxi.status = '1';
        console.log(this.xinxi);
        let res = await this.transactionupdate(this.xinxi);
        this.$checkRes(res, '审核成功', '审核失败');
      } else if (this.form.result == '2') {
        this.xinxi.status = '3';
        let res = await this.transactionupdate(this.xinxi);
        this.$checkRes(res, '审核成功', '审核失败');
      }
      this.$router.push({ path: '/enterprise/transaction' });
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  padding: 20px;
  margin: 10px 20px;
  border: 1px solid #ccc;
  width: 96%;
}
</style>
