<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div>
        <el-badge :value="undoNumbers.enterpriseAudit" :hidden="!undoNumbers.enterpriseAudit">
          <router-link to="/c/enterprise/index">
            <el-button class="filter-item" size="small">企业申请待审批</el-button>
          </router-link>
        </el-badge>
        <el-badge :value="undoNumbers.leaderSchedulingChangeAudit" :hidden="!undoNumbers.leaderSchedulingChangeAudit" style="margin-left: 30px;">
          <router-link to="/c/leader/change">
            <el-button class="filter-item" size="small">排班变更待审核</el-button>
          </router-link>
        </el-badge>
        <!-- <el-badge :value="undoNumbers.dangerousWorkAudit" :hidden="!undoNumbers.dangerousWorkAudit" style="margin-left: 30px;">
          <router-link to="/c/underground/dangerousWork">
            <el-button class="filter-item" size="small">危险作业待审核</el-button>
          </router-link>
        </el-badge> -->
      </div>
    </div>
    <!--弹出框1-->
    <el-dialog append-to-body :close-on-click-modal="true" :visible.sync="dialog1Show" :title="'停产申请'" width="640px">
      <el-form ref="dialog1Form" :model="dialog1Data" size="mini" label-width="180px" style="margin-right: 80px;">
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="矿山名称：" prop="mineName">
              <span>{{ dialog1Data.mineName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="所属企业：" prop="enterpriseName">
              <span>{{ dialog1Data.enterpriseName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="申请时间：" prop="createDatetime">
              <span>{{ dialog1Data.createDatetime }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="停产说明：" prop="createDatetime">
              <span>{{ dialog1Data.note }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="附件：" prop="filesPath">
              <el-link v-for="file in dialog1Data._fileList" :key="file.url" @click="openFile(file)">{{ file.name }}</el-link>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="error" @click="audit(3)">审核不通过</el-button>
        <el-button type="primary" @click="audit(2)">审核通过</el-button>
      </div>
    </el-dialog>
    <!--矿山停产申请-->
    <el-badge :value="undoNumbers.mineStopAudit" :hidden="!undoNumbers.mineStopAudit" style="width: 90%;">
      <el-card>
        <h3 style="margin-top: 0;">矿山停产申请审核</h3>
        <el-table ref="table" v-loading="searching" :data="tableData" row-key="id">
          <el-table-column :show-overflow-tooltip="true" prop="mineName" label="矿山名称" align="center" />
          <el-table-column :show-overflow-tooltip="true" prop="enterpriseName" label="所属企业" align="center" />
          <el-table-column :show-overflow-tooltip="true" prop="createDatetime" label="申请时间" align="center" />
          <el-table-column :show-overflow-tooltip="true" prop="note" label="停产说明" width="100px" align="center" />
          <el-table-column label="操作" width="400px" align="center" fixed="right">
            <template slot-scope="scope">
              <el-button size="mini" round @click="doLook(scope.row)">查看详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          :current-page.sync="searchParam.page"
          :page-size.sync="searchParam.count"
          :total="searchResult.total"
          layout="total, prev, pager, next, jumper"
          @size-change="searchSubmit"
          @current-change="searchSubmit"
        />
      </el-card>
    </el-badge>
  </div>
</template>

<script>
import noticeAPI from '@/api/kd/noticeApi'
import mineStopApplyApi from '@/api/kd/mineStopApply'
import mineApi from '@/api/kd/mine'
import { getToken } from '@/utils/auth'
import { mapGetters } from 'vuex'
const searchParam = {// 默认搜索条件
  page: 1,
  count: 10,
  searchCount: true,
  auditState: 1
}
export default {
  name: 'CNoticeMix', // 本页面名
  components: {},
  data() {
    return {
      httpHeaders: {
        'Authorization': getToken()
      },
      mineList: [],
      searching: false,
      undoNumbers: {},
      searchParam: {},
      searchResult: {
        total: 0,
        results: [] // 搜索结果
      },
      dialog1Show: false,
      dialog1Data: {}
    }
  },
  computed: {
    ...mapGetters([
      'baseApi',
      'user'
    ]),
    tableData() {
      // 此处对返回值进行算法重组
      return this.searchResult.results
    }
  },
  mounted() {
    // 矿山List
    mineApi.getEnableMine().then(response => {
      let i = 1
      response.results.forEach(x => { x.index = i++ })
      this.mineList = response.results
    })
    this.searchParamReset()
    this.searchSubmit()
  },
  methods: {
    searchParamReset() {
      this.searchParam = JSON.parse(JSON.stringify(searchParam))
    },
    searchSubmit() {
      this.searching = true
      // 总数统计
      noticeAPI.undo().then(response => {
        this.undoNumbers = response
      })
      mineStopApplyApi.getPage(this.searchParam).then(response => {
        this.searching = false
        this.searchResult = response
      }).catch(() => {
        this.searching = false
      })
    },
    doLook(rowData) {
      this.dialog1Data = JSON.parse(JSON.stringify(rowData))
      if (this.dialog1Data.filePath) {
        this.dialog1Data._fileList = JSON.parse(this.dialog1Data.filePath)
      }
      this.dialog1Show = true
    },
    audit(auditState) {
      this.dialog1Saving = true
      const auditParam = {
        id: this.dialog1Data.id,
        auditState
      }
      mineStopApplyApi.audit(auditParam).then(() => {
        this.dialog1Saving = false
        this.dialog1Show = false
        this.dialog1Data = {}
        this.$message.success('审核完成')
        this.searchSubmit()
      }).catch(() => {
        this.dialog1Saving = false
      })
    },
    openFile(file) {
      if (file.url) {
        window.open(this.baseApi + '/file' + file.url)
      } else if (file.response && file.response.result) {
        window.open(this.baseApi + '/file' + file.response.result)
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  ::v-deep .el-input-number .el-input__inner {
    text-align: left;
  }
  ::v-deep .vue-treeselect__control,::v-deep .vue-treeselect__placeholder,::v-deep .vue-treeselect__single-value {
    height: 30px;
    line-height: 30px;
  }
</style>
