<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="巡检日期" prop="recordTime">
        <el-date-picker
          v-model="queryParams.recordTime"
          type="month"
          value-format="yyyy-MM"
          placeholder="选择巡检日期"
          :clearable="false">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="pressureList" @selection-change="handleSelectionChange" :height="clientHeight" border>
      <el-table-column label="巡检日期" align="center" prop="recordTime" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.recordTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="H109 OUT" align="center" prop="h109Out" :show-overflow-tooltip="true">
        <el-table-column v-for="(item,index) in 8" :label="'PASS '+(index+1).toString()" align="center" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.h109Out[index] }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="H110 OUT" align="center" prop="h110Out" :show-overflow-tooltip="true">
        <el-table-column v-for="(item,index) in 8" :label="'PASS '+(index+1).toString()" align="center" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.h110Out[index] }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="H111 OUT" align="center" prop="h111Out" :show-overflow-tooltip="true">
        <el-table-column v-for="(item,index) in 8" :label="'PASS '+(index+1).toString()" align="center" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.h111Out[index] }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="H112 OUT" align="center" prop="h112Out" :show-overflow-tooltip="true">
        <el-table-column v-for="(item,index) in 8" :label="'PASS '+(index+1).toString()" align="center" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.h112Out[index] }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="H113 OUT" align="center" prop="h113Out" :show-overflow-tooltip="true">
        <el-table-column v-for="(item,index) in 8" :label="'PASS '+(index+1).toString()" align="center" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.h113Out[index] }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="H114 OUT" align="center" prop="h114Out" :show-overflow-tooltip="true">
        <el-table-column v-for="(item,index) in 8" :label="'PASS '+(index+1).toString()" align="center" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.h114Out[index] }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="H115 OUT" align="center" prop="h115Out" :show-overflow-tooltip="true">
        <el-table-column v-for="(item,index) in 8" :label="'PASS '+(index+1).toString()" align="center" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.h115Out[index] }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="H116 OUT" align="center" prop="h116Out" :show-overflow-tooltip="true">
        <el-table-column v-for="(item,index) in 8" :label="'PASS '+(index+1).toString()" align="center" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.h116Out[index] }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="H117 OUT" align="center" prop="h117Out" :show-overflow-tooltip="true">
        <el-table-column v-for="(item,index) in 8" :label="'PASS '+(index+1).toString()" align="center" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.h117Out[index] }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="H118 OUT" align="center" prop="h118Out" :show-overflow-tooltip="true">
        <el-table-column v-for="(item,index) in 8" :label="'PASS '+(index+1).toString()" align="center" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.h118Out[index] }}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="H130 OUT" align="center" prop="h130Out" :show-overflow-tooltip="true">
        <el-table-column v-for="(item,index) in 12" :label="'PASS '+(index+1).toString()" align="center" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.h130Out[index] }}</span>
          </template>
        </el-table-column>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  import { listCoil } from "@/api/production/pressure";
  import { treeselect } from "@/api/system/dept";
  import { getToken } from "@/utils/auth";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";

  export default {
    name: "Pressure",
    components: { Treeselect },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 裂解炉炉管测压表格数据
        pressureList: [],
        // 弹出层标题
        title: "",
        // 部门树选项
        deptOptions: undefined,
        clientHeight:300,
        // 是否显示弹出层
        open: false,
        // 用户导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/production/pressure/importData"
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 20,
          furnanceName: null,
          recordTime: null,
          pass1: null,
          pass2: null,
          pass3: null,
          pass4: null,
          pass5: null,
          pass6: null,
          pass7: null,
          pass8: null,
          pass9: null,
          pass10: null,
          pass11: null,
          pass12: null,
          pass13: null,
          pass14: null,
          pass15: null,
          pass16: null,
          deptId: null,
        },
        recordTime: null,
        // 表单参数
        form: {},
        h109Out:[],
        h110Out:[],
        h111Out:[],
        h112Out:[],
        h113Out:[],
        h114Out:[],
        h115Out:[],
        h116Out:[],
        h117Out:[],
        h118Out:[],
        h130Out:[],
        // 表单校验
        rules: {
          id: [
            { required: true, message: "主键id不能为空", trigger: "blur" }
          ],
        }
      };
    },
    watch: {
      // 根据名称筛选部门树
      deptName(val) {
        this.$refs.tree.filter(val);
      }
    },
    created() {
      //设置表格高度对应屏幕高度
      this.$nextTick(() => {
        this.clientHeight = document.body.clientHeight -250
      })
      // this.getList();
      // this.getTreeselect();
    },
    methods: {
      init() {
        let date = new Date();
        this.queryParams.recordTime = date.getFullYear() + "-" + Number(date.getMonth() + 1);
        this.getList();
      },
      /** 查询裂解炉炉管测压列表 */
      getList() {
        this.loading = true;
        listCoil(this.queryParams).then(response => {
          if (response.msg == "incompleteData") {
            this.msgInfo("巡检数据录入不完整，暂时无法生成此表格。");
            this.pressureList = [];
          } else {
            for (let i = 0; i < response.data.length; i++) {
              if (response.data[i].h109Out == null) {
                response.data[i].h109Out = [];
              } else {
                response.data[i].h109Out = response.data[i].h109Out.split(',');
              }
              if (response.data[i].h110Out == null) {
                response.data[i].h110Out = [];
              } else {
                response.data[i].h110Out = response.data[i].h110Out.split(',');
              }
              if (response.data[i].h111Out == null) {
                response.data[i].h111Out = [];
              } else {
                response.data[i].h111Out = response.data[i].h111Out.split(',');
              }
              if (response.data[i].h112Out == null) {
                response.data[i].h112Out = [];
              } else {
                response.data[i].h112Out = response.data[i].h112Out.split(',');
              }
              if (response.data[i].h113Out == null) {
                response.data[i].h113Out = [];
              } else {
                response.data[i].h113Out = response.data[i].h113Out.split(',');
              }
              if (response.data[i].h114Out == null) {
                response.data[i].h114Out = [];
              } else {
                response.data[i].h114Out = response.data[i].h114Out.split(',');
              }
              if (response.data[i].h115Out == null) {
                response.data[i].h115Out = [];
              } else {
                response.data[i].h115Out = response.data[i].h115Out.split(',');
              }
              if (response.data[i].h116Out == null) {
                response.data[i].h116Out = [];
              } else {
                response.data[i].h116Out = response.data[i].h116Out.split(',');
              }
              if (response.data[i].h117Out == null) {
                response.data[i].h117Out = [];
              } else {
                response.data[i].h117Out = response.data[i].h117Out.split(',');
              }
              if (response.data[i].h118Out == null) {
                response.data[i].h118Out = [];
              } else {
                response.data[i].h118Out = response.data[i].h118Out.split(',');
              }
              if (response.data[i].h130Out == null) {
                response.data[i].h130Out = [];
              } else {
                response.data[i].h130Out = response.data[i].h130Out.split(',');
              }
            }
            this.pressureList = response.data;
          }
          this.loading = false;
        });
      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          furnanceName: null,
          recordTime: null,
          pass1: null,
          pass2: null,
          pass3: null,
          pass4: null,
          pass5: null,
          pass6: null,
          pass7: null,
          pass8: null,
          pass9: null,
          pass10: null,
          pass11: null,
          pass12: null,
          pass13: null,
          pass14: null,
          pass15: null,
          pass16: null,
          deptId: null,
          delFlag: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
        };
        this.pass1 = [];
        this.pass2 = [];
        this.pass3 = [];
        this.pass4 = [];
        this.pass5 = [];
        this.pass6 = [];
        this.pass7 = [];
        this.pass8 = [];
        this.pass9 = [];
        this.pass10 = [];
        this.pass11 = [];
        this.pass12 = [];
        this.pass13 = [];
        this.pass14 = [];
        this.pass15 = [];
        this.pass16 = [];
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.form.furnanceName = "H130";
        this.open = true;
        this.title = "添加裂解炉炉管测压";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getPressure(id).then(response => {
          this.form = response.data;
          if (response.data.pass1 == null) { this.pass1 = []; } else { this.pass1 = response.data.pass1.split(','); }
          if (response.data.pass2 == null) { this.pass2 = []; } else { this.pass2 = response.data.pass2.split(','); }
          if (response.data.pass3 == null) { this.pass3 = []; } else { this.pass3 = response.data.pass3.split(','); }
          if (response.data.pass4 == null) { this.pass4 = []; } else { this.pass4 = response.data.pass4.split(','); }
          if (response.data.pass5 == null) { this.pass5 = []; } else { this.pass5 = response.data.pass5.split(','); }
          if (response.data.pass6 == null) { this.pass6 = []; } else { this.pass6 = response.data.pass6.split(','); }
          if (response.data.pass7 == null) { this.pass7 = []; } else { this.pass7 = response.data.pass7.split(','); }
          if (response.data.pass8 == null) { this.pass8 = []; } else { this.pass8 = response.data.pass8.split(','); }
          if (response.data.pass9 == null) { this.pass9 = []; } else { this.pass9 = response.data.pass9.split(','); }
          if (response.data.pass10 == null) { this.pass10 = []; } else { this.pass10 = response.data.pass10.split(','); }
          if (response.data.pass11 == null) { this.pass11 = []; } else { this.pass11 = response.data.pass11.split(','); }
          if (response.data.pass12 == null) { this.pass12 = []; } else { this.pass12 = response.data.pass12.split(','); }
          this.open = true;
          this.title = "修改裂解炉炉管测压";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.form.pass1 = this.pass1.join(",");
        this.form.pass2 = this.pass2.join(",");
        this.form.pass3 = this.pass3.join(",");
        this.form.pass4 = this.pass4.join(",");
        this.form.pass5 = this.pass5.join(",");
        this.form.pass6 = this.pass6.join(",");
        this.form.pass7 = this.pass7.join(",");
        this.form.pass8 = this.pass8.join(",");
        this.form.pass9 = this.pass9.join(",");
        this.form.pass10 = this.pass10.join(",");
        this.form.pass11 = this.pass11.join(",");
        this.form.pass12 = this.pass12.join(",");
        this.form.pass13 = this.pass13.join(",");
        this.form.pass14 = this.pass14.join(",");
        this.form.pass15 = this.pass15.join(",");
        this.form.pass16 = this.pass16.join(",");
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updatePressure(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addPressure(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$confirm('是否确认删除?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delPressure(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$confirm('是否确认导出所有裂解炉炉管测压数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportPressure(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
      },
      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = "用户导入";
        this.upload.open = true;
      },
      /** 下载模板操作 */
      importTemplate() {
        importTemplate().then(response => {
          this.download(response.msg);
        });
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
        this.getList();
      },
      // 提交上传文件
      submitFileForm() {
        this.$refs.upload.submit();
      }
    }
  };
</script>
