<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="defaultSelected"
    />
    <div class="thetopbox">
      <el-form label-width="100px">
        <el-row>
          <el-col :span="4">
            <el-form-item label="来源系统" prop="source">
              <el-select v-model="form.source" clearable>
                <el-option v-for="item in systemSourceList" :key="item.value" :label="item.label" :value="item.value" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="来源订单号" prop="orderCode">
              <el-input v-model="form.orderCode" clearable />
            </el-form-item>
          </el-col>

          <el-col :span="8">
            <el-form-item label="时间范围" prop="timeRange">
              <el-date-picker
                v-model="timeRange"
                value-format="yyyy-MM-dd"
                type="daterange"
                clearable
                :range-separator="'至'"
                :start-placeholder="'开始日期'"
                :end-placeholder="'结束日期'"
                @change="timeRangeHandleChange"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <div class="searchbox">
              <el-button
                class="my_search"
                @click="
                  () => {
                    getSearch();
                    resetPageNum();
                  }
                "
              >
                搜索</el-button>
              <el-button class="my_reset" @click="resetHandle">
                重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="main">
      <div class="maintop">
        <div class="mainbtn">
          <el-button v-hasButtons="['WholeNetworkProductManageDetailsExport']" size="small" class="thebtn1" @click="handleExport">
            {{ '导出' }}</el-button>
        </div>
      </div>
      <div class="maintable">
        <el-table
          v-loading="loading"
          :data="tableData"
          height="700px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
        >
          <el-table-column
            align="center"
            prop="sourceVal"
            label="来源系统"
            width="90px"
          />
          <el-table-column
            align="center"
            prop="orderCode"
            label="来源订单号"
            width="200px"
          />
          <el-table-column
            align="center"
            prop="changeNum"
            label="变动数量"
            width="100px"
          />
          <el-table-column
            align="center"
            prop="remark"
            label="变动说明"
          />
          <el-table-column
            align="center"
            prop="creationTime"
            label="创建时间"
            width="180px"
          />

        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getSearch"
    />
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import { getSystemSourceList } from '@/api/wholeNetwork'
import { getProductDetailsList } from '@/api/wholeNetwork/productManage'
const initSearch = {
  startDate: null,
  endDate: null
}
export default {
  name: 'WholeNetworkProductManageDetails',
  components: {
    topBar
  },

  data() {
    return {
      defaultSelected: 'productManageDetails',
      topList: [
        {
          name: '全网商品管理详情',
          path: 'productManageDetails'
        }
      ],
      tableData: [],
      loading: false,
      queryParams: {
        pageNum: 1,
        pageSize: 50

      },
      form: {
        ...initSearch
      },
      total: 0,
      pkId: '',
      timeRange: [],
      systemSourceList: []
    }
  },
  created() {
    this.pkId = this.$route.query.pkId
    this.getSystemSourceList()
    this.getSearch()
  },
  methods: {
    getSystemSourceList() {
      getSystemSourceList().then((res) => {
        if (res.code === 200) {
          this.systemSourceList = res.data
        }
      })
    },
    // 导出
    handleExport() {
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((_) => {
        this.download(
          '/sale/manage/all-product-detail/export',
          { ...this.queryParams, ...this.form },
          `${'全网商品管理'}${new Date().getTime()}.xlsx`
        )
      })
    },
    timeRangeHandleChange() {
      this.form.startDate = this.timeRange?.[0] || null
      this.form.endDate = this.timeRange?.[1] || null
    },
    resetHandle() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 50
      }
      this.timeRange = []
      this.getSearch()
    },
    getSearch() {
      this.loading = true
      const params = {
        ...this.queryParams,
        ...this.form,
        pkAllProduct: this.pkId
      }
      getProductDetailsList(params).then((res) => {
        this.loading = false
        if (res.code === 200) {
          this.tableData = res.rows
          this.total = res.total
        }
      })
    },
    resetPageNum() {
      this.queryParams.pageNum = 1
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-image-viewer__close {
  right: 500px;
}
::v-deep .dizhi .el-cascader {
  width: 100%;
}
::v-deep .el-range-editor.el-input__inner {
  width: 100%;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}
.page {
  padding: 10px 20px;
  background: #f9f9f9;
  font-size: 14px;
  .thetopbox {
    padding: 15px 20px 15px 0;
    background: #ffffff;
    border-radius: 8px;
    .searchbox {
      display: flex;
      align-items: center;
      margin-left: 40px;
    }
    .searchtitle {
      margin-right: 10px;
    }
    .searchbtn {
      background: #08143f;
      color: #ffffff;
    }
  }
  .main {
    //margin-top: 20px;
    background: #f9f9f9;
    //border-radius: 8px;
    //box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

    .maintop {
      display: flex;
      // padding: 10px 0;
      justify-content: space-between;
      align-items: center;
      .mainbtn {
        .thebtn1 {
          color: #ffffff;
          background: #ffad41;
          width: 68px;
          height: 32px;
        }
        .thebtn2 {
          color: #ffffff;
          background: #009b58;
          width: 68px;
          height: 32px;
        }
        .thebtn3 {
          color: #ffffff;
          background: #c8161d;
          width: 68px;
          height: 32px;
        }
      }
    }
  }
}
</style>
