<!-- @desc:供应商详情  @auth:常皓宁  @time:2024/7/15 13:15 -->
<template>
  <div class="main-div">
    <Card class="card">
      <p slot="title">
        {{ $t('supInfo') }}
      </p>
      <DkRow>
        <Col span="8">
          <Icon type="md-person" size="20"/>
          {{ $t('supName') + '：' }}
          <b>{{ formData.supName }}</b>
        </Col>
        <Col span="16">
          <Tag color="blue" size="medium" v-if="formData.supTypeName">{{ formData.supTypeName }}</Tag>
        </Col>
      </DkRow>
      <DkRow>
        <Col span="8" v-if="formData.contactPhone">
          <Icon type="md-call" size="20"/>
          {{ $t('contactPhone') + '：' + formData.contactPhone }}
        </Col>
        <Col span="16" v-if="formData.returnAddress">
          <Icon type="md-pin" size="20"/>
          {{ $t('addressFull') + '：' + formData.returnAddress }}
        </Col>
      </DkRow>
    </Card>
    <Card class="card">
      <!--  新结构重写一下    -->
      <div class="order-info">

        <div>
          <span
            class="yuan-fh">￥</span><b>{{
            formData.purchaseAmount ? XEUtils.commafy(Number(formData.purchaseAmount), {digits: 2}) : '0.00'
          }}元</b>
          <span style="display: block;">订单（{{ formData.purchaseQuantity }}单）</span>
        </div>

        <div>
          <span
            class="yuan-fh">￥</span><b>{{
            formData.inboundReturnAmount ? XEUtils.commafy(Number(formData.inboundReturnAmount), {digits: 2}) : '0.00'
          }}元</b>
          <span style="display: block;">退货（{{ formData.inboundReturnQuantity }}单）</span>
        </div>

        <div>
          <span
            class="yuan-fh">￥</span><b>{{
            formData.payment ? XEUtils.commafy(Number(formData.payment), {digits: 2}) : '0.00'
          }}元</b>
          <span style="display: block;">收款总额</span>
        </div>

        <div>
          <span class="yuan-fh">￥</span><b>{{
            ((formData.purchaseAmount ? formData.purchaseAmount : 0) +
              (formData.inboundReturnAmount ? formData.inboundReturnAmount : 0) -
              (formData.payment ? formData.payment : 0)) > 0 ? XEUtils.commafy(Number(((formData.purchaseAmount ? formData.purchaseAmount : 0) +
              (formData.inboundReturnAmount ? formData.inboundReturnAmount : 0) -
              (formData.payment ? formData.payment : 0))), {digits: 2}  ) : '0.00'
          }}元</b>
          <span style="display: block;">欠款</span>
        </div>


      </div>
    </Card>
    <Card>
      <DkTabs ref="tab" v-model="tabsModel" :options="tabsOptions">
        <!--采购订单-->
        <div slot="22">
          <div style="margin-top: 5px">
            <Card>
              <DkTable :pageFlag="true" primaryKey="orderId" :id="'table-'+$options.name" name="table"
                       @pageChange="orderPageSizeChange" :refreshSelect="false" :show-footer="true"
                       ref="orderTable2" :data="purOrderList" :height="tableHeight - 140" :choose-flag="false">
                <DkTableColumn field="purNo" width="200px"></DkTableColumn>
                <DkTableColumn field="purStatusName" :title="$t('orderStatus')" width="120px"></DkTableColumn>
                <DkTableColumn field="intoStatusName" width="120px"></DkTableColumn>
                <DkTableColumn field="sumQuantity" width="120px" :title="$t('sumQuantity')" sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="sumAmount" width="120px" :title="$t('sumAmount')" :digits="2"
                               sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="intoingAmt" width="150px" :digits="2" sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="intoingQty" width="150px" sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="intoAmt" width="150px" :digits="2" sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="intoQty" width="150px"  sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="contactName" width="120px"></DkTableColumn>
                <DkTableColumn field="contactPhone" width="120px"></DkTableColumn>
                <DkTableColumn field="whName" :title="$t('whId')" width="180px"></DkTableColumn>
                <DkTableColumn field="orgName" :title="$t('orgId')" width="180px"></DkTableColumn>
                <DkTableColumn field="staffName" :title="$t('staffId')" width="120px"></DkTableColumn>
                <DkTableColumn field="makeTime" width="120px" data-type="dateTime"></DkTableColumn>
                <DkTableColumn field="remarks" width="250px"></DkTableColumn>
              </DkTable>
            </Card>
          </div>
        </div>

        <!--采购入库单-->
        <div slot="21">
          <div style="margin-top: 5px">
            <Card>
              <DkTable :pageFlag="true" primaryKey="outId" :id="'table-'+$options.name" name="table"
                       @pageChange="outPageSizeChange" :refreshSelect="false" :show-footer="true"
                       ref="orderTable1" :data="purEnterList" :height="tableHeight - 140" :choose-flag="false">
                <DkTableColumn field="intoNo"/>
                <DkTableColumn field="intoStatusName"></DkTableColumn>
                <DkTableColumn field="intoingQty" dataType="number" sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="intoingAmt" :digits="2" sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="intoQty" dataType="number" sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="intoAmt" :digits="2" dataType="number" sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="intoDate" data-type="date" :dataType="$config.columnType.date"></DkTableColumn>
                <DkTableColumn field="orgName"></DkTableColumn>
                <DkTableColumn field="staffName" :title="$t('staffIds')"></DkTableColumn>
                <DkTableColumn field="makeTime" data-type="dateTime"></DkTableColumn>
                <DkTableColumn field="remarks"></DkTableColumn>
              </DkTable>
            </Card>
          </div>
        </div>

        <!--采购退货单-->
        <div slot="23">
          <div style="margin-top: 5px">
            <Card>
              <DkTable :pageFlag="true" primaryKey="outId" :id="'table-'+$options.name" name="table"
                       @pageChange="outReturnPageSizeChange2" :refreshSelect="false" :show-footer="true"
                       ref="orderTable3" :data="purReturnList" :height="tableHeight - 140" :choose-flag="false">
                <DkTableColumn field="intoNo"/>
                <DkTableColumn field="intoStatusName"></DkTableColumn>
                <DkTableColumn field="intoingQty" sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="intoingAmt" :digits="2" sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="intoQty" sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="intoAmt" :digits="2" sum :dataType="$config.columnType.number"></DkTableColumn>
                <DkTableColumn field="intoDate" :dataType="$config.columnType.date"></DkTableColumn>
                <DkTableColumn field="orgName"></DkTableColumn>
                <DkTableColumn field="staffName" :title="$t('staffIds')"></DkTableColumn>
                <DkTableColumn field="makeTime" data-type="dateTime"></DkTableColumn>
                <DkTableColumn field="remarks"></DkTableColumn>
              </DkTable>
            </Card>
          </div>
        </div>

        <!--付款记录-->
        <div slot="3">
          <Card>
            <DkTable :id="'table-'+$options.name" ref="table-select" :data="receiptList"
                     :pageFlag=true @pageChange="receiptPageSizeChange"
                     :height="tableHeight - 140" primaryKey="receiptId"
                     :choose-flag="false"
                     name="table">
              <DkTableColumn field="rpNo" :title="$t('paymentNo')"/>
              <DkTableColumn field="rpTypeName" :title="$t('paymentType')"/>
              <DkTableColumn field="macNames" :title="$t('macName')"/>
              <DkTableColumn field="amtPay" :digits="2" sum :dataType="$config.columnType.number"/>
              <DkTableColumn field="accDate" :title="$t('paymentDate')"/>
              <DkTableColumn field="orgName"/>
              <DkTableColumn field="staffName" :title="$t('staffIds')"/>
              <DkTableColumn field="makeStaffName"/>
              <DkTableColumn field="makeTime" data-type="dateTime"/>
              <DkTableColumn field="remarks"/>
            </DkTable>
          </Card>
        </div>

        <!--退款记录-->
        <div slot="5">
          <Card>
            <DkTable :id="'table-'+$options.name" ref="table-select" :data="refundList"
                     :pageFlag=true @pageChange="refundPageSizeChange"
                     :height="tableHeight - 140" primaryKey="receiptId"
                     name="table" :choose-flag="false">
              <DkTableColumn field="rpNo" :title="$t('paymentNo')"/>
              <DkTableColumn field="rpTypeName" :title="$t('paymentType')"/>
              <DkTableColumn field="macNames" :title="$t('macName')"/>
              <DkTableColumn field="amtPay" :digits="2" sum :dataType="$config.columnType.number"/>
              <DkTableColumn field="accDate" :title="$t('paymentDate')"/>
              <DkTableColumn field="orgName"/>
              <DkTableColumn field="staffName" :title="$t('staffIds')"/>
              <DkTableColumn field="makeStaffName"/>
              <DkTableColumn field="makeTime" data-type="dateTime"/>
              <DkTableColumn field="remarks"/>
            </DkTable>
          </Card>
        </div>

        <!--供应商信息-->
        <div slot="4">
          <div style="margin-top: 5px;">
            <DkRow>
              <Col span="12">
                <DkRow style="padding-top: 20px">
                  <Col class="col" span="12">
                    {{ $t('supName') + '：' + (formData.supName || '') }}
                  </Col>
                  <Col class="col" span="12">
                    {{ $t('supTypeName') + '：' + (formData.supTypeName || '') }}
                  </Col>
                  <Col class="col" span="12">
                    {{ $t('brandName') + '：' + (formData.brandNames || '') }}
                  </Col>
                  <Col class="col" span="12">
                    {{ $t('contactName') + '：' + (formData.contactName || '') }}
                  </Col>
                  <Col class="col" span="12">
                    {{ $t('contactPhone') + '：' + (formData.contactPhone || '') }}
                  </Col>
                  <Col class="col" span="12">
                    {{ $t('returnAddress') + '：' + (formData.returnAddress || '') }}
                  </Col>
                  <Col class="col" span="12">
                    {{ $t('staffName') + '：' + (formData.staffName || '') }}
                  </Col>
                  <Col class="col" span="12">
                    {{ $t('orgName') + '：' + (formData.orgName || '') }}
                  </Col>
                </DkRow>
              </Col>
            </DkRow>
          </div>
        </div>
      </DkTabs>
    </Card>
  </div>
