<!-- @desc:收发存汇总报表查询  @auth:宋扬  @time:2024-02-18 16:28 -->
<template>
  <div class="main-div" ref="mainDiv">
    <!--加载中-->
    <loading :loading="loading" v-if="!modalVisible"></loading>
    <BaseIndexButtonGroup id="BaseIndexButtonGroup">
      <template #left>
        <!--    查询    -->
        <BaseIndexButton right-button="user-select" ref="search" name="search"></BaseIndexButton>
        <!--    清空条件    -->
        <BaseIndexButton ref="clear" name="clear"></BaseIndexButton>
      </template>

    </BaseIndexButtonGroup>

    <!--  卡片区  -->
    <div class="index-card">
      <!--  查询条件区域  -->
      <div id="search-cond-div" ref="search-cond-div" class="search-cond-class">
        <SearchCond ref="searchCond" v-model="searchCond"
                    @collapse-change="collapseChange" :setFlag="false"
                    :searchContent="searchContent"
        ></SearchCond>
      </div>
      <!--  表格部分  -->
      <div slot="bottom">
        <DkTabs v-model="detailModel" :options="detailOptions" @on-click="detailTabsClick"></DkTabs>
        <div v-show="visGoodsDetailFlag">
          <DkTable :id="'table-'+$options.name"
                   ref="table-select"
                   :data="tableData"
                   showFooter
                   :height="this.tableHeight-59"
                   primaryKey="invId"
                   @pageChange="pageSizeChange"
                   :page-total="pageInfo.total"
                   :current-page="pageInfo.currentPage"
                   :choose-flag="false"
                   :page-size-opts="pageSizeOpts"
                   :page-size="pageInfo.pageSize"
                   name="table">
            <DkTableColumn field="skuModel"/>
            <DkTableColumn field="skuName"/>
            <DkTableColumn field="nonStdCode" />
            <DkTableColumn field="brandName" />
            <DkTableColumn field="whName" />
            <DkTableColumn field="openingIvtQty"dataType="number" :sum="true" />
            <DkTableColumn field="openingIvtAmt"dataType="number" :sum="true" />
            <DkTableColumn field="currentIntoQty" dataType="number" type="link" @on-link="currentIntoRights()"></DkTableColumn>
            <DkTableColumn field="currentIntoAmt"dataType="number" :sum="true" />
            <DkTableColumn field="currentOutQty" dataType="number" type="link" @on-link="currentOutRights()"></DkTableColumn>
            <DkTableColumn field="currentOutAmt"dataType="number" :sum="true" />
            <DkTableColumn field="endingIvtQty"dataType="number" :sum="true" />
            <DkTableColumn field="endingIvtAmt"dataType="number" :sum="true" />
          </DkTable>
        </div>
        <div v-show="visIntoDetailFlag">
          <DkTable :id="'table-'+$options.name" ref="detail-select" :data="intoDetailData" showFooter
                   :height="this.tableHeight -35"
                   primaryKey="invId"
                   @pageChange="pageSizeChange"
                   :page-total="pageInfo.total"
                   :current-page="pageInfo.currentPage"
                   :choose-flag="false"
                   :page-size-opts="pageSizeOpts"
                   :page-size="pageInfo.pageSize"
                   name="table">
            <!-- 入库单号-->
            <DkTableColumn field="intoNo" width="auto"></DkTableColumn>
            <!-- 单据类型-->
            <DkTableColumn field="intoTypeName" width="auto"></DkTableColumn>
            <!-- 入库日期-->
            <DkTableColumn field="intoDate" width="auto" :dataType="$config.columnType.date"
            ></DkTableColumn>
            <!-- 来源单号-->
            <DkTableColumn field="fromNo" width="auto"></DkTableColumn>
            <!-- 已入库数量-->
            <DkTableColumn field="intoQty"
                           :sum="true" dataType="number" ></DkTableColumn>
            <!-- 已入库金额-->
            <DkTableColumn field="intoAmt"
                           :sum="true" dataType="number"></DkTableColumn>
            <!-- 仓库-->
            <DkTableColumn field="whName"></DkTableColumn>
            <!-- 商品型号-->
            <DkTableColumn field="skuModel"/>
            <!-- 商品名称-->
            <DkTableColumn field="skuName"/>
            <!-- 唯一编码-->
            <DkTableColumn field="skuCode"/>
            <!-- 品牌-->
            <DkTableColumn field="brandName"/>
            <!-- 非标号-->
            <DkTableColumn field="nonStdCode" />
            <!--制单人-->
            <DkTableColumn field="makeStaffName" :filter="false"></DkTableColumn>
            <!-- 备注-->
            <DkTableColumn field="remarks" :filter="false"></DkTableColumn>
          </DkTable>
        </div>
        <div v-show="visOutDetailFlag">
          <DkTable :id="'table-'+$options.name" ref="detail-select" :data="outDetailData" showFooter
                   :height="this.tableHeight-35"
                   primaryKey="invId"
                   @pageChange="pageSizeChange"
                   :page-total="pageInfo.total"
                   :current-page="pageInfo.currentPage"
                   :choose-flag="false"
                   :page-size-opts="pageSizeOpts"
                   :page-size="pageInfo.pageSize"
                   name="table">
            <!-- 出库单号-->
            <DkTableColumn field="outNo" width="auto"></DkTableColumn>
            <!-- 来源单号-->
            <DkTableColumn field="fromNo" width="auto"></DkTableColumn>
            <!-- 单据类型-->
            <DkTableColumn field="outTypeName" width="auto"></DkTableColumn>
            <!-- 出库日期-->
            <DkTableColumn field="outDate" width="auto" :dataType="$config.columnType.date"
            ></DkTableColumn>
            <!-- 已出库数量-->
            <DkTableColumn field="outQty"
                           :sum="true" dataType="number" ></DkTableColumn>
            <!-- 已出库金额-->
            <DkTableColumn field="outAmt"
                           :sum="true" dataType="number" ></DkTableColumn>
            <!-- 仓库-->
            <DkTableColumn field="whName"></DkTableColumn>
            <!-- 商品型号-->
            <DkTableColumn field="skuModel"/>
            <!-- 商品名称-->
            <DkTableColumn field="skuName"/>
            <!-- 唯一编码-->
            <DkTableColumn field="skuCode"/>
            <!-- 品牌-->
            <DkTableColumn field="brandName"/>
            <!-- 非标号-->
            <DkTableColumn field="nonStdCode" />
            <!--制单人-->
            <DkTableColumn field="makeStaffName" :filter="false"></DkTableColumn>
            <!-- 备注-->
            <DkTableColumn field="remarks" :filter="false"></DkTableColumn>
          </DkTable>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {indexMixin} from '@/mixins'
