<!-- @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>
        <BaseIndexButton ref="outHandle" name="outHandle"></BaseIndexButton>
        <BaseIndexButton ref="outBack" name="outBack"></BaseIndexButton>
      </template>
      <template #right>
        <BaseIndexButton ref="add" name="add"></BaseIndexButton>
      </template>
    </BaseIndexButtonGroup>

    <!--  查询条件区域  -->
    <div id="search-cond-div" ref="search-cond-div" style="margin-top: 1px;padding: 0">
      <SearchCond ref="searchCond" v-model="searchCond"
                  @collapse-change="collapseChange" :setFlag="false"
                  :searchContent="searchContent"
                  @on-switch-change="changeShowItem"></SearchCond>
    </div>
    <DkSplit mode="vertical" v-model="split" :height="tableHeight">
      <div slot="top" style="margin-left: 5px;">
        <!--  表格部分  -->
        <DkTabs v-model="tabsModel" :options="tabsOptions" @on-click="tabsClick"></DkTabs>
        <!--TODO  :refreshSelect="false" 后续看是否需要去掉-->                 <!--导出权限-->
        <DkTable :pageFlag="true" primaryKey="rejectId" :id="'table-'+$options.name" name="table"
                 @current-change="selectChangeTable" :refreshSelect="false" :show-footer="true"
                 :export-url="$libaray.checkButtonHasRight('sale-export')?'/order-server/sale/purchase_return/export/':''"
                 :export-condition="exportCondition"
                 sum-total-type="total"
                 @pageChange="pageSizeChange" ref="table-select" :data="tableData"
                 :height="this.tableHeight * split - 60">
          <!--所属公司-->
          <DkTableColumn field="cpName"></DkTableColumn>
          <!--退货单号-->
          <DkTableColumn field="rejectNo"></DkTableColumn>
          <!--退货日期-->
          <DkTableColumn field="makingTime" :dataType="$config.columnType.date"></DkTableColumn>
          <!--供应商-->
          <DkTableColumn field="supplierName"></DkTableColumn>
          <!--退货状态-->
          <DkTableColumn field="rejectStatusName" title="退货状态"></DkTableColumn>
          <!--出库状态-->
          <DkTableColumn field="outStatusString" :color-cards="['未出库','出库中','出库完成']"></DkTableColumn>
          <!--出库日期-->
          <DkTableColumn field="outDate"></DkTableColumn>
          <!--退件收货人-->
          <DkTableColumn field="contactName"></DkTableColumn>
          <!--退件收货电话-->
          <DkTableColumn field="contactPhones"></DkTableColumn>
          <!--退件收货地址-->
          <DkTableColumn field="addressFull"></DkTableColumn>
          <!--退货数量-->
          <DkTableColumn field="sumRejectQuantity"></DkTableColumn>
          <!--退货金额-->
          <DkTableColumn field="sumRejectAmount" ></DkTableColumn>
          <!--出库数量-->
          <DkTableColumn field="outOutQuantity"></DkTableColumn>
          <!--出库金额-->
          <DkTableColumn field="outOutAmount" ></DkTableColumn>
          <!--制单人-->
          <DkTableColumn field="makingUserPurName"></DkTableColumn>
          <!--出库办理人-->
          <DkTableColumn field="doneUserName"></DkTableColumn>
          <!--推送状态-->
          <DkTableColumn field="erpPushStatusString"></DkTableColumn>
          <!--推送结果-->
          <DkTableColumn field="erpPushResult"></DkTableColumn>
          <!--备注-->
          <DkTableColumn field="remarks"></DkTableColumn>
        </DkTable>
      </div>
      <div slot="bottom">
        <DkTabs v-model="detailModel" :options="detailOptions" @on-click="detailTabsClick"></DkTabs>
        <!--订单明细-->
        <div v-show="visGoodsDetailFlag">
          <DkTable :pageFlag="false" :pageTotalFlag="false" primaryKey="itemId"
                   :id="'table-'+$options.name" :show-footer="true"
                   :export-url="$libaray.checkButtonHasRight('sale-export')?'/order-server/sale/purchase_return_item/export/'+rejectId:''"
                   name="table" ref="detail-select" :data="tableDataDetail_goodsDetail"
                   :height="this.tableHeight * (1-split)">
            <DkTableColumn
              v-for="(item, index) in tableDataTitle_goodsDetail"
              :key="detailModel+index"
              align="center"
              :type="item.type"
              :field="item.field"
              :title="item.title"
              :sum="item.sum"
              :digits="item.digits"
              :width="item.width"
              :dataType="item.dataType"
              :tree-node="item.treeNode"
            >
            </DkTableColumn>
          </DkTable>
        </div>
        <!--条码明细-->
        <div v-show="visBarcodeDetailsFlag">
          <DkTable :pageFlag="false" :pageTotalFlag="false" primaryKey="itemId"
                   :id="'table-'+$options.name" :show-footer="true"
                   :export-url="$libaray.checkButtonHasRight('sale-export')?'/order-server/sale/purchase_return_item/export/'+rejectId:''"
                   name="table" ref="detail-select" :data="tableDataDetail_barCodeDetail"
                   :height="this.tableHeight * (1-split)">
            <DkTableColumn
              v-for="(item, index) in tableDataTitle_barCodeDetail"
              :key="detailModel+index"
              align="center"
              :type="item.type"
              :field="item.field"
              :title="item.title"
              :sum="item.sum"
              :digits="item.digits"
              :width="item.width"
              :dataType="item.dataType"
              :tree-node="item.treeNode"
            >
            </DkTableColumn>
          </DkTable>
        </div>
        <!--附件-->
        <div v-show="visFilesDetailFlag">
          <DkTable :pageFlag="false" :pageTotalFlag="false" :id="'table-'+$options.name"
                   name="table" ref="file-select" :data="tableDataDetail_files" :height="this.tableHeight * (1-split)">
            <DkTableColumn field="docType" min-width="150" width="150"></DkTableColumn>
            <DkTableColumn field="name" min-width="300" width="300"></DkTableColumn>
            <vxe-column field="createTime" min-width="150" width="150"></vxe-column>
            <vxe-column :title="$t('picture')" class-name="img-column" width="100">
              <template #default="{row}">
                <img :src="$config.imgUrl + row.url" v-if="row.type == 'img' || row.type == 'image'"
                     style="width: 100px; height: 100px; cursor: pointer;"
                     @click="openFile(row)"/>
              </template>
            </vxe-column>
            <vxe-column>
              <template #default="{row}">
                <DkButton @click="openFile(row)">
                  <Icon type="md-download"/>
                </DkButton>
              </template>
            </vxe-column>
          </DkTable>
        </div>
      </div>
    </DkSplit>
  </div>