</template>

<script>

import {indexMixin} from '@/mixins'
import XEUtils from "xe-utils";

export default {
  name: 'supplier-detail',
  mixins: [indexMixin],
  data() {
    let self = this
    return {
      XEUtils: XEUtils,
      formData: {},
      followList: [],
      followListOrigin: [],
      loading: false,
      orderPageInfo: {
        pageSize: this.$config.pageSize,
        currentPage: 1
      },
      purEnterList: [],
      orderPageInfo2: {
        pageSize: this.$config.pageSize,
        currentPage: 1
      },
      purOrderList: [],
      outRejectPageInfo: {
        pageSize: this.$config.pageSize,
        currentPage: 1
      },
      purReturnList: [],
      receiptPageInfo: {
        pageSize: this.$config.pageSize,
        currentPage: 1
      },
      refundPageInfo: {
        pageSize: this.$config.pageSize,
        currentPage: 1
      },
      receiptList: [],
      refundList: [],
      tabsModel: '22',
      tabsOptions: [
        {label: self.$t('purchase'), name: '22'},
        {label: self.$t('purEnter'), name: '21'},
        {label: self.$t('purReturn'), name: '23'},
        {label: self.$t('paymentRecord'), name: '3'},
        {label: self.$t('saleRefund'), name: '5'},
        {label: self.$t('supInfo'), name: '4'},
      ],
    }
  },
  methods: {
    /**
     * @desc   : 通过id查询
     * @author : 付斌
     * @date   : 2024-02-01 14:28
     */
    detail() {
      //编辑将只读属性改为true
      this.loading = true
      //供应商信息
      this.excuteNoParam(this.$service.suppliersService, this.$service.suppliersService.selectById, [this.$route.params.id]).then(res => {
        if (res.code === 200) {
          // 过滤地址中的undefined
          if (res.data.addressFull) {
            res.data.addressFull = res.data.addressFull.replace(/undefined/g, '')
          }
          this.formData = res.data
          this.loading = false

          //查询采购订单
          this.getPurchase()
          //查询采购入库单
          this.getPurEnter()
          //查询销售退货
          this.getPurReturn()
          //查询付款记录
          this.getReceipt()
          //查询退款记录
          this.getRefund()
        } else {
          this.$Message.error(res.message)
          this.loading = false
        }
      })
    },
    /**
    * @desc   : 查询采购入库单
    * @author : 常皓宁
    * @date   : 2024/7/15 14:40
    */
    getPurEnter() {
      let param = {
        supId: this.$route.params.id,
        flgValid: true,
        intoType: this.$config.intoTypeBySql.purchase,
        cpId: this.$store.state.user.cpId,
      }
      this.excute(this.$service.purEnterService, this.$service.purEnterService.selectTotalDetail, param).then(res=>{
        if (res.code == 200) {
          this.purEnterList = res.data.list
          this.$refs['orderTable1'].pageInfo.total = res.data.total
        } else {
          this.$Message.error(res.message)
        }
      })
    },
    /**
    * @desc   : 查询采购订单
    * @author : 常皓宁
    * @date   : 2024/7/15 14:05
    */
    getPurchase() {
      let param = {
        supId: this.$route.params.id,
        flgValid: true,
        cpId: this.$store.state.user.cpId,
      }
      this.excute(this.$service.purOrderService, this.$service.purOrderService.selectTotalDetail, param).then(res=>{
        if (res.code == 200) {
          this.purOrderList = res.data.list
          this.$refs['orderTable2'].pageInfo.total = res.data.total
        } else {
          this.$Message.error(res.message)
        }
      })
    },
    /**
    * @desc   : 查询采购退货单
    * @author : 常皓宁
    * @date   : 2024/7/15 14:49
    */
    getPurReturn() {
      let param = {
        supId: this.$route.params.id,
        flgValid: true,
        intoType: this.$config.intoTypeBySql.purchaseReturn,
        cpId: this.$store.state.user.cpId,
      }
      this.excute(this.$service.purEnterService, this.$service.purEnterService.selectTotalDetail, param).then(res=>{
        if (res.code == 200) {
          this.purReturnList = res.data.list
          this.$refs['orderTable3'].pageInfo.total = res.data.total
        } else {
          this.$Message.error(res.message)
        }
      })
    },
    /**
     * @desc   : 查询付款记录
     * @author : 付斌
     * @date   : 2024-02-01 14:29
     */
    getReceipt() {
      let param = {
        objectId: this.$route.params.id,
        rpTypeList:[this.$config.rpType.fuKuan],
        flgValidList: [true],
        cpId: this.$store.state.user.cpId,
      }
      this.excute(this.$service.receiptService, this.$service.receiptService.getRrpSupList, param).then(res=>{
        if (res.code == 200) {
          this.receiptList = res.data.list
          this.$refs['orderTable2'].pageInfo.total = res.data.total
        } else {
          this.$Message.error(res.message)
        }
      })
    },
    /**
     * @desc   : 查询退款记录
     * @author : 常皓宁
     * @date   : 2024/5/20 16:10
     */
    getRefund(){
      let param = {
        objectId: this.$route.params.id,
        rpTypeList: [this.$config.rpType.tuifuKuan],
        cpId: this.$store.state.user.cpId,
        flgValidList: [true],
      }
      this.excute(this.$service.receiptService, this.$service.receiptService.getRrpSupList, param).then(res=>{
        if (res.code == 200) {
          this.refundList = res.data.list
          this.$refs['orderTable2'].pageInfo.total = res.data.total
        } else {
          this.$Message.error(res.message)
        }
      })
    },
    /**
     * @desc   : 分页
     * @author : 付斌
     * @date   : 2024-02-01 14:29
     */
    orderPageSizeChange(pageInfo) {
      this.orderPageInfo = pageInfo
      this.getPurchase() // 查询数据
    },
    outPageSizeChange(pageInfo) {
      this.orderPageInfo2 = pageInfo
      this.getPurEnter() // 查询数据
    },
    outReturnPageSizeChange2(pageInfo) {
      this.outRejectPageInfo = pageInfo
      this.getPurReturn() // 查询数据
    },
    receiptPageSizeChange(pageInfo) {
      this.receiptPageInfo = pageInfo
      this.getReceipt() // 查询数据
    },
    refundPageSizeChange(pageInfo) {
      this.receiptPageInfo = pageInfo
      this.getRefund() // 查询数据
    },
  },
  activated() {
    //通过id查询
    this.detail()
  }
}
</script>


<style scoped>
.card{
  width: 99%;
  margin-bottom: 10px;
}
.col{
  padding-bottom: 10px;
}
.order-info{
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.order-info>div:nth-child(n){
  text-align: center;
}
.yuan-fh{
  font-size: 8px
}
</style>
