<template>
  <div class="content-main">
    <el-row class="search-bm-boder">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-row>
		  <!-- <el-form-item label="申报单位:">
		    <el-input clearable v-model="formInline.sskdmc" placeholder="请输入"></el-input>
		  </el-form-item> -->
		  <el-form-item label="上报期数:">
		  	<el-date-picker
		  	      v-model="formInline.reportMonth"
		  	      type="month"
		  	      placeholder="选择期数"
		  	      format="yyyy年M月"
		  	      value-format="yyyy年M月">
		  	    </el-date-picker>
		    <!-- <el-input clearable v-model="formInline.period" placeholder="请输入"></el-input> -->
		  </el-form-item>
		  <el-form-item>
		    <div class="search-button">
		      <span class="search-line"></span>
		      <el-button
		        type="primary"
		        size="small"
		        class="iconfont iconchaxun"
		        @click="getList"
		        >查询</el-button
		      >
		     <el-button
		       type="primary"
		       @click="
		         doSearch();
		       "
		       size="small"
		       class="iconfont iconzhongzhi"
		       >重置</el-button
		     >
		    </div>
		  </el-form-item>	
		</el-row>
      </el-form>
    </el-row>
    <el-row>
      <el-table
        :data="tableData"
        stripe
        v-loading="listLoading"
        border
        fit
        highlight-current-row
        style="width: 100%"
      >
        <el-table-column align="center" label="序号" width="70">
          <template slot-scope="scope">
            <span>{{ scope.$index + 1 }}</span>
          </template>
        </el-table-column>
		<el-table-column
		  align="center"
		  prop="orgName"
		  label="上报企业"
		  show-overflow-tooltip
		>
		</el-table-column>
        <el-table-column
          align="center"
          prop="reportMonth"
          label="上报期数"
          show-overflow-tooltip
        >
		<template slot-scope="scope">
			<span>{{scope.row.reportMonth ? scope.row.reportMonth : '--'}}</span>
		</template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="statusName"
          label="状态"
          show-overflow-tooltip
        >
        </el-table-column>
        <el-table-column align="center" label="操作" width="180px">
          <template slot-scope="scope">
            <el-tooltip
			v-if="scope.row.status != '91000000'"
              class="item"
              effect="light"
              content="查看"
              placement="top"
            >
              <el-button
                @click="addSubmit(scope.row,'ck')"
                style="float: left"
                type="primary"
                size="small"
                class="operate_show_btn iconfont iconchakan2"
              ></el-button>
            </el-tooltip>
            <el-tooltip
            v-if="scope.row.status == '90100000' && buttonNameList.indexOf('接收') > -1"
              class="item"
              effect="light"
              content="接收"
              placement="top"
            >
              <el-button
                @click="addSubmit(scope.row,'js')"
                style="float: left"
                type="primary"
                size="small"
                class="operate_edit_btn iconfont iconjieshou"
              ></el-button>
            </el-tooltip>
			<!-- v-if="scope.row.status == '90200000' && scope.row.summaryStatus == 0 && buttonNameList.indexOf('撤销') > -1" -->
           <el-tooltip
            v-if="scope.row.status == '90200000' && scope.row.haveSummary != 1 && buttonNameList.indexOf('撤销') > -1"
              class="item"
              effect="light"
              content="撤销"
              placement="top"
            >
              <el-button
                @click="addSubmit(scope.row,'gz')"
                style="float: left"
                type="primary"
                size="small"
                class="operate_edit_btn iconfont iconfanhui"
              ></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
	<el-row>
	  <el-pagination
	    @size-change="handleSizeChange"
	    @current-change="handleCurrentChange"
	    :current-page.sync="pageForm.pageNum"
	    :page-sizes="[10, 20, 30, 40]"
	    :page-size="pageForm.pageSize"
	    layout="total, sizes, prev, pager, next, jumper"
	    :total="pageForm.total"
	  ></el-pagination>
	</el-row>
  </div>
</template>

<script>
import {
  receiveGetList
} from "@/api/riceMonthReport/index";
import { authorityControl } from "@/api/login/login.js";

