<!-- 外部机构审核的其他文件配置页面 -->
<template>
  <div>
      <up-down-layout :handleFlag.sync="handleFlag">
        <template slot="query">
          <!-- 搜索栏 -->
          <div class="flex-left js-between" style="height:70px">
            <el-form class="form-wd" :rules="rules" :model="queryParas" ref="form">
              <dym-form :formValue.sync="queryParas" :componentList="componentList" @selectChanged="selectedOptionsCheck"></dym-form>
            </el-form>
            <div align="right" style="margin:0 0 10px 20px">
                <auth-button type="primary" :size="'medium'" icon="iconfont iconycchaxun" :label="$t('common.search')" @click="search"></auth-button>
                <auth-button size="medium" :openPerms="false" :label="$t('common.reset')" icon="iconfont iconyczhongzhi" @click="clearParam"></auth-button>
            </div>
          </div>
        </template>
        <template slot="table">
          <data-table :showPage="false" :sourceData.sync="data" :columns="columns" v-bind="elHeightObj" :queryParas.sync="queryParas" :api="mgrApi" :loadCount="loadCount" :loadPage="loadPage" @getTableData="getTableData">
            <!-- <template slot="invalidFileFlaghead" slot-scope="scope">
              <el-checkbox :index="scope.data.$index"  v-model="scope.data.column.prop" @change="allReviewFlag(scope.data.column.prop)" true-label="1" false-label="2"></el-checkbox>
            </template>
            <template slot="invalidFileFlag" slot-scope="scope">
              <el-checkbox :index="scope.data.$index"  v-model="scope.data.row.invalidFileFlag" true-label="1" false-label="2"></el-checkbox>
            </template> -->
            <template slot="auditAssetScope" slot-scope="scope">
              <el-radio-group class="flex-center" v-model="scope.data.row.auditAssetScope" :disabled="!UtilJs.isEmpty(scope.data.row.keyId)">
                <el-radio-group v-model="scope.data.row.auditAssetScope" :disabled="scope.data.row.changeFlag === '0'">
                  <el-radio v-for="item in auditAssetScopeRdiao" :key="item.dictId" :label="item.dictId">{{item.dictName}}</el-radio>
                </el-radio-group>
                <!-- 查看 -->
                <auth-button v-if="!UtilJs.isEmpty(scope.data.row.keyId) && scope.data.row.oldAuditAssetScope === '3'" style="margin-left: 10px" size="small" class="iconCircle" :title="$t('common.view')" icon="iconfont iconchakan" :disabled="scope.data.row.auditAssetScope !== '3'" @click="edit(scope.data.row,scope.data.$index)"></auth-button>
                <!-- 编辑 -->
                <auth-button v-else style="margin-left: 10px" size="small" class="iconCircle" :title="$t('common.edit')" icon="iconfont iconbianji" @click="edit(scope.data.row,scope.data.$index)" :disabled="scope.data.row.auditAssetScope !== '3'"></auth-button>
              </el-radio-group>
            </template>
          </data-table>
        <div align="center">
            <auth-button type="primary" :size="'medium'" :label="$t('common.save')" @click="save"></auth-button>
        </div>
        </template>
      </up-down-layout>
      <custom-asset-select-pop v-if="custVisible" :visible.sync="custVisible" :form="otherForm" @selectedRowsData="selectedRowsData" :formData="formData" :index="index"></custom-asset-select-pop>
  </div>
</template>