import Config from "@/config";
export default {
  name: "ivt-sum-report",
  mixins: [indexMixin],
  data() {
    let self = this
    return {
      detailModel: 'invGoodsDetail',
      detailOptions: [
        {label: self.$t('invGoodsDetail'), name: 'invGoodsDetail'}, //库存明细
        {label: self.$t('intoDetail'), name: 'intoDetail'}, //入库明细
        {label: self.$t('outDetail'), name: 'outDetail'}, //出库明细
      ],
      tableData:[],         // 库存商品
      intoDetailData:[],    // 入库明细
      outDetailData: [],    // 出库明细
      visGoodsDetailFlag: true,
      visIntoDetailFlag: false,
      visOutDetailFlag: false,
      searchContent:
        [
          {
            itemCode: 'skuName',
          },
          {
            itemCode: 'skuModel',
          },
          {
            itemCode: 'nonStdCode',
          },
          {
            itemCode: 'whName',
            valueFormat: {
              code: 'whList',
            },
            magnifierType: Config.MagnifierType.warehouse,
            valueKind: 'M-SEARCH'
          },
          {
            itemCode: 'accDate',
            valueFormat: {
              code: 'accDate',
              default: [new Date().addMonths(-1).format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd')]
            },
            valueKind: 'DATE_RANGE',
          },
        ],
      // 查询条件
      searchCond: {}
    }
  },
  methods: {
    /**
     * @desc   : 查询数据
     * @author : 宋扬
     * @date   : 2024/3/13 10:42
     */
    getData(params) {
      // 清空数据
      this.tableData = [];
      this.intoDetailData = [];
      this.outDetailData = [];
      // 自动显示收发存数据
      this.visGoodsDetailFlag = true
      this.visIntoDetailFlag = false
      this.visOutDetailFlag = false
      return this.excute(this.$service.detailReportService, this.$service.detailReportService.getIvtSumReport, params)
    },

    /**
     * @desc   : 点击Tab进行切换
     * @author : 宋扬
     * @date   : 2024/4/3 16:24
     */
    detailTabsClick(val) {
      if (val === 'invGoodsDetail') {
        this.detailModel = val
        this.visGoodsDetailFlag = true
        this.visIntoDetailFlag = false
        this.visOutDetailFlag = false
      } else if (val === 'intoDetail' && this.intoDetailData.length > 0) {
        this.detailModel = val
        this.visGoodsDetailFlag = false
        this.visIntoDetailFlag = true
        this.visOutDetailFlag = false
      }else if (val === 'outDetail' && this.outDetailData > 0) {
        this.detailModel = val
        this.visGoodsDetailFlag = false
        this.visIntoDetailFlag = false
        this.visOutDetailFlag = true
      }
    },
    /**
     * @desc   : 赋值查询条件
     * @author : 宋扬
     * @date   : 2024/4/23 10:44
     */
    setSearchParams(params){
      // 赋值JSON查询条件
      let skuquerys = {}
      if(this.searchCond && this.searchCond._value){
        Object.assign(skuquerys,this.searchCond._value)
      }
      let skuQuerystr = JSON.stringify(skuquerys);
      if(skuQuerystr && skuQuerystr !='{}'){
        params['querys']= skuQuerystr;
      }
      return params;
    },

    /**
     * @desc   : 入库点击跳转事件
     * @author : 宋扬
     * @date   : 2024/4/23 13:22
     */
    currentIntoRights(row){
      this.intoDetailData = [];
      if (!row) {
        row = [this.$refs['table-select'].getCurrentRow()]
      }
      let searchParams = {...this.searchParams};
      let params={}
      if (row != null) {
        // 赋值入库查询条件
        params = {
          invId:row[0].invId,
          invType:1,
          accDateStart:searchParams.accDateStart,
          accDateEnd:searchParams.accDateEnd,
          currentPage:searchParams.currentPage,
          pageSize:searchParams.pageSize
        }
      }
      // 查询入库明细
      this.excute(this.$service.detailReportService, this.$service.detailReportService.getIvtItemReport, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.intoDetailData = res.data.list;
          // 显示入库明细信息页面
          this.detailModel = 'intoDetail'
          this.visGoodsDetailFlag = false
          this.visIntoDetailFlag = true
          this.visOutDetailFlag = false
        }
      })
    },

    /**
     * @desc   : 出库点击跳转事件
     * @author : 宋扬
     * @date   : 2024/4/23 13:22
     */
    currentOutRights(row){
      this.outDetailData = [];
      if (!row) {
        row = [this.$refs['table-select'].getCurrentRow()]
      }
      let searchParams = {...this.searchParams};
      let params={}
      if (row != null) {
        // 赋值出库查询条件
        params = {
          invId:row[0].invId,
          invType:2,
          accDateStart:searchParams.accDateStart,
          accDateEnd:searchParams.accDateEnd,
          currentPage:searchParams.currentPage,
          pageSize:searchParams.pageSize
        }
      }
      // 查询出库明细
      this.excute(this.$service.detailReportService, this.$service.detailReportService.getIvtItemReport, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          this.outDetailData = res.data.list;
          // 显示出库明细信息页面
          this.detailModel = 'outDetail'
          this.visGoodsDetailFlag = false
          this.visIntoDetailFlag = false
          this.visOutDetailFlag = true
        }
      })
    },

  },
  created() {
    this.primaryKey = 'invId'  // 设置主键Id
    this.routeObjName = 'detailReport'  // 设置路由名称
  }
}
</script>


