<template>
  <div class="content-main">
	<el-tabs v-model="activeName" @tab-click="handletabClick">
		<el-tab-pane label="进销存" name="jxc"></el-tab-pane>
		<el-tab-pane label="补贴" name="bt"></el-tab-pane>
	</el-tabs>
    <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.period"
		  	      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>
		    <div class="search-button">
		      <span class="search-line"></span>
		      <div class="search-select" @click="searchShowMore">
		        更多条件
		        <i class="el-icon-arrow-up" v-show="searchShowMoreBool"></i
		        ><i class="el-icon-arrow-down" v-show="!searchShowMoreBool"></i>
		      </div>
		      <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-row v-show="searchShowMoreBool">
			<el-form-item label="填报日期:">
			  <el-date-picker
			  @change="ChangereportDate"
				v-model="formInline.reportDate"
				type="daterange"
				range-separator="至"
				start-placeholder="开始日期"
				end-placeholder="结束日期"
				format="yyyy-MM-dd"
				value-format="yyyy-MM-dd">
			  </el-date-picker>
			</el-form-item>
			<el-form-item label="状态:">
			   <el-select
			     clearable
			     class="inputCompatible"
			     v-model="formInline.status"
			     placeholder="请选择"
			   >
			     <el-option
			       v-for="item in statusOptions"
			       :key="item.value"
			       :label="item.label"
			       :value="item.value"
			     ></el-option>
			   </el-select>
			</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="sskdmc"
		  label="申报单位"
		  show-overflow-tooltip
		>
		</el-table-column>
        <el-table-column
          align="center"
          prop="period"
          label="填报期数"
          show-overflow-tooltip
        >
		<template slot-scope="scope">
			<span>{{scope.row.period ? scope.row.period : '--'}}</span>
		</template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="reportDate"
          label="填报日期"
          show-overflow-tooltip
        >
		<template slot-scope="scope">
			<span>{{scope.row.reportDate ? scope.row.reportDate : '--'}}</span>
		</template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="initial"
          :label="activeName == 'bt' ? '上月期末库存' : '期初库存'"
          show-overflow-tooltip
        >
		<template slot-scope="scope">
			<span v-if="activeName == 'bt'">
				{{scope.row.syyqmkc ? String(scope.row.syyqmkc).indexOf(".") > -1
              ? (Math.round((scope.row.syyqmkc)*1000)/1000).toFixed(3)
              : scope.row.syyqmkc
			  : '--'}}
			</span>
			<span v-if="activeName == 'jxc'">{{scope.row.initial ?  String(scope.row.initial).indexOf(".") > -1
              ? (Math.round((scope.row.initial)*1000)/1000).toFixed(3)
              : scope.row.initial : '--'}}</span>
		</template>
		<!-- <template slot-scope="scope">
		  <span>{{activeName == 'bt' ? scope.row.syyqmkc : scope.row.initial}}</span>
		</template> -->
        </el-table-column>
        <el-table-column
          align="center"
          prop="incomeTotal"
          :label="activeName == 'bt' ? '本月应补' : '收入'"
          show-overflow-tooltip
        >
		<template slot-scope="scope">
			<span v-if="activeName == 'bt'">
				{{scope.row.byyb ? String(scope.row.byyb).indexOf(".") > -1
              ? (Math.round((scope.row.byyb)*100)/100).toFixed(2)
              : scope.row.byyb : '--'}}
			</span>
			<span v-if="activeName == 'jxc'">{{scope.row.incomeTotal ? 
			 String(scope.row.incomeTotal).indexOf(".") > -1
			 ? (Math.round((scope.row.incomeTotal)*1000)/1000).toFixed(3)
			 : scope.row.incomeTotal: '--'}}</span>
		</template>
        </el-table-column>
        <el-table-column
          align="center"
          prop=""
          :label="activeName == 'bt' ? '本年累计已补' : '支出'"
          show-overflow-tooltip
        >
		<template slot-scope="scope">
			<span v-if="activeName == 'bt'">
				{{scope.row.bnljyb ? String(scope.row.bnljyb).indexOf(".") > -1
              ? (Math.round((scope.row.bnljyb)*100)/100).toFixed(2)
              : scope.row.bnljyb  : '--'}}
			</span>
		  <span v-if="activeName == 'jxc'">{{scope.row.expenseTotal ? String(scope.row.expenseTotal).indexOf(".") > -1
			 ? (Math.round((scope.row.expenseTotal)*1000)/1000).toFixed(3)
			 : scope.row.expenseTotal : '--'}}</span>
		</template>
        </el-table-column>
        <el-table-column
		v-if="activeName == 'jxc'"
          align="center"
          prop="ending"
          label="期末库存"
          show-overflow-tooltip
        >
		<template slot-scope="scope">
			{{ scope.row.ending ? String(scope.row.ending).indexOf(".") > -1
			 ? (Math.round((scope.row.ending)*1000)/1000).toFixed(3)
			 : scope.row.ending : '--' }}
		</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 == '91000200' && 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 == '91000201' && scope.row.summaryStatus == 0 && 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 {
  purchaseStockList,storageSubsidyList
} from "@/api/cwbb/index";
import { authorityControl } from "@/api/login/login.js";