export default {
  data() {
    return {
		buttonNameList:[],
		statusOptions:[
			{
			    label:'未上报',
			    value:'91000000'
			},
			{
			    label:'待接收',
			    value:'91000200'
			},
			{
			    label:'已接收',
			    value:'91000201'
			},
			{
			    label:'已驳回',
			    value:'91000202'
			}
		],
      formInline: {
        reportMonth:'',
      },
      listLoading: false,
      tableData: [],
	  pageForm: {
	    pageNum: 1,
	    pageSize: 10,
	    total: 0,
	  },
    };
  },
  created() {
	  this.getButtonList(
	    sessionStorage.getItem("resourceCode"),
	    sessionStorage.getItem("userCode")
	  );
	this.getList("start");
  },
  methods: {
	  getButtonList(menuCode, userCode) {
	    let codeData = {
	      resourceCode: menuCode,
	      userId: userCode,
	    };
	    authorityControl(codeData).then((res) => {
	      let buttonNameList = [];
	      res.data.forEach((item) => {
	        this.buttonNameList.push(item.resourceName);
	      });
	      this.getList();
	    });
	  },
	  searchShowMore(){
		this.searchShowMoreBool=!this.searchShowMoreBool
	  },
	  ChangereportDate(val){
	    console.log(val,'ppiu88=========')
	    this.formInline.startDate=val[0]
	    this.formInline.endDate=val[1]
	  },
    doSearch() {
		const now = new Date();
		const year = now.getFullYear(); // 年
		// const month = now.getMonth()+1
		const month = now.getMonth() <9 ? (now.getMonth()+ 1) : now.getMonth()+ 1; // 月
		// this.formInline.period=`${year}年${month}月`
		this.formInline= {
		  // sskdmc:'',
		  reportMonth:`${year}年${month}月`,
		// reportDate:[],
		// status:'',
		// dataType:'0',
		// startDate:'',
		// endDate:"",
		},
      this.getList();
    },
    //获取列表
    getList(type) {
		 this.listLoading=true
      if (type != "start") {
        //非初始化调用：查询、分页
        sessionStorage.setItem("searchData", JSON.stringify(this.formInline));
        sessionStorage.setItem("pageData", JSON.stringify(this.pageForm));
      } else {
        //初始化分两种情况，详情页等返回后的初始化，以及第一次进入此菜单的初始化
        if (JSON.parse(sessionStorage.getItem("searchData"))) {
          //详情页返回后，将对应查询条件和分页的字段赋值，页面回显参数
          this.formInline = JSON.parse(sessionStorage.getItem("searchData"));
          this.pageForm = JSON.parse(sessionStorage.getItem("pageData"));
        } else {
			const now = new Date();
			const year = now.getFullYear(); // 年
			// const month = now.getMonth()+1
			const month = now.getMonth() <9 ? '0'+(now.getMonth()+ 1) : now.getMonth()+ 1; // 月
			this.formInline.reportMonth=`${year}年${month}月`
          //第一次进去此菜单时，保存上方默认的data
          sessionStorage.setItem("searchData", JSON.stringify(this.formInline));
          sessionStorage.setItem("pageData", JSON.stringify(this.pageForm));
        }
      }
      var data={
       // ...this.formInline,
	   month:this.formInline.reportMonth,
	   ...this.pageForm
      }
		  
		  receiveGetList(data).then((res) => {
		    if(res.infoCode == 200){
		     this.tableData = res.data.data.items
			 this.pageForm.total = res.data.data.total;
			  this.listLoading=false
		    }else{
				this.$message.error(res.msg);
				this.listLoading=false
		    }
		  });
      
    },
    //新增
    addSubmit(row,type) {
			console.log(row,'888888888=======')
			this.$router.push({
			  name: "riceReceiveDetail",
			  query: {
			    id:row ? row.id : undefined,
			    type:type ? type : undefined,
				status:row ? row.status : undefined,
				reportMonth:row ? row.reportMonth : undefined
			  },
			});
      
    },
	handleSizeChange(val) {
	  this.pageForm.pageSize = val;
	  this.getList();
	},
	handleCurrentChange(val) {
	  this.pageForm.pageNum = val;
	  this.getList();
	},
  },
};
</script>
<style scoped>
.h3 {
  text-align: center;
  font-size: 1em;
  line-height: 2.5;
  color: #fff;
  background-color: #49a2fa;
  margin-bottom: 20px;
}
</style>
