<template>
  <ele-modal
    custom-class="ele-dialog-form long-dialog-form"
    :centered="true"
    v-if="visible"
    :visible.sync="visible"
    :title="title"
    :close-on-click-modal="false"
    width="70%"
    @close="cancel"
  >
    <div class="switch">
      <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>
    <div v-show="activeComp == 'order'">
      <el-form ref="form" class="el-form-box" :model="form" :rules="rules" label-width="120px">
        <headerTitle title="订单信息"> </headerTitle>
        <el-row>
          <el-col :span="12">
            <el-form-item
              label="订单编号："
              prop="orderNo"

            >
              <el-input v-model="form.orderNo" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="合同名称："
              prop="contractName"

            >
              <el-input v-model="form.contractName" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="合同编号："
              prop="contractNumber"

            >
              <el-input v-model="form.contractNumber" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="结算方式："
              prop="settlementModeName"

            >
              <el-input v-model="form.settlementModeName" disabled></el-input>
            </el-form-item>


            <el-form-item
              label="客户收货地址："
              prop="receiveAddress">
              <el-input v-model="form.receiveAddress" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="订单备注："
              prop="remark">
              <el-input type="textarea" v-model="form.remark" disabled></el-input>
            </el-form-item>
            <el-form-item prop="orderFiles" label="订单附件：">
              <div
                v-if="detailData.orderFiles && detailData.orderFiles?.length"
              >
                <el-link
                  v-for="link in detailData.orderFiles"
                  :key="link.id"
                  type="primary"
                  :underline="false"
                  @click="downloadFile(link)"
                >
                  {{ link.name }}</el-link
                >
              </div>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <!-- <el-form-item
              label="交货日期："
              prop="deliveryDate"

            >
              {{ form.deliveryDate }}
            </el-form-item> -->

            <el-form-item
              label="项目名称："
              prop="projectName">
              <el-input v-model="form.projectName" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="销售部门："
              prop="salesDeptName">
              <el-input v-model="form.salesDeptName" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="销售类型："
              prop="saleTypeName">
              <el-input v-model="form.saleTypeName" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="总金额："
              prop="totalAmount">
              <el-input v-model="form.totalAmount" disabled>
                <template slot="append">
                  元
                </template>
              </el-input>
            </el-form-item>
            <el-form-item
              label="优惠总金额："
              prop="payAmount">
              <el-input v-model="form.payAmount" disabled>
                <template slot="append">
                  元
                </template>
              </el-input>
            </el-form-item>
            <el-form-item
              label="计价方式：">
              <el-radio v-model="form.pricingWay" disabled :label="1">按数量计费</el-radio>
              <el-radio v-model="form.pricingWay" disabled :label="2">按重量计费</el-radio>
            </el-form-item>
            <el-form-item
              label="订单类型："
              prop="needProduce"
              style="margin-bottom: 22px">
              <el-radio v-model="form.needProduce" disabled :label="1">生产性订单</el-radio>
              <el-radio v-model="form.needProduce" disabled :label="0">库存式订单</el-radio>
            </el-form-item>

          </el-col>
        </el-row>
        <headerTitle title="基本信息"></headerTitle>
        <el-row>
          <el-col :span="12">
            <el-form-item
              label="客户名称："
              prop="partaName">
              <el-input v-model="form.partaName" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="客户统一社会信用代码："
              prop="partaUnifiedSocialCreditCode"
             class="form_item_label">
              <el-input v-model="form.partaUnifiedSocialCreditCode" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="客户联系人："
              prop="partaLinkName">
              <el-input v-model="form.partaLinkName" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="客户电话："
              prop="partaTel">
              <el-input v-model="form.partaTel" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="客户传真："
              prop="partaFax">
              <el-input v-model="form.partaFax" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="	客户Email："
              prop="partaEmail">
              <el-input v-model="form.partaEmail" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="客户地址："
              prop="partaAddress">
              <el-input v-model="form.partaAddress" disabled></el-input>
            </el-form-item>
            <!-- <el-form-item
              label="客户税号"
              prop="contactAddress"

            >
              <el-input
                clearable
                v-model="form.contactAddress"
                placeholder="请输入"
              />
            </el-form-item> -->
          </el-col>

          <el-col :span="12">
            <el-form-item
              label="售出方名称："
              prop="partbName">
              <el-input v-model="form.partbName" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="售出方统一社会信用代码："
              prop="partbUnifiedSocialCreditCode"
              class="form_item_label">
              <el-input v-model="form.partbUnifiedSocialCreditCode" disabled></el-input>
            </el-form-item>
            <el-form-item
              label="售出方联系人："
              prop="partbLinkName">
              <el-input v-model="form.partbLinkName" disabled></el-input>
            </el-form-item>
            <el-form-item
              prop="partbTel"
              label="售出方联系电话：" class="form_item_label">
              <el-input v-model="form.partbTel" disabled></el-input>
            </el-form-item>
            <el-form-item prop="partbFax" label="售出方传真：">
              <el-input v-model="form.partbFax" disabled></el-input>
            </el-form-item>

            <el-form-item
              label="售出方Email："
              prop="partbEmail">
              <el-input v-model="form.partbEmail" disabled></el-input>
            </el-form-item>

            <el-form-item
              label="售出方地址："
              prop="partbAddress">
              <el-input v-model="form.partbAddress" disabled></el-input>
            </el-form-item>
            <!-- <el-form-item
              label="售出方税号"
              prop="contactAddress"

            >
              <el-input
                clearable
                v-model="form.contactAddress"
                placeholder="请输入"
              />
            </el-form-item> -->
          </el-col>
        </el-row>
      </el-form>

      <headerTitle title="产品清单"></headerTitle>
      <inventoryTabledetail
        @toSendTab="toSendTab"
        ref="inventoryTabledetailRef"
        :isCustomerMark="true"
        :isDiscountTotalPrice="true"
      ></inventoryTabledetail>
    </div>
    <bpmDetail v-if="activeComp==='bpm'&&form.processInstanceId" :id="form.processInstanceId"></bpmDetail>

    <div v-if="activeComp == 'invoice'">
      <invoiceList :orderId="detailId"></invoiceList>
    </div>
    <div v-if="activeComp == 'returnorder'">
      <returnGoodsList :orderId="detailId"></returnGoodsList>
    </div>
    <div v-if="activeComp == 'accountstatement'">
      <accountstatementList :orderId="detailId"></accountstatementList>
    </div>
    <div slot="footer" class="footer">
      <el-button @click="cancel">返回</el-button>
    </div>
  </ele-modal>
