<!-- @desc:采购跟踪  @auth:常皓宁  @time:2024/04/22 09:15 -->
<template>
  <div slot="top">
    <DkTabs v-model="tabsModel" :options="tabsOptions" @on-click="tabsClick"></DkTabs>
    <!--    采购订单-->
    <DkCollapse @on-change="changeCollapse" ref="collapse" v-if="this.tabsModel ==='purchase' ">
      <DkPanel prop="essentialInformation">
        <!--  单据信息  -->
        <DkForm slot="content" ref="formInline" v-model="purData"
                style="width:100%" :label-max-words="5">
          <!--采购单号-->
          <DkFormItem prop="purNo" :label="$t('purNo')">
            <InputPop ref="purNo" v-model="purData.purNo" :readonly="true"/>
          </DkFormItem>
          <!--供应商-->
          <DkFormItem prop="supId" :label="$t('supplierName')" :required="true">
            <InputPop ref="purNo" v-model="purData.supplierName" :readonly="true"/>
          </DkFormItem>
          <!--收货时间-->
          <DkFormItem :label="$t('DeliveryDate')"
                      prop="pickupDate" :required="true" :data-type="$config.dataType.date">
            <DatePickerPop v-model="purData.pickupDate"
                           :placeholder="$t('inputWords',{'search-name':$t('DeliveryDate')})"
                           type="date" :short-cut-flag="true" :readonly="true"/>
          </DkFormItem>
          <!--收货仓库-->
          <DkFormItem prop="whId" :label="$t('wareHouse')" :required="true">
            <InputPop ref="purNo" v-model="purData.whName" :readonly="true"/>
          </DkFormItem>
          <!--收货人-->
          <DkFormItem prop="contactName" :label="$t('contactName')">
            <InputPop ref="contactName" :readonly="true" v-model="purData.contactName"/>
          </DkFormItem>
          <!--收货电话-->
          <DkFormItem prop="contactPhone" :label="$t('contactPhone')">
            <InputPop :telephone="true" ref="contactPhone" :readonly="true" v-model="purData.contactPhone"/>
          </DkFormItem>
          <!--备注-->
          <DkFormItem prop="remarks" :span="12">
            <InputPop ref="remarks" v-model="purData.remarks"
                      maxlength=500 :readonly="true"/>
          </DkFormItem>
        </DkForm>
      </DkPanel>
      <!--商品信息-->
      <DkPanel prop="goodsInformation">
        <div id="pur-order" ref="pur-order" slot="content">
          <EditTable v-if="purFlag"
                     ref="purChaseTable"
                     majorField="purItemId"
                     :data="purChaseItemList"
                     :columns="goodsColumns"
                     :height="400"
                     :freeze="false"
                     :show-footer="true"
                     :delete-flag="false"
                     :add-flag="false"
          ></EditTable>
        </div>
      </DkPanel>
    </DkCollapse>
    <!--    采购入库单-->
    <DkCollapse @on-change="changeCollapse" ref="collapse" v-if="this.tabsModel ==='purEnter' ">
      <DkTabs v-model="tabsModel1" :options="tabsOptions1" @on-click="tabsClick1" v-if="tabFlag"></DkTabs>
      <DkPanel prop="essentialInformation">
        <!--  单据信息  -->
        <DkForm slot="content" ref="formInline" v-model="purEntryData"
                style="width:100%" :label-max-words="5">
          <!--供应商-->
          <DkFormItem prop="supId" :label="$t('supplierName')" :required="true">
            <InputPop ref="purNo" v-model="purEntryData.supplierName" :readonly="true"/>
          </DkFormItem>
          <!--收货仓库-->
          <DkFormItem prop="whId" :label="$t('wareHouse')" :required="true">
            <InputPop ref="purNo" v-model="purEntryData.whName" :readonly="true"/>
          </DkFormItem>
          <!-- 采购人 -->
          <DkFormItem prop="makingUser" :label="$t('staffPurName')">
            <InputPop ref="purNo" v-model="purEntryData.makeStaffName" :readonly="true"/>
          </DkFormItem>
          <!--部门-->
          <DkFormItem prop="orgId" :label="$t('department')">
            <InputPop ref="purNo" v-model="purEntryData.orgName" :readonly="true"/>
          </DkFormItem>
          <!--来源单号-->
          <DkFormItem prop="fromNo" :label="$t('fromNo')">
            <InputPop ref="fromNo" v-model="purEntryData.fromNo" :readonly="true"/>
          </DkFormItem>
          <!--入库日期-->
          <DkFormItem prop="intoDate" :label="$t('intoDate')">
            <DatePickerPop v-model="purEntryData.intoDate"
                           :placeholder="$t('inputWords',{'search-name':$t('intoDate')})"
                           type="date" :short-cut-flag="true" :readonly="true"/>
          </DkFormItem>
          <!--备注-->
          <DkFormItem prop="remarks" :span="12">
            <InputPop ref="remarks" v-model="purEntryData.remarks"
                      maxlength=500 :readonly="true"/>
          </DkFormItem>
        </DkForm>
      </DkPanel>
      <!--商品信息-->
      <DkPanel prop="goodsInformation">
        <div id="pur-enter" ref="pur-enter" slot="content">
          <EditTable v-if="purEntryFlag"
                     ref="purEntryTable"
                     majorField="intoItemId"
                     :data="purEntryItemList"
                     :columns="purEntryColumns"
                     :height="400"
                     :freeze="false"
                     :show-footer="true"
                     :delete-flag="false"
                     :add-flag="false"
          ></EditTable>
        </div>
      </DkPanel>
    </DkCollapse>
    <!--    采购退货单-->
    <DkCollapse @on-change="changeCollapse" ref="collapse" v-if="this.tabsModel ==='purReturn' ">
      <DkTabs v-model="tabsModel2" :options="tabsOptions2" @on-click="tabsClick2" v-if="tabFlag1"></DkTabs>
      <DkPanel prop="essentialInformation">
        <!--  单据信息  -->
        <DkForm slot="content" ref="formInline" v-model="purReturnData"
                style="width:100%" :label-max-words="5">
          <!--供应商-->
          <DkFormItem prop="supId" :label="$t('supplierName')" :required="true">
            <InputPop ref="purNo" v-model="purReturnData.supName" :readonly="true"/>
          </DkFormItem>
          <!--收货仓库-->
          <DkFormItem prop="whId" :label="$t('wareHouse')" :required="true">
            <InputPop ref="purNo" v-model="purReturnData.whName" :readonly="true"/>
          </DkFormItem>
          <!-- 采购人 -->
          <DkFormItem prop="makingUser" :label="$t('staffPurName')">
            <InputPop ref="purNo" v-model="purReturnData.makeStaffName" :readonly="true"/>
          </DkFormItem>
          <!--部门-->
          <DkFormItem prop="orgId" :label="$t('department')">
            <InputPop ref="purNo" v-model="purReturnData.orgName" :readonly="true"/>
          </DkFormItem>
          <!--来源单号-->
          <DkFormItem prop="fromNo" :label="$t('fromNo')">
            <InputPop ref="fromNo" v-model="purReturnData.fromNo" :readonly="true"/>
          </DkFormItem>
          <!--入库日期-->
          <DkFormItem prop="intoDate" :label="$t('intoDate')">
            <DatePickerPop v-model="purReturnData.intoDate"
                           :placeholder="$t('inputWords',{'search-name':$t('intoDate')})"
                           type="date" :short-cut-flag="true" :readonly="true"/>
          </DkFormItem>
          <!--备注-->
          <DkFormItem prop="remarks" :span="12">
            <InputPop ref="remarks" v-model="purReturnData.remarks"
                      maxlength=500 :readonly="true"/>
          </DkFormItem>
        </DkForm>
      </DkPanel>
      <!--商品信息-->
      <DkPanel prop="goodsInformation">
        <div id="pur-return" ref="pur-return" slot="content">
          <EditTable v-if="purReturnFlag"
                     ref="purReturnable"
                     majorField="retuenItemId"
                     :data="purReturnItemList"
                     :columns="purReturnColumns"
                     :height="400"
                     :freeze="false"
                     :show-footer="true"
                     :delete-flag="false"
                     :add-flag="false"
          ></EditTable>
        </div>
      </DkPanel>
    </DkCollapse>
    <!--    订单付款-->
    <DkCollapse @on-change="changeCollapse" ref="collapse" v-if="this.tabsModel ==='purPay'">
      <!--商品信息-->
      <DkPanel prop="BillInformation">
        <div id="pur-pay" ref="pur-pay" slot="content">
          <EditTable v-if="purPayFlag"
                     ref="purReturnable"
                     majorField="retuenItemId"
                     :data="purPayData"
                     :columns="purPayColumns"
                     :height="400"
                     :freeze="false"
                     :show-footer="true"
                     :delete-flag="false"
                     :add-flag="false"
          ></EditTable>
        </div>
      </DkPanel>
    </DkCollapse>
  </div>

