<template>
  <div class="content-main">
    <el-row>
      <el-form :inline="true" :model="formInline" class="search-bm-boder" ref="formInline">
        <el-form-item label="设施名称" prop="sbyqmc">
          <el-input clearable v-model="formInline.sbyqmc" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="类型" prop="sbfl">
          <el-input clearable v-model="formInline.sbfl" placeholder="请输入"></el-input>
        </el-form-item>
        <!-- <el-form-item label="状态" prop="sfba">
					<el-select
						v-model="formInline.sfba"
						clearable
						placeholder="请选择"
					>
						<el-option
							v-for="item in options"
							:key="item.value"
							:label="item.label"
							:value="item.value"
						></el-option>
					</el-select>
        </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="doSearch">查询</el-button>
            <el-button
              type="primary"
              @click="resetInfo('formInline')"
              size="small"
              class="iconfont iconzhongzhi"
            >重置</el-button>
          </div>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row></el-row>
    <el-row class="addBtnBg">企业名称: {{ this.$route.query.qymc }}</el-row>
    <el-row>
      <el-table
        :data="tableData"
        stripe
        v-loading="listLoading"
        @selection-change="handleSelectionChange"
        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="sbbm" label="编码">
          <template slot-scope="scope">{{ scope.row.sbbm }}</template>
        </el-table-column>
        <el-table-column align="center" prop="sbfl" label="类型">
          <template slot-scope="scope">{{ scope.row.sbfl }}</template>
        </el-table-column>
        <el-table-column align="center" prop="sbyqmc" label="名称">
          <template slot-scope="scope">
            {{
            scope.row.sbyqmc
            }}
          </template>
        </el-table-column>
        <el-table-column align="center" prop="sbsl" label="数量">
          <template slot-scope="scope">{{ scope.row.sbsl }}</template>
        </el-table-column>
        <el-table-column align="center" prop="whsj" label="维护日期">
          <template slot-scope="scope">{{ scope.row.whsj }}</template>
        </el-table-column>
        <el-table-column align="center" prop="djr" label="维护人">
          <template slot-scope="scope">{{ scope.row.djr }}</template>
        </el-table-column>
        <el-table-column align="center" prop="sfba" label="状态">
          <template slot-scope="scope">
            <!-- <span v-if="scope.row.sfba == '0'">未备案</span> -->
            <span v-if="scope.row.sfba == '1'">待提交</span>
            <span v-if="scope.row.sfba == '2'">审核中</span>
            <span v-if="scope.row.sfba == '3'">已驳回</span>
            <span v-if="scope.row.sfba == '5'">审核通过</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="180">
          <template slot-scope="scope">
            <!-- <el-button  @click="deleteSubmit(scope.row.sbbh)" title="删除" type="primary"  size="small"  class="operate_delete_btn iconfont iconshanchu"></el-button> -->
            <el-button
              @click="detailSubmit(scope.row)"
              title="查看"
              type="primary"
              size="small"
              class="operate_show_btn iconfont iconchakan2"
            ></el-button>
            <!-- <el-button
							@click="editSubmit(scope.row)"
							title="审批"
							type="primary"
							v-if="scope.row.sfba == 2"
							size="small"
							class="operate_edit_btn iconfont iconshenpi"
            ></el-button>-->
            <!--            <el-button  @click="sendSubmit(scope.row.sbbh)" title="提交" type="primary" :disabled="scope.row.sfba!=1" size="small"  class="operate_show_btn iconfont icontijiao"></el-button>-->
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="pageForm.page"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageForm.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pageForm.total"
      ></el-pagination>
    </el-row>

    <el-dialog :visible.sync="addDialog" title="器材信息审核" width="48%">
      <!-- <el-form ref="dialogForm" :model="dialogForm" label-width="220px" :rules="rules"> -->
      <el-form ref="dialogForm" :model="dialogForm" label-width="100px">
        <el-row v-if="showInfo">
          <el-col :span="12">
            <el-form-item label="编码" prop="sbbm">
              <el-input v-model="dialogForm.sbbm" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="类型" prop="sbfl">
              <el-input v-model="dialogForm.sbfl" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="名称" prop="sbyqmc">
              <el-input v-model="dialogForm.sbyqmc" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="数量" prop="sbsl">
              <el-input
                placeholder="请输入内容"
                v-model="dialogForm.sbsl"
                :disabled="true"
                class="input-with-select"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="维护人" prop="djr">
              <el-input v-model="dialogForm.djr" :disabled="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="维护日期" prop="whsj">
              <el-date-picker
                style="width:100%"
                v-model="dialogForm.whsj"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期"
                :disabled="true"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="isChecked">
          <el-col :span="24" v-if="showInfo">
            <h3 class="h3">审批信息</h3>
          </el-col>
        </el-row>
        <el-row v-if="isChecked">
          <el-col :span="24">
            <el-form-item label="审批:">
              <el-radio v-model="dialogForm.sfba" :disabled="disSign" :label="5">通过</el-radio>
              <el-radio v-model="dialogForm.sfba" :disabled="disSign" :label="3">驳回</el-radio>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="审批意见:">
              <el-input type="textarea" :rows="2" :disabled="disSign" v-model="dialogForm.shyj"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="审核人:">
              <el-input :disabled="true" v-model="dialogForm.shrmc"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="审核时间:">
              <el-input :disabled="true" v-model="dialogForm.shsj"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div style="text-align:center;margin-top:20px">
              <el-button
                icon="iconfont icontijiao"
                type="primary"
                v-if="dialogTitle !== 'detail'"
                @click="saveSubmit('dialogForm')"
              >保存</el-button>
              <el-button
                type="primary"
                icon="iconfont iconfanhui"
                @click="cancel"
                v-if="dialogTitle === 'detail'"
              >返回</el-button>
              <el-button
                type="primary"
                icon="iconfont iconfanhui"
                @click="cancel"
                v-if="dialogTitle !== 'detail'"
              >返回</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  getPageList,
  detailsFn,
  deleteFn,
  addFn,
  editFn,
  reviewInfo,
  plsh,
} from "@/api/jcxxwh/ssxx";
// import { kd } from '@/api/jcxxwh/kd'

