<template>
  <div class="financialBox">
    <el-form ref="form" :model="form" label-width="80px" class="line-bottom" inline>
          <el-form-item label="主管部门:">
            <el-input v-model="form.projectName"  clearable  placeholder="主管部门" style="width:180px"></el-input>
          </el-form-item>
          <el-form-item label="状态:">
            <el-select v-model="form.findingsAudit" clearable placeholder="请选择"  style="width:180px">
              <el-option
                v-for="(item,index) in findingsAuditObj"
                :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-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="projectName" label="主管部门" align="center"></el-table-column>
      <el-table-column
        :show-overflow-tooltip="true"
        prop="projectContent"
        label="资金总额"
        align="center"
      ></el-table-column>
      <el-table-column :show-overflow-tooltip="true" prop="expenditureProgress" label="财政拨款" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.expenditureProgress=='null'?'':scope.row.expenditureProgress}}</span>
        </template>
      </el-table-column>
      <el-table-column label="填写日期" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.fillDate?scope.row.fillDate.split('T')[0]:""}}</span>
        </template>
      </el-table-column>
      <el-table-column
        :show-overflow-tooltip="true"
        prop="findingsAudit"
        label="状态"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" width="170" 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,'show')"
                    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.findingsAudit=='未提交' || scope.row.findingsAudit=='驳回'"
          >
            <el-button
              type="primary"
              class="button operate_edit_btn"
              @click.stop="modify(scope.row,'update')"
              id="ml-9"
              style="float:left;"
            >
              <i class="iconfont iconxiugai" style="font-size: 13px"></i>
            </el-button>
          </el-tooltip>
          <el-tooltip
                  class="item"
                  effect="light"
                  content="提交"
                  placement="top"
                  v-show="scope.row.findingsAudit=='未提交' || scope.row.findingsAudit=='驳回'"
          >
<!--            <el-button-->
<!--                    @click="submission(scope.row,'update')"-->
<!--                    type="primary"-->
<!--                    class="button operate_submit_btn"-->
<!--                    style="float:left;"-->
<!--            >-->
<!--              <i class="iconfont icontijiao" style="font-size: 13px"></i>-->
<!--            </el-button>-->
            <i class="iconfont icontijiao"
               @click="submission(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
            class="item"
            effect="light"
            content="删除"
            placement="top"
            v-show="scope.row.findingsAudit=='未提交'"
          >
            <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>


        </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 {
  budgetPerformanceManagementByPage,
  budgetPerformanceManagementDelete1,
  budgetPerformanceManagementSubmission
} from "@/api/budgetPerformanceManagement/index";

export default {
  data() {
    return {
      form: {},
      formPage: {
        page: 1,
        size: 10,
        total: 0
      },
      //状态
      findingsAuditObj: [
        {
          value: "未提交",
          code: "0"
        },
        {
          value: "处室处长审核",
          code: "1"
        },
        {
          value: "办公室财务人员审核",
          code: "2"
        },
        {
          value: "办公室财务处长审核",
          code: "3"
        },
        {
          value: "规划财务处人员审核",
          code: "4"
        },
        {
          value: "规划财务处处长审核",
          code: "5"
        },
        {
          value: "审核通过",
          code: "6"
        },
        {
          value: "驳回",
          code: "0"
        },
      ],
      //列表数据
      tableData: [],
      //列表loading控制
      tableLoading: false
    };
  },
  methods: {
    //清空
    clearInfo() {
      this.form = {};
      this.initTableData();
    },
    // 编辑
    modify(row, state) {
      this.$router.push({
        path: "applyAdd",
        query: {
          id: row.id,
          state: state,
          row: JSON.stringify(row),
          fundSo: row.fundSources,
          bolF: "fundSources"
        }
      });
    },
    // 查看
    modifyShow(row, state) {
      this.$router.push({
        path: "applyShow",
        query: {
          id: row.id,
          state: state,
          row: JSON.stringify(row),
          fundSo: row.fundSources,
          bolF: "fundSources"
        }
      });
    },
    //查询
    searchInfo() {
      this.initTableData();
    },
    //新增
    newAdd() {
      this.dialogForm = {};
      this.$router.push({
        path: "/grainHarvestSys/service/companyInfoDetail",
        query: { state: "add" }
      });
    },
    look(id) {
      this.$router.push({
        path: "/grainHarvestSys/service/companyInfoDetail",
        query: { state: "detail", id: id }
      });
    },
    edit(id) {
      this.$router.push({
        path: "/grainHarvestSys/service/companyInfoDetail",
        query: { state: "edit", id: id }
      });
    },
    //分页大小
    handleSizeChange(val) {
      this.formPage.size = val;
      this.initTableData();
    },
    //分页页数
    handleCurrentChange(val) {
      this.formPage.page = val;
      this.initTableData();
    },
    //初始化列表数据
    initTableData() {
      this.tableLoading = true;
      budgetPerformanceManagementByPage(this.form, this.formPage, 0).then(
        response => {
          if (response.infoCode === 200) {
            this.tableData = response.data.list;
            this.formPage.total = response.data.total;
          } else {
            this.$message({
              type: "error",
              message: response.msg
            });
          }
          this.tableLoading = false;
        }
      );
    },
    //列表删除
    // 单点删除
    deleteInfo(row) {
      this.$confirm("是否确认删除？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {

        let tokenMsg = window.sessionStorage.getItem('TOKENL')
        let msg1 = tokenMsg.split('.')[1]
        let base64 = require('js-base64').Base64;
        let userInfo = JSON.parse(base64.decode(msg1));
        let params={
          deleteBy:userInfo.userName,
          deleteTime:new Date(),
          id:row.id
        }
        budgetPerformanceManagementDelete1(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("已过提交日期，不可提交")
    },
    // 提交
    submission(row, state) {
      var date = new Date();
      // var month = date.getMonth() + 1;
      var month = 3;
      // var day = date.getDate();
      var day = 24;
      // if (month == 3) {
      //   if (day >= 26) {
      //   } else {
      //     this.open(month, day);
      //     return false;
      //   }
      // } else if (month == 6) {
      //   if (day >= 25) {
      //   } else {
      //     this.open(month, day);
      //     return false;
      //   }
      // } else if (month == 9) {
      //   if (day >= 25) {
      //   } else {
      //     this.open(month, day);
      //     return false;
      //   }
      // } else if (month == 12) {
      //   if (day >= 26) {
      //   } else {
      //     this.open(month, day);
      //     return false;
      //   }
      // } else {
      //   this.open(month, day);
      //   return false;
      // }
      if (
        row.fillDate == null ||
        row.projectCompletionSchedule == null
      ) {
        this.$router.push({
          path: "applyAdd",
          query: {
            id: row.id,
            state: state,
            row: JSON.stringify(row),
            fundSo: row.fundSources,
            bolF: "fundSources"
          }
        });
        // this.$message.info("请填写项目完成进度")
      } else {
        row.findingsAudit = row.projectName === '内蒙古自治区粮食和物资储备局601001' ? "处室处长审核" : "待二级单位财务审核",
        budgetPerformanceManagementSubmission(row).then(response => {
          if (response.infoCode === 200) {
            this.$message.success("提交成功")
            this.initTableData();
          } else {
            this.$message({
              type: "error",
              message: response.msg
            });
          }
        });
      }
    }
  },
  created() {
    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>

