<!--自定义文件盖章配置-->
<template>
  <div class="documentSealingTaskManage">
    <up-down-layout :header="$t('documentSealingConfig.listHead')" :handleFlag.sync="handleFlag" :footerFlag.sync="footerFlag">
      <search-form
        @handleFilter="handleFilter"
        @clearParam="clearParam"
        :menuCode="menuId"
        searchPerms="searchPerms"
        :formValue.sync="queryParas"
        :componentList="componentList"
        resetPerms="resetPerms"
        slot="query">
      </search-form>
      <template slot="table">
        <data-table
          :headTitle="$t('documentSealingConfig.listHeadCenter')"
          operateBtnLayout=""
          :queryParas="queryParas"
          :columns="columns"
          :menuFlag="true"
          :sourceData="showsourceData"
          :api="api" v-bind="elHeightObj"
          :loadCount="loadCount">
          <template slot="headButton">
            <div class="btn-right">
              <!--导出-->
              <btn-export btnSize="small" :openPerms="true" :menuCode="menuId" perms="btnExport"
                          :templateCode="'shourangsql004'" class="marg10px"></btn-export>
              <!--新增-->
              <auth-button size="small" icon="iconfont iconxinzeng" :label="$t('enterpriseInfoManage.supplierInfoManage.create')"
                           :menuCode="menuId" perms="btnCreate" :openPerms="true"
                           @click="createBtn({}, 'C')" type="primary"></auth-button>
            </div>
          </template>
          <!-- 签章方 -->
          <template slot="participant" slot-scope="scope">
              <el-row v-for="(item, index) in scope.data.row.participateList" :key="index">
                <span>{{item.participant | formatDict( 'SCRS0138')}}</span>
              </el-row>
          </template>
          <!-- 签章关键字 -->
          <template slot="keyword" slot-scope="scope">
            <el-row v-for="(item, index) in scope.data.row.participateList" :key="index">
              <span>{{changeLocation(item, 'keyword')}}</span>
            </el-row>
          </template>
          <!-- 盖章位置 -->
          <template slot="stampLocation" slot-scope="scope">
            <el-row v-for="(item, index) in scope.data.row.participateList" :key="index">
              <span>{{changeLocation(item, 'stampLocation') | formatDict( 'ZD0083')}}</span>
            </el-row>
          </template>
          <template>
            <el-table-column style="float: right" align="center" :label="$t('common.operate')" width="300px">
              <template slot-scope="scope">
                <!--启用-->
                <auth-button size="small" class="iconCircle" icon="iconfont iconenable"
                             :title="$t('documentSealingConfig.Enable')" v-if="handCheckQ(scope)"
                             :menuCode="menuId" perms="btnEnable" :openPerms="true"
                             @click="handleClick(scope.row, 'Q')"></auth-button>
                <!--禁用-->
                <auth-button size="small" class="iconCircle" icon="iconfont iconjinyong1"
                             :title="$t('documentSealingConfig.Prohibit')" v-if="handCheckJ(scope)"
                             :menuCode="menuId" perms="btnProhibit" :openPerms="true"
                             @click="handleClick(scope.row, 'J')"></auth-button>
                <!--删除-->
                <auth-button size="small" class="iconCircleDel" icon="iconfont iconycjian"
                             :menuCode="menuId" perms="btnDel" :openPerms="true" v-if="scope.row.stampTaskStatus === '0'"
                             :title="$t('common.del')" @click="handleClick(scope.row, 'D')"></auth-button>
                <!--编辑-->
                <auth-button size="small" class="iconCircle" icon="iconfont iconbianji"
                             :menuCode="menuId" perms="btnEdit" :openPerms="true" v-if="scope.row.stampTaskStatus === '0'"
                             :title="$t('common.edit')" @click="handleClick(scope.row, 'E')"></auth-button>
              </template>
            </el-table-column>
          </template>
        </data-table>
      </template>
    </up-down-layout>
    <document-sealing-config-create :visible.sync="editVisible" :form.sync="formItem"
                                    :menuCode="menuId"
                                    :editModel="editModel" @refresh-datum="refreshDatum" @refresh-table="refreshTable"></document-sealing-config-create>
  </div>
</template>

<script>
import BasePage from '@/pages/basePage'
import DocumentSealingConfigCreate from '@/pages/shourang/documentSealingConfig/documentSealingConfigCreate'
import { searchForm, DataTable, authButton, upDownLayout, btnExport } from 'newepoch-components'
import uninvoiceApi from '@/api/uninvoiceApi'
import SelectFileName from '@/components/element/shourang/SelectFileName'
import mixin from '@/pages/mixin.js'
// import * as format from '@/filters/index'

