<template>
  <div>
    <div class="d-flex flex-between">
      <div>
        <!-- <el-button type="primary" size="medium" @click="addData">
          <span class="d-in-block v-mid el-icon-plus font-size-16"></span>
          <span class="d-in-block v-mid font-size-16">新建项目类别</span>
        </el-button> -->
      </div>
      <el-form label-width="100px" :inline="true">
        <el-form-item prop="filteTime">
          <el-date-picker style="width: 100%" v-model="filteTime" type="year" value-format="yyyy" placeholder="请选择时间">
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item prop="state_value">
          <el-select class="mr10" v-model="type_value" placeholder="请选择类别">
            <el-option v-for="item in type_list" :key="item.value" :label="item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item prop="keyword">
          <el-input placeholder="请输入搜索关键字" v-model="keyword" clearable @clear="getListData"></el-input>
        </el-form-item>
        <el-button type="primary" class="ml5" @click="getListData">搜索</el-button>
      </el-form>
    </div>
    <el-table :data="tableData" tooltip-effect="dark" v-loading="loading" style="width: 100%">
      <el-table-column type="selection" align="center" width="55"></el-table-column>
      <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
      <el-table-column label="项目名称"  prop="xm_name" show-overflow-tooltip></el-table-column>
      <el-table-column label="项目类别" prop="lb_name" show-overflow-tooltip></el-table-column>
      <el-table-column label="项目理由" prop="xm_reason" show-overflow-tooltip></el-table-column>
      <el-table-column label="申请科室" prop="department_name" show-overflow-tooltip></el-table-column>
      <el-table-column label="项目预算（元）" prop="xm_price" show-overflow-tooltip></el-table-column>
      <el-table-column label="申报时间" prop="xm_sbsj" show-overflow-tooltip></el-table-column>
      <el-table-column label="项目方式" prop="xm_type"></el-table-column>
      <el-table-column label="状态" prop="xm_status"></el-table-column>
      <el-table-column label="操作" width="150">
        <template slot-scope="scope">
          <el-popover placement="left" width="175" trigger="click">
            <el-button type="text" @click="detailShow(scope.row)">详情</el-button>
            <el-button type="text" @click="printForm(scope.row)">打印表单</el-button>
            <el-button type="text" @click="getConfirm(scope.row)">获批</el-button>
            <div slot="reference" class="optionMore" style="padding-left:10%;">
              <img src="../../../assets/icon/optionIcon.png" style="width:3%;" alt="">
            </div>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <footer class="flex-item-none" style="display: flex; justify-content: flex-end; margin-top: 30px">
      <el-pagination background layout="total,prev, pager, next" :page-size="limit" :total="total"
        :current-page.sync="cur_page" @current-change="handleCurrentChange"></el-pagination>
    </footer>

    <!--详情dialog-->
    <el-dialog title="详情" :visible.sync="dialogFormVisible_detail">
      <el-form :model="detail_form">
        <el-form-item label="项目名称" :label-width="formLabelWidth">
          <el-input v-model="detail_form.xmmc" autocomplete="off" :disabled="markDis"></el-input>
        </el-form-item>
        <el-form-item label="项目类别" :label-width="formLabelWidth">
          <el-input v-model="detail_form.xmlb" autocomplete="off" :disabled="markDis"></el-input>
        </el-form-item>
        <el-form-item label="项目理由" :label-width="formLabelWidth">
          <el-input v-model="detail_form.xmly" autocomplete="off" :disabled="markDis"></el-input>
        </el-form-item>
        <el-form-item label="申请科室" :label-width="formLabelWidth">
          <el-input v-model="detail_form.sqks" autocomplete="off" :disabled="markDis"></el-input>
        </el-form-item>
        <el-form-item label="项目预算（元）" :label-width="formLabelWidth">
          <el-input v-model="detail_form.xmys" autocomplete="off" :disabled="markDis"></el-input>
        </el-form-item>
        <el-form-item label="申报时间" :label-width="formLabelWidth">
          <el-input v-model="detail_form.sbsj" autocomplete="off" :disabled="markDis"></el-input>
        </el-form-item>
        <el-form-item label="项目方式" :label-width="formLabelWidth">
          <el-input v-model="detail_form.xmfs" autocomplete="off" :disabled="markDis"></el-input>
        </el-form-item>
        <el-form-item label="状态" :label-width="formLabelWidth">
          <el-input v-model="detail_form.xmfs" autocomplete="off" :disabled="markDis"></el-input>
        </el-form-item>
       
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible_detail = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { xmds_list, xmds_add, xmds_edit, shsz_del, org_users } from "./itemApi";
import { useUserStore } from "@/stores/user";
const { real_name, dept_ids } = useUserStore();
export default {
  name: "jblx",
  data() {
    return {
      filteTime: "",
      keyword: "",
      tableData: [],
      type_value: "",
      type_list: [
        {
          label: "全部",
          value: "0",
        },
        {
          label: "待审",
          value: "1",
        }
      ],
      limit: 10,
      total: 12,
      cur_page: 1,
      dialogFormVisible_detail: false,
      detail_form: {
        xmmc:"",
        xmlb: "",
        xmlb_id: "",
        xmly: "",
        sqks: "",
        xmys: "",
        sbsj: "",
        xmnr: "",
        xmfs: "",
        xmfj: "",
      },
      formLabelWidth: '120px',
      title: "",
      isEdit: false,
      id: "",
      loading: false,
      time_type: [
        {
          id: "1",
          label: "工作日",
        },
        {
          id: "2",
          label: "休息日",
        },
        {
          id: "3",
          label: "节假日",
        },
        {
          id: "4",
          label: "其他",
        },
      ],
      userList: [],
      markDis:false,
    };
  },
  mounted() {
    // this.getUserList();
    this.getListData();
  },
  methods: {
    getUserList() {
      let data = {
        dept_id: dept_ids[0],
        page: 1,
        limit: 9999,
      };
      org_users(data).then((res) => {
        if (res.code == 1) {
          this.userList = res.data.page_data;
        }
      });
    },
    //初始化列表数据
    getListData() {
      this.loading = true;
      let transObj = {
        page: this.cur_page,
        limit: this.limit,
        keyword: this.keyword,
        xm_is_wc:3,
        year:this.filteTime,
      };
      xmds_list(transObj).then((res) => {
        this.loading = false;
        this.tableData = res.data.page_data;
        this.cur_page = Number(res.data.page_now);
        this.total = Number(res.data.total_rows);
      });
    },
    //详情
    detailShow(item) {
      let chooseID = item.xm_id;
      this.$router.push({ name: "xmlxsb_xmsq_xq", params: { id: chooseID } });
    },
    //打印表单
    printForm(item) {
      let chooseID = item.xm_id;
      this.$router.push({ name: "xmlxsb_xmsq_dybb", params: { id: chooseID } });
    },
    //最终获批
    getConfirm(item) {
      let transObj = {
        xm_id: item.xm_id,
        jdbg_xmlxsb_xmsq: {
          xm_is_wc:1//是否获批 1是 2否 3待审
        }
      }
      this.$confirm("确认获批该项目?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          xmds_edit(transObj)
          .then(res=>{
            if (res.code == "1") {
              this.$message({
                message: "添加成功！",
                type: "success",
              });
              this.getListData();
            }else {
              this.$message({
                message: res.msg,
                type: "error",
              });
            }
          })
        .catch(err=>{console.log(err)})
      })
    },
    //翻页
    handleCurrentChange(val) {
      this.cur_page = val;
      this.getListData();
    },
  },
  
};
</script>

<style lang="scss" scoped>
.time-type-list {
  width: 100%;
  border-bottom: 1px solid #f3f3f3;
  margin-bottom: 20px;
  display: flex;

  li {
    position: relative;
    top: 2px;
    cursor: pointer;
    width: 50px;
    font-size: 14px;
    line-height: 30px;
    text-align: center;

    &+li {
      margin-left: 20px;
    }

    &.selected {
      color: #265cd4;
      border-bottom: 2px solid #265cd4;
    }
  }
}
</style>
