<template>
  <div class="bargainListDetail">
    <div class="bargainListDetail-main">
      <el-tabs v-model="projectTabs" v-loading="loading">
        <el-tab-pane label="付款申请管理" name="1">
          <el-collapse v-model="activeNames" style="margin: -18px 0 0 0">
            <el-collapse-item :title="'付款申请信息'" name="1">
              <show-data-table
                v-if="newTime !== ''"
                style="padding: -5px 0 10px 0"
                :newTime="newTime"
                :sitem="sitem"
                :columns="editColumns"
                @selection-change="handleSelection"
              >
                <template #status>
                  <el-tag size="mini">
                    {{ (statusList.find(({id}) => id === String(sitem.status)) || {}).label || '--' }}
                  </el-tag>
                </template>
              </show-data-table>
            </el-collapse-item>

            <el-collapse-item 
              v-if="sitem && Number(sitem.status) === 1"
               v-loading="status_loading" 
              title="待客户上传付款凭证" 
              name="2"
              >
              <credentials-node :is-amount="true" @confirm="handleUpload" />
            </el-collapse-item>

            <el-collapse-item title="待供应商确认付款" name="3" v-if="sitem && Number(sitem.status) === 2">
              <div style="width:100%;display:flex;justify-content:flex-end;margin:10px 0px">
                <el-button size="mini" type="primary" @click="handleConfirm">确认已付款</el-button>
              </div>
            </el-collapse-item>
          </el-collapse>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>
<script>
import asyncRequest from "@/apis/service/customerService/paymentApply";
import { editColumns, statusList } from "./columns";
import privateField from '@/mixins/privateField';
import resToken from "@/mixins/resToken";
import { mapGetters } from "vuex";

export default {
  name: "bargainListDetail",
  mixins: [resToken,privateField],
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size", "private_field", "isSupertube"]),
    powers() {
      const { btnList } = this.$store.getters;
      const tran = btnList.find((item) => item.menu_route == "paymentApplyDetail") || {};
      const { action } = tran ?? {};
      return action ?? [];
    },
  },

  data() {
    return {
      statusList,
      size: "small",
      eaxmList: [],
      editColumns,
      projectTabs: "1",
      activeNames: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "20"],
      newTime: "",
      loading: false,
      queryType: "",
      queryId: "",
      status: "",
      sitem: null,
      status_loading:false,
      selected:[],
      orderItem: {},
      moneyDirItem: {},
      moneyItem: {},
      BossItem: {},
    };
  },
  mounted() {
    this.initForm();
  },
  methods: {
    async initForm() {
      const { id, type } = this.$route.query;
      this.queryId = id;
      this.queryType = type;
      this.projectTabs = "1";
      this.loading = true;
      await this.initData();
      this.loading = false;
    },

    handleClick(row) {
      console.log(row);
    },
    async refresh() {
      this.routeReGoto("bargainList", {});
    },
   async handleUpload(data){
      const { amount: pay_amount, credentials: pay_proof } = data
      this.status_loading = true
      const { code } = await asyncRequest.status({
        id:this.queryId,
        pay_amount,
        pay_proof: pay_proof.join(","),
        status:2
      })
      this.status_loading = false

      if(code !== 1) return
      this.initForm()
    },
    async handleConfirm(){
      this.status_loading = true
      const { code } = await asyncRequest.status({
        id:this.queryId,
        status:3
      })
      this.status_loading = false

      if(code !== 1) return
      this.initForm()
    },
    async initData() {
      this.loading = true;
      const { code, data } = await asyncRequest.detail({
        id: this.queryId,
      });

      this.loading = false

      if(code !== 1) return
      this.sitem = data
      this.newTime = this.getNewTime()
    },
    getNewTime() {
      this.newTime = new Date().valueOf();
    },
    handleSelection({list}){
      this.selected = list
    },
    async statusSubmit(model, title) {
      if (model.status === "0") model.status = "2";
      const { code, data, message } = await asyncRequest.status(model);
      this.loading = false;
      // console.log("res", data);
      if (code === 0) {
        this.$notify.success({
          title: title + "成功！",
          message: "",
        });
        await this.initForm();
      } else if (code >= 100 && code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(message);
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.bargainListDetail {
  position: relative;
  height: 100%;
  width: 100%;
  box-sizing: border-box;
  .bargainListDetail-main {
    position: relative;
    padding: 10px;
    height: 100%;
    width: 100%;
  }
  .bargainListDetail-title {
    border-top: 1px solid #ebeef5;
    span {
      height: 50px;
      line-height: 50px;
      font-family: "微软雅黑", sans-serif;
      font-weight: 400;
      font-style: normal;
      font-size: 16fpx;
      text-align: left;
    }
  }
  /deep/ .ddiv {
    border-top: 1px solid #dcdfe6;
  }
  /deep/ .dtitle {
    width: 40px;
    text-align: center;
    height: 100%;
    min-height: 100%;
    ul {
      padding: 12px 0 0 0;
    }
  }
  /deep/ .dmain {
    padding: 20px 0 0 0;
    width: calc(100% - 40px);
    border-left: 1px solid #dcdfe6;
  }
}
</style>
