<template>
  <view class="content">
    <view class="search card">
      <u--text suffixIcon="arrow-down" text="筛选" @click="showPicker"></u--text>
      <u--input
          prefixIcon="search"
          placeholder="请输入关键字"
          border="surround"
          v-model="companyName"
          clearable
          shape="circle"
      ></u--input>
      <view class="bth-mini ml-10">
        <u-button type="success" text="确定" @click="resetList"></u-button>
      </view>

    </view>
    <u-picker :show="show" :columns="columns" keyName="name" @cancel="show = false" @confirm="confirmPicker"></u-picker>
    <u-list @scrolltolower="scrolltolower" v-if="list.length > 0">
      <u-list-item v-for="(item, index) in list" :key="index">
        <view>
          <view class="flex-between main-title">
            <text>被检查单位：{{ item.inspectedCorpName }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>检查发起人：{{ item.inspectionOriginatorUserName }}</text>
            <text>检查类型：{{ item.inspectionTypeName }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>检查时间：自 {{ item.inspectionTimeStart }} 至 {{ item.inspectionTimeEnd }} 止</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>
              状态：
              <template v-if="item.inspectionStatus === '0'">待检查人核实</template>
              <template v-else-if="item.inspectionStatus === '1'">检查人核实中</template>
              <template v-else-if="item.inspectionStatus === '2'">待被检查人确认</template>
              <template v-else-if="item.inspectionStatus === '3'">待指派</template>
              <template v-else-if="item.inspectionStatus === '4'">指派中</template>
              <template v-else-if="item.inspectionStatus === '5'">指派完成</template>
              <template v-else-if="item.inspectionStatus === '6'">检查待验收</template>
              <template v-else-if="item.inspectionStatus === '7'">检查已验收</template>
              <template v-else-if="item.inspectionStatus === '8'">已归档</template>
              <template v-else-if="item.inspectionStatus === '-1'">检查人核实打回</template>
              <template v-else-if="item.inspectionStatus === '-2'">被检查人申辩</template>
            </text>
          </view>
          <view class="mt-10 see_btn">
            <view class="wrap">
              <u-button type="primary" text="查看" size="mini"
                        @click="fnNavigatorDetail(item.inspectionId, 'view')"></u-button>
            </view>
            <view class="wrap ml-10">
              <u-button type="primary" text="流程图" size="mini"
                        @click="showFlowChart(item.inspectionId)"></u-button>
            </view>
            <view class="wrap ml-10" v-if="item.inspectionStatus === '-1'">
              <u-button type="primary" text="编辑" size="mini"
                        @click="fnNavigatorDetail(item.inspectionId,'edit')"></u-button>
            </view>
            <view class="wrap ml-10" v-if="item.inspectionStatus === '-2'">
              <u-button type="primary" text="申辩处理" size="mini"
                        @click="fnNavigatorPlead(item)"></u-button>
            </view>
          </view>
        </view>
      </u-list-item>
    </u-list>
    <empty v-else></empty>
    <fab-button @click="fnNavigatorDetail('', 'add')" />
  </view>
</template>

<script>
import {getSafetyenvironmentalList} from "@/api";
import FabButton from '@/components/fab_button/index.vue'

export default {
  components: {
    FabButton,
  },
  data() {
    return {
      show: false,
      columns: [
        [
          {id: '', name: '请选择'},
          {id: '0', name: '待检查人核实'},
          {id: '1', name: '检查人核实中'},
          {id: '2', name: '待被检查人确认'},
          {id: '3', name: '已归档'},
          {id: '4', name: '指派中'},
          {id: '5', name: '指派完成'},
          {id: '6', name: '待验收'},
          {id: '7', name: '已验收'},
          {id: '-1', name: '检查人核实打回'},
          {id: '-2', name: '被检查人申辩'}
        ]
      ],
      companyName: '',
      inspectionStatus: '',
      limit: 10,
      curPage: 1,
      totalPage: 0,
      list: [],
    }
  },
  computed: {
    userInfo() {
      return this.$store.getters.getUserInfo
    }
  },
  onShow() {
    this.resetList()
  },
  methods: {
    async getData() {
      let { page } = await getSafetyenvironmentalList({
        companyName: this.companyName,
        inspectionStatus: this.inspectionStatus,
        limit: this.limit,
        curPage: this.curPage,
        pageType: 'jg-list-app',
      });
      this.list = [...this.list, ...page.list];
      this.totalPage = page.totalPage;
    },
    resetList() {
      this.limit = 10
      this.curPage = 1
      this.list = []
      this.getData()
    },
    showPicker() {
      this.show = true;
    },
    confirmPicker(e) {
      this.inspectionStatus = e.value[0].id
      this.show = false;
      this.resetList()
    },
    fnNavigatorDetail(inspectionId, type) {
      uni.$u.route({
        url: '/pages/safety-environmental-inspection/initiate/detail',
        params: {
          inspectionId,
          type
        }
      })
    },
    fnNavigatorPlead(info) {
      uni.$u.route({
        url: '/pages/safety-environmental-inspection/initiate/plead',
        params: {
          inspectionId: info.inspectionId,
          inspectedSiteuserSignTime: info.inspectedSiteuserSignTime,
          inspectedExplain: info.inspectedExplain,
          inspectedExplainFilename: info.inspectedExplainFilename,
          inspectedExplainFilepath: info.inspectedExplainFilepath,
          inspectionSource: info.inspectionSource,
          inspectedSiteuserSignImg: info.inspectedSiteuserSignImg
        }
      })
    },
    scrolltolower() {
      this.curPage++;
      if (this.totalPage >= this.curPage) this.getData();
    },
    showFlowChart(id) {
      uni.navigateTo({
        url: '/pages/safety-environmental-inspection/initiate/steps?ID=' + id
      });
    },
  }
}
</script>

<style scoped lang="scss">
.ml-10 {
  margin-left: 10rpx;
}

.search {
  display: flex;

  .ml-10 {
    margin-left: 10rpx;
  }

  .bth-mini {
    width: 100rpx;
  }

}

.see_btn {
  display: flex;
  justify-content: flex-end;

  .wrap {
    //width: 200rpx;
    margin: 0 10rpx;
  }


}

</style>
