<!-- 集货区任务 -->
<template>
<div>
	<p-modal title="集货区转移"
	             :visible="visible"
	             :enlargeable="true"
	             :draggable="true"
	             @ok="handleOk"
	             @cancel="handleCancel"
	             @enlargeChange="enlargeChange">
		<p-grid-form
			  ref="modal_area"
		     :items="items_modal"
		   />
	</p-modal>
	<p-card title="集货区任务" style="border: none;" >
		<template slot="extra">
			<p-button type="primary" icon="retweet" @click="showModal">集货区转移</p-button>
			<!-- <p-button type="primary" icon="close" @click="hanlderRest">取消任务</p-button> -->
		</template>
		<div class="plg-inner-form-mb">
		 <p-grid-form
			  ref="search"
		      :span="8"
		      :label-col="{ span: 6 }"
		      :items="items"
		      @submit="hanlderSubmit"
		    />
		</div>
		 <p-table
			:columns="columns"
			:data-source="data"
			rowKey="rowId"
			dragle
			autoWidth
			:scroll="{x:true}"
			hasRowSelectCheck
			:selectedRowKeys.sync="selectedRowKeys"
			@checkRow="checkRow"
			@change='changePagination'
			:pagination="pagination"
			:loading = "loading"
		    bordered>
		   <!-- <span slot="action"
		         slot-scope="text, record,index">

		     <a @click="showModal(record)">编辑</a>
		     <a-divider type="vertical"
		                style="" />
		     <a @click="del(record)">删除</a>

		   </span> -->
		 </p-table>


	</p-card>

</div>
</template>

<script>
	// 设置默认仓库
	import { setwarehouse }  from  '@/views/kzyWMS/SearchModal/mixins_warehouse.js';
	import { items,items_modal,columns } from  './api/cargoAreaTask.js';
    import { sorter } from '@/views/kzyWMS/utils/sort.js'
	import { wave_bill_workstage, search_page,workstage_transfer }  from './api/api.js';
export default {
	mixins:[setwarehouse],
	data() {
		return {
			items,
			items_modal:items_modal(this),
			columns: sorter(columns),
			data: [],
			visible:false,
			loading: false,
			options:[{title:'未索取',value:0},{title:'已索取',value:1}],
			pagination: {
			  total: 0,
			  pageSize: 10, //每页中显示10条数据
			  current: 1,
			  showSizeChanger: true,
			  pageSizeOptions: ['10', '15', '20'], //每页中显示的数据
			  showTotal: (total) => `共有 ${total} 条数据`, //分页中显示总的数据
			},
			selectedRows:[],
			selectedRowKeys:[],
		}
	},
	methods:{
		getData(params){
			params = {
				pageNum : this.pagination.current,
				pageSize: this.pagination.pageSize,
				num:'workstageQuery',  //id:"[string] 查询接口id" 查询服务菜单
				params:params
			}
			this.loading = true;
			search_page(params).then(res => {
				if(res.data){
				  if (res.success) {
					this.data = res.data.list;
					this.pagination.total = Number(res.data.totalCount);
					this.loading = false;
					this.selectedRows.length = 0;
					this.selectedRowKeys.length = 0;
				  } else {
					this.loading = false;
					this.$exception(res);
				  }
				} else {
					this.data = [];
					this.loading = false;
				}
			})
		},
		/* getData(params){
			params = {
				pageNum : this.pagination.current,
				pageSize: this.pagination.pageSize,
				...params
			},
			this.loading = true;
			wave_bill_workstage(params).then(res => {
			  if (res.success) {
			    this.data = res.data.list;
				this.pagination.total = Number(res.data.totalCount);
			    this.loading = false;
			  } else {
			    this.loading = false;
			    this.$exception(res);
			  }
			}).finally(()=>{
				this.loading = false;
			})
		}, */
		hanlderSubmit(event, form) {
			 event.preventDefault();
			// console.log("getFieldsValue:",form.getFieldsValue());
			// this.getData(form.getFieldsValue())
			this.$refs.search.form.validateFields((err, values) => {
			        if (!err) {
			          console.log('验证通过: ', values);
					  this.getData(values);
			        }
			      });
		},
		// 取消任务
		hanlderRest(event,form){
			this.$refs.search.form.resetFields();
		},
		changePagination(pagination, filters, sorter) { // 分页变化
		  console.log(pagination, filters, sorter, '分页变化分页变化');
			this.pagination = pagination;
			this.getData({...this.$refs.search.form.getFieldsValue()});  //分页查询所有列表
		},
		checkRow(selectedRowKeys, selectedRows) {
		  console.log("当前点击选择行：", selectedRowKeys, selectedRows);
		  this.selectedRows = [...selectedRows];
		  },
		handleChange (value) {
		      console.log(`selected ${value}`);
		    },
		// 弹出窗确认
		handleOk(e) {
			this.$nextTick(()=>{
				this.$refs.modal_area.form.validateFields((error, values) => {
				if (!error) {
							 console.log('...做提交操作逻辑');

							let params = {
									billGroupId : this.selectedRows[0].billGroupId,
									srcBldgCode : this.selectedRows[0].bldgCode,
									destBldgCode: values.bldgCode,
									stageCode: values.stageCode,
									stageId: values.stageId,
								}
						workstage_transfer(params).then(res=>{
							if(res.success){
								this.$message.success('集货区转移成功！');
								// this.selectedRows.splice(0,this.selectedRows.length);
								this.visible = false;
							} else {
								this.$exception(res);
							}
						}).then(res=>{
								this.getData({...this.$refs.search.form.getFieldsValue()});
						})
						.finally((e)=>{
							this.visible = false;
						})

				}
				})
			})
		},
		handleCancel(e) {
			this.$refs.modal_area.form.resetFields();
			this.visible = false;
		},
		enlargeChange(isEnlarge){
		  console.log(isEnlarge);
		},
		showModal(){
			if(this.selectedRows.length){
					this.visible = true;
			}	else {
				this.$message.warning('请选择！');
			}
		},
	},	// methods
	mounted() {
		this.getData({...this.$refs.search.form.getFieldsValue()});
	}
}
</script>

<style>
</style>
