<template>
  <div class="content-main">
    <el-row class="search-bm-boder">
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="申报单位:">
          <el-input clearable v-model="formInline.ccqy" placeholder="请输入"></el-input>
        </el-form-item>
		<el-form-item label="状态:">
		  <el-select
		    v-model="formInline.status"
		    class="inputWidth"
		    placeholder="请选择"
		  >
		    <el-option
		      v-for="i in ysZtOptions"
		      :key="i.value"
		      :label="i.label"
		      :value="i.value"
		    ></el-option>
		  </el-select>
		</el-form-item>
		<el-form-item label="轮换年度:">
          <el-date-picker
              v-model="formInline.lhnd"
              type="year"
              placeholder="选择轮换年度"
              format="yyyy"
              value-format="yyyy">
            </el-date-picker>
        </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="
                formInline = { };
                doSearch();
              "
              size="small"
              class="iconfont iconzhongzhi"
              >重置</el-button
            >
          </div>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row></el-row>
	<el-row
	  class="addBtnBg"
	  style="
	    background: rgb(237, 245, 253);
	    line-height: 50px;
	    margin-bottom: 10px;
	  "
	>
	  <el-button
	    type="primary"
	    class="iconfont"
	    size="small"
	    @click="summaryDialog(undefined,'xg')"
	    >生成审批表</el-button
	  >
	</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="lhnd"
          label="轮换年度"
          show-overflow-tooltip
        >
        </el-table-column>
		<el-table-column
		  align="center"
		  prop="sbqysl"
		  label="申报企业数量"
		  show-overflow-tooltip
		>
		</el-table-column>
        <el-table-column
          align="center"
          prop="pzmc"
          label="品种"
          show-overflow-tooltip
        >
        </el-table-column>
		<el-table-column
		  align="center"
		  prop="ygbflhbt"
		  label="应拨付轮换补贴"
		  show-overflow-tooltip
		>
		<template slot-scope='scope'>
			<span>{{ String(scope.row.ygbflhbt).indexOf(".") > -1
			  ? Number(scope.row.ygbflhbt).toFixed(2)
			  : scope.row.ygbflhbt }}</span>
		</template>
		</el-table-column>
        <el-table-column
          align="center"
          prop="bcybje"
          label="本次预拨金额(70%)"
          show-overflow-tooltip
        >
		<template slot-scope='scope'>
			<span>{{ String(scope.row.bcybje).indexOf(".") > -1
			  ? Number(scope.row.bcybje).toFixed(2)
			  : scope.row.bcybje }}</span>
		</template>
        </el-table-column>
		<el-table-column
		  align="center"
		  prop="bfrq"
		  label="生成日期"
		  show-overflow-tooltip
		>
		</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 == '91000290' || scope.row.status == '91000301') && buttonNameList.indexOf('修改') > -1"
			  class="item"
			  effect="light"
			  content="修改"
			  placement="top"
			>
			  <el-button
			    @click="addSubmit(scope.row,'xg')"
			    style="float: left"
			    type="primary"
			    size="small"
			    class="operate_edit_btn iconfont iconxiugai1"
			  ></el-button>
			</el-tooltip>
		    <el-tooltip
			v-if="(scope.row.status == '91000300' || scope.row.status == '91000401') && buttonNameList.indexOf('复核') > -1"
		      class="item"
		      effect="light"
		      content="复核"
		      placement="top"
		    >
		      <el-button
		        @click="addSubmit(scope.row,'fh')"
		        style="float: left"
		        type="primary"
		        size="small"
		        class="operate_edit_btn iconfont iconshenhe"
		      ></el-button>
		    </el-tooltip>
			<el-tooltip
			v-if="(scope.row.status == '91000400' || scope.row.status =='91000501') && buttonNameList.indexOf('财务审核') > -1"
			  class="item"
			  effect="light"
			  content="财务审核"
			  placement="top"
			>
			  <el-button
			    @click="addSubmit(scope.row,'cwsh')"
			    style="float: left"
			    type="primary"
			    size="small"
			    class="operate_edit_btn iconfont iconshenhe"
			  ></el-button>
			</el-tooltip>
			<el-tooltip
			v-if="scope.row.status == '91000500' && buttonNameList.indexOf('负责人审核') > -1"
			  class="item"
			  effect="light"
			  content="负责人审核"
			  placement="top"
			>
			  <el-button
			    @click="addSubmit(scope.row,'fzrsh')"
			    style="float: left"
			    type="primary"
			    size="small"
			    class="operate_edit_btn iconfont iconshenhe"
			  ></el-button>
			</el-tooltip>
		   <el-tooltip
		   v-if="scope.$index == 0 && buttonNameList.indexOf('删除') > -1"
		     class="item"
		     effect="light"
		     content="删除"
		     placement="top"
		   >
		     <el-button
		       @click="deleteSubmit(scope.row)"
		       style="float: left"
		       type="primary"
		       size="small"
		       class="operate_delete_btn iconfont iconshanchu"
		     ></el-button>
		   </el-tooltip>
		   <el-tooltip
		     class="item"
		     effect="light"
		     content="导出"
		     placement="top"
		   >
		     <el-button
		       @click="addSubmit(scope.row,'dc')"
		       style="float: left"
		       type="primary"
		       size="small"
		       class="operate_edit_btn iconfont icondaochu11"
		     ></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>
	<el-dialog
	  title="选择批量审批的申报单位"
	  :visible.sync="dialogVisible"
	  width="60%"
	  :show-close="false"
	  :before-close="handleClose">
	  <el-table
	    :data="sbdwDataList"
	    stripe
	    v-loading="sbdwlistLoading"
	    border
	    fit
	    highlight-current-row
	    style="width: 100%"
		@selection-change="handselectionChange"
	  >
	    <el-table-column
	        type="selection"
	        width="55"
			:selectable="selectBox"
			>
	      </el-table-column>
	    <el-table-column align="center" label="序号" type="index" width="70">
	    </el-table-column>
		<el-table-column
		  align="center"
		  prop="ccqy"
		  label="申报单位"
		  width="300px"
		  show-overflow-tooltip
		>
		</el-table-column>
	    <el-table-column
	      align="center"
	      prop="lhnd"
	      label="轮换年度"
	      show-overflow-tooltip
	    >
	    </el-table-column>
	    <el-table-column
	      align="center"
	      prop="pzmc"
	      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="checkCcqy(scope.row)"
	  		        style="float: left"
	  		        type="primary"
	  		        size="small"
	  		        class="operate_show_btn iconfont iconchakan2"
	  		      ></el-button>
	  		    </el-tooltip>
			  </template>
			</el-table-column>
		</el-table>
	  <span slot="footer" class="dialog-footer">
		  <el-button type="primary" @click="addSubmit('','xg','scsp')">生成审批表</el-button>
	    <el-button @click="dialogVisible = false">返回</el-button>
	  </span>
	</el-dialog>
  </div>
