<template>
  <view class="zhixing-container" style="margin: 20rpx;margin-top: 220rpx; min-height: 300px; ">
    <view class="zhixing_top" style="display: flex; flex-direction: column;">
      <view style="display: flex; flex-direction: row;margin-bottom: 10px; margin-left: 10px;">
        <view class="querybox" style=" margin-right:20px;">
          <view class="querybox_title" style="display: flex; flex-direction: row;">
            <view style="color: #ca4341; margin-right:5px;">*</view>
            <view>制单人：</view>
          </view>
          <u-input @change="chaxunqy()" v-model="queryParams.createBy" clearable placeholder="请输入制单人"></u-input>
        </view>
        <view class="querybox">
          <u-button style="width:100px; float: left;margin-left: 20px;" type="warning" icon="reload" text="重置"
            @click="resetqy()" size="small"></u-button>
          <u-button style="width:100px; float: left;margin-left:30px;" type="primary" icon="search" text="查询"
            @click="chaxunqy()" size="small"></u-button>
        </view>
      </view>
    </view>

    <view class="zhixing_center">
      <u-table row-key="createTime" rowHeight="150" customClass="mewtable2" ref="pageTable" :scrollX="true"
        :data="tableData" :ellipsis="false" height="550" :border="true" style="width:100%">
        <!-- :span-method="spanMethodWithColspan" -->
        <u-table-column type="index" fixed width="55" label="序号" align="center" headerAlign="center"></u-table-column>
        <u-table-column prop="name1" align="center" width="150" label="专业" headerAlign="center">
          <template #default="{ row, index }">
            {{row.name1}}
          </template>
        </u-table-column>
        <u-table-column prop="name2" width="200" align="center" label="单项" headerAlign="center">
          <template #default="{ row, index }">
            {{row.name2}}
          </template>
        </u-table-column>
        <u-table-column prop="name3" align="center" label="子项" headerAlign="center">
          <template #default="{ row, index }">
            {{row.name3}}
          </template>
        </u-table-column>
        <u-table-column prop="name4" width="200" align="center" label="要素" headerAlign="center">
          <template #default="{ row, index }">
            {{row.name4}}
          </template>
        </u-table-column>
        <u-table-column prop="riskLevel" width="80" align="center" label="风险等级" headerAlign="center">
          <template #default="{ row, index }">
            <u-tag v-if="row.riskLevel" :text="row.riskLevel=='1'?'A':row.riskLevel=='2'?'B':row.riskLevel=='3'?'C':''"
              :type="row.riskLevel=='1'?'error':row.riskLevel=='2'?'warning':row.riskLevel=='3'?'success':''"
              size="mini"></u-tag>
          </template>
        </u-table-column>
        <u-table-column prop="createBy" width="80" label="制单" align="center" headerAlign="center" />
        <u-table-column prop="createTime" width="180" label="创建时间" align="center" headerAlign="center">
          <template #default=" { row, index }">
            {{row.createTime?$dayjs(row.createTime).format("YYYY-MM-DD HH:mm"):''}}
          </template>
        </u-table-column>
      </u-table>

    </view>

    <!-- <LandScape style="width:1000px; height: 100%;" v-if="qianzishow" /> -->
    <UniMenu />
  </view>
</template>

