<!-- @desc:销售出库 @auth:付斌 @time : 2023/9/25 14:45 -->
<template>
  <div class="main-div">
    <BaseIndexButtonGroup id="BaseIndexButtonGroup">
      <template #left>
        <BaseIndexButton ref="search" name="search"></BaseIndexButton>
        <BaseIndexButton ref="clear" name="clear"></BaseIndexButton>
        <BaseIndexButton ref="edit" name="edit" :isMustChooseFlag="false"></BaseIndexButton>
        <!-- 出库办理-->
        <BaseIndexButton ref="outHandle" name="outHandle" :isMustChooseFlag="false"></BaseIndexButton>
        <!-- 出库撤回-->
        <BaseIndexButton ref="outBack" name="outBack" :isMustChooseFlag="false"></BaseIndexButton>
        <!--出库冲正-->
        <BaseIndexButton ref="outReverse" name="outReverse" :isMustChooseFlag="false"></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"></SearchCond>
    </div>
    <!--  表格部分  -->
    <DkSplit mode="vertical" v-model="split" :height="tableHeight">
      <div slot="top" style="width: 100%;height: 100%;top: 0;">
        <DkTabs v-model="tableModel" :options="tabsOptions" @on-click="initData(1)"></DkTabs>
        <DkTable
          ref="table-select"
          :data="tableData"
          :height="tableHeight/2-70"
          primaryKey="outId"
          :show-footer="true"
          @current-change="currentChangeStandard"
          @pageChange="pageSizeChange">
          <DkTableColumn field="outNo" :type="$libaray.checkButtonHasRight('order-edit')?'link':''"
                         @on-link="edit"></DkTableColumn>
          <DkTableColumn field="orderNo"></DkTableColumn>
          <DkTableColumn field="cusName"></DkTableColumn>
          <DkTableColumn field="cusPhone"></DkTableColumn>
          <DkTableColumn field="contactPhone"></DkTableColumn>
          <DkTableColumn field="addressFull"></DkTableColumn>
          <DkTableColumn field="outingQty" sum></DkTableColumn>
          <DkTableColumn field="outingAmt"></DkTableColumn>
          <DkTableColumn field="outStatusName"></DkTableColumn>
          <DkTableColumn field="orgName"></DkTableColumn>
          <DkTableColumn field="staffName"></DkTableColumn>
          <DkTableColumn field="returnQty"></DkTableColumn>
          <DkTableColumn field="returnAmt"></DkTableColumn>
          <DkTableColumn field="remarks"></DkTableColumn>
          <DkTableColumn field="makeStaffName"></DkTableColumn>
          <DkTableColumn field="makeTime" data-type="dateTime"></DkTableColumn>
        </DkTable>
      </div>
      <!-- 明细表格 -->
      <div slot="bottom">
        <DkTabs v-model="tabsModel" :options="detailTabsOptions" @on-click="tabsClick"></DkTabs>
        <!-- 出库明细-->
        <div v-show="standardGoodsFlag">
          <DkTable ref="standardGoodsFlag"
                   primaryKey="itemId"
                   :id="'table-'+$options.name"
                   name="table2" :data="goodsDetailData"
                   :height="this.tableHeight/2-40" s
                   :show-footer="true"
                   :select-flag="false"
                   :pageFlag="false"
                   :pageTotalFlag="false">
            <DkTableColumn field="orderNo"></DkTableColumn>
            <DkTableColumn field="skuModel"></DkTableColumn>
            <DkTableColumn field="skuName"></DkTableColumn>
            <DkTableColumn field="skuCode"></DkTableColumn>
            <DkTableColumn field="outStatusName"></DkTableColumn>
            <DkTableColumn field="outingQty" sum></DkTableColumn>
            <DkTableColumn field="outQty" sum></DkTableColumn>
            <DkTableColumn field="priceSale"></DkTableColumn>
            <DkTableColumn field="outAmt" sum></DkTableColumn>
            <DkTableColumn field="whName"></DkTableColumn>
            <DkTableColumn field="nonStdCode"></DkTableColumn>
            <DkTableColumn field="returnQty" sum></DkTableColumn>
            <DkTableColumn field="returnAmt" sum></DkTableColumn>
            <DkTableColumn field="remarks"></DkTableColumn>
          </DkTable>
        </div>
        <!--  附件明细-->
        <div v-show="reviewResumeFlag">
          <DkTable :pageFlag="false" :pageTotalFlag="false" :id="'table-'+$options.name"
                   name="table" ref="file-select" :data="tableDataDetail_files" :height="tableHeight-15">
            <DkTableColumn field="docType" min-></DkTableColumn>
            <DkTableColumn field="name"></DkTableColumn>
            <DkTableColumn field="createTime" min-></DkTableColumn>
            <vxe-column :title="$t('picture')" class-name="img-column">
              <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: 'sale-out',
  mixins: [indexMixin],
  data() {
    let self = this
    return {
      searchContent: [
        {
          itemCode: '出库单号-文本',
          itemName: 'outNo',
          valueFormat: {code: 'outNo'},
          valueKind: 'STR'
        },
        {
          itemCode: '订单单号-文本',
          itemName: 'orderNo',
          valueFormat: {code: 'orderNo'},
          valueKind: 'STR'
        },
        {
          itemCode: '客户电话-文本',
          itemName: 'cusPhone',
          valueFormat: {code: 'customerPhone'},
          valueKind: 'STR'
        },
        {
          itemCode: '客户名称-文本',
          itemName: 'cusName',
          valueFormat: {code: 'customerName'},
          valueKind: 'STR'
        },
        {
          itemCode: '制单时间-日期',
          itemName: 'makeTime',
          //valueFormat: {code: 'makeTime'},
          valueFormat: {
            code: 'makeTime',
            default: [new Date().addMonths(-1).format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd')]
          },
          valueKind: 'DATE_RANGE',
        },
        // {
        //   itemCode: '出库日期-日期',
        //   itemName: 'outDate',
        //   valueFormat: {
        //     code: 'outDate',
        //     default: [new Date().addMonths(-1).format('yyyy-MM-dd'), new Date().format('yyyy-MM-dd')]
        //   },
        //   valueKind: 'DATE_RANGE',
        // },
        {
          itemCode: '出库状态-下拉',
          itemName: 'outStatus',
          valueFormat: {
            code: 'outStatusList',
            data: [
              {outStatus: '出库状态-未出库', outStatusName: '未出库'},
              {outStatus: '出库状态-出库中', outStatusName: '出库中'},
              {outStatus: '出库状态-出库完成', outStatusName: '出库完成'}],
            valueKey: 'outStatus',
            labelKey: 'outStatusName',
            default: []
          },
          valueKind: 'M-CHOICE'
        },
        {
          itemCode: '业务部门-文本',
          itemName: 'orgId',
          valueFormat: {
            code: 'orgId',
            data: [],
            valueKey: 'orgId',
            labelKey: 'orgName',
          },
          valueKind: 'M-CHOICE'
        },
        {
          itemCode: '业务员-文本',
          itemName: 'staffId',
          valueFormat: {
            code: 'staffId',
            data: [],
            valueKey: 'staffId',
            labelKey: 'staffCodeName',
          },
          valueKind: 'M-CHOICE'
        },
      ],
      orgList: [],//部门
      staffList: [],//业务员
      channelList: [],//渠道
      fromList: [],//客户来源
      companyList: [],//所属公司
      outStatusList: [],//出库状态
      tableHeight: 600,
      tableModel: 'waitOut',
      tabsModel: 'goodsDetail',
      tabsOptions: [
        {
          label: this.$t('waitOut'),
          name: 'waitOut'//待出库
        },
        {
          label: this.$t('ingOut'),
          name: 'ingOut'//已出库
        }
      ],
      detailTabsOptions: [
        {
          label: this.$t('goodsDetail'),
          name: 'goodsDetail'
        },
        {
          label: this.$t('filesDetail'),
          name: 'filesDetail'
        }
      ],
      standardGoodsFlag: true,
      barcodeDetailsFlag: false,
      reviewResumeFlag: false,
      goodsDetailData: [],//出库明细
      barCodeData: [],//条码明细
      tableDataDetail_files: [],  // 用于存放订单附件
    }
  },
  methods: {
    /**
     * @desc   : 出库单号超链接
     * @author : 付斌
     * @date   : 2023/11/15 15:11
     */
    edit(row) {
      this.$router.push('/sale/saleOut/edit/')
    },
    /**
     * @desc   : 出库办理
     * @author : 付斌
     * @date   : 2024-02-27 13:17
     */
    outHandle() {
      this.$router.push('/sale/saleOut/handle/')
    },

    /**
     * @desc   : 回退
     * @author : 付斌
     * @date   : 2023/9/01 14:02
     */
    outBack() {

    },


    /**
     * @desc   : 冲正
     * @author : 付斌
     * @date   : 2023/9/01 14:02
     */
    revert() {

    },
    /**
     * @desc   : 打开附件
     * @author : 付斌
     * @date   : 2022-07-19 19:56
     */
    openFile(row) {
      window.open(this.$config.imgUrl + row.url)
    },

    /**
     * @desc   : 明细tab切换事件
     * @author : 付斌
     * @date   : 2023/8/31 14:58
     */
    tabsClick(val) {
      if (val === 'goodsDetail') {
        this.standardGoodsFlag = true
        this.barcodeDetailsFlag = false
        this.reviewResumeFlag = false
      }
      if (val === 'barcodeDetails') {
        this.standardGoodsFlag = false
        this.barcodeDetailsFlag = true
        this.reviewResumeFlag = false
      } else if (val === 'filesDetail') {
        this.standardGoodsFlag = false
        this.barcodeDetailsFlag = false
        this.reviewResumeFlag = true
      }
    },
    /**
     * @desc   : 显示数量改变事件
     * @author : 付斌
     * @date   : 2023/8/31 14:25
     */
    pageSizeChange(pageInfo) {

    },
    /**
     * @desc   : 初始加载
     * @author : 付斌
     * @date   : 2023/8/31 13:50
     */
    initData(currentPage) {
      //查询业务部门
      this.selectOrg()
      //查询业务员
      this.selectStaff()
    },
    /**
     * @desc   : 查询业务部门
     * @author : 付斌
     * @date   : 2024-02-26 14:27
     */
    selectOrg() {
      let params = {
        cpId: 1,//this.$store.state.user.cpId,
        flgValid: true
      }
      this.excute(this.$service.commonService, this.$service.commonService.getOrg, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          let list = this.searchContent.filter(it => it.valueFormat.code == 'orgId')
          if (list.length > 0) {
            list[0].valueFormat.data = res.data
          }
        }
      })
    },
    /**
     * @desc   : 查询业务员
     * @author : 付斌
     * @date   : 2024-02-26 14:27
     */
    selectStaff() {
      let params = {
        cpId: 1,//this.$store.state.user.cpId,
        flgValid: true
      }
      this.excute(this.$service.commonService, this.$service.commonService.getStaff, params).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          let list = this.searchContent.filter(it => it.valueFormat.code == 'staffId')
          if (list.length > 0) {
            list[0].valueFormat.data = res.data
          }
        }
      })
    },
    /**
     * @desc   : 查询数据
     * @author : 付斌
     * @date   : 2023/8/31 13:57
     */
    getData() {

    },
    /**
     * @desc   : 行改变事件
     * @author : 付斌
     * @date   : 2023/9/27 14:03
     */
    currentChangeStandard({row}) {

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