<template>
  <div>
    <avue-crud :option="option"
               :table-loading="loading"
               :data="data"
               ref="crud"
               @refresh-change="refreshChange"
               @selection-change="selectionChange"
               @search-change="searchChange"
               @saveColumn="saveColumn"
               :page.sync="page"
               @on-load="onLoad">
    </avue-crud>
    <div style="margin-left: 90%">
       <span slot="footer" class="dialog-footer" >
           <el-button @click="closeFun()">取 消</el-button>
           <el-button type="primary" @click="importMarket" :disabled="selectMarketList.length == 0">导入</el-button>
       </span>
    </div>
  </div>
</template>

<script>
  import option from './config/market.json'
  import {getMarketDetailsList} from "@/api/importTrade/purchase";

  export default {
    name: "index",
    props: {
      itemId: {
        type: String
      },
      closeFun: {
        type: Function
      }
    },
    data(){
      return {
        option:{},
        loading:false,
        data:[],
        selectMarketList:[],
        page: {
          pageSize: 10,
          pagerCount: 5,
          total: 0,
        },
      }
    },
    async created() {
      this.option = await this.getColumnData(this.getColumnName(42), option);
    },
    methods:{
      refreshChange(){
        this.onLoad(this.page);
      },
      searchChange(params,done){
        this.onLoad(this.page, params);
        done()
      },
      selectionChange(row){
        this.selectMarketList = row
      },
      onLoad(page, params = {}){
        this.loading = true;
        if (params.marketDate != undefined) {
          params.orderStartDate = params.marketDate[0]+ " " + "00:00:00";
          params.orderEndDate = params.marketDate[1] + " " + "23:59:59";
          this.$delete(params,'marketDate')
        }
        getMarketDetailsList(page.currentPage, page.pageSize,params).then(res=>{
          this.data = res.data.data.records
          this.page.total = res.data.data.total
        })
          .finally(()=>{
          this.loading = false;
        })
      },
      importMarket(){
        this.$emit('importMarket',this.selectMarketList);
      },
      //列保存触发
      async saveColumn() {
        const inSave = await this.saveColumnData(
          this.getColumnName(42),
          this.option
        );
        if (inSave) {
          this.$message.success("保存成功");
          //关闭窗口
          this.$refs.crud.$refs.dialogColumn.columnBox = false;
        }
      },
    }
  }
</script>
<style scoped>

</style>