export default {
  extends: new BasePage(),
  mixins: [mixin],
  name: 'documentSealingConfigList',
  components: {
    SelectFileName,
    DocumentSealingConfigCreate,
    searchForm,
    DataTable,
    authButton,
    upDownLayout,
    btnExport
  },
  computed: {
    api () {
      return uninvoiceApi.sealConfig
    }
  },
  data () {
    return {
      formItem: {},
      formValue: {},
      sourceData: [],
      showsourceData: [],
      footerFlag: true,
      editVisible: false,
      componentList: [
        // 盖章方
        {
          label: this.$i18n.messages[this.$i18n.locale].documentSealingConfig.stampParty,
          value: 'participantList',
          multiple: true,
          componentName: 'SelectDictionary',
          // placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingConfig.selectstampParty,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: '70px',
          dictTypeCode: 'SCRS0138'
        },
        // 资料名称
        {
          label: this.$i18n.messages[this.$i18n.locale].documentSealingConfig.materialName,
          value: 'assetCustomStampConfigId',
          componentName: SelectFileName,
          // placeholder: this.$i18n.messages[this.$i18n.locale].documentSealingConfig.selectmaterialName,
          placeholder: this.$i18n.messages[this.$i18n.locale].common.pleaseSelect,
          labelWidth: '70px',
          reload: false
        }
      ],
      columns: [
        // 资料名称
        {
          prop: 'assetName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingConfig.materialName
        },
        // 签章方
        {
          prop: 'participant',
          align: 'center',
          label: this.$i18n.messages[this.$i18n.locale].documentSealingConfig.stampParty,
          slot: true
        },
        // 盖章关键字
        {
          prop: 'keyword',
          align: 'left',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].documentSealingConfig.sealKeywords
        },
        // 盖章位置
        {
          prop: 'stampLocation',
          align: 'center',
          slot: true,
          label: this.$i18n.messages[this.$i18n.locale].documentSealingConfig.sealLocation
        }
      ]
    }
  },
  methods: {
    // 盖章位置变化
    changeLocation (item, key) {
      if (this.UtilJs.isEmpty(item[key]) || item[key] === '-1' || item[key] === '0') {
        return '-'
      } else {
        return item[key]
      }
    },
    refreshDatum () {
      this.componentList[1].reload = !this.componentList[1].reload
    },
    refreshTable () {
      this.handleFilter()
    },
    handCheckQ (item) {
      return item.row.ifsEnabled === '1'
    },
    handCheckJ (item) {
      return item.row.ifsEnabled === '0'
    },
    // 创建按钮
    createBtn (data, model) {
      this.editModel = model
      // this.formItem = Object.assign({ assetSources: [], assetCustomStampConfigEnterpriseDtoList: [] }, data)
      this.formItem = {
        assetSources: [],
        assetCustomStampConfigEnterpriseDtoList: [],
        keyId: ''
      }
      this.editVisible = true
    },
    handleClick (data, model) {
      let common = this.$i18n.messages[this.$i18n.locale].common
      if (model === 'E') {
        this.editModel = model
        this.formItem = Object.assign({ assetSources: [], assetCustomStampConfigEnterpriseDtoList: [] }, data)
        this.formItem.assetCustomStampConfigEnterpriseDtoList = JSON.parse(JSON.stringify(data.participateList))
        data.participateList.forEach(it => {
          this.formItem.assetSources.push(it.participant)
        })
        this.editVisible = true
      } else if (model === 'D') {
        this.$confirm(common.delTip, common.warningTip, {
          type: 'warning'
        }).then(() => {
          uninvoiceApi.customconfigpage.setdeleteConfig(data.keyId).then(res => {
            if (res.data) {
              this.success(this.$i18n.messages[this.$i18n.locale].documentSealingConfig.deleteseccessinfo)
              this.handleFilter()
            } else {
              this.success(this.$i18n.messages[this.$i18n.locale].documentSealingConfig.deletefialinfo)
            }
          })
        }).catch(() => {})
      } else if (model === 'Q' || model === 'J') {
        console.log(data)
        let putdata = {
          keyId: '',
          ifsEnabled: '',
          assetName: ''
        }
        putdata.keyId = data.keyId
        putdata.assetName = data.assetName
        this.$set(putdata, 'ifsEnabled', 0)
        if (model === 'J') {
          this.$set(putdata, 'ifsEnabled', 1)
        }
        uninvoiceApi.customconfigpage.setEnableConfig(putdata).then(res => {
          if (res.data) {
            this.handleFilter()
            if (model === 'J') {
              return this.success(this.$i18n.messages[this.$i18n.locale].documentSealingConfig.disableinfo)
            }
            return this.success(this.$i18n.messages[this.$i18n.locale].documentSealingConfig.enableinfo)
          } else {
            if (model === 'J') {
              return this.success(this.$i18n.messages[this.$i18n.locale].documentSealingConfig.enablefialinfo)
            } else {
              return this.success(this.$i18n.messages[this.$i18n.locale].documentSealingConfig.disablefialinfo)
            }
          }
        })
      }
    }
  }
}
</script>

<style scoped>

</style>
