<template>
  <div class="content-main">
    <el-form
      ref="searchForm"
      :inline="true"
      :model="searchForm"
      class="demo-form-inline search-form"
      label-position="left"
    >
      <el-row>
        <el-form-item label="编号:" prop="orderNumber">
          <el-input
            v-model="searchForm.orderNumber"
            clearable
            placeholder="请输入编号"
          ></el-input>
        </el-form-item>
        <el-form-item label="申请单位:" prop="applyOrgName">
          <el-input
            v-model="searchForm.applyOrgName"
            clearable
            placeholder="请输入申请单位"
          ></el-input>
        </el-form-item>
        <el-form-item label="需求描述:" prop="problemDesc">
          <el-input
            v-model="searchForm.problemDesc"
            clearable
            placeholder="请输入问题情况描述"
          ></el-input>
        </el-form-item>
        <!-- <el-form-item label="系统名称:" prop="webSysName">
          <el-select
            v-model="searchForm.webSysName"
            style="width: 170px"
            clearable
            placeholder="请选择系统名称"
            >
            <el-option
              v-for="item in systemNameOptions"
              :key="item.name"
              :label="item.name"
              :value="item.name"
            ></el-option>
          </el-select>
        </el-form-item> -->

        <el-form-item>
          <div class="search-button">
            <span class="search-line"></span>
            <div
              class="search-select"
              @click="searchShowMoreBool = !searchShowMoreBool"
            >
              更多条件
              <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="searchInfo"
              >查询</el-button
            >
            <el-button
              type="primary"
              @click="resetInfo('searchForm')"
              size="small"
              class="iconfont iconzhongzhi"
            >
              重置</el-button
            >
          </div>
        </el-form-item>
      </el-row>
      <el-row v-show="searchShowMoreBool">
        <el-form-item label="状态:" prop="status">
          <el-select
            v-model="searchForm.status"
            style="width: 170px"
            clearable
            placeholder="请选择状态"
          >
            <el-option
              v-for="item in shztOptions"
              :key="item.code"
              :label="item.name"
              :value="item.code"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="提交时间:" prop="signatureDate">
          <el-date-picker
            v-model="searchForm.signatureDate"
            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="受理时间:" prop="acceptDate">
          <el-date-picker
            v-model="searchForm.acceptDate"
            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="解决时间:" prop="solveDate">
          <el-date-picker
            v-model="searchForm.solveDate"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
      </el-row>
    </el-form>
    <el-row class="addBtnBg">
      <el-button
        type="primary"
        class="iconfont icondaochu11"
        size="mini"
        @click="handleExport"
        >导出</el-button
      >
    
    </el-row>
    <el-row>
      <el-table
        :data="tableData"
        stripe
        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="orderNumber"
          show-overflow-tooltip
          label="编号"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="applyOrgName"
          label="申请单位"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          align="center"
          prop="requirementDescription"
          label="需求描述"
          show-overflow-tooltip
        ></el-table-column>
        <!-- <el-table-column
          align="center"
          prop="webSysName"
          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"
          prop="signatureDate"
          label="提交时间"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="acceptDate"
          label="受理时间"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="solveDate"
          label="解决时间"
        ></el-table-column>
        <el-table-column align="center" label="操作" width="120">
          <template slot-scope="scope">
            <el-tooltip effect="light" content="查看" placement="top">
              <el-button
                @click="handleClick(scope.row, 'CK')"
                type="primary"
                size="small"
                class="operate_show_btn iconfont iconchakan2"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="审核"
              placement="top"
              v-if="buttonNameList.indexOf('待区粮办审核') > -1"
            >
              <!--  -->
              <el-button
                @click="handleClick(scope.row, 'sh')"
                type="primary"
                class="operate_edit_btn iconfont iconshenhe"
                v-show="scope.row.status == '92000020'"
                size="small"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="审核"
              placement="top"
              v-if="buttonNameList.indexOf('待市储备处审核') > -1"
            >
              <!--  -->
              <el-button
                @click="handleClick(scope.row, 'shone')"
                type="primary"
                class="operate_edit_btn iconfont iconshenhe"
                v-show="scope.row.status == '92000030'"
                size="small"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="审核"
              placement="top"
              v-if="buttonNameList.indexOf('征求市储备公司意见') > -1"
            >
              <!--  -->
              <el-button
                @click="handleClick(scope.row, 'shtwo')"
                type="primary"
                class="operate_edit_btn iconfont iconshenhe"
                v-show="scope.row.status == '92000040'"
                size="small"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="审核"
              placement="top"
              v-if="buttonNameList.indexOf('待市储备处二次审核') > -1"
            >
              <!--  -->
              <el-button
                @click="handleClick(scope.row, 'shthree')"
                type="primary"
                class="operate_edit_btn iconfont iconshenhe"
                v-show="scope.row.status == '92000050'"
                size="small"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="审核"
              placement="top"
              v-if="buttonNameList.indexOf('征求业务处室意见') > -1"
            >
              <!--  -->
              <el-button
                @click="handleClick(scope.row, 'shfour')"
                type="primary"
                class="operate_edit_btn iconfont iconshenhe"
                v-show="scope.row.status == '92000052'"
                size="small"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="审核"
              placement="top"
              v-if="buttonNameList.indexOf('待市储备处三次审核') > -1"
            >
              <!--  -->
              <el-button
                @click="handleClick(scope.row, 'shfive')"
                type="primary"
                class="operate_edit_btn iconfont iconshenhe"
                v-show="scope.row.status == '92000055'"
                size="small"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="受理"
              placement="top"
              v-if="buttonNameList.indexOf('待受理') > -1"
            >
              <!--  -->
              <el-button
                @click="handleClick(scope.row, 'sl')"
                type="primary"
                class="operate_edit_btn iconfont iconqueren"
                v-show="scope.row.status == '92000060'"
                size="small"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="解决"
              placement="top"
              v-if="buttonNameList.indexOf('办理中') > -1"
            >
              <!--  -->
              <el-button
                @click="handleClick(scope.row, 'jj')"
                type="primary"
                class="operate_edit_btn iconfont iconqueren"
                v-show="
                  scope.row.status == '92000070' ||
                  scope.row.status == '92000071'
                "
                size="small"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="确认"
              placement="top"
              v-if="buttonNameList.indexOf('待信息中心确认') > -1"
            >
              <el-button
                @click="handleClick(scope.row, 'qr')"
                type="primary"
                class="operate_edit_btn iconfont iconqueren"
                v-show="scope.row.status == '92000091'"
                size="small"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="追加问题处理"
              placement="top"
              v-if="buttonNameList.indexOf('追加问题处理') > -1"
            >
              <el-button
                @click="handleClick(scope.row, 'zj')"
                type="primary"
                class="operate_edit_btn iconfont iconxinzeng"
                v-show="
                  scope.row.status == '92000060' ||
                  scope.row.status == '92000070'
                "
                size="small"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              effect="light"
              content="删除"
              placement="top"
              v-if="buttonNameList.indexOf('删除') > -1"
            >
              <el-button
                @click="deleteRow(scope.row)"
                type="primary"
                v-show="scope.row.status == '91000001'"
                size="small"
                class="operate_delete_btn iconfont iconshanchu"
              ></el-button>
            </el-tooltip>
			<el-tooltip
			  class="item"
			  effect="light"
			  content="导出"
			  placement="top"
			>
			  <el-button
			    @click="handleClick(scope.row, 'dc')"
			    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>
  </div>