</template>

<script>
  import { getSaleOrderDetail } from '@/api/saleManage/saleorder';
  import invoiceList from '@/views/saleManage/saleOrder/orderAssociation/invoiceList.vue';
  import returnGoodsList from '@/views/saleManage/saleOrder/orderAssociation/returnGoodsList.vue';
  import accountstatementList from '@/views/saleManage/saleOrder/orderAssociation/accountstatementList.vue';
  import { getFile } from '@/api/system/file';
  import dictMixins from '@/mixins/dictMixins';
  import { copyObj } from '@/utils/util';
  import bpmDetail from '@/views/bpm/processInstance/detail.vue';
  import inventoryTabledetail from './inventoryTabledetail.vue';

  export default {
    mixins: [dictMixins],
    components: {
      invoiceList,
      returnGoodsList,
      accountstatementList,bpmDetail,inventoryTabledetail
    },
    data() {
      return {
        activeComp: 'order',
        tabOptions: [
          { key: 'order', name: '订单详情' },
          { key: 'bpm', name: '流程详情' },
          { key: 'invoice', name: '发货列表' },
          { key: 'returnorder', name: '退货列表' },
          { key: 'accountstatement', name: '对账列表' }
        ],
        visible: false,
        detailId: '',
        title: '详情',
        row: {},
        activeName: 'base',
        form: {
          orderFiles: [{ name: '222' }]
        },
        rules: {},
        detailData: {},


      };
    },
    methods: {
      async open(row) {
        this.form = row;
        this.visible = true;
        this.getDetailData(row.id);
        this.detailId = row.id;
      },
      toSendTab(tabName){
        this.activeComp = tabName
      },
      cancel() {
        this.$nextTick(() => {
          // 关闭后，销毁所有的表单数据
          (this.form = copyObj(this.formDef)),
            (this.otherForm = copyObj(this.otherFormDef)),
            (this.tableBankData = []);
          this.tableLinkData = [];
          this.visible = false;
        });
      },
      downloadFile(file) {
        getFile({ objectName: file.storePath }, file.name);
      },
      async getDetailData(id) {
        this.loading = true;
        const data = await getSaleOrderDetail(id);
        this.loading = false;
        if (data) {
          this.form = data;
          this.detailData = data;
          this.$nextTick(() => {
            this.$refs.inventoryTabledetailRef &&
              this.$refs.inventoryTabledetailRef.putTableValue(data);
          });
        }
      }
    }
  };
</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;
    }
  }

  .switch_left ul .active {
    border-top: 4px solid var(--color-primary);
    color: var(--color-primary-5);
  }

  .switch {
    padding-bottom: 20px;
  }

  :deep .divider .content {
    justify-content: flex-start;
  }
</style>
