<template>
  <div id="policy">
    <supermarketlist-detail
      @handleCurrentChange="handleCurrentChange"
      :contentList="contentList"
      :total="total"
      :columnName="columnName"
      @fetch="fetchInfo"
      :display="display"
      :policyInfo="policyInfo"
      @onSubmit="onSubmit"
    ></supermarketlist-detail>
  </div>
</template>

<script>
import supermarketlistDetail from '@/components/supermaket/supermarketlistDetail.vue';
import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
import _ from 'loadsh';

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

export default {
  name: 'policy',
  props: {},
  components: {
    supermarketlistDetail,
  },
  data: () => ({
    policyInfo: {},
    display: 'detail',
    columnName: '',
    contentList: [],
    total: 1,
    skip: '',
  }),
  async created() {
    this.searchinfos();
  },
  computed: {
    id() {
      return this.$route.query.id;
    },
    ...mapState(['user']),
    totaltype() {
      return this.$route.query.totaltype;
    },
  },
  methods: {
    ...mapEnterpriseproject({ list: 'query', fetch: 'newfetch' }),
    ...transaction({ transactioncreate: 'create', transactionfetch: 'fetch' }),
    ...tranaudit({ tranauditcreate: 'create' }),
    fetchInfo() {},
    async searchinfos() {
      console.log(this.id);

      this.display = 'detail';
      const res = await this.fetch(this.id);
      this.$set(this, `policyInfo`, res.data);
    },
    async handleCurrentChange({ skip, limit, currentPage }) {
      this.$set(this, `skip`, skip);
      this.search();
    },
    async onSubmit() {
      console.log(this.user.uid);
      let form = {};
      form.userid = this.user.uid;
      form.username = this.user.name;
      form.product_id = this.policyInfo.id;
      form.product_name = this.policyInfo.name;
      form.market_userid = this.policyInfo.userid;
      form.market_username = this.policyInfo.contact_user;
      form.status = '0';
      console.log(form);
      let res = await this.transactioncreate(form);
      this.$checkRes(res, '发起交易成功', '交易失败');
      let shenhe = {};
      shenhe.result = '0';
      shenhe.transaction_id = res.data.id;
      shenhe.userid = this.policyInfo.userid;
      shenhe.product_id = this.policyInfo.userid;
      console.log(shenhe);
      let ress = await this.tranauditcreate(shenhe);
    },
  },
};
</script>

<style lang="scss" scoped></style>
