<template>
  <div class="financialBox">
    <el-form ref="form" :model="form" label-width="80px" class="line-bottom" inline>
          <el-form-item label="年度:">
			<el-date-picker
			      v-model="form.tbnf"
			      type="year"
			      placeholder="选择年度"
			      format="yyyy"
			      value-format="yyyy">
			</el-date-picker>
            <!-- <el-input v-model="form.tbnf"  clearable  placeholder="主管部门" style="width:180px"></el-input> -->
          </el-form-item>
          <el-form-item v-if="dldePotCode == 'DP001007'" label="填报部门:">
			  <el-cascader
			    clearable
			    :options="deptData"
			    v-model="form.depotCode"
			    change-on-select
			    :show-all-levels="true"
			    :props="departprops"
			  ></el-cascader>
           <!-- <el-select v-model="form.depotCode" clearable placeholder="请选择"  style="width:180px">
              <el-option
                v-for="(item,index) in depotCodeOptions"
                :key="index"
                :label="item.value"
                :value="item.value"
              ></el-option>
            </el-select> -->
          </el-form-item>
      <div class="searchBox">
        <div class="search-line"></div>
        <el-button
                class="iconfont iconchaxun"
                size="mini"
                type="primary"
                style="margin-top:3px;margin-left:10px;"
                @click="searchInfo"
        > 查询
        </el-button>
        <el-button
                class="iconfont iconzhongzhi"
                size="mini"
                style="margin-top:3px;margin-left:10px;"
                @click="clearInfo"
                type="primary"
        > 重置
        </el-button>
      </div>
    </el-form>
	<el-row></el-row>
	<el-row
	  v-if="buttonNameList.indexOf('新增') > -1"
	  class="addBtnBg"
	  style="
	    background: rgb(237, 245, 253);
	    line-height: 50px;
	    margin-bottom: 10px;
	  "
	>
	  <el-button
	    type="primary"
	    class="iconfont iconxinzeng"
	    size="small"
	    @click="addSubmit(undefined,'update')"
	    >新增</el-button
	  >
	</el-row>
    <el-table
      :data="tableData"
      v-loading="tableLoading"
      stripe
      border
      style="width: 100%;margin-top:10px;"
    >
      <el-table-column type="index" label="序号" width="60" align="center"></el-table-column>
      <el-table-column
        :show-overflow-tooltip="true"
        prop="mname"
        label="名称"
        align="center"
      ></el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="tbnf" label="年度" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.tbnf=='null'?'':scope.row.tbnf}}</span>
        </template>
      </el-table-column>
      <el-table-column label="填报时间" prop='createTime' align="center">
        <template slot-scope="scope">
          <span>{{scope.row.createTime?scope.row.createTime.split('T')[0]:""}}</span>
        </template>
      </el-table-column>
	  <el-table-column :show-overflow-tooltip="true" prop="depotName" label="填报部门" align="center"></el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="createPerson" label="填报人" align="center"></el-table-column>
	  <el-table-column
        :show-overflow-tooltip="true"
        prop="dataStatus"
        label="状态"
        align="center"
      >
	  <template slot-scope="scope">
	    <span>{{scope.row.dataStatus== 1 ? '待提交' : '已提交'}}</span>
	  </template>
	  </el-table-column>
      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-tooltip class="item" effect="light" content="查看" placement="top">
            <el-button
                    type="primary"
                    class="button operate_show_btn"
                    @click.stop="modifyShow(scope.row,'详情')"
                    style="float:left;"
            >
              <i class="iconfont iconchakan2" style="font-size: 13px"></i>
            </el-button>
          </el-tooltip>
          <!-- <el-tooltip
            class="item"
            effect="light"
            content="保存"
            placement="top"
            v-show="scope.row.dataStatus=='1'"
          >
            <el-button
              type="primary"
              class="button operate_edit_btn"
              @click.stop="addSubmit(scope.row,'update')"
              id="ml-9"
              style="float:left;"
            >
              <i class="iconfont iconbaocun" style="font-size: 13px"></i>
            </el-button>
          </el-tooltip> -->
          <el-tooltip
                  class="item"
                  effect="light"
                  content="编辑"
                  placement="top"
                  v-show="scope.row.dataStatus=='1' && buttonNameList.indexOf('编辑') > -1"
          >
            <i class="iconfont iconxiugai"
               @click="addSubmit(scope.row,'update')"
               style="width:24px;
						height:24px;
						float:left;
						margin:0 10px;
						text-align:center;
						line-height:24px;
						font-size:13px;
						color:#fff;
						background:#3082bc;
						border-radius:3px;
						cursor:pointer;
						display:inline-block;"></i>
          </el-tooltip>
		  <el-tooltip
		    v-show="scope.row.dataStatus=='0' && buttonNameList.indexOf('退回') > -1"
		     class="item"
		     effect="light"
		     content="退回"
		     placement="top"
		   >
		    <i class="iconfont iconfanhui"
		       @click="addSubmit(scope.row,'cx')"
		       style="width:24px;
		    			height:24px;
		    			float:left;
		    			margin:0 0 0 10px;
		    			text-align:center;
		    			line-height:24px;
		    			font-size:13px;
		    			color:#fff;
		    			background:#3082bc;
		    			border-radius:3px;
		    			cursor:pointer;
		    			display:inline-block;"></i>
		   </el-tooltip>
          <el-tooltip
            class="item"
            effect="light"
            content="删除"
            placement="top"
            v-show="scope.row.dataStatus=='1' && buttonNameList.indexOf('删除') > -1"
          >
            <el-button
              type="primary"
              class="button operate_delete_btn"
              @click="deleteInfo(scope.row)"
              style="float:left;"
            ><i class="iconfont iconshanchu" style="font-size: 13px"></i></el-button>
          </el-tooltip>
		  <el-tooltip
		  v-if="buttonNameList.indexOf('导出') > -1"
		    class="item"
		    effect="light"
		    content="导出"
		    placement="top"
		  >
		    <el-button
		      type="primary"
		      class="button operate_delete_btn"
		      @click="handleExportWord(scope.row,'dc')"
		      style="float:left;"
		    ><i class="iconfont icondaochu11" style="font-size: 13px"></i></el-button>
		  </el-tooltip>

        </template>
      </el-table-column>
    </el-table>
    <div class="pag-right clearFix">
      <el-pagination
        class="right"
        style="text-align:right;margin-right: 20px;"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="formPage.page"
        :page-sizes="[10,20,30,40]"
        :page-size="formPage.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="formPage.total"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import {
	sysCwModelsGetList,
	sysCwModelsRemove,
	sysCwModelsExportWord,
	findByOrgCode
} from "@/api/budgetFilling/index";
import { authorityControl } from "@/api/login/login.js";
export default {
  data() {
    return {
		dldePotCode:sessionStorage.getItem("deptId"),
      form: {
		depotCode:sessionStorage.getItem("deptId") == 'DP001007' ? '' : [sessionStorage.getItem("deptId")],
		orgCode:sessionStorage.getItem("orgCode"),
		dataType:'0',
		tbnf:'',
	  },
      formPage: {
        page: 1,
        size: 10,
        total: 0
      },
	  departprops: {
	    label: "deptName",
	    value: "deptCode",
	    children: "children",
	  },
      //状态
      deptData: [
      ],
      //列表数据
      tableData: [],
      //列表loading控制
      tableLoading: false,
	  buttonNameList:[],
    };
  },
  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);
	      });
	    });
	  },
	//获取部门list
	GetFindByOrgCode(){
		var data={
			orgCode:sessionStorage.getItem("orgCode"),
		}
		findByOrgCode(data).then(res =>{
			if(res.infoCode == 200){
				res.data.forEach((item) =>{
					if(item.deptType == '10330000'){
						this.deptData=item.children
					}
				})
			}
		})
	},
	  
    //清空
    clearInfo() {
      this.form = {
		  orgCode:sessionStorage.getItem("orgCode"),
		  dataType:'0',
		  tbnf:'',
	  };
	  this.formPage.page = 1
	  if(sessionStorage.getItem("deptId") == 'DP001007'){
	  	this.form.depotCode=[]  
	  }else{
	  	this.form.depotCode=[sessionStorage.getItem("deptId")]
	  }
      this.initTableData();
    },
	//导出
	handleExportWord(row,btnAction) {
		// this.$router.push({
		//   path: "ysxmpsbgDetail",
		//   query: { btnAction: btnAction,id:row? row.id : undefined }
		// });
	  let data = {
		  id:row.id
	 //    modelName:'年度财政预算项目事前绩效评估报告',
		// modelText:this.formData.mtext,
	  };
	  sysCwModelsExportWord(data)
	    .then((response) => {
	      let modelName = "年度财政预算项目评审报告";
		  
		  // { type: "application/json;charset=utf-8" }
	      let blob = new Blob([response], { type: "application/x-www-form-urlencoded" });
	      if (!!window.ActiveXObject || "ActiveXObject" in window) {
	        window.navigator.msSaveOrOpenBlob(blob, modelName );
	      } else {
	        const link = document.createElement("a");
	        link.style.display = "none";
	        link.href = URL.createObjectURL(blob);
	        link.setAttribute("download", `${modelName}.doc` );
	        document.body.appendChild(link);
	        link.click();
	        document.body.removeChild(link);
	      }
	    })
	    .catch();
	},
    // 查看
    modifyShow(row, btnAction) {
      this.$router.push({
        path: "ysxmpsbgDetail",
        query: { 
			btnAction: btnAction,
			id:row.id
			}
      });
    },
    //查询
    searchInfo() {
      this.initTableData();
    },
    //新增
    addSubmit(row,btnAction) {
      this.$router.push({
        path: "ysxmpsbgDetail",
        query: { btnAction: btnAction,id:row? row.id : undefined }
      });
    },
    //分页大小
    handleSizeChange(val) {
      this.formPage.size = val;
      this.initTableData();
    },
    //分页页数
    handleCurrentChange(val) {
      this.formPage.page = val;
      this.initTableData();
    },
    //初始化列表数据
    initTableData() {
      this.tableLoading = true;
	  console.log(this.form,'yue777777-',this.form.depotCode)
	  if (typeof this.form.depotCode=='object') {
	    this.form.depotCode = this.form.depotCode.slice(-1)[0];
	  }
	  var data={
		  ...this.form,
		  ...this.formPage
	  }
      sysCwModelsGetList(data).then(
        res => {
          if (res.infoCode === 200) {
            this.tableData = res.data.list;
            this.formPage.total = res.data.total;
          } else {
            this.$message({
              type: "error",
              message: res.msg
            });
          }
          this.tableLoading = false;
        }
      );
    },
    //列表删除
    // 单点删除
    deleteInfo(row) {
      this.$confirm("是否确认删除？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let params={
          id:row.id
        }
        sysCwModelsRemove(params).then(response => {
          if (response.infoCode == "200") {
            this.$message.success("删除成功")
            this.initTableData();
          } else {
            this.$message({
              type: "error",
              message: response.msg
            });
          }
        });
      });
    },
    open(month, day) {
      this.$message.info("已过提交日期，不可提交")
    },
  },
  created() {
	this.getButtonList(
	  sessionStorage.getItem("resourceCode"),
	  sessionStorage.getItem("userCode")
	);
	  // console.log(new Date().getFullYear(),'375432=')
	  this.GetFindByOrgCode()
    this.initTableData();
  }
};
</script>
<style scoped>
#ml-9 {
  margin-left: 9px;
}
.financialBox{
  overflow-y: auto;
  margin: 10px;
  border: 1px solid #f4f5f8;
  padding: 10px;
  min-width: 960px;
}
.textRed{
  color:#F56C6C ;
}
.dashboard-container{
  overflow: auto;
}
.searchBox{
  position: relative;
  display: inline-block;
}
.line-bottom{
  border-bottom:1px dashed #006bd5;
}
.search-line {
  cursor: pointer;
  border-right: 1px dashed #737bf1;
  height: 38px;
  display: inline-block;
  margin:0 10px 0 20px;
  vertical-align: middle;
}
</style>

