<template>
  <view class="content">
    <view v-if="isView !== '1'" class="flex-end padding" style="padding: 20upx;">
      <u-button type="primary" text="添加" size="mini" class="bth-mini" @click="goToAdd"/>
    </view>
    <u-list v-if="list.length > 0">
      <u-list-item v-for="(item, index) in list" :key="index">
        <view class="flex-between main-title">
          <text>分析时间：{{ item.ANALYZE_TIME }}</text>
        </view>
        <view class="flex-between main-title">
          <text>分析地点：{{ item.ANALYZE_PLACE }}</text>
        </view>
        <view class="flex-between main-title" v-if="GAS_NAME1 && item.DATA1">
          <text>{{ GAS_NAME1 }}：{{ item.DATA1 }}</text>
        </view>
        <view class="flex-between main-title" v-if="GAS_NAME2 && item.DATA2">
          <text>{{ GAS_NAME2 }}：{{ item.DATA2 }}</text>
        </view>
        <view class="flex-between main-title" v-if="GAS_NAME3 && item.DATA3">
          <text>{{ GAS_NAME3 }}：{{ item.DATA3 }}</text>
        </view>
        <view class="flex-between main-title" v-if="GAS_NAME4 && item.DATA4">
          <text>{{ GAS_NAME4 }}：{{ item.DATA4 }}</text>
        </view>
        <view class="flex-between main-title">
          <text>含氧量：{{ item.OXYGEN_CONTENT }}</text>
        </view>
        <view class="flex-between main-title">
          <text>分析人：{{ item.ANALYZE_USER_NAME }}</text>
        </view>
        <view v-if="isView !== '1'" class="flex-between mt-10 subtitle">
          <view></view>
          <view class="flex-between">
            <u-button type="error" text="删除" size="mini" class="bth-mini"
                      @click="fnDelete(item)"/>
          </view>
        </view>
      </u-list-item>
    </u-list>
    <empty v-else></empty>
  </view>
</template>

<script>
import {getConfinedSpaceGasInfo, setConfinedSpaceGasDelete} from "@/api";

export default {
  data() {
    return {
      GAS_NAME1: '',
      GAS_NAME2: '',
      GAS_NAME3: '',
      GAS_NAME4: '',
      EW_RU_TASK_ID: '',
      EW_RU_JOB_ID: '',
      list: [],
      isView: '0'
    }
  },
  onLoad(query) {
    this.GAS_NAME1 = query.GAS_NAME1;
    this.GAS_NAME2 = query.GAS_NAME2;
    this.GAS_NAME3 = query.GAS_NAME3;
    this.GAS_NAME4 = query.GAS_NAME4;
    this.EW_RU_TASK_ID = query.EW_RU_TASK_ID;
    this.EW_RU_JOB_ID = query.EW_RU_JOB_ID;
    this.isView = query.isView
  },
  onNavigationBarButtonTap(e) {
    if (e.index === 0) {
      uni.$u.route({
        url: '/pages/eight_assignments/confined_space/gas/add',
        params: {
          GAS_NAME1: this.GAS_NAME1,
          GAS_NAME2: this.GAS_NAME2,
          GAS_NAME3: this.GAS_NAME3,
          GAS_NAME4: this.GAS_NAME4,
          EW_RU_TASK_ID: this.EW_RU_TASK_ID,
          EW_RU_JOB_ID: this.EW_RU_JOB_ID,
        }
      })
    }
  },
  onShow() {
    this.resetList()
  },
  methods: {
    async getData() {
      let resData = await getConfinedSpaceGasInfo({
        EW_RU_JOB_ID: this.EW_RU_JOB_ID,
        EW_RU_TASK_ID: this.EW_RU_TASK_ID,
        postMethod: 'application/json',
      });
      this.list = [...this.list, ...resData.data.main];
    },
    resetList() {
      this.list = []
      this.getData()
    },
    fnDelete(item) {
      uni.showModal({
        title: '提示',
        content: '确定要删除这条记录？',
        success: async res => {
          if (res.confirm) {
            await setConfinedSpaceGasDelete({
              data: item,
              EW_RU_JOB_ID: this.EW_RU_JOB_ID,
              EW_RU_TASK_ID: this.EW_RU_TASK_ID,
              postMethod: 'application/json',
            })
            uni.$u.toast('删除成功')
            this.resetList()
          }
        }
      })
    },
    goToAdd() {
      uni.$u.route({
        url: '/pages/eight_assignments/confined_space/gas/add',
        params: {
          GAS_NAME1: this.GAS_NAME1,
          GAS_NAME2: this.GAS_NAME2,
          GAS_NAME3: this.GAS_NAME3,
          GAS_NAME4: this.GAS_NAME4,
          EW_RU_TASK_ID: this.EW_RU_TASK_ID,
          EW_RU_JOB_ID: this.EW_RU_JOB_ID,
        }
      })
    }
  },

}
</script>

<style scoped lang="scss">

</style>
