<template>
  <a-form :model="actModel" :label-col="labelCol" :wrapper-col="wrapperCol">
    <a-row :gutter="24">
          <a-col :lg="18">
              <a-row :gutter="24">
                  <a-col>
                      <a-form-item label="控制活动名称">
                          <JInput placeholder="请输入" v-model:value="actModel.caName"></JInput>
                      </a-form-item>
                  </a-col>
              </a-row>
              <a-row :gutter="24">
                  <a-col>
                      <a-form-item label="标签">
                          <a-input placeholder="请输入" v-model:value="actModel.lableName" ></a-input>
                      </a-form-item>
                  </a-col>
              </a-row>
          </a-col>
          <a-col :span="3">
              <a-button style="width: 100%;height: 80%;line-height: 50%;" type="primary" @click="searchQuery">查询</a-button>
          </a-col>
          <a-col :span="3">
            <a-button style="width: 100%;height: 80%;line-height: 50%;" type="primary" @click="handleAdd"> 新建</a-button>
          </a-col>
      </a-row>
      <a-row :gutter="24">
          <a-col :span="24" :pull="1">
              <a-form-item label="查询结果">
                <BasicTable @register="registerTable" :rowSelection="rowSelection" @selection-change="handlerRowClick"  :scroll="{ y: 240 }" size="small">
                    <!-- update-begin-author:taoyan date:2022-5-25 for: VUEN-1112一对多 用户选择 未显示选择条数，及清空 -->
                    <template #tableTitle></template>
                    <!-- update-end-author:taoyan date:2022-5-25 for: VUEN-1112一对多 用户选择 未显示选择条数，及清空 -->
                </BasicTable>
                 
              </a-form-item>
          </a-col>
      </a-row>
      <StCaMainModal @register="registerModal" @success="handleSuccess"></StCaMainModal>
  </a-form>
</template>
<script setup>
import { reactive, ref, toRaw } from 'vue';
import { JInput } from '/@/components/Form';
import { useModal } from '/@/components/Modal';
import { BasicTable } from '/@/components/Table';
import { useListPage } from '/@/hooks/system/useListPage';
import { list } from '/@/views/standardlib/controlactivity/StCaMain.api';
import StCaMainModal from '/@/views/standardlib/controlactivity/components/StCaMainModal.vue';
const emit = defineEmits(['register','success','setModifyAct']);
const [registerModal, {openModal}] = useModal();
const props = defineProps({
ctinfo: Map,
});
const columns = [
   {
    title: '活动编号',
    align:"left",
    dataIndex: 'caNo'
   },
   {
    title: '控制活动名称',
    align:"left",
    dataIndex: 'caName'
   },
];
const { prefixCls,tableContext,onExportXls,onImportXls } = useListPage({
      tableProps:{
           title: '控制活动',
           api: list,
           columns,
           canResize:false,
           useSearchForm: false,
           scroll: { x: false },
           actionColumn: {ifShow: false},
           clickToRowSelect: true,
           rowSelection: { 
                hideSelectAll: true,
                //onSelect: handlerChecked,
                //onChange: handlerChange,
            },
        //    actionColumn: {
        //        width: 160
        //     },
            showTableSetting: false,
            beforeFetch(params) {
              params = Object.assign(params,{ column: 'updatedTime', order: 'desc' })
            },
      },
  })

  const [registerTable, {setProps,reload},{ rowSelection, selectedRowKeys }] = tableContext
  function handleAdd() {
    
    openModal(true, {
        isUpdate: false,
        showFooter: true,
    });
  }
  function handleSuccess() {
    reload();
  }

  function handlerRowClick({keys,rows}){
    let tmpAry = []
    for(let i=0;i<keys.length;i++) {
        tmpAry.push(rows[i].caNo)
    }
    // Object.assign(props.actinfo,tmpAry)
    emit('setReturnVals',tmpAry);
  }
const actModel = ref({
    caName:'',
    lableName:''
})
const labelCol = reactive({
      xs: {span: 24},
      sm: {span: 4},
  })
const wrapperCol = reactive({
    xs: {span: 24},
    sm: {span: 20},
})
// const pagination = reactive({
//     current: 1,
//     pageSize: 10,
//     total: 0,
//     showTotal: total => `共 ${total} 条数据`
// })
function searchQuery(){
    setProps({searchInfo:toRaw(actModel)});
    reload()
}
</script>