</template>

<script>
import {subsidySummaryList,getPzOptions,subsidyApprovalList,subsidysummaryDelete} from '@/api/bglhbt/index'
import { authorityControl } from "@/api/login/login.js";
export default {
  data() {
    return {
		dialogVisible:false,
		sbdwlistLoading:false,
		sbdwDataList:[],
		pzOptions:[],
		yslist:[],
		ysZtOptions:[
			{
			    label:'待提交',
			    value:'91000290'
			},
			{
			    label:'待复核',
			    value:'91000300'
			},
			{
			    label:'复核驳回',
			    value:'91000301'
			},
			{
			    label:'待财务领导批示',
			    value:'91000400'
			},
			{
			    label:'财务领导驳回',
			    value:'91000401'
			},
			{
			    label:'待单位负责人批示',
			    value:'91000500'
			},
			{
			    label:'单位负责人驳回',
			    value:'91000501'
			},
			{
			    label:'审核完成',
			    value:'91000600'
			}
		],
      formInline: {
        lhnd:'',
		pzbm:'',
		ysZt:'',
		ccqy:'',
      },
      listLoading: false,
      tableData: [
        {
          lhnd:'2019'
        }
      ],
      pageForm: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
      },
	  buttonNameList:[],
    };
  },
  created() {
	this.getButtonList(
	  sessionStorage.getItem("resourceCode"),
	  sessionStorage.getItem("userCode")
	);
	  if(this.$route.query.ordialog == '1'){
	  	this.summaryDialog()
	  }
    this.getList("start");
	getPzOptions().then((res) => {
	  this.pzOptions = res.data;
	});
	
  },
  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);
	      });
	    });
	  },
    doSearch() {
      this.pageForm.pageNum = 1;
      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 {
          //第一次进去此菜单时，保存上方默认的data
          sessionStorage.setItem("searchData", JSON.stringify(this.formInline));
          sessionStorage.setItem("pageData", JSON.stringify(this.pageForm));
        }
      }
      var data={
        ...this.pageForm,
       ...this.formInline,
	   dataType:'1'
	   // type:'budget'
      }
      subsidySummaryList(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
        }
      });

    },
	//生成审批表
	summaryDialog(){
		this.dialogVisible=true
		var data={
			type:'budget'
		}
		subsidyApprovalList(data).then(res =>{
			if(res.infoCode == 200){
				this.sbdwDataList=res.data
			}
		})
	},
	selectBox(row,index){
		console.log(row,'jhhu------')
		if(row.ysbfzt == 1 || row.ysbfzt == 2){
			return false
		}else{
			return true
		}
	},
	//获取选中的list
	handselectionChange(e){
		this.yslist=e.map((item) =>item.id)
		console.log(this.yslist,'jhgh===========')
	},
	handleClose(){
		
	},
	//查看企业上报数据
	checkCcqy(row){
		this.$router.push({
		  name: "bglhbtDetail",
		  query: {
		    id:row ? row.id : undefined,
			jstype:'ys',
		    type:'ck',
			pageType:'summary'
		  },
		});
	},
    //新增
    addSubmit(row,type,scspType) {
		if(scspType){
			if(this.yslist.length > 0){
				this.$router.push({
				  name: "ysbtsummaryysDetail",
				  query: {
				    id:row ? row.id : undefined,
				    type:type ? type : undefined,
					yslist:this.yslist.toString()
				  },
				});
			}else{
				this.$message({
				  showClose: true,
				  message: "请选择审批单位",
				  type: "success",
				});
			}
		}else{
			this.$router.push({
			  name: "ysbtsummaryysDetail",
			  query: {
			    id:row ? row.id : undefined,
			    type:type ? type : undefined,
				yslist:this.yslist.toString()
			  },
			});
		}
      

    },
	deleteSubmit(row){
		console.log('666666666========')
		this.$confirm("是否确认删除？", "提示", {
		  confirmButtonText: "确定",
		  cancelButtonText: "取消",
		  type: "warning",
		}).then(() => {
			console.log('666666666========')
			var data={
				id:row.id
			}
		  subsidysummaryDelete(data)
			.then((response) => {
			  if (response.infoCode == 200) {
				this.getList();
				this.activeName ='bt'
				this.$message({
				  showClose: true,
				  message: "删除成功！",
				  type: "success",
				});
			  }
			})
			.catch(function (error) {
			  console.log(error);
			});
		});	
	},
    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>