</template>

<script>
import {indexMixin} from '@/mixins'
import {formMixin} from "@/mixins/form";

export default {
  name: "pur-track-report",
  mixins: [formMixin],
  data() {
    let self = this
    return {
      tabFlag:false,
      tabFlag1:false,
      purFlag:true,
      purEntryFlag: true,
      purReturnFlag: true,
      purPayFlag:true,
      purData: {},//采购订单
      purChaseItemList: [],//采购订单明细
      //采购订单明细列
      goodsColumns: [
        {
          field: 'skuCode',
          type: 'disabled',
        },
        {
          field: 'skuName',
          type: 'disabled',
        },
        {
          field: 'pricePur',
          type: 'disabled',
          digits: 2,
          number: true,
          sum: true
        },//采购价
        {
          field: 'pricePurchase',
          type: 'disabled',
          digits: 2,
          number: true,
          sum: true
        },//采购标价
        {
          field: 'intoingQty',
          type: 'disabled',
          number: true,
          sum: true
        },//入库中数量
        {
          field: 'intoingAmt',
          type: 'disabled',
          digits: 2,
          number: true,
          sum: true
        },//入库中金额
        {
          field: 'intoQty',
          type: 'disabled',
          number: true,
          sum: true
        },//已入库数量
        {
          field: 'intoAmt',
          type: 'disabled',
          digits: 2,
          number: true,
          sum: true
        },//已入库金额
        {
          field: 'returnQty',
          type: 'disabled',
          number: true,
          sum: true
        },//已入库退货数量
        {
          field: 'returnAmt',
          type: 'disabled',
          digits: 2,
          number: true,
          sum: true
        },//已入库退货金额
        {
          field: 'intoStatusName',
          type: 'disabled',
        },//入库状态
        {
          field: 'remarks',
        },
      ],

      purEntryData: {},//采购入库单
      purEntryItemList: [],//采购入库单明细
      //采购入库明细列
      purEntryColumns: [
        {
          field: 'skuCode',
          type: 'disabled',
        },
        {
          field: 'skuName',
          type: 'disabled',
        },
        {
          field: 'priceInto',
          type: 'disabled',
          digits: 2,
          number: true,
          sum: true
        },//入库价
        {
          field: 'intoingQty',
          type: 'disabled',
          number: true,
          sum: true
        },//入库中数量
        {
          field: 'intoingAmt',
          type: 'disabled',
          digits: 2,
          number: true,
          sum: true
        },//入库中金额
        {
          field: 'intoQty',
          type: 'disabled',
          number: true,
          sum: true
        },//已入库数量
        {
          field: 'intoAmt',
          type: 'disabled',
          digits: 2,
          number: true,
          sum: true
        },//已入库金额
        {
          field: 'intoStatusName',
          type: 'disabled',
        },//入库状态
      ],

      purReturnData:{},//采购退货
      purReturnItemList:[],//采购退货明细
      //采购退货明细列
      purReturnColumns:[
        {
          field: 'skuCode',
          type: 'disabled',
        },
        {
          field: 'skuName',
          type: 'disabled',
        },
        {
          field: 'intoingQty',
          type: 'disabled',
          number: true,
          sum: true
        },//入库中数量
        {
          field: 'intoingAmt',
          type: 'disabled',
          digits: 2,
          number: true,
          sum: true
        },//入库中金额
        {
          field: 'intoQty',
          type: 'disabled',
          number: true,
          sum: true
        },//已入库数量
        {
          field: 'intoAmt',
          type: 'disabled',
          digits: 2,
          number: true,
          sum: true
        },//已入库金额
        {
          field: 'intoStatusName',
          type: 'disabled',
        },//入库状态
      ],

      purPayData:[],//订单收款
      purPayColumns:[
        {
          field: 'intoNo',
          type: 'disabled',
        },//入库单号
        {
          field: 'amtPayableHandle',
          type: 'disabled',
        },//核销金额
        {
          field: 'amtWaive',
          type: 'disabled',
        },//优惠金额
        {
          field: 'accDate',
          type: 'disabled',
        },//账务日期
      ],

      purNo: null,//采购订单号
      purEntryVOList: [],//入库
      purReturnVOList:[],//退货
      // 模式切换值
      tabsModel: 'purchase',
      tabsOptions: [{label: self.$t('purchase'), name: 'purchase'}, //采购订单
        {label: self.$t('purEnter'), name: 'purEnter'}, //采购入库单
        {label: self.$t('purReturn'), name: 'purReturn'},//采购退货
        {label: self.$t('purPay'), name: 'purPay'},//订单收款
      ],
      tabsModel1: null,
      tabsModel2: null,
      tabsModel3: null,
      tabsOptions1: [],
      tabsOptions2: [],
      tabsOptions3: [],
    }
  },
  methods: {
    /**
     * @desc   : tab切换
     * @author : 常皓宁
     * @date   : 2024/4/22 13:44
     */
    tabsClick(val) {
      this.purEntryFlag = false
      this.purReturnFlag = false
      this.purPayFlag = false
      //如果切换的tab存在就去根据条件查询
      if (val) {
        this.totalTab = val
        if(val == 'purchase'){
          setTimeout(() => {
            this.purFlag = true;
            this.purEntryFlag = false;
            this.purReturnFlag = false;
            this.purPayFlag = false;
          }, 100)
        }
        else if(val == 'purEnter'){
          setTimeout(() => {
            this.purFlag = false;
            this.purEntryFlag = true;
            this.purReturnFlag = false;
            this.purPayFlag = false;
          }, 100)
        }
        else if(val == 'purReturn'){
          setTimeout(() => {
            this.purFlag = false;
            this.purEntryFlag = false;
            this.purReturnFlag = true;
            this.purPayFlag= false;
          }, 100)
        }
        else if(val == 'purPay'){
          setTimeout(() => {
            this.purFlag = false;
            this.purEntryFlag = false;
            this.purReturnFlag = false;
            this.purPayFlag= true;
          }, 100)
        }

      }
    },
    /**
     * @desc   : 入库tab切换
     * @author : 常皓宁
     * @date   : 2024/4/22 13:44
     */
    tabsClick1(val) {
      //如果切换的tab存在就去根据条件查询
      if (val) {
        this.totalTab = val
        this.purEntryVOList.forEach(it => {
          if (it.intoNo == val) {
            this.purEntryData = it
            this.purEntryItemList = it.purEntryItemVOList
          }
        })
      }
    },
    /**
     * @desc   : 退货tab切换
     * @author : 常皓宁
     * @date   : 2024/4/22 13:44
     */
    tabsClick2(val) {
      //如果切换的tab存在就去根据条件查询
      if (val) {
        this.totalTab = val
        this.purReturnVOList.forEach(it => {
          if (it.intoNo == val) {
            this.purReturnData = it
            this.purReturnItemList = it.purReturnItemVOList
          }
        })
      }
    },
    /**
     * @desc   : 通过id查询
     * @author : 常皓宁
     * @date   : 2024/2/29 8:49
     */
    getPur(id) {
      let params = {
        purId: id,
        cpId:this.$store.state.user.cpId
      }
      this.excute(this.$service.purOrderService, this.$service.purOrderService.selectTrackReport, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.purData = res.data.list[0]
          this.purChaseItemList = res.data.list[0].purItemVOList
          this.purEntryVOList = res.data.list[0].purEntryVOList
          this.purReturnVOList = res.data.list[0].purReturnVOList
          let purEntryList = res.data.list[0].purEntryVOList
          if (purEntryList && purEntryList.length > 0) {
            this.tabFlag = true
            this.purEntryData = this.purEntryVOList[0]
            this.purEntryItemList = res.data.list[0].purEntryVOList[0].purEntryItemVOList
            this.tabsOptions1 = purEntryList.map(m => {
              return {label: m.intoNo, name: m.intoNo}
            })
          }
          let purReturnList = res.data.list[0].purReturnVOList
          if (purReturnList && purReturnList.length > 0) {
            this.tabFlag1 = true
            this.purReturnData = this.purReturnVOList[0]
            this.purReturnItemList = res.data.list[0].purReturnVOList[0].purReturnItemVOList
            this.tabsOptions2 = purReturnList.map(m => {
              return {label: m.retuenIntoNo, name: m.retuenIntoNo}
            })
          }
          this.purPayData = res.data.list[0].purPayList
        }
      })
    },
  },
  created() {
    this.getPur(this.$route.params.row.purId)
  },
  activated() {
  },
}
</script>

<style scoped>

</style>