</template>

<script>
import { authorityControl } from "@/api/login/login";
import {
  dataReviseOrderPage,
  exportDataReviseOrderExcel
  // findYWRYPDictCode,
  // removeList,
} from "@/api/operationServices/datadeletAndUp/index.js";
export default {
  data() {
    return {
      searchShowMoreBool: false,
      buttonNameList: [],
      searchForm: {
        orderNumber: "",
        applyOrgName: "",
        workOrderType: "",
        problemDesc: "",
        // webSysName:'',
        status: "",
        signatureDate: [],
        acceptDate: [],
        solveDate: [],
      },
      shztOptions: [
        {
          code: "92000002",
          name: "审核驳回",
        },
        {
          code: "92000010",
          name: "待审核",
        },
        {
          code: "92000011",
          name: "盖章驳回",
        },
        {
          code: "92000012",
          name: "待盖章",
        },
        {
          code: "92000013",
          name: "区粮办驳回",
        },
        {
          code: "92000020",
          name: "待区粮办审核",
        },
        {
          code: "92000021",
          name: "区粮办不同意",
        },
        {
          code: "92000022",
          name: "市储备处驳回",
        },
        {
          code: "92000030",
          name: "待市储备处审核",
        },
        {
          code: "92000031",
          name: "市储备处不同意",
        },
        {
          code: "92000040",
          name: "征求市储备公司意见",
        },
        {
          code: "92000050",
          name: "待市储备处二次审核",
        },
        {
          code: "92000051",
          name: "待市储备处二次审核",
        },

        {
          code: "92000052",
          name: "征求业务处室意见",
        },
        {
          code: "92000055",
          name: "待市储备处三次审核",
        },
        {
          code: "92000056",
          name: "市储备处三次审核不同意",
        },
        {
          code: "92000060",
          name: "待受理",
        },
        {
          code: "92000070",
          name: "办理中",
        },
        {
          code: "92000071",
          name: "未完成继续办理",
        },
        {
          code: "92000080",
          name: "待申请人确认",
        },
        {
          code: "92000081",
          name: "未完成再次确认",
        },
        {
          code: "92000091",
          name: "待信息中心确认",
        },
        {
          code: "92000099",
          name: "完成",
        },
      ],
      pageForm: {
        pageNum: 1,
        pageSize: 10,
        total: 0,
      },
      tableData: [],
    };
  },
  created() {
    this.getButtonList(
      sessionStorage.getItem("resourceCode"),
      sessionStorage.getItem("userCode")
    );
  },
  methods: {
	//导出
	handleExport() {
	  let data = {
	    orderNumber: this.searchForm.orderNumber,
	    workOrderType: this.searchForm.workOrderType,
	    problemDesc: this.searchForm.problemDesc,
	    applyOrgName: this.searchForm.applyOrgName,
	    status: this.searchForm.status,
	    signatureStartDate:
	      this.searchForm.signatureDate.length > 0
	        ? this.searchForm.signatureDate[0]
	        : "",
	    signatureEndDate:
	      this.searchForm.signatureDate.length > 0
	        ? this.searchForm.signatureDate[1]
	        : "",
	    acceptStartDate:
	      this.searchForm.acceptDate.length > 0
	        ? this.searchForm.acceptDate[0]
	        : "",
	    acceptEndDate:
	      this.searchForm.acceptDate.length > 0
	        ? this.searchForm.acceptDate[1]
	        : "",
	    solveStartDate:
	      this.searchForm.solveDate.length > 0
	        ? this.searchForm.solveDate[0]
	        : "",
	    solveEndDate:
	      this.searchForm.solveDate.length > 0
	        ? this.searchForm.solveDate[1]
	        : "",
	    // type: 2,
	    type: this.searchForm.type,
	  };
	  exportDataReviseOrderExcel(data)
	    .then((response) => {
	      let exportName = "系统数据删改单申请表";
	      let blob = new Blob([response], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8" });
	      if (!!window.ActiveXObject || "ActiveXObject" in window) {
	        window.navigator.msSaveOrOpenBlob(blob, exportName);
	      } else {
	        const link = document.createElement("a");
	        link.style.display = "none";
	        link.href = URL.createObjectURL(blob);
	        link.setAttribute("download", exportName);
	        document.body.appendChild(link);
	        link.click();
	        document.body.removeChild(link);
	      }
	    })
	    .catch();
	},
    searchShowMore() {
      this.searchShowMoreBool = !this.searchShowMoreBool;
    },
    //获取按钮权限
    getButtonList(menuCode, userCode) {
      let codeData = {
        resourceCode: menuCode,
        userId: userCode,
      };
      authorityControl(codeData).then((res) => {
        let buttonNameList = [];
        res.data.forEach((item) => {
          this.buttonNameList.push(item.resourceName);
        });
        if (this.buttonNameList.indexOf("待区粮办审核") > -1) {
          this.searchForm.type = 1;
        }
        if (this.buttonNameList.indexOf("待市储备处审核") > -1) {
          this.searchForm.type = 2;
        }
        if (this.buttonNameList.indexOf("征求市储备公司意见") > -1) {
          this.searchForm.type = 3;
        }
        if (this.buttonNameList.indexOf("办理中") > -1) {
          this.searchForm.type = 4;
        }
        if (this.buttonNameList.indexOf("待信息中心确认") > -1) {
          this.searchForm.type = 5;
        }
        if (this.buttonNameList.indexOf("征求业务处室意见") > -1) {
          this.searchForm.type = 7;
        }

        // 1:区粮办 2:市储备粮处 3:市储备公司 4:运维部门5.信息重信，7其他业务处室
        this.getList("start");
      });
    },
    getList(type) {
      if (type != "start") {
        //非初始化调用：查询、分页
        sessionStorage.setItem("searchData", JSON.stringify(this.searchForm));
        sessionStorage.setItem("pageData", JSON.stringify(this.pageForm));
      } else {
        //初始化分两种情况，详情页等返回后的初始化，以及第一次进入此菜单的初始化
        if (JSON.parse(sessionStorage.getItem("searchData"))) {
          //详情页返回后，将对应查询条件和分页的字段赋值，页面回显参数
          this.searchForm = JSON.parse(sessionStorage.getItem("searchData"));
          this.pageForm = JSON.parse(sessionStorage.getItem("pageData"));
        } else {
          //第一次进去此菜单时，保存上方默认的data
          sessionStorage.setItem("searchData", JSON.stringify(this.searchForm));
          sessionStorage.setItem("pageData", JSON.stringify(this.pageForm));
        }
      }
      let data = {
        orderNumber: this.searchForm.orderNumber,
        workOrderType: this.searchForm.workOrderType,
        problemDesc: this.searchForm.problemDesc,
        applyOrgName: this.searchForm.applyOrgName,
        status: this.searchForm.status,
        pageSize: this.pageForm.pageSize,
        pageNum: this.pageForm.pageNum,
        signatureStartDate:
          this.searchForm.signatureDate.length > 0
            ? this.searchForm.signatureDate[0]
            : "",
        signatureEndDate:
          this.searchForm.signatureDate.length > 0
            ? this.searchForm.signatureDate[1]
            : "",
        acceptStartDate:
          this.searchForm.acceptDate.length > 0
            ? this.searchForm.acceptDate[0]
            : "",
        acceptEndDate:
          this.searchForm.acceptDate.length > 0
            ? this.searchForm.acceptDate[1]
            : "",
        solveStartDate:
          this.searchForm.solveDate.length > 0
            ? this.searchForm.solveDate[0]
            : "",
        solveEndDate:
          this.searchForm.solveDate.length > 0
            ? this.searchForm.solveDate[1]
            : "",
        // type: 2,
        type: this.searchForm.type,
      };
      dataReviseOrderPage(data).then((res) => {
        if (res.infoCode == 200) {
          this.pageForm.total = res.data.total;

          // res.data.items.forEach((item) => {
          //   this.shztOptions.forEach((i) => {
          //     if (item.shzt == i.code) {
          //       item.shztmc = i.name;
          //     }
          //   });
          // });
          this.tableData = res.data.items;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    //查询
    searchInfo() {
      this.pageForm.pageNum = 1;
      this.getList();
    },

    //重置
    resetInfo(searchForm) {
      this.$refs[searchForm].resetFields();
      this.pageForm.pageNum = 1;
      this.getList();
    },
    //查看
    handleClick(row, type) {
      this.$router.push({
        name: "datadeletAndUpDetail",
        query: {
          shzt: row.status,
          id: row.id,
          type: type,
        },
      });
    },
    //新增运维单
    addclick() {
      this.$router.push({
        name: "datadeletAndUpDetail",
        query: {
          shzt: "add",
        },
      });
    },
    handleSizeChange(val) {
      this.pageForm.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.pageForm.pageNum = val;
      this.getList();
    },
    deleteRow(row) {
      let data = {
        fid: row.fid,
      };
      this.$confirm("是否确认删除？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        removeList(data)
          .then((response) => {
            if (response.infoCode == 200) {
              this.getList();
              this.$message({
                showClose: true,
                message: "删除成功！",
                type: "success",
              });
            }
          })
          .catch(function (error) {
            console.log(error);
          });
      });
    },
  },
  beforeCreate() {},
  mounted() {},
};
</script>

<style lang="scss" scoped>
.line {
  border-bottom: 1px solid #000;
}
.iconfont {
  color: white;
}
.title {
  margin-bottom: 20px;
  text-align: center;
  font-size: 16px;
}

.text {
  text-align: center;
}

.iconfont {
  font-size: 13px;
}
.addTable {
  text-align: right;
  margin-right: 50px;
}

.addTable span {
  font-size: 20px;
  font-weight: bold;
  color: #4588db;
  cursor: pointer;
}
</style>
<style>
</style>