export default {
  data() {
    return {
      kd: "",
      formInline: {
        sbyqmc: "",
        ssfl: 3,
        sfba: "",
        zts: [5],
      },
      addDialog: false,
      disSign: false,
      showInfo: true,
      dialogTitle: "add",
      dialogForm: {
        sbdwmc: "1",
        sfba: "4",
      },
      listLoading: false,
      tableData: [],
      multipleSelection: [],
      pageForm: {
        page: 1,
        size: 10,
        total: 0,
      },
      options: [
        // {
        // 	value: 1,
        // 	label: '待提交'
        // },
        {
          value: 2,
          label: "审核中",
        },
        {
          value: 3,
          label: "已驳回",
        },
        {
          value: 5,
          label: "审核通过",
        },
      ],
      isChecked: false,
    };
  },
  created() {
    // this.init()
    this.getList();
  },
  methods: {
    doSearch() {
      this.pageForm.page = 1;
      this.getList();
    },
    resetInfo(formName) {
      this.$refs[formName].resetFields();
      this.doSearch();
    },
    init() {
      // kd().then((res) => {
      // 	if (!res) return
      // 	if (!res.data[0]) return
      // 	this.kd = res.data[0].kddm
      // 	this.getList()
      // })
    },
    //获取列表
    getList() {
      this.formInline.tyshxydm = this.$route.query.tyshxydm;
      this.formInline.kddm = this.$route.query.kddm;
      getPageList(this.pageForm, this.formInline).then((res) => {
        this.tableData = res.data.list;
        this.tableData.forEach((d) => {
          if (d.whsj) {
            d.whsj = d.whsj.slice(0, 10);
          }
        });
        this.pageForm.total = res.data.total;
      });
    },
    checkboxT(row, index) {
      if (row.sfba == 2) {
        return 1;
      } else {
        return 0;
      }
    },
    batchApproval() {
      if (this.multipleSelection.length > 0) {
        this.dialogTitle = "edit";
        this.disSign = false;
        this.dialogForm.shrmc = sessionStorage.getItem("userName");
        this.dialogForm.sfba = 5;
        var date = new Date();
        var year = date.getFullYear();
        var month =
          date.getMonth() + 1 < 10
            ? "0" + (date.getMonth() + 1)
            : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours =
          date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes =
          date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var seconds =
          date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        this.dialogForm.shsj = year + "-" + month + "-" + day;
        this.showInfo = false;
        this.addDialog = true;
        this.isChecked = true;
      } else {
        this.$message({
          message: "请先勾选",
          type: "warning",
        });
      }
    },
    //批量审批
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 审批
    saveSubmit(formObj) {
      if (!this.showInfo) {
        let data = {
          sbbhs: [],
          sfba: this.dialogForm.sfba,
          ssfl: 3,
          shrmc: this.dialogForm.shrmc,
          shyj: this.dialogForm.shyj,
          shsj: this.dialogForm.shsj,
        };
        this.multipleSelection.map((item) => {
          data.sbbhs.push(item.sbbh);
        });
        plsh(data).then((res) => {
          if (res.infoCode == 200) {
            this.$message({
              message: "审核成功",
              type: "success",
            });
            this.addDialog = false;
            this.getList();
            this.rest();
          } else {
            this.$message.error("审核失败");
          }
        });
      } else {
        this.$refs[formObj].validate((valid) => {
          if (valid) {
            this.dialogForm.ssfl = 3;
            // this.dialogForm.sfba = 1
            editFn(this.dialogForm).then((res) => {
              if (res.infoCode == 200) {
                this.$message({
                  message: "审批成功",
                  type: "success",
                });
                this.addDialog = false;
                this.rest();
                this.getList();
              }
            });
          } else {
            return false;
          }
        });
      }
    },

    //详情
    detailSubmit(row) {
      this.showInfo = true;
      if (row.sfba == "2") {
        this.isChecked = false;
      } else {
        this.isChecked = true;
      }
      this.dialogTitle = "detail";
      detailsFn(row.sbbh).then((res) => {
        this.dialogForm = res.data;
        this.addDialog = true;
        this.disSign = true;
      });
    },

    // 编辑
    editSubmit(row) {
      this.showInfo = true;
      this.isChecked = true;
      this.dialogTitle = "edit";
      this.disSign = false;
      detailsFn(row.sbbh).then((res) => {
        this.dialogForm = res.data;
        this.dialogForm.sfba = 5;
        this.dialogForm.shrmc = sessionStorage.getItem("userName");
        this.$set(this.dialogForm, "shyj", "");
        var date = new Date();
        var year = date.getFullYear();
        var month =
          date.getMonth() + 1 < 10
            ? "0" + (date.getMonth() + 1)
            : date.getMonth() + 1;
        var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
        var hours =
          date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
        var minutes =
          date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
        var seconds =
          date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
        this.dialogForm.shsj = year + "-" + month + "-" + day;
        this.addDialog = true;
      });
    },

    // 取消返回
    cancel() {
      this.addDialog = false;
    },
    /* 初始化表单*/
    rest() {
      this.dialogForm = {
        sbdwmc: "1",
      };
      if (this.$refs["dialogForm"] !== undefined) {
        this.$refs["dialogForm"].resetFields();
      }
    },

    handleSizeChange(val) {
      this.pageForm.size = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.pageForm.page = 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>