<script>
  import {
    getsafety_hazardInfo,
    getexecutionprojectlist
  } from "@/apis/zhixing"
  import {
    getthstatus
  } from "@/apis/hetong"

  import {
    getstandardchecktablelist

  } from "@/apis/biaozhunku"

  import {
    getToken,
    setToken,
    removeToken
  } from '@/utils/auth'
  import {
    parseObjectToArray
  } from "@/utils/util"
  import UniMenu from '@/components/uni-menu/uni-menu.vue'
  import comboxMore from '@/components/wl-combox-more/combox-more.vue'
  import useUserStore from '@/store/user';
  import CustomPicker from '@/components/custom-search-picker/index.vue';
  import AddEditnr from '@/pages/zhixing/addwenjuan.vue';
  import LandScape from '@/components/signature/landscape.vue';
  export default {
    components: {
      UniMenu,
      comboxMore,
      CustomPicker,
      AddEditnr,
      LandScape
    },
    data() {
      return {
        // upurl: import.meta.env.VITE_APP_BASE_PRE + '/safety_hazard/table/img',
        //  httpurl: import.meta.env.VITE_APP_BASE_PRE,
        xmpickerVisible: false,
        addxmpickerVisible: false,
        xththlist: [],
        yjdwlist: [],
        contractId: '',
        qianziimg: '',
        qiaziimgnum: 0,
        rowitem: null,
        sjnum: 0,
        isedit: false,
        modaltitle: '添加调查问卷',
        pjmodaltitle: '非火灾高危单位',
        pjmodalshow: false,
        pjtableInfolist: [],
        imgboxshow: false,
        imgurlslist: [],
        tableData: [],
        queryParams: {
          createBy: '',
        },
        addshow: false,
        infolist: [],
        activeitem: null,
        activenum: 0,
        qianzishow: false,
        addxmdwlist: [],
        activenumlist: [],
        xmdwlist: [
          //   {
          //   projectId: 0,
          //   projectNo: "001",
          //   customerCompany3Name: "撒大苏打",
          //   lablename: "001（撒大苏打）",
          // }, {
          //   projectId: 1,
          //   projectNo: "002",
          //   customerCompany3Name: "法国",
          //   lablename: "002（法国）",
          // },

        ],
      }
    },
    computed: {
      nick() {
        // debugger
        // return  userStore.username
        const userStore = useUserStore();
        return userStore.name
      },
      imageSrc() {

        const userStore = useUserStore();
        return userStore.avatar
      },

      username() {
        // debugger
        // return  userStore.username
        const userStore = useUserStore();
        return userStore.username
      },
      avatar() {
        //debugger
        const userStore = useUserStore();
        return userStore.avatar
      },
      windowHeight() {
        return uni.getSystemInfoSync().windowHeight - 50
      }
    },
    // // 监听页面返回
    // onBackPress() {
    //   //debugger
    //   uni.redirectTo({
    //     url: '/pages/index/index'
    //   });
    //   // 阻止界面返回默认操作， 这一步主要是为了防止界面出现异常，uniapp有对onBackPress的详细讲解
    //   return true;
    // },

    onShow() {

      this.getlistinfo()
      //  this.getxmdwlist(); //获取项目单位列表
      const userStore = useUserStore();
      userStore.setparentmenutitle('标准库');
      userStore.setchildrenmenutitle('检查表标准');
    },
    onLoad() {
      // this.getUser()
    },
    methods: {
      parseObjectToArray,


      chaxunqy() {
        //查询
        this.getlistinfo()

      },
      resetqy() {
        //重置
        this.queryParams = {
          createBy: '',
        };
        this.getlistinfo(); //获取列表
      },
      hideKeyboard() {
        uni.hideKeyboard()
      },
      changeyjdw(e) {
        //一级单位
        if (!e) {
          this.queryParams.contractId = null;
        }
        this.getlistinfo(); // //获取发现问题列表
      },
      getlistinfo() {
        //获取发现问题列表
        this.tableData = [];
        getstandardchecktablelist(this.queryParams).then((res) => {
          //debugger
          this.tableData = res.rows || [];

        })
      },
      // 合并单元格方法三：自动合并相同值的单元格
      spanMethodWithColspan({
        row,
        column,
        rowIndex,
        columnIndex
      }) {
        if (column.prop === 'customerCompany2') {
          // 计算相同地区的连续行数
          const currentValue = row[column.prop]
          let startIndex = rowIndex
          let endIndex = rowIndex
          //console.log('currentValue', this.tableData)
          // 向前找到开始位置
          while (startIndex > 0 && this.tableData[startIndex - 1][column.prop] === currentValue) {
            startIndex--
          }

          // 向后找到结束位置
          while (endIndex < this.tableData.length - 1 && this.tableData[endIndex + 1][column.prop] === currentValue) {
            endIndex++
          }

          const spanCount = endIndex - startIndex + 1

          if (spanCount > 1) {
            if (rowIndex === startIndex) {
              // 第一行显示合并的单元格
              return {
                rowspan: spanCount,
                colspan: 1
              }
            } else {
              // 其他行隐藏
              return {
                rowspan: 0,
                colspan: 0
              }
            }
          }
        }
        if (column.prop === 'sysCtcNo') {
          // 计算相同地区的连续行数
          const currentValue = row[column.prop]
          let startIndex = rowIndex
          let endIndex = rowIndex
          //console.log('currentValue', this.tableData)
          // 向前找到开始位置
          while (startIndex > 0 && this.tableData[startIndex - 1][column.prop] === currentValue) {
            startIndex--
          }

          // 向后找到结束位置
          while (endIndex < this.tableData.length - 1 && this.tableData[endIndex + 1][column.prop] === currentValue) {
            endIndex++
          }

          const spanCount = endIndex - startIndex + 1

          if (spanCount > 1) {
            if (rowIndex === startIndex) {
              // 第一行显示合并的单元格
              return {
                rowspan: spanCount,
                colspan: 1
              }
            } else {
              // 其他行隐藏
              return {
                rowspan: 0,
                colspan: 0
              }
            }
          }
        }
        if (column.prop === 'riskLevel') {
          // 计算相同地区的连续行数
          const currentValue = row[column.prop]
          let startIndex = rowIndex
          let endIndex = rowIndex
          //console.log('currentValue', this.tableData)
          // 向前找到开始位置
          while (startIndex > 0 && this.tableData[startIndex - 1][column.prop] === currentValue) {
            startIndex--
          }

          // 向后找到结束位置
          while (endIndex < this.tableData.length - 1 && this.tableData[endIndex + 1][column.prop] === currentValue) {
            endIndex++
          }

          const spanCount = endIndex - startIndex + 1

          if (spanCount > 1) {
            if (rowIndex === startIndex) {
              // 第一行显示合并的单元格
              return {
                rowspan: spanCount,
                colspan: 1
              }
            } else {
              // 其他行隐藏
              return {
                rowspan: 0,
                colspan: 0
              }
            }
          }
        }

        return {
          rowspan: 1,
          colspan: 1
        }
      },

    }
  }