export default {
  data() {
    return {
		buttonNameList:[],
		searchShowMoreBool:false,
		activeName:'jxc',
		statusOptions:[
			{
			    label:'未上报',
			    value:'91000000'
			},
			{
			    label:'待接收',
			    value:'91000200'
			},
			{
			    label:'已接收',
			    value:'91000201'
			},
			{
			    label:'已驳回',
			    value:'91000202'
			}
		],
      formInline: {
        sskdmc:'',
        period:'',
		reportDate:[],
		status:'',
		dataType:0
      },
      listLoading: false,
      tableData: [],
	  pageForm: {
	    pageNum: 1,
	    pageSize: 10,
	    total: 0,
	  },
    };
  },
  created() {
	  this.getButtonList(
	    sessionStorage.getItem("resourceCode"),
	    sessionStorage.getItem("userCode")
	  );
	  // console.log(`${year}-${month}-${date}`); // 2022-5-7
	if (this.$route.query.active == "bt") {
	  this.activeName = "bt";
	  this.searchShowMoreBool=this.$route.query.searchShowMoreBool
	  // this.bhWidth='250'
	} else {
	  this.activeName = "jxc";
	  this.searchShowMoreBool=this.$route.query.searchShowMoreBool
	  // this.bhWidth='250'
	}
	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]
	  },
	  handletabClick(tab, event) {
		  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 = {
			  sskdmc:'',
	        reporter:'',
	        period:`${year}年${month}月`,
	        reportDate:'',
	        status:'',
			dataType:0,
			startDate:'',
			endDate:"",
	      });
		  this.pageForm= {
		  	pageNum: 1,
		  	pageSize: 10,
		  	total: 0,
		  },
		  this.searchShowMoreBool = false
	    this.activeName = tab.name;
	    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= {
		  sskdmc:'',
		  period:`${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.period=`${year}年${month}月`
          //第一次进去此菜单时，保存上方默认的data
          sessionStorage.setItem("searchData", JSON.stringify(this.formInline));
          sessionStorage.setItem("pageData", JSON.stringify(this.pageForm));
        }
      }
      var data={
       ...this.formInline,
	   ...this.pageForm
      }
	  if(this.activeName == 'jxc'){
		 purchaseStockList(data).then((res) => {
		   if(res.infoCode == 200){
		    this.tableData = res.data.list
			this.pageForm.total = res.data.total;
			 this.listLoading=false
		   }else{
			   this.$message.error(res.msg);
			   this.listLoading=false
		   }
		 }); 
	  }else{
		  
		  storageSubsidyList(data).then((res) => {
		    if(res.infoCode == 200){
		     this.tableData = res.data.list
			 this.pageForm.total = res.data.total;
			  this.listLoading=false
		    }else{
				this.$message.error(res.msg);
				this.listLoading=false
		    }
		  });
	  }
      
    },
    //新增
    addSubmit(row,type) {
		if(this.activeName == 'jxc'){
			this.$router.push({
			  name: "storageFeeDetail",
			  query: {
			    id:row ? row.id : undefined,
			    type:type ? type : undefined,
				searchShowMoreBool:this.searchShowMoreBool
			  },
			});
		}else{
			console.log(row,'888888888=======')
			this.$router.push({
			  name: "storageFeebtDetail",
			  query: {
			    id:row ? row.id : undefined,
			    type:type ? type : undefined,
				searchShowMoreBool:this.searchShowMoreBool
			  },
			});
		}
      
    },
	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>