<script>
import customAssetSelectPop from '@/pages/assetoutfeedback/otherFileSetup/customAssetSelectPop'
import issueInput from '@/components/element/assetaudit/issueInput'
// import TraceProjectSelectList from '@/components/element/assetoutfeedback/TraceProjectSelectList'
import absFileSelectList from '@/components/element/assetoutfeedback/absFileSelectList'
import otherFileSetupApi from '@/api/assetoutfeedback/otherFileSetup/otherFileSetupApi'
import { dymForm, DataTable, upDownLayout, authButton } from 'newepoch-components'
import BasePage from '@/pages/basePage'
import mixin from '@/pages/mixin'
export default {
  extends: new BasePage(),
  mixins: [mixin],
  components: { DataTable, dymForm, upDownLayout, authButton, customAssetSelectPop, issueInput },
  computed: {
    mgrApi () {
      return otherFileSetupApi.getOtherMgr
    },
    auditAssetScopeRdiao () {
      let options = this.$store.state.sys.dictionarys.filter(function (dict) {
        return dict.dictTypeCode === 'AUDIT_OUT_ASSET_SCOPE'
      })
      return options
    }
  },
  data () {
    let isPositiveInteger = (rule, value, callback) => {
      if (value === undefined || value === '') {
        return callback()
      }
      const reg = /\./
      if (Number(value) > 0 && !reg.test(value)) {
        callback()
      } else {
        callback(new Error('请输入大于0的整数'))
      }
    }
    return {
      otherForm: {},
      data: [
      ],
      index: 0,
      // 表单校验
      rules: {
        projectId: [
          {
            required: true,
            message: this.$t('sampleMgrMain.projectPrompt'),
            trigger: 'change'
          }
        ],
        periods: [
          {
            validator: isPositiveInteger,
            trigger: 'blur'
          }
        ]
      },
      loadPage: 'getList',
      // 表单
      form: {},
      formData: [],
      custVisible: false,
      handleFlag: true,
      importFlag: false,
      componentList: [
        {
          // 产品名称
          label: this.$i18n.messages[this.$i18n.locale].sampleMgrMain.projectName,
          disabled: false,
          value: 'projectId',
          prop: 'projectId',
          name: 'project',
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: '55px',
          cols: [12, 12, 12, 12],
          clearable: true,
          // componentName: TraceProjectSelectList
          componentName: absFileSelectList
        },
        {
          // 期数
          label: this.$i18n.messages[this.$i18n.locale].common.periodsNum,
          disabled: false,
          value: 'periods',
          prop: 'periods',
          maxlength: 3,
          cols: [12, 12, 12, 12],
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseInput,
          labelWidth: '55px',
          clearable: true,
          componentName: issueInput
        }
      ],
      columns: [
        // {
        //   // 是否无效
        //   prop: 'invalidFileFlag',
        //   align: 'center',
        //   width: '20px',
        //   slot: true,
        //   headslot: true,
        //   label: ''
        // },
        {
          // 审核文件
          prop: 'fileName',
          align: 'left',
          width: '200px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.auditAssetFile
        }, {
          // 审核资产范围
          prop: 'auditAssetScope',
          align: 'center',
          slot: true,
          width: '200px',
          label: this.$i18n.messages[this.$i18n.locale].effectDealFeedBackMain.auditAssetScope
        }
      ]
    }
  },
  methods: {
    // 编辑
    edit (row, index) {
      this.otherForm = row
      this.otherForm.projectId = this.queryParas.projectId
      this.otherForm.projectName = this.queryParas.projectName
      this.formData = row.saveOtherFileDetailDTOList
      this.index = index
      this.custVisible = true
    },
    getTableData (data) {
      data.forEach((item, index) => {
        item.oldAuditAssetScope = item.auditAssetScope
      })
    },
    // 选择所有
    // allReviewFlag (headCheck) {
    //   if (this.data.length > 0) {
    //     this.data.forEach((res, i) => {
    //       this.data[i].invalidFileFlag = headCheck
    //     })
    //   }
    // },
    // 查询
    search () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          // this.queryParas = Object.assign(this.queryParas, this.form)
          console.log(this.handleFilter)
          this.$nextTick(() => {
            this.handleFilter()
          })
        }
      })
    },
    // 保存
    save () {
      this.assetpkgmgrFullScreenLoading()
      this.mgrApi.defaultSave(this.data).then(res => {
        this.assetpkgmgrFullScreenLoading().close()
        if (res.success && res.data) {
          this.success('保存成功')
          this.formData = {}
          this.search()
        } else {
          this.warning('没有修改数据或保存出错')
        }
      }).catch(res => {
        this.assetpkgmgrFullScreenLoading().close()
      })
    },
    selectedOptionsCheck (obj, index) {
      if (!this.UtilJs.isEmpty(index)) {
        this.queryParas = Object.assign(this.queryParas, { 'projectName': obj.projectInfo.projectName })
      }
    },
    // 所编辑的数据
    selectedRowsData (val, obj, index) {
      // if (obj.keyId !== '') {
      //   this.data.forEach((res, i) => {
      //     if (this.data[i].keyId === obj.keyId) {
      //       this.data[i] = Object.assign(this.data[i], { saveOtherFileDetailDTOList: val })
      //     }
      //   })
      // } else {
      //   this.data.forEach((res, i) => {
      //     console.log(res)
      //     if (this.data[i].fileCode === obj.fileCode) {
      //       this.data[i] = Object.assign(this.data[i], { saveOtherFileDetailDTOList: val })
      //     }
      //   })
      // }
      // this.data.forEach((res, i) => {
      //   this.data[i] = Object.assign(this.data[i], { saveOtherFileDetailDTOList: val })
      // })
      this.data[index] = Object.assign(this.data[index], { saveOtherFileDetailDTOList: val })
    }
  }
}
</script>

<style scoped>
.js-between {
  justify-content: space-between;
}
.form-wd {
  width: 60%;
}
.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}
</style>