</template>

<script>

import {indexMixin} from '@/mixins'

export default {
  name: 'purchase-return',
  mixins: [indexMixin],
  data() {
    let self = this
    return {
      rejectStatusFlag: true,
      visGoodsDetailFlag: true,
      visBarcodeDetailsFlag: false,
      visFilesDetailFlag: false,
      totalTab: null,//存放总单tab切换到那个标签
      // 模式切换值
      tabsModel: 'all',
      tabsOptions: [
        {label: self.$t('all'), name: 'all'}, //全部
        {label: self.$t('inApproval'), name: 'inApproval'}, //审批中
        {label: self.$t('returning'), name: 'returning'},//退货中
        {label: self.$t('returned'), name: 'returned'},//已退货
        {label: self.$t('noApproval'), name: 'noApproval'},//审拒绝
      ],
      detailModel: 'goodsDetail',
      detailOptions: [{label: self.$t('goodsDetail'), name: 'goodsDetail'}, //货物明细
        {label: self.$t('barCodeDetail'), name: 'barCodeDetail'}, //条码明细
        {label: self.$t('filesDetail'), name: 'filesDetail'}, //附件明细
      ],
      //总单导出条件
      exportCondition: null,
      tableData: [],
      tableDataDetail_goodsDetail: [],  // 用于存放订单明细数据
      tableDataDetail_barCodeDetail: [], // 用于条码明细数据
      tableDataDetail_files: [],  // 用于存放订单附件
      tableDataTitle_goodsDetail: [
        //采购入库单号
        {field: 'entryNo', title: self.$t('entryPurchaseNo')},
        //采购订单号
        {field: 'orderNo', title: self.$t('procureOrderNo1')},
        //商品型号
        {field: 'skuModel'},
        //商品名称
        {field: 'skuName'},
        //唯一编码
        {field: 'skuCode'},
        //采购退货数量
        {
          field: 'rejectQuantity',
          title: self.$t('purchaseReturnQuantity'),
          type: 'text',
          digits: 0,
          sum: true
        },
        //采购单价
        {
          field: 'rejectPrice',
          title: self.$t('orderPriceSale'),
          digits: 0,
          type: 'number',
          sum: true,
          UserSensitiveFlag: true
        },
        //采购金额
        {
          field: 'rejectAmount',
          title: self.$t('purchasePrice'),
          type: 'number',
          digits: 2,
          sum: true,
          UserSensitiveFlag: true
        },
        //已出库数量
        {
          field: 'outGoingQuantity',
          title: self.$t('outboundQuantity'),
          type: 'number',
          digits: 2,
          sum: true
        },
        //未出库数量
        {
          field: 'outQuantity',
          title: self.$t('undeliveredQuantity'),
          type: 'number',
          digits: 2,
          sum: true
        },
        //单位
        {field: 'unitName'},
        //商品品牌
        {field: 'brandName'},
        //型号分类
        {field: 'skuTypeName', title: self.$t('skuTypeBom')},
        //仓库名称
        {field: 'whName', title: self.$t('whName')},
        //备注
        {field: 'remarks'},
      ],
      tableDataTitle_barCodeDetail: [
        //出库单号
        {field: 'outNo'},
        //商品型号
        {field: 'skuModel'},
        //商品名称
        {field: 'skuName'},
        //唯一编码
        {field: 'skuCode'},
        //商品条码
        {field: 'skuBarcode'},
        //箱码
        {field: 'boxcode'},
        //扫码日期
        {field: 'opCreateTime'},
        //操作员
        {field: 'opCreateUserName'},
      ],
      rejectId: 0,//查询明细需要的总单Id
      searchContent: [
        {
          itemCode: '退货单号-文本',
          itemName: 'rejectNo',
          valueFormat: {code: 'rejectNo'},
          valueKind: 'STR'
        },
        {
          itemCode: '采购订单号-文本',
          itemName: 'procureOrderNo1',
          valueFormat: {code: 'orderNo'},
          valueKind: 'STR'
        },
        {
          itemCode: '供应商',
          valueFormat: {code: 'supplierId'},
          valueKind: 'S-SEARCH',
          magnifierType: self.$config.MagnifierType.staff,
        },
        {
          itemCode: '收货人-文本',
          itemName: 'consignee',
          valueFormat: {code: 'contactName'},
          valueKind: 'STR'
        },
        {
          itemCode: '收货地址-文本',
          itemName: 'takeOverAddress',
          valueFormat: {code: 'addressFull'},
          valueKind: 'STR'
        },
        {
          itemCode: '所属公司',
          valueFormat: {code: 'asCpIds'},
          valueKind: 'M-SEARCH',
          magnifierType: self.$config.MagnifierType.staff,
        },
        {
          itemCode: '商品编码-文本',
          itemName: 'goodCode',
          valueFormat: {code: 'skuCode'},
          valueKind: 'STR'
        },
        {
          itemCode: '商品名称-文本',
          itemName: 'skuName',
          valueFormat: {code: 'skuName'},
          valueKind: 'STR'
        },
        {
          itemCode: '商品型号-文本',
          itemName: 'skuModel',
          valueFormat: {code: 'skuModel'},
          valueKind: 'STR'
        },
        {
          itemCode: '出库状态-下拉',
          itemName: 'outStatus',
          valueFormat: {
            code: 'outStatusList',
            data: [
              {valueKey: '出库状态-未收', flgValid: '未出库'},
              {valueKey: '出库状态-部分', flgValid: '出库中'},
              {valueKey: '出库状态-完成', flgValid: '出库完成'}],
            valueKey: 'valueKey',
            labelKey: 'flgValid',
            default: []
          },
          valueKind: 'M-CHOICE'
        },
        {
          itemCode: '制单时间-时间',
          itemName: 'rejectDate',
          valueFormat: {
            code: 'makingTime',
            default: [new Date().addMonths(-1).format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd')]
          },
          valueKind: 'DATE_RANGE'
        },
        {
          itemCode: '来源单号-文本',
          itemName: 'entryPurchaseNo',
          valueFormat: {code: 'refundSourceNo'},
          valueKind: 'STR'
        },
        {
          itemCode: '不查冲正单据',
          itemName: '不查冲正单据',
          valueFormat: {code: 'rejectStatusFlag', default: true},
          valueKind: 'SWITCH'
        },
      ],
    }
  },

  methods: {
    /**
     * @desc   : 新建
     * @author : 付斌
     * @date   : 2024-02-19 9:59
     */
    add() {
      this.$router.push('/pur/purReject/add')
    },
    /**
     * @desc   : 不查冲正单据
     * @author : 付斌
     * @date   : 2024/02/20 15:56
     */
    changeShowItem({code, e}) {

    },
    /**
     * @desc   : 打开附件
     * @author : 付斌
     * @date   : 2024/02/20 19:56
     */
    openFile(row) {
      window.open(this.$config.imgUrl + row.url)
    },
    /**
     * @desc   : 一览查询
     * @author : 付斌
     * @date   : 2024/02/20 16:05
     */
    initData(currentPage, StringOrderTab) {

    },
    /**
     * @desc   : 调用api方法进行查询
     * @author : 付斌
     * @date   : 2024/02/20 16:10
     */
    getData(StringOrderTab) {

    },
    /**
     * @desc   : 出库撤销
     * @author : 付斌
     * @date   : 2024-02-20 11:25
     */
    outBack() {

    },
    /***************************列表及其他事件************************************/

    /**
     * @desc   : 分页
     * @author : 付斌
     * @date   : 2022/3/17 15:01
     */
    pageSizeChange(pageInfo) {
    },
    /**
     * @desc   : 总单行事件选择
     * @author : 付斌
     * @date   : 2024-02-20 11:26
     */
    selectChangeTable(e) {

    },
    /**
     * @desc   : 总单tab切换
     * @author : 付斌
     * @date   : 2024-02-20 11:26
     */
    tabsClick(val) {

    },
    /**
     * @desc   : 点击Tab进行切换
     * @author : 付斌
     * @date   : 2024-02-19 11:33
     */
    detailTabsClick(val) {
      if (val === 'goodsDetail') {
        this.visGoodsDetailFlag = true
        this.visBarcodeDetailsFlag = false
        this.visFilesDetailFlag = false
      } else if (val === 'barCodeDetail') {
        this.visGoodsDetailFlag = false
        this.visBarcodeDetailsFlag = true
        this.visFilesDetailFlag = false
      } else if (val === 'filesDetail') {
        this.visGoodsDetailFlag = false
        this.visBarcodeDetailsFlag = false
        this.visFilesDetailFlag = true
      }
    },
    /***************************设定参数函数************************************/

    /***************************created调用数据接口函数************************************/

  },
  /**
   * @desc   : 在实例创建完成后被立即同步调用
   * @author : 付斌
   * @date   : 2024/02/20 10:32
   */
  created() {
    this.primaryKey = 'purRejectId'  // 设置主键Id
    this.routeObjName = 'purReject'  // 设置路由名称
  },
}
</script>
