<!-- @desc:明细报表  @auth:付斌  @time:2024/02/20 15:15 -->
<template>
  <div class="main-div">
    <BaseIndexButtonGroup id="BaseIndexButtonGroup">
      <template #left>
        <BaseIndexButton 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"
                    @on-switch-change="handleSwitchChange"></SearchCond>
      </div>

      <!--  表格部分  -->
      <DkTable slot="top" :id="'table-'+$options.name"
               ref="table-select" name="table" :data="tableData"
               @pageChange="pageSizeChange"
               :page-total="pageInfo.total"
               :page-size="pageInfo.pageSize"
               :page-size-opts="pageSizeOpts"
               :current-page="pageInfo.currentPage"
               :choose-flag="false"
               :height="tableHeight-30" :showFooter="showFooter">
        <div v-for="(item, index) in columns" :key="item.field">
          <DkTableColumn
            :type="item.type"
            :field="item.field"
            :title="item.title"
            :digits="item.digits"
            :sum="item.sum"
            :dataType="item.dataType"
            :align="item.align"
            @on-link="(row)=>handleLink(row,item)"
          >
          </DkTableColumn>
        </div>
      </DkTable>
    </div>

  </div>
</template>

<script>

import {indexMixin} from '@/mixins'
import setting from "./setting";

export default {
  name: 'detail-report',
  mixins: [indexMixin],
  data() {
    return {
      service: {},
      methodsName: null,
      showFooter: true,
      columns: [],
      columns_socail: [],// 记录原始列
      detailColumns: [],
      searchContent: [],
    }
  },

  methods: {
    /**
    * @desc   : 链接跳转
    * @author : 常皓宁
    * @date   : 2024/5/21 16:55
    */
    handleLink(row,item){
      console.log('row',row,item)
      if(row && item['linkType']){
        //客户跳转
        if(item['linkType'] == 'CUS'){
          this.$router.push('/mst/customer/detail/' + row['cusId'])
        }
        //订单跳转
        if(item['linkType'] == 'ORD'){
          this.$router.push('/sale/order/edit/' + row['orderId'])
        }
        //采购跳转
        if(item['linkType'] == 'PUR'){
          this.$router.push('/pur/pur-order/edit/' + row['purId'])
        }
        //入库跳转
        if(item['linkType'] == 'INTO'){
          //采购入库
          if(row['intoTypeName'] == this.$config.intoType.purchase){
            this.$router.push('/pur/pur-enter/edit/' + row['intoId'])
          }
          //采退入库
          if(row['intoTypeName'] == this.$config.intoType.saleReturn){
            this.$router.push('/pur/pur-return/edit/' + row['intoId'])
          }
          //其他入库
          else if(row['intoTypeName'] == this.$config.intoType.other){
            this.$router.push({
              name: 'entry-handle-edit',
              params: {id: row['intoId']}
            });
          }
        }
        //出库跳转
        if(item['linkType'] == 'OUT'){
          //销售出库
          if(row['outTypeName'] == this.$config.outType.sale){
            this.$router.push('/sale/order-out/edit/' + row['outId'])
          }
          //销退回库
          if(row['outTypeName'] == this.$config.outType.saleReturn){
            this.$router.push('/sale/order-return/edit/' + row['outId'])
          }
          //其他出库
          else if(row['outTypeName'] == this.$config.outType.other){
            this.$router.push({
              name: 'out-handle-edit',
              params: {id: row['outId']}
            });
          }
        }
      }
    },
    /**
     * @desc   : desc
     * @author : 周兴
     * @date   : 2024/4/9 13:21
     */
    handleSwitchChange(e) {
      let code = e.code
      let checked = e.e;
      // 查看明细
      if (code == 'flgViewItem') {
        // 勾选，把明细列显示出来
        if (checked && this.detailColumns && this.detailColumns.length > 0) {
          this.columns = this.columns.union(this.detailColumns);
        }
        // 还原列
        if (!checked) {
          this.columns = this.columns_socail.copy();
        }
        this.routeNameByExport = this.$route.name + '-item'
      }else{
        this.routeNameByExport = this.$route.name
      }
    },
    /**
     * @desc   : 查询数据
     * @author : 周兴
     * @date   : 2024-02-20 15:53
     */
    getData(params) {
      return this.excute(this.service, this.service[this.methodsName], params)
    },
    /**
     * @desc   : 根据类型给属性赋值
     * @author : 周兴
     * @date   : 2022/3/16 18:12
     */
    setProperty() {
      let self = this
      // 设置接口相关信息
      console.log('eee',self.formType)
      let set = setting.setSetting(this.$service, self.formType);
      self = this.objectMerge(self, set)
      if (self.pageSize) {
        self.pageInfo.pageSize = self.pageSize;
      }
      // 对下拉查询条件查询数据源
      this.getSelectDataSource();
      this.columns_socail = this.columns.copy();
    },
    /**
     * @desc   : 获取下拉的数据源
     * @author : 周兴
     * @date   : 2024/4/9 13:56
     */
    getSelectDataSource() {
      let filters = this.searchContent.filter(it => it.valueKind == 'M-CHOICE' || it.valueKind == 'S-CHOICE');
      if (filters && filters.length > 0) {
        filters.forEach(it => {
          if (it.valueFormat && it.valueFormat.service && it.valueFormat.method) {
            // 系统字典直接读取缓存
            if(it.valueFormat.method == 'getDataKind'){
              let dataKindList =this.$store.state.user.dataKindList
              let data = dataKindList.filter(t=>t.kindType == it.valueFormat.kindType);
              it.valueFormat.data = data
            }else{
              this.excute(this.$service[it.valueFormat.service],
                this.$service[it.valueFormat.service][it.valueFormat.method], {}).then(res => {
                if (res.code === this.$config.SUCCESS_CODE) {
                  let data = []
                  if (res.data && res.data.list) {
                    data = [...res.data.list]
                  }
                  if (data.length === 0 && res.data && Array.isArray(res.data)) {
                    data = [...res.data]
                  }
                  it.valueFormat.data = data
                }
              })
            }
          }
        })
      }
    },
    /**
     * @desc   : 同一页面的初始化方法
     * @author : 周兴
     * @date   : 2024/4/9 12:54
     */
    createdInit() {
      this.setProperty();
      this.routeObjName = 'detailReport'
    },
  },
  /**
   * @desc   : 在实例创建完成后被立即同步调用
   * @author : 周兴
   * @date   : 2022/3/3 10:32
   */
  created() {
  },
}
</script>

