<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-date-picker
			      v-model="formInline.month"
			      type="month"
			      placeholder="选择月份"
			      format="yyyy-MM"
			      value-format="yyyy-MM">
			    </el-date-picker>
          <!-- <el-input clearable v-model="formInline.period" placeholder="请输入"></el-input> -->
        </el-form-item>
		<el-form-item label="粮食性质:">
		   <el-select
		     clearable
		     class="inputCompatible"
		     v-model="formInline.orgLevel"
		     placeholder="请选择"
		   >
		     <el-option
		       v-for="item in orgOptions"
		       :key="item.value"
		       :label="item.label"
		       :value="item.value"
		     ></el-option>
		   </el-select>
		</el-form-item>
		<el-form-item label="状态:">
		  <el-select
		    v-model="formInline.status"
		    class="inputWidth"
		    placeholder="请选择"
		  >
		    <el-option
		      v-for="i in statusOptions"
		      :key="i.value"
		      :label="i.label"
		      :value="i.value"
		    ></el-option>
		  </el-select>
		</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
		>
		<template slot-scope="scope">
			<span>{{scope.row.orgName ? scope.row.orgName : '--'}}</span>
		</template>
		</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="reportDay"
          label="上报日期"
          show-overflow-tooltip
        >
		<template slot-scope="scope">
			<span>{{scope.row.reportDay ? scope.row.reportDay : '--'}}</span>
		</template>
        </el-table-column>
		<el-table-column
		  align="center"
		  prop="orgLevelName"
		  label="上报粮食性质"
		  show-overflow-tooltip
		>
		<template slot-scope="scope">
			<span>{{scope.row.orgLevelName ? scope.row.orgLevelName : '--'}}</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
              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>
           <el-tooltip
            v-if="(scope.row.status == '90200000') && buttonNameList.indexOf('撤销') > -1"
              class="item"
              effect="light"
              content="撤销"
              placement="top"
            >
              <el-button
                @click="addSubmit(scope.row,'cx')"
                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 {
  reserveSizeAccept
} from "@/api/reserveScaleReport/index";
import { authorityControl } from "@/api/login/login.js";

export default {
  data() {
    return {
		orgOptions:[
			{
			    label:'区级储备粮',
			    value:'10180007'
			},
			{
			    label:'市级储备粮',
			    value:'10180005'
			}
		],
		statusOptions:[
			{
			    label:'未上报',
			    value:'90000000'
			},
			{
			    label:'待上报',
			    value:'90000002'
			},
			{
			    label:'待接收',
			    value:'90100000'
			},
			{
			    label:'已接收',
			    value:'90200000'
			},
			{
			    label:'已驳回',
			    value:'90000001'
			}
		],
      formInline: {
        month :'',
		orgLevel:'',
      },
      listLoading: false,
      tableData: [
		  {
			  period:'2023'
		  }
	  ],
	  buttonNameList:[],
    };
  },
  created() {
	  this.getButtonList(
	    sessionStorage.getItem("resourceCode"),
	    sessionStorage.getItem("userCode")
	  );
	  // console.log(`${year}-${month}-${date}`); // 2022-5-7
	
	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();
	    });
	  },
    doSearch() {
		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.period=`${year}年${month}月`
		this.formInline= {
		  month :`${year}-${month}`,
		  orgLevel:'',
		// reportDate:[],
		// status:'',
		// dataType:'1',
		// 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.month=`${year}-${month}`
          //第一次进去此菜单时，保存上方默认的data
          sessionStorage.setItem("searchData", JSON.stringify(this.formInline));
          // sessionStorage.setItem("pageData", JSON.stringify(this.pageForm));
        }
      }
      var data={
       ...this.formInline,
      }
	  reserveSizeAccept(data).then((res) => {
		if(res.infoCode == 200){
			this.listLoading=false
		 this.tableData = res.data
		 // this.pageForm.total = res.data.total;
		  
		}else{
			this.$message.error(res.msg);
			 this.listLoading=false
		}
	  });
      
    },
    //新增
    addSubmit(row,type) {
		this.$router.push({
		  name: "receiveDetail",
		  query: {
		    id:row ? row.id : undefined,
		    type:type ? type : undefined,
			orgLevelName:row ? row.orgLevelName :undefined,
			orgName:row ? row.orgName : undefined,
			reportDay:row ? row.reportDay : undefined,
			reportMonth:row ? row.reportMonth : undefined,
			status:row ? row.status : undefined
		  },
		}); 
    },
  },
};
</script>
<style scoped>
.h3 {
  text-align: center;
  font-size: 1em;
  line-height: 2.5;
  color: #fff;
  background-color: #49a2fa;
  margin-bottom: 20px;
}
</style>
