<template>
    <div>
      <ex-table
        v-loading="loading"
        :table="table"
        :data="tableData"
        :columns="columns"
        :page="pageInfo"
        :size="size"
        @page-curr-change="handlePageChange"
        @page-size-change="handleSizeChange"
        @screen-reset="
          pageInfo.curr = 1;
          parmValue.page = 1;
          searchList();
        "
        @screen-submit="
          pageInfo.curr = 1;
          parmValue.page = 1;
          searchList();
        "
        @selection="selection_change"
      >
        <template #table-header="{}">
          <div style="width: 100%">
            <el-row style="padding: 0 0 0 80px">
             
               <el-col :span="6" style="width: 363px;">
                <periodDatePickerActive
                      :start="parmValue.start_date"
                      :end="parmValue.end_date"
                      :placeholder="'下线'"
                      :width="'165px'"
                      :size="searchSize"
                      @timeReturned="time"
                    />
              </el-col>  
              <el-col :span="6" style="width: 163px;">
                <el-input
                :size="searchSize"
                v-model="parmValue.creater"
                :maxlength="40"
                @blur="
                  pageInfo.curr = 1;
                  parmValue.page = 1;
                  searchList();
                "
                placeholder="创建人"
                ></el-input> 
              </el-col>  
              
              <el-col :span="3" style="width: 66px; float: right">
                <el-button
                  :size="searchSize"
                  type="primary"
                  style="float: right; margin-left: 5px"
                  @click="searchList"
                >
                  刷新
                </el-button>
              </el-col>
              <el-col :span="4" style="width: 66px; float: right">
                <el-button
                  type="warning"
                  class="fr"
                  :size="searchSize"
                  @click="restSearch"
                >
                  重置
                </el-button>
              </el-col>  
            </el-row>
          
          </div>
       </template>
      <template #operation="{ scope }">
        <el-tooltip
          v-if="powers.some((item) => item == '007')"
          effect="dark"
          content="详情"
          placement="top"
        >
          <i
            class="el-icon-view tb-icon"
            @click="getRouter('goodsOfflineDetail', scope.row.spuCode)"
          ></i>
        </el-tooltip>
    
      </template>
        
      </ex-table>
    </div>

  
</template>
   <script>
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import urlConfig from "@/apis/url-config";
import asyncRequest from "@/apis/service/goodStore/goodsOffline";
import periodDatePickerActive from "./period-date-picker/main.vue";
import { columns} from "./columns";
import { mapGetters } from "vuex";

export default {
  name: "goodsOffline",
  mixins: [mixinPage, resToken],
  components: {
    periodDatePickerActive
  },
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      let tran =
        this.$store.getters.btnList.find((item) => item.menu_route == "goodsOffline") ||
        {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
    
  },
  data() {
    return {
      //选中数组
      changeList: [],
      //全局url
      fileUrl: urlConfig.baseURL,
      //loading
      loading: false,
      //请求参数集合
      parmValue: {
        
        start_date: "", //起始时间
        end_date: "", // 结束时间
        // is_export:0,//是否导出0/1
        creater:"",//创建人
        page: 1, // 页码
        size: 15, // 每页显示条数
       
      },
      // 表格 - 数据集合
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格表头 - 列参数
      columns: columns,
    };
  },
  mounted() {
    // alert("此页面暂时只用做开发人员测试、数据不真实")
    const { back } = this.$route.query;

     if (back) {
      this.parmValue = JSON.parse(back);
      console.log(this.parmValue);
      const { page, size } = this.parmValue;

      this.pageInfo = {
        size: size,
        curr: page,
        total: 0,
      };
      //多选条件
      // this.select = this.parmValue.select;
      // this.sselect = this.parmValue.sselect;
      // this.sinput = this.parmValue.sinput;
    } else {
      // this.select = "1";
      //  this.sselect = "创建时间"
    }
    this.searchList();
  },

  methods: {
    getRouter(toRouter, queryId){
      if (toRouter && queryId) {
        let model = {
          id: queryId,
          type: 'view',
        };

        //有多选框的条件
        // this.parmValue.select = this.select ;
        // this.parmValue.sselect = this.sselect ;
        // this.parmValue.sinput= this.sinput;
        //
        // console.log(this.parmValue)
         let routerModel = {
          options: JSON.parse(JSON.stringify(this.parmValue)),
          router: this.$route.path,
        };
        model.preModel = JSON.stringify(routerModel);
        
        this.routeGoto(toRouter, model);
      } else {
        this.$message.warning("暂未找到相关流程！");
      }
    },
    //初始化http请求
    async searchList() {
      if (
        (this.parmValue.start_date !== "" && this.parmValue.end_date === "") ||
        (this.parmValue.start_date === "" && this.parmValue.end_date !== "")
      ) {
        this.$message.warning("时间区间不完整！");
        return;
      }
      this.loading = true;
      console.log(this.parmValue)
      const res = await asyncRequest.goodofflist(this.parmValue);
      if (res && res.code === 0 && res.data) {
        this.tableData = res.data.list;
        
        this.pageInfo.total = Number(res.data.count);
      } else if (res && res.code >= 100 && res.code <= 104) {
        await this.logout();
      } else {
        this.$message.warning(res.message)
        this.tableData = [];
        this.pageInfo.total = 0;
      }
      this.loading = false;
    },
   
    //重置
    restSearch() {
      this.parmValue = {
        start_date: "", //新建起始时间
        end_date: "", // 新建结束时间
        creater:"",//创建人
        // is_export:0,//是否导出0/1
        page: 1, // 页码
        size: 15, // 每页显示条数
      };
      // 表格 - 分页
      this.pageInfo = {
        size: 15,
        curr: 1,
        total: 0,
      };
      this.searchList();
    },
    
    // 时间函数
    async time(e) {
      this.parmValue.start_date = e.startTime || "";
      this.parmValue.end_date = e.endTime || "";
      if (
        (this.parmValue.start_date !== "" && this.parmValue.end_date === "") ||
        (this.parmValue.start_date === "" && this.parmValue.end_date !== "")
      ) {
        this.$message.warning("时间区间不完整！");
        return;
      }
      this.pageInfo.curr = 1;
      this.parmValue.page = 1;
      await this.searchList();
    },

     //选中触发函数
    selection_change(e) {
      const { list } = e;
      //选中的数组集合
      this.changeList = list.length > 0 ? JSON.parse(JSON.stringify(list)) : [];
    },

  },
};
</script>
   <style lang="scss" scoped>
.purchaseOrder {
  // text-align: right;
}
</style>
   