<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-left">
        <div class="filter-item">
          报修类型:
          <el-select v-model="value" placeholder="" style="width: 110px">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>

        <div class="filter-item">
          时间:
          <el-date-picker
            style="width: 42%"
            v-model="formDaliog.startTime"
            type="datetime"
            placeholder="选择日期时间"
            align="right"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
            :picker-options="pickerOptions1"
          >
          </el-date-picker>
          ~
          <el-date-picker
            style="width: 42%"
            v-model="formDaliog.endTime"
            type="datetime"
            placeholder="选择日期时间"
            align="right"
            format="yyyy-MM-dd HH:mm:ss"
            value-format="yyyy-MM-dd HH:mm:ss"
            :picker-options="pickerOptions2"
          >
          </el-date-picker>
        </div>

        <div class="filter-item">
          处理状态:
          <el-select v-model="value2" placeholder="" style="width: 100px">
            <el-option
              v-for="item in options2"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div class="filter-item">
          责任人:
          <el-input
            v-model="input"
            placeholder=""
            style="width: 100px"
          ></el-input>
        </div>

        <div class="filter-item">
          任务名称:
          <el-input
            v-model="input"
            placeholder=""
            style="width: 100px"
          ></el-input>
        </div>

        <el-button type="primary" icon="el-icon-search" class="search-button"
          >搜索</el-button
        >
      </div>
      <div class="report">
        <div class="filter-item">
          <el-button @click="dialogAnalysisVisible=true">报修分析</el-button>
        </div>
      </div>
    </div>

    <el-divider></el-divider>
    <el-table
      :data="tableData"
      stripe
      border
      :header-cell-style="{ background: '#EBF1FF', color: '#606266' }"
      style="width: 100%"
      id="out-table"
      :cell-style="cellStyle"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="40"> </el-table-column>

      <el-table-column prop="taskName" label="报修任务名称" width="100">
      </el-table-column>
      <el-table-column prop="taskType" label="报修类型"> </el-table-column>
      <el-table-column prop="dueTime" label="应完成时间" width="180">
      </el-table-column>
      <el-table-column prop="actualTime" label="实际完成时间" width="180">
      </el-table-column>
      <el-table-column prop="reportDetail" label="上报详情" width="100">
        <template slot-scope="{ row }">
          <div class="check" @click="dialogReportDetailVisible = true">
            {{ row.reportDetail }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="当前状态" width="100">
        <template slot-scope="{ row }">
          <div class="check" v-if="row.currentStatus=='未指派'"  @click="dialogAssignmentVisible=true">
            {{ row.currentStatus }}
          </div>
          <div class="check" v-if="row.currentStatus=='已指派'" @click="dialogAssignmentVisible2=true">
            {{ row.currentStatus }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="responser" label="相关责任人"> </el-table-column>
      <el-table-column prop="contact" label="联系电话" width="120">
      </el-table-column>

      <el-table-column label="处理状态" fixed="right">
        <template slot-scope="{ row }">
          <div class="cursorP" @click="dialogStatusVisible = true">
            {{ row.handleStatus }}
          </div>
        </template>
      </el-table-column>
    </el-table>

    <!-- 报修分析start -->
    <el-dialog title="报修分析" :visible.sync="dialogAnalysisVisible" class="filter-container">
      <el-form :model="form">
        <el-row :gutter="10">
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12"
            ><div class="grid-content bg-purple">
              开始日期:
              <el-date-picker
                v-model="formDaliog.startTime"
                type="datetime"
                placeholder="选择日期时间"
                align="right"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                :picker-options="pickerOptions1"
                style="width: 75%; margin: 10px 0"
              >
              </el-date-picker></div
          ></el-col>
          <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12"
            ><div class="grid-content bg-purple-light">
              结束日期
              <el-date-picker
                v-model="formDaliog.endTime"
                type="datetime"
                placeholder="选择日期时间"
                align="right"
                format="yyyy-MM-dd HH:mm:ss"
                value-format="yyyy-MM-dd HH:mm:ss"
                :picker-options="pickerOptions2"
                style="width: 75%; margin: 10px 0"
              >
              </el-date-picker></div
          ></el-col>

          <el-button type="primary"  class="search-button" style="float:right"
          >确定</el-button>
        </el-row>

        

        <div class="analysisBox">
          <h3>数据分析</h3>
          <p>1.1资源及工作内容</p>
          <p>人员：2个</p>
          <p>报修总次数：0个</p>
          <p>已完成的报修任务：0个</p>
          <p>审核未通过的报修任务：0个</p>
          <p>未审核的报修任务：0个</p>
          <p>未处理的报修任务：0个</p>
        </div>
      <br>
      <br>
      <br>

        <el-table
            :data="tableData2"
            stripe
            border
            :header-cell-style="{ background: '#EBF1FF', color: '#606266' }"
            style="width: 100%"
            id="out-table"
            @selection-change="handleSelectionChange"
          >
            <el-table-column prop="taskName" label="报修任务名称" >
            </el-table-column>
            <el-table-column prop="taskOrigin" label="任务来源">
            </el-table-column>
            <el-table-column prop="reportMan" label="上报人" >
            </el-table-column>
            <el-table-column label="任务状态"  prop="status">
              <!-- <template slot-scope="{ row }">
                <div class="check" @click="dialogPointObjectVisible = true">
                  {{ row.detail }}
                </div>
              </template> -->
            </el-table-column>
          </el-table>
      </el-form>



      <div slot="footer" class="dialog-footer">
        <el-button
          @click="dialogAnalysisVisible = false"
          style="background: #f6f6f6"
          >关 闭</el-button
        >
        <el-button type="primary" @click="dialogAnalysisVisible = false"
          >导出</el-button
        >
      </div>
    </el-dialog>
    <!-- 报修分析end -->

    <!-- 上报详情弹框start -->
    <el-dialog title="上报详情" :visible.sync="dialogReportDetailVisible">
      <el-form :model="form">
        <el-form-item label="上报人员:" :label-width="formLabelWidth">
          <div>吉超博</div>
        </el-form-item>

        <el-form-item label="上报时间:" :label-width="formLabelWidth">
          <div>2020-08-18 09:22:21</div>
        </el-form-item>

        <el-form-item label="现场照片:" :label-width="formLabelWidth">
          <img src="@/assets/route.png" alt="" width="120" />
        </el-form-item>
        <el-form-item label="备注:" :label-width="formLabelWidth">
          <div>报修测试</div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          @click="dialogReportDetailVisible = false"
          style="background: #f6f6f6"
          >关 闭</el-button
        >
        <el-button type="primary" @click="dialogReportDetailVisible = false"
          >处 理</el-button
        >
      </div>
    </el-dialog>
    <!-- 上报详情弹框end -->

    <!-- 人员指派start -->
    <el-dialog title="人员指派" :visible.sync="dialogAssignmentVisible">
      <el-form :model="form">
        <el-form-item label="报修类型:" :label-width="formLabelWidth">
          <el-select v-model="form.region" placeholder="" style="width: 100%">
            <el-option label="报修类型1" value="3"></el-option>
            <el-option label="报修类型2" value="4"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="责任人:" :label-width="formLabelWidth">
          <el-select v-model="form.region2" placeholder="" style="width: 100%">
            <el-option label="责任人1" value="5"></el-option>
            <el-option label="责任人2" value="6"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="应完成时间:" :label-width="formLabelWidth">
          <el-input v-model="form.name3" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="备注:" :label-width="formLabelWidth">
          <el-input v-model="form.name3" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          @click="dialogAssignmentVisible = false"
          style="background: #f6f6f6"
          >关 闭</el-button
        >
        <el-button type="primary" @click="dialogAssignmentVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <!-- 人员指派end -->

    <!-- 人员指派（已指派）start -->
    <el-dialog title="人员指派" :visible.sync="dialogAssignmentVisible2">
      <el-form :model="form">
        <el-form-item label="报修类型:" :label-width="formLabelWidth">
          <div>类型123</div>
        </el-form-item>

        <el-form-item label="责任人:" :label-width="formLabelWidth">
          <div>责任人123</div>
        </el-form-item>

        <el-form-item label="发起账号:" :label-width="formLabelWidth">
          <div>13245677890</div>
        </el-form-item>

        <el-form-item label="发起时间:" :label-width="formLabelWidth">
          <div>2020-09-04 12：23：45</div>
        </el-form-item>

        <el-form-item label="应完成时间:" :label-width="formLabelWidth">
          <div>2020-09-09 12：23：45</div>
        </el-form-item>

        <el-form-item label="备注:" :label-width="formLabelWidth">
          <div>报修测试</div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          @click="dialogAssignmentVisible = false"
          style="background: #f6f6f6"
          >关 闭</el-button
        >
        <el-button type="primary" @click="dialogAssignmentVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <!-- 人员指派（已指派）end -->

    <!--处理状态弹框 start -->
    <el-dialog title="处理状态" :visible.sync="dialogStatusVisible">
      <el-form :model="form">
        <el-form-item label="处理状态:" :label-width="formLabelWidth">
          <div>未审核</div>
        </el-form-item>

        <el-form-item label="责任人:" :label-width="formLabelWidth">
          <div>张三</div>
        </el-form-item>

        <el-form-item label="发起账号:" :label-width="formLabelWidth">
          <div>13245677890</div>
        </el-form-item>

        <el-form-item label="应处理时间:" :label-width="formLabelWidth">
          <div>2020-09-04 12：23：45</div>
        </el-form-item>

        <el-form-item label="上报时间:" :label-width="formLabelWidth">
          <div>2020-09-09 12：23：45</div>
        </el-form-item>

        <div class="feedbackTit">反馈与审核记录</div>
        <div class="feedbackBox">
          <el-row :gutter="10">
            <el-form-item label="结果照片:" :label-width="formLabelWidth">
              <img src="@/assets/route.png" alt="" width="120" />
            </el-form-item>

            <el-form-item label="处理时间:" :label-width="formLabelWidth">
              <div>无</div>
            </el-form-item>

            <el-form-item label="审核结果:" :label-width="formLabelWidth">
              <div>无</div>
            </el-form-item>

            <el-form-item label="审核时间:" :label-width="formLabelWidth">
              <div>无</div>
            </el-form-item>

            <el-form-item
              label="备注结果:"
              :label-width="formLabelWidth"
              style="width: 100%"
            >
              <div>无</div>
            </el-form-item>

            <el-form-item
              label="处理结果:"
              :label-width="formLabelWidth"
              style="width: 100%"
            >
              <el-select
                v-model="form.region"
                placeholder=""
                style="width: 60%"
              >
                <el-option label="处理结果1" value="3"></el-option>
                <el-option label="处理结果2" value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-row>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          @click="dialogStatusVisible = false"
          style="background: #f6f6f6"
          >关 闭</el-button
        >
        <el-button type="primary" @click="dialogStatusVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <!--处理状态弹框 end -->

    <el-pagination background layout="prev, pager, next" :total="1000">
    </el-pagination>
  </div>
</template>


<script>
// 引入导出Excel表格依赖
import FileSaver from "file-saver";
import XLSX from "xlsx";

export default {
  name: "javascriptthree",
  data() {
    return {
      tableData: [
        {
          taskName: "报修测试",
          taskType: "故障",
          dueTime: "2020-09-14 12:15:23",
          actualTime: "-",
          reportDetail: "查看",
          currentStatus: "已指派",
          responser: "张三",
          contact: "13456789008",
          handleStatus: "未处理",
        },
        {
          taskName: "故障报修",
          taskType: "故障",
          dueTime: "2020-09-14 12:15:23",
          actualTime: "2020-09-14 12:15:23",
          reportDetail: "查看",
          currentStatus: "已指派",
          responser: "张三",
          contact: "13456789008",
          handleStatus: "已完成",
        },
        {
          taskName: "测试维保122",
          taskType: "故障",
          dueTime: "2020-09-14 12:15:23",
          actualTime: "-",
          reportDetail: "查看",
          currentStatus: "未指派",
          responser: "张三",
          contact: "13456789008",
          handleStatus: "审核未通过",
        },
        {
          taskName: "故障报修1",
          taskType: "故障",
          dueTime: "2020-09-14 12:15:23",
          actualTime: "2020-09-14 12:15:23",
          reportDetail: "查看",
          currentStatus: "未指派",
          responser: "张三",
          contact: "13456789008",
          handleStatus: "超时完成",
        },
      ],

      tableData2: [
        {
          taskName: "任务名称1",
          taskOrigin: "来源测试",
          reportMan: "张三",
          status: "状态1",
        },
        {
          taskName: "任务名称1",
          taskOrigin: "来源测试",
          reportMan: "张三",
          status: "状态2",
        },
         
      ],
      multipleSelection: [],

      options: [
        {
          value: "1",
          label: "类型1",
        },
        {
          value: "2",
          label: "类型2",
        },
        {
          value: "3",
          label: "类型3",
        },
      ],
      options2: [
        {
          value: "1",
          label: "状态1",
        },
        {
          value: "2",
          label: "状态2",
        },
        {
          value: "3",
          label: "状态3",
        },
      ],
      input: "",
      value: "",
      value2: "",

      dialogFormVisible: false,
      form: {
        name: "",
        region: "",
        region2: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      formLabelWidth: "120px",

      //日期时间选择器
      formDaliog: {
        startTime: "",
        endTime: "",
      },
      pickerOptions1: {
        disabledDate: (time) => {
          if (this.formDaliog.endTime) {
            return (
              time.getTime() < Date.now() - 8.64e7 ||
              time.getTime() > new Date(this.formDaliog.endTime).getTime()
            );
          } else {
            return time.getTime() < Date.now() - 8.64e7;
          }
        },
      },
      pickerOptions2: {
        disabledDate: (time) => {
          if (this.formDaliog.startTime) {
            return (
              time.getTime() < Date.now() - 8.64e7 ||
              time.getTime() < new Date(this.formDaliog.startTime).getTime()
            );
          } else {
            return time.getTime() < Date.now() - 8.64e7;
          }
        },
      },

      //单选
      radio: "1",
      radio2: "1",

      // 报修分析
      dialogAnalysisVisible: false,

      // 上报详情
      dialogReportDetailVisible: false,

      // 人员指派
      dialogAssignmentVisible: false,
      dialogAssignmentVisible2: false,

      // 处理状态弹框
      dialogStatusVisible: false,
    };
  },
  methods: {
    //处理状态状态值变色
    cellStyle(row, column, rowIndex, columnIndex) {
      console.log("rowIndex");
      console.log(row.row.handleStatus);
      if (row.column.label == "处理状态" && row.row.handleStatus == "未处理") {
        return "color:#FF747B";
      }
      if (row.column.label == "处理状态" && row.row.handleStatus == "已完成") {
        return "color:#8DCF6E";
      }
      if (
        row.column.label == "处理状态" &&
        row.row.handleStatus == "审核未通过"
      ) {
        return "color:#5c88fa";
      }
      if (
        row.column.label == "处理状态" &&
        row.row.handleStatus == "超时完成"
      ) {
        return "color:red";
      }
    },

    //定义导出Excel表格事件
    exportExcel() {
      /* 从表生成工作簿对象 */
      var wb = XLSX.utils.table_to_book(document.querySelector("#out-table"));
      /* 获取二进制字符串作为输出 */
      var wbout = XLSX.write(wb, {
        bookType: "xlsx",
        bookSST: true,
        type: "array",
      });
      try {
        FileSaver.saveAs(
          //Blob 对象表示一个不可变、原始数据的类文件对象。
          //Blob 表示的不一定是JavaScript原生格式的数据。
          //File 接口基于Blob，继承了 blob 的功能并将其扩展使其支持用户系统上的文件。
          //返回一个新创建的 Blob 对象，其内容由参数中给定的数组串联组成。
          new Blob([wbout], { type: "application/octet-stream" }),
          //设置导出文件名称
          "sheetjs.xlsx"
        );
      } catch (e) {
        if (typeof console !== "undefined") console.log(e, wbout);
      }
      return wbout;
    },
    handleEdit(index, row) {
      alert(index, row);
    },
    handleDelete(index, row) {
      this.$confirm("确定删除该单位吗?", "删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.tableData.splice(index, 1);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    batchDelete() {
      let multData = this.multipleSelection;
      let tableData = this.tableData;
      let multDataLen = multData.length;
      let tableDataLen = tableData.length;

      for (let i = 0; i < multDataLen; i++) {
        for (let y = 0; y < tableDataLen; y++) {
          if (JSON.stringify(tableData[y]) == JSON.stringify(multData[i])) {
            //判断是否相等，相等就删除
            this.tableData.splice(y, 1);
            console.log("aa");
          }
        }
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  },
};
</script>
<style scoped>
.feedbackBox .el-form-item {
  width: 50%;
  display: inline-block;
  vertical-align: top;
}
.feedbackBox {
  width: 100%;
  /* height: 200px; */
  padding: 20px 0 0;
  border: 1px solid #e9e9e9;
}
</style>
<style>
.el-radio {
  width: 70px;
}
.handled {
  color: hsl(194, 71%, 61%);
}
.unhandle {
  color: #fe5d0e;
}

.report {
  float: right;
}
.report .el-button {
  background: hsl(194, 71%, 61%);
  color: #fff;
}
.el-button:hover {
  opacity: 0.7;
}

.feedbackTit {
  background: red;
  display: inline-block;
  padding: 7px 12px;
  background-color: #5c88fa;
  border-color: #5c88fa;
  color: #fff;
}

.analysisBox p {
  margin: 5px;
}
</style>