<template>
  <div class="app-container">
    <button-bar ref="btnbar" view-title="在途商品汇总统计表" :btndisabled="btndisabled" @btnhandle="btnHandle" />
    <div class="main-content">
      <div class="searchcon">
        <el-button size="small" class="searchbtn" @click="clicksearchShow">
          {{ searchxianshitit }}
        </el-button>
        <div v-show="isSearchShow" class="search">
          <el-form ref="queryParams" :model="jmdListQuery" :inline="true" class="tab-header">
            <el-form-item label="日期">
              <el-date-picker v-model="jmdListQuery.date" type="date" clearable value-format="yyyy-MM-dd"
                placeholder="选择日期" />
            </el-form-item>
          </el-form>
          <div class="btn" style="text-align: center;">
            <el-button type="primary" size="small" icon="el-icon-search" @click="dosearch">查询</el-button>
            <el-button type="primary" size="small" icon="el-icon-refresh" @click="resetQuery">重置</el-button>
          </div>
        </div>
      </div>
      <el-row style="margin-left: 20px;margin-right: 20px;">
        <el-col>
          <el-tabs  v-model="tabActiveName" @tab-click="handleOrder">
            <el-tab-pane label="到货汇总表" name="uplog">
              <div>
                <el-table v-loading="tableLoading1" :data="logList" border style="width: 100%">
                  <el-table-column fixed width="100" type="index" label="序号" :index="indexMethod" align="center" />
                  <el-table-column prop="supplierName" label="供应商名称" align="center" />
                  <el-table-column prop="loanAmount" label="贷款金额"  width="150" align="center" />
                  <el-table-column prop="orderAmount" label="订单金额"  width="150" align="center" />
                  <el-table-column prop="actualArrival" label="实际到货价值"  width="150"align="center" />
                  <el-table-column prop="transit" label="在途货价值" width="150" align="center" />
                  <el-table-column prop="exceed" label="超出货价值"  width="150"align="center" />
                  <el-table-column prop="arrivalDate" label="全部到货日期" width="150" align="center" />
                  <el-table-column prop="logo" label="是否延期到货"  width="150" align="center" />
                </el-table>
              </div>
              <div class="pages">
                <!-- 翻页 -->
                <pagination v-show="logListTotal > 0" :total="logListTotal" :page.sync="logListQuery.current"
                  :limit.sync="logListQuery.size" class="pagination" @pagination="loadLogList" />
              </div>
            </el-tab-pane>
            <el-tab-pane label="商品到货明细表" name="k112">
              <div>
                <el-table v-loading="tableLoading2" :data="in112List" border style="width: 100%">
                  <el-table-column fixed width="100" type="index" label="序号" :index="indexMethod2" align="center" />
                  <el-table-column prop="supplierName" label="供应商名称" align="center" />
                  <el-table-column prop="code" label="商品编码"  width="120" align="center" />
                  <el-table-column prop="proName" label="商品名称"  align="center" />
                  <el-table-column prop="number" label="单品数量"  width="100"align="center" />
                  <el-table-column prop="orderAmount" label="订单商品价值" width="140" align="center" />
                  <el-table-column prop="actualArrivalNumber" label="实际到货数量"  width="140"align="center" />
                  <el-table-column prop="actualArrival" label="实际到货价值" width="120" align="center" />
                  <el-table-column prop="transitNumber" label="在途货数量" width="120" align="center" />
                  <el-table-column prop="transit" label="在途货价值"  width="120"align="center" />
                  <el-table-column prop="exceed" label="超出货价值"  width="120"align="center" />
                </el-table>
              </div>
              <div class="pages">
                <!-- 翻页 -->
                <pagination v-show="in112ListTotal > 0" :total="in112ListTotal" :page.sync="in112ListQuery.current"
                  :limit.sync="in112ListQuery.size" class="pagination" @pagination="loadIn112List" />
              </div>
            </el-tab-pane>
            <el-tab-pane label="订单明细表" name="all">
              <div>
                <el-table v-loading="tableLoading3" :data="inallList" border style="width: 100%">
                  <el-table-column fixed width="100" type="index" label="序号" :index="indexMethod3" align="center" />
                  <el-table-column prop="supplierName" label="供应商名称" align="center" />
                  <el-table-column prop="code" label="订单编号" align="center" />
                  <el-table-column prop="orderAmount" label="订单金额" align="center" />
                  <el-table-column prop="purchaseDate" label="订单日期" align="center" />
                  <el-table-column prop="arrivalDate" label="到货日期" align="center" />
                </el-table>
              </div>
              <div class="pages">
                <!-- 翻页 -->
                <pagination v-show="inallListTotal > 0" :total="inallListTotal" :page.sync="inallListQuery.current"
                  :limit.sync="inallListQuery.size" class="pagination" @pagination="loadInallList" />
              </div>
            </el-tab-pane>
            <el-tab-pane label="商品到货明细表（烟草）" name="hz">
              <div>
                <el-table v-loading="tableLoading4" :data="inall4List" border style="width: 100%">
                  <el-table-column fixed width="100" type="index" label="序号" :index="indexMethod4" align="center" />
                  <el-table-column prop="supplierName" label="供应商名称" align="center" />
                  <el-table-column prop="storeName" label="销售渠道" align="center" />
                  <el-table-column prop="orderAmount" label="订单商品价值" align="center" />
                  <el-table-column prop="orderArrivalAmount" label="订单到货价值" align="center" />
                  <el-table-column prop="actualArrival" label="实际到货价值" align="center" />
                  <el-table-column prop="transit" label="在途货价值" align="center" />
                  <el-table-column prop="exceed" label="超出货价值" align="center" />
                </el-table>
              </div>
              <div class="pages">
                <!-- 翻页 -->
                <pagination v-show="inall4ListTotal > 0" :total="inall4ListTotal" :page.sync="inall4ListQuery.current"
                  :limit.sync="inall4ListQuery.size" class="pagination" @pagination="inall4List" />
              </div>
            </el-tab-pane>
            <el-tab-pane label="订单明细表（烟草）" name="jmd">
              <div>
                <el-table v-loading="tableLoading5" :data="inall5List" border style="width: 100%">
                  <el-table-column fixed width="100" type="index" label="序号" :index="indexMethod5" align="center" />
                  <el-table-column prop="supplierName" label="供应商名称" align="center" />
                  <el-table-column prop="code" label="订单编号" align="center" />
                  <el-table-column prop="loanAmount" label="放款金额" align="center" />
                  <el-table-column prop="orderAmount" label="订单金额" align="center" />
                  <el-table-column prop="purchaseDate" label="订单日期" align="center" />
                  <el-table-column prop="arrivalDate" label="到货日期" align="center" />
                  <el-table-column prop="actualArrival;" label="实际到货价值" align="center" />
                  <el-table-column prop="transit" label="在途货价值" align="center" />
                </el-table>
              </div>
              <div class="pages">
                <!-- 翻页 -->
                <pagination v-show="inall5ListTotal > 0" :total="inall5ListTotal" :page.sync="inall5ListQuery.current"
                  :limit.sync="inall5ListQuery.size" class="pagination" @pagination="inall5List" />
              </div>
            </el-tab-pane>
          </el-tabs>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
  import {
    in112PagerList,
    inallPagerList,
    logPagerList,
    inall4PagerList,
    inall5PagerList,
  } from '@/api/inventorySummary/inventorySummary'
  import Pagination from '@/components/pagination'
  import {
    parseTime
  } from '@/utils/index'
  import ButtonBar from '@/components/ButtonBar'
  export default {
    components: {
      ButtonBar,
      Pagination
    },
    data() {
      return {
          tabActiveName: 'uplog',
        index: "0",
        isSearchShow: false,
        searchxianshitit: '显示查询条件',
        btndisabled: false,
        tableLoading1: false,
        tableLoading2: false,
        tableLoading3: false,
        tableLoading4: false,
        tableLoading5: false,
        btnList: [ // 右上角按钮
          {
            type: 'success',
            size: 'small',
            icon: 'export',
            btnKey: 'build',
            btnLabel: '导出'
          },
          {
            type: 'info',
            size: 'small',
            icon: 'cross',
            btnKey: 'doClose',
            btnLabel: '关闭'
          }
        ],
        logList: [],
        logListQuery: {
          current: 1,
          size: 10
        },
        logListTotal: 1,
        in112List: [],
        in112ListQuery: {
          current: 1,
          size: 10
        },
        in112ListTotal: 1,
        inallList: [],
        inallListQuery: {
          current: 1,
          size: 10
        },
        inallListTotal: 1,
        inall4List: [],
        inall4ListQuery: {
          current: 1,
          size: 10
        },
        inall4ListTotal: 1,
        inall5List: [],
        inall5ListQuery: {
          current: 1,
          size: 10
        },
        inall5ListTotal: 1,
        jmdListQuery: {
          date: parseTime(new Date(), '{y}-{m}-{d}')
        }
      }
    },
    mounted() {
      // 初始化按钮
      this.$refs['btnbar'].setButtonList(this.btnList)
    },
    created() {
      // 初始化变量
      this.init()
    },
    methods: {
      // 搜索条件效果
      clicksearchShow() {
        this.isSearchShow = !this.isSearchShow
        if (this.isSearchShow) {
          this.searchxianshitit = '隐藏查询条件'
        } else {
          this.searchxianshitit = '显示查询条件'
        }
      },
      dosearch() {
        this.jmdListQuery = {
          date: parseTime(new Date(), '{y}-{m}-{d}')
        }
        if (this.index == "0") {
          this.loadLogList()
        } else if (this.index == "1") {
          this.loadInallList()
        } else if (this.index == "2") {
          this.loadIn112List()
        } else if (this.index == "3") {
          this.loadInall4List()
        } else if (this.index == "4") {
          this.loadInall5List()
        }

      },
      resetQuery() {
        this.jmdListQuery = {
          date: parseTime(new Date(), '{y}-{m}-{d}')
        }
      },
      // 右上角点击事件
      btnHandle(btnKey) {
        switch (btnKey) {
          case 'build': // 导出
            this.doBuild()
            break
          case 'doClose': // 关闭
            this.doClose()
            break
          default:
            break
        }
      },
      init() {
        this.loadLogList()
      },
      handleOrder(tab, event) {
        console.log("tab", tab)
        // this.listQuery.status = tab.name;
        // this.getList();
        // this.orderDatas(tab.name);

        this.index = tab.index

        switch (tab.index) {
          // 供应商到货汇总表
          case "0":
            if (this.logList.length == 0)
              this.loadLogList()

            break;
            // 商品到货明细表
          case "1":
            if (this.in112List.length == 0)
              this.loadIn112List()
            break;
            // 订单明细
          case "2":
            if (this.inallList.length == 0)
              this.loadInallList()
            break;
            // 商品到货明细（烟草）
          case "3":
            if (this.inall4List.length === 0)
              this.loadInall4List()
            break;
            //  订单明细（烟草）
          case "4":
            if (this.inall5List.length === 0)
              this.loadInall5List()
            break;
          default:
            break;
        }

      },
      loadLogList() {
        logPagerList({
          current: this.logListQuery.current,
          size: this.logListQuery.size,
          params: {
            date: ''
          }
        }).then(response => {
          if (response.code === '200' && response.data && response.data.total > 0) {
            this.logList = response.data.records
            this.logListTotal = response.data.total
            this.logListQuery.current = response.data.current
            this.logListQuery.size = response.data.size
          } else {
            this.logList = []
            this.logListTotal = 0
          }
        })
      },
      // 序号
      indexMethod(index) {
        var pagestart = (this.logListQuery.current - 1) * this.logListQuery.size
        var pageindex = index + 1 + pagestart
        return pageindex
      },
      loadIn112List() {
        in112PagerList({
          current: this.in112ListQuery.current,
          size: this.in112ListQuery.size,
          params: {
            date: ''
          }
        }).then(response => {
          if (response.code === '200' && response.data && response.data.total > 0) {
            this.in112List = response.data.records
            this.in112ListTotal = response.data.total
            this.in112ListQuery.current = response.data.current
            this.in112ListQuery.size = response.data.size
          } else {
            this.in112List = []
            this.in112ListTotal = 0
          }
        })
      },
      // 序号
      indexMethod2(index) {
        var pagestart = (this.in112ListQuery.current - 1) * this.in112ListQuery.size
        var pageindex = index + 1 + pagestart
        return pageindex
      },
      loadInallList() {
        inallPagerList({
          current: this.inallListQuery.current,
          size: this.inallListQuery.size,
          params: {
            date: ''
          }
        }).then(response => {
          if (response.code === '200' && response.data && response.data.total > 0) {
            this.inallList = response.data.records
            this.inallListTotal = response.data.total
            this.inallListQuery.current = response.data.current
            this.inallListQuery.size = response.data.size
          } else {
            this.inallList = []
            this.inallListTotal = 0
          }
        })
      },
      // 序号
      indexMethod3(index) {
        var pagestart = (this.inallListQuery.current - 1) * this.inallListQuery.size
        var pageindex = index + 1 + pagestart
        return pageindex
      },
      loadInall4List() {
        this.tableLoading4 = true
        inall4PagerList({
          current: this.inall4ListQuery.current,
          size: this.inall4ListQuery.size,
          params: {
            date: ""
          }
        }).then(response => {
          this.tableLoading4 = false
          if (response.code === '200' && response.data && response.data.total > 0) {
            this.inall4List = response.data.records
            this.inall4ListTotal = response.data.total
            this.inall4ListQuery.current = response.data.current
            this.inall4ListQuery.size = response.data.size
          } else {
            this.inall4List = []
            this.inall4ListTotal = 0
          }
        })
      },
      // 序号
      indexMethod4(index) {
        var pagestart = (this.inall4ListQuery.current - 1) * this.inall4ListQuery.size
        var pageindex = index + 1 + pagestart
        return pageindex
      },

      loadInall5List() {
        this.tableLoading5 = true
        inall5PagerList({
          current: this.inall5ListQuery.current,
          size: this.inall5ListQuery.size,
          params: {
            date: ""
          }
        }).then(response => {
          this.tableLoading5 = false
          if (response.code === '200' && response.data && response.data.total > 0) {
            this.inall5List = response.data.records
            this.inall5ListTotal = response.data.total
            this.inall5ListQuery.current = response.data.current
            this.inall5ListQuery.size = response.data.size
          } else {
            this.inall5List = []
            this.inall5ListTotal = 0
          }
        })
      },
      // 序号
      indexMethod5(index) {
        var pagestart = (this.inall5ListQuery.current - 1) * this.inall5ListQuery.size
        var pageindex = index + 1 + pagestart
        return pageindex
      },

      // 导出文件
      doBuild() {

        // var url = ""
        // var fileName = ""

        // if (this.index == "0") {
        //   url = ""
        //   fileName = "" + '.xls'
        //   if (this.logList.length == 0) {
        //     this.$message({
        //       message: '暂无数据可导出！',
        //       type: 'warning',
        //       duration: 1000
        //     });
        //     return
        //   }
        // } else if (this.index == "1") {
        //   url = ""
        //   fileName = "" + '.xls'
        //   if (this.in112List.length == 0) {
        //     this.$message({
        //       message: '暂无数据可导出！',
        //       type: 'warning',
        //       duration: 1000
        //     });
        //     return
        //   }
        // } else if (this.index == "2") {
        //   url = ""
        //   fileName = "" + '.xls'
        //   if (this.inallList.length == 0) {
        //     this.$message({
        //       message: '暂无数据可导出！',
        //       type: 'warning',
        //       duration: 1000
        //     });
        //     return
        //   }
        // } else if (this.index == "3") {
        //   url = ""
        //   fileName = "" + '.xls'
        //   if (this.inall4List.length == 0) {
        //     this.$message({
        //       message: '暂无数据可导出！',
        //       type: 'warning',
        //       duration: 1000
        //     });
        //     return
        //   }
        // }
        
        this.$message({
          showClose: true,
          type: 'success',
          message: '功能暂未完善...'
        })

        // const loading = this.$loading({
        //   lock: true,
        //   text: 'Loading',
        //   spinner: 'el-icon-loading',
        //   background: 'rgba(0, 0, 0, 0.7)'
        // })

        // exportExcel(this.jmdListQuery).then((resp) => {
        //   loading.close()
        //   const blob = new Blob([resp], {
        //     type: 'application/vnd.ms-excel;charset=UTF-8'
        //   })
        //   const fileName = '库存明细列表' + '.xls'
        //   const elink = document.createElement('a')
        //   elink.download = fileName
        //   elink.style.display = 'nonde'
        //   elink.href = URL.createObjectURL(blob)
        //   document.body.appendChild(elink)
        //   elink.click()
        //   URL.revokeObjectURL(elink.href)
        //   document.body.removeChild(elink)
        // }).catch(() => {
        //   loading.close()
        // })

      },
    }
  }
</script>
<style scoped>
  .wenjiantit {
    font-size: 16px;
    font-weight: bold;
    margin: 25px 0 10px 0;
  }

  .forminfo {
    margin: 0;
    padding: 0;
  }

  .listcon {
    height: calc(100vh - 250px);
    overflow-y: auto;
    overflow-x: hidden;
  }
</style>