</script>

<style lang="scss" scoped>
  .zhixing_top {
    width: 100%;
    display: flex;
    flex-direction: column;


  }

  .querybox {
    display: flex;
    flex-direction: row;
    align-items: center;

    .querybox_title {
      font-size: 13px;
      text-align: right;
      justify-content: end;
    }
  }

  ::v-deep .infotable {
    .xincellclass {}

    .u-table-header {
      z-index: 0;
    }

    .u-table-cell {
      .u-table-cell_content {
        padding: 0rpx 16rpx 0rpx 16rpx;
        white-space: normal;
        text-align: left;

      }
    }
  }


  ::v-deep .uni-table {
    // tr:first-child th:nth-of-type(1) {

    //   /* 你的样式 */
    //   .uni-table-checkbox {
    //     display: none !important;
    //   }

    //   //
    // }
    .frisytr {
      .uni-table-checkbox {
        display: none !important;
      }
    }

    .checkbox__inner {
      z-index: 0 !important;
    }
  }

  .wenjuanadbox {
    display: flex;
    flex-direction: column;

    .querybox1 {
      display: flex;
      flex-direction: row;
      // align-items: center;
      justify-content: space-between;

      .querybox_title {
        justify-content: end;
      }
    }

  }

  ::v-deep .mewtable2 {
    .u-table__header {
      .u-checkbox {
        // display: none !important;
        visibility: hidden !important;
      }

      .u-table__cell {
        //justify-content: center !important;
        min-height: 50px !important;

      }

      .u-table__rows {
        //border-bottom: 1px solid #dadbde !important;

        ::v-deep .u-table__cell {
          //justify-content: center !important;
          // min-height: 50px !important;
          height: auto !important;
        }

      }


    }

    .u-table__body {
      .u-table__rows {
        border-bottom: 1px solid #dadbde !important;

        .u-table__cell {
          z-index: 0 !important;
        }
      }
    }

  }
</style>