<!-- 线下审核另需提供文件 -->
<template>
  <div class="otherFile">
    <data-table :handleFlag.sync="handleFlag" :showPage="false" :queryParas="queryParas" :showSelection="true"
                :sourceData.sync="sourceData" :selectedRows.sync="selectedRows" :columns="columns"
                :loadCount.sync="loadCount" operateBtnLayout="" :menuFlag="true">
      <template slot="headButton">
        <div class="headButton">
          <auth-button type="primary" size="medium" icon="iconfont iconxinzeng" :label="$t('common.create')" @click="add"></auth-button>
          <auth-button type="primary" size="medium" icon="iconfont iconshanchu" :label="$t('common.del')" @click="del"></auth-button>
        </div>
      </template>

      <!-- 文件名称 -->
      <template slot="fileName" slot-scope="scope">
        <!-- 文件名称组件 -->
        <select-file-name v-if="scope.data.row.status" v-model="scope.data.row.fileId" :placeholder="$t('common.pleaseSelect')" class="dymForm"></select-file-name>
        <span v-else>{{scope.data.row.fileName}}</span>
      </template>

      <!-- 有效份数 -->
      <template slot="effectiveCopies" slot-scope="scope">
        <el-input v-model="scope.data.row.effectiveCopies"></el-input>
      </template>

      <!-- 是否扫描件 -->
      <template slot="ifsScanner" slot-scope="scope">
        <select-dictionary v-model="scope.data.row.ifsScanner" dictTypeCode="ZDZD0024"></select-dictionary>
      </template>

      <!-- 审核意见 -->
      <template slot="auditOpinions" slot-scope="scope">
        <el-input v-model="scope.data.row.auditOpinions" :placeholder="$t('taskManage.todoTask.auditOpinionMsg')"></el-input>
      </template>

      <!-- 操作 -->
      <el-table-column :label="$t('common.operate')" align="center">
        <template slot-scope="scope">
          <btn-upload :uploadApi="uploadApi" :classType="true" :fileID="scope.row.fileId" :rowData="scope.row" @uploadSuccess="uploadSuccess"></btn-upload>
        </template>
      </el-table-column>
      <!-- 显示总数项 -->
      <template slot="paginationLeft">
        <span>{{$t('common.viewTip1')}}{{startNum}}{{$t('common.viewTip2')}}{{endNum}}{{$t('common.viewTip3')}}{{endNum}}{{$t('common.viewTip4')}}</span>
      </template>
    </data-table>
  </div>
</template>
<script>
import BasePage from '@/pages/basePage.js'
import { DataTable, authButton, SelectDictionary, btnUpload } from 'newepoch-components'
import { UPLOAD_API } from '@/constant.js'
import SelectFileName from '@/components/element/dataAduit/SelectFileName.vue'
import cn from '@/i18n/langs/cn.js'

const { common, taskManage } = cn
export default {
  extends: new BasePage(),
  components: {
    DataTable,
    authButton,
    btnUpload,
    SelectDictionary,
    SelectFileName
  },
  prop: {
    form: {
      type: [Object],
      default: function () {
        return {}
      }
    }
  },
  data () {
    return {
      uploadApi: UPLOAD_API,
      startNum: 0,
      endNum: 0,
      selectedRows: [],
      sourceData: [],
      columns: [
        // 文件名称
        {
          prop: 'fileName',
          align: 'left',
          width: '200px',
          label: taskManage.todoTask.file,
          slot: true
        },
        // 需求份数
        {
          prop: 'needCopies',
          align: 'right',
          width: '150px',
          label: taskManage.todoTask.neededNumber,
          format: (row) => { return row.needCopies === '' ? '-' : row.needCopies }
        },
        // 有效份数
        {
          prop: 'effectiveCopies',
          align: 'right',
          width: '150px',
          label: taskManage.todoTask.effectiveNumbers,
          slot: true
        },
        // 是否扫描件
        {
          prop: 'ifsScanner',
          align: 'center',
          width: '150px',
          label: taskManage.todoTask.scan,
          slot: true
        },
        // 审核意见
        {
          prop: 'auditOpinions',
          align: 'left',
          width: '250px',
          label: taskManage.todoTask.auditOpinion,
          slot: true
        }
      ]
    }
  },
  methods: {
    loadData () {},
    uploadSuccess (returnData, rowData) {
      rowData.fileCode = returnData.fileID
    },
    add () {
      let _this = this
      _this.sourceData.push({
        fileId: '',
        fileCode: '',
        fileName: '',
        needCopies: '',
        effectiveNumber: '',
        comments: '',
        ifsDelete: 0,
        date: new Date().valueOf(),
        status: true
      })
    },
    del () {
      let _this = this
      if (_this.selectedRows.length === 0) {
        _this.warning(common.delSelectedTip)
        return
      }
      _this.$confirm(common.confirmTip, common.tip, {
        type: 'warning'
      }).then(() => {
        let arr = _this.filterData(_this.sourceData, _this.selectedRows)
        // _this.submitDto.otherAssetPoolMaterialGroupDtos = arr
        _this.sourceData = arr.filter(it => {
          return it.ifsDelete === 0
        })
        _this.success(common.delSuccess)
      }).catch(() => {})
    },
    filterData (data, rows) {
      let arr1 = []
      let arr2 = []
      rows.forEach(item => {
        if (item.keyId) {
          arr1.push(item.keyId)
        } else {
          arr2.push(item.date)
        }
      })
      data.forEach(item => {
        if (item.keyId) {
          if (arr1.indexOf(item.keyId) !== -1) {
            item.ifsDelete = 1
          }
        } else {
          if (arr2.indexOf(item.date) !== -1) {
            item.ifsDelete = 1
          }
        }
      })
      return data
    }
  }
}
</script>
<style scoped lang="scss" src="@/styles/dataAudit/taskManage/auditList.scss">
</style>
