<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">任务编号</label>
        <el-input v-model="query.taskCode" clearable placeholder="任务编号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <!-- <label class="el-form-item-label">审批状态</label>
        <el-input v-model="query.approvalStatus" clearable placeholder="审批状态" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> -->
        <!-- <label class="el-form-item-label">是否为最新审批</label>
        <el-input v-model="query.isNew" clearable placeholder="是否为最新审批" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> -->
        <label class="el-form-item-label">审批状态</label>
        <el-select v-model="query.approvalStatus" clearable placeholder="请选择审批状态" class="filter-item" style="width: 185px" @keyup.enter.native="crud.toQuery">
          <el-option
            v-for="item in dict.print_approval_status"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <requestInfoTmp />
      <!--审批组件-->
      <el-dialog
        title="审批"
        :visible.sync="approvalVisible"
        width="40%"
      >
        <el-form>
          <el-form-item label="审批意见:">
            <el-input v-model="form.approvalRemark" placeholder="请输入审批意见" :rows="2" type="textarea" style="width: 70%;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="warning" @click="approval('02')">驳回</el-button>
          <el-button type="primary" @click="approval('01')">通过</el-button>
        </div>
      </el-dialog>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="审批意见">
            <el-input v-model="form.approvalRemark" :rows="3" type="textarea" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="审批状态">
            <el-select v-model="form.approvalStatus" filterable placeholder="请选择">
              <el-option
                v-for="item in dict.print_approval_status"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="false" prop="id" label="申请详情">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="warning"
              icon="el-icon-view"
              @click="crud.doOpenPrintRequestInfo(scope.row.printingRequest.id)"
            >文印申请详情</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="taskCode" label="任务编号" />
        <el-table-column prop="printingRequest.taskCode" label="文印申请任务编号" />
        <el-table-column prop="printingRequest.taskName" label="文印申请任务名称" />
        <el-table-column prop="printingRequest.file.name" label="文件">
          <template slot-scope="scope">
            <a style="color:-webkit-link !important;" :href="baseApi+ '/file/' + scope.row.printingRequest.file.type + '/' + scope.row.printingRequest.file.realName">{{ scope.row.printingRequest.file.name }}</a>
          </template>
        </el-table-column>
        <el-table-column prop="approvalStatus" label="审批状态">
          <template slot-scope="scope">
            {{ dict.label.print_approval_status[scope.row.approvalStatus] }}
          </template>
        </el-table-column>
        <el-table-column prop="approvalRemark" label="审批意见" />
        <el-table-column prop="approvalUser.name" label="审批人" />
        <el-table-column prop="printingRequest.requestUser.name" label="申请人" />
        <el-table-column prop="printingRequest.remark" show-overflow-tooltip label="申请备注" />
        <el-table-column prop="printingRequest.requestUser.createTime" label="申请时间" />
        <el-table-column v-if="checkPer(['admin','dmPrintingApproval:edit','dmPrintingApproval:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.approvalStatus == '00'"
              size="mini"
              type="warning"
              icon="el-icon-user"
              @click="openSpproval(scope.row.id)"
            >审批</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudDmPrintingApproval from '@/api/dm/printingApproval/dmPrintingApproval'
import { mapGetters } from 'vuex'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import requestInfoTmp from '@/views/dm/printingRequest/info'

const defaultForm = { id: null, requestId: null, taskCode: null, approvalRemark: null, approvalStatus: null, approvalLeave: null, lastLeave: null, isNew: null, createBy: null, updateBy: null, createTime: null, updateTime: null, approvalUser: null }
export default {
  name: 'DmPrintingApproval',
  components: { pagination, crudOperation, rrOperation, requestInfoTmp },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['print_approval_status', 'is_true', 'is_true'],
  cruds() {
    return CRUD({ title: 'dmPrintingApproval', url: 'api/dmPrintingApproval', idField: 'id', sort: 'id,desc', crudMethod: { ...crudDmPrintingApproval }, optShow: { del: true, edit: false, add: false, download: true, reset: true }})
  },
  data() {
    return {
      approvalVisible: false,
      approvalId: '',
      permission: {
        add: ['admin', 'dmPrintingApproval:add'],
        edit: ['admin', 'dmPrintingApproval:edit'],
        del: ['admin', 'dmPrintingApproval:del']
      },
      rules: {
        id: [
          { required: true, message: '主键不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'taskCode', display_name: '任务编号' },
        { key: 'approvalStatus', display_name: '审批状态' },
        { key: 'isNew', display_name: '是否为最新审批' }
      ]
    }
  },
  computed: {
    ...mapGetters([
      'baseApi'
    ])
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    openSpproval(rowId) {
      this.approvalId = rowId
      this.approvalVisible = true
    },
    approval(value) {
      crudDmPrintingApproval.approval({ 'id': this.approvalId, 'approvalStatus': value, 'approvalRemark': this.form.approvalRemark }).then(res => {
        this.$message({
          message: '审批成功',
          type: 'success'
        })
        this.approvalId = ''
        this.approvalVisible = false
        this.crud.refresh()
      }).catch((res) => {
      })
    },
    test() {
      console.info('test')
    }
  }
}
</script>

<style scoped>

</style>
