<template>
  <ele-modal
    custom-class="ele-dialog-form long-dialog-form"
    :centered="true"
    :visible.sync="detailDialogFlag"
    title="收款详情"
    :append-to-body="false"
    :close-on-click-modal="false"
    width="60%"
    :before-close="cancel"
  >
    <div class="switch_left">
      <ul>
        <li
          v-for="item in tabOptions"
          :key="item.key"
          :class="{ active: activeComp == item.key }"
          @click="activeComp = item.key"
        >
          {{ item.name }}
        </li>
      </ul>
    </div>
    <div v-if="activeComp === 'main'">
      <el-form ref="form" :model="form" class="el-form-box" label-width="120px">
        <headerTitle title="基本信息"></headerTitle>
        <el-row :gutter="12">
          <el-col :span="12">
            <el-form-item
              label="应收日期"
              prop="receivableDate"
             >
              <el-date-picker
                style="width: 100%"
                v-model="form.receivableDate"
                disabled
                type="date"
                value-format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="应收金额"
              prop="receivableTotalPrice"
             >
              <el-input-number disabled v-model="form.receivableTotalPrice" :precision="2" :controls="false"
                               style="width: 100%"
                               :min="0"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="12">
          <el-col :span="12">
            <el-form-item
              label="会计科目"
              prop="accountingSubjectId"
             >
              <ele-tree-select
                disabled
                clearable
                filterable
                ref="treeSelect"
                :data="accountingSubjectList"
                v-model="form.accountingSubjectId"
                valueKey="id"
                labelKey="name"
                placeholder="请选择"
                @change="changeSubjectInfo"
                default-expand-all
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="发票编码"
              prop="invoiceCode"
             >
              <el-input disabled v-model="form.invoiceCode"></el-input>
            </el-form-item>
          </el-col>


        </el-row>
        <el-row :gutter="12">
          <el-col :span="12">
            <el-form-item
              label="来源类型"
              prop="sourceType"
             >
              <el-input value="销售订单" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="来源编码"
              prop="sourceCode"
             >
              <el-input v-model="form.sourceCode" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="12">
          <el-col :span="12">
            <el-form-item
              label="公司名称"
              prop="contactName"
             >
              <el-input disabled v-model="form.contactName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="附件">
              <el-link
                v-if="form.files.length"
                v-for="item in form.files"
                type="primary"
                :underline="false"
                @click="downloadFile(item)"
              >
                {{ item.name }}
              </el-link
              >
            </el-form-item>
          </el-col>
        </el-row>
        <headerTitle title="收款信息"></headerTitle>
        <info-table ref="feeRelatedInfoTable" dialog-type="view" v-if="form.id" :form.sync="form"></info-table>
      </el-form>
    </div>
    <bpmDetail v-if="activeComp === 'bpm' && form.processInstanceId" :id="form.processInstanceId"></bpmDetail>
    <div slot="footer">
      <el-button @click="cancel">返回</el-button>
    </div>
  </ele-modal>
</template>

<script>
import {getFile} from '@/api/system/file';
import dictMixins from '@/mixins/dictMixins';
import fileUpload from "@/components/upload/fileUpload.vue";
import {getFinReceivableInfoAPI} from "@/api/financialManage/receivableManage";
import {getTreeByPid} from "@/api/classifyManage";
import infoTable from "@/views/financialManage/receivableManage/components/infoTable.vue";
import bpmDetail from "@/views/bpm/processInstance/detail.vue";
import tableInfo from "@/views/financialManage/invoiceManage/components/tableInfo.vue";

export default {
  mixins: [dictMixins],
  components: {
    tableInfo, bpmDetail,
    infoTable,
    fileUpload
  },

  data() {
    return {
      activeComp: 'main',
      tabOptions: [
        {key: 'main', name: '付款详情'},
        {key: 'bpm', name: '流程详情'}
      ],
      dialogType: '',
      form: {
        accountingSubjectCode: "",
        accountingSubjectId: '',
        accountingSubjectName: "",
        contactId: '',
        contactName: "",
        files: [],
        id: '',
        invoiceCode: "",
        receivableDate: "",
        receivableTotalPrice: '',
        receivedTotalPrice: '',
        remark: "",
        sourceCode: "",
        sourceId: "",
        sourceType: '',
        unreceiveTotalPrice: 0
      },
      accountingSubjectList: [],
      rules: {
        accountingSubjectId: {required: true, message: '请选择', trigger: 'change'},
        receivableDate: {required: true, message: '请选择', trigger: 'change'},
      }
    };
  },
  props: {
    detailDialogFlag: {
      type: Boolean,
      default: false,
    },
  },
  async created() {

  },
  methods: {
    //获取详情
    async init(id) {
      await this.getClassifyList(24, 'accountingSubjectList')
      this.form = await getFinReceivableInfoAPI(id)
    },
    downloadFile(file) {
      getFile({objectName: file.storePath}, file.name);
    },

    //获取分类管理中的数据
    async getClassifyList(id, listName) {
      let res = await getTreeByPid(id)
      this[listName] = res.data
    },
    //获取会计科目选中数据
    changeSubjectInfo(val) {
      if (!val) return this.form.accountingSubjectName = ''
      let data = this.$refs.treeSelect?.$refs?.tree?.getCurrentNode() || {}
      this.form.accountingSubjectName = data.name
    },
    cancel() {
      this.$emit('update:detailDialogFlag', false)
    }
  }
};
</script>

<style scoped lang="scss">
.ele-dialog-form {
  .el-form-item {
    margin-bottom: 10px;
  }
}

.headbox {
  display: flex;
  justify-content: flex-start;
  align-items: center;

  .amount {
    font-size: 14px;
    font-weight: bold;
    margin-right: 20px;
  }
}
</style>
