<template>
  <div class="app-container">
    <el-col :span="8">
      <el-card style="width: 480px">
        <div class="send-person">删除录制数据</div>
        <el-divider style="margin: 0;width: 420px"/>
        <el-date-picker
          v-model="positionDate"
          type="daterange"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          style="width: 400px"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"/>
        <el-row style="text-align: center;margin-top: 20px">
          <el-button :disabled="loadingPosition" icon="el-icon-delete" type="primary" style="width: 150px" @click="deletePositionData()">删除数据</el-button>
          <div v-show="deleteResultPositionData" style="margin-top: 5px">正在删除······</div>
        </el-row>
      </el-card>
    </el-col>
    <el-col :span="8">
      <el-card style="width: 480px">
        <div class="send-person">删除质量数据</div>
        <el-divider style="margin: 0;width: 420px"/>
        <el-date-picker
          v-model="measureDate"
          type="daterange"
          value-format="yyyy-MM-dd"
          format="yyyy-MM-dd"
          style="width: 400px"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"/>
        <el-row style="text-align: center;margin-top: 20px">
          <el-button :disabled="loadingMeasure" icon="el-icon-delete" type="primary" style="width: 150px" @click="deleteMeasureData()">删除数据</el-button>
          <div v-show="deleteResultMeasureData" style="margin-top: 5px">正在删除······</div>
        </el-row>
      </el-card>
    </el-col>
  </div>
</template>

<script>

export default {
  data() {
    return {
      positionDate: [],
      measureDate: [],
      loadingPosition: true,
      loadingMeasure: true,
      deleteResultPositionData: false,
      deleteResultMeasureData: false
    }
  },
  watch: {
    positionDate: {
      handler() {
        this.loadingPosition = !this.positionDate
      }
    },
    measureDate: {
      handler() {
        this.loadingMeasure = !this.measureDate
      }
    }
  },
  created() {
  },
  methods: {
    // 删除
    deletePositionData() {
      this.$confirm('当前日期范围内的数据将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirm-confirm-button',
        cancelButtonClass: 'confirm-cancel-button',
        type: 'warning'
      }).then(() => {
        this.deleteResultPositionData = true
        const url = '/DeletePositionData'
        const params = {
          StartTime: this.positionDate[0],
          EndTime: this.positionDate[1]
        }
        this.ExecDT_ProcessData_Post(url, params).then(response => {
          this.deleteResultPositionData = false
          this.$message.success('删除成功')
        }).catch(res => {
          this.deleteResultPositionData = false
          this.$message.error('删除失败')
        })
      }).catch(() => {
        this.deleteResultPositionData = false
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    deleteMeasureData() {
      this.$confirm('当前日期范围内的数据将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirm-confirm-button',
        cancelButtonClass: 'confirm-cancel-button',
        type: 'warning'
      }).then(() => {
        this.deleteResultMeasureData = true
        var param = []
        param[0] = ['StartTime', this.measureDate[0]]
        param[1] = ['EndTime', this.measureDate[1]]
        var Data = this.CreateData('12', '测量数据_历史数据_删除', param)
        this.ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.deleteResultMeasureData = false
            this.$message.success('删除成功')
          } else {
            this.deleteResultMeasureData = false
            this.$message.error('删除失败')
          }
        })
      }).catch(() => {
        this.deleteResultMeasureData = false
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>
<style scoped>
  .send-person {
    font-size: 22px;
    font-family: "MiSans Demibold",serif;
    text-align: center;
    margin-bottom: 12px;
  }
</style>
