<template>
  <div class="app-container">
    <el-card shadow="never">
      <el-form ref="queryForm" :model="queryParams" size="small" :inline="true">
        <el-form-item prop="keyword">
          <template slot="label">{{ stdT('queryKeyword') }}</template>
          <el-input
            v-model="queryParams.keyword"
            :placeholder="stdT('queryKeywordPh')"
            clearable
            style="width: 220px"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item prop="standardType">
          <template slot="label">{{ stdT('queryStdType') }}</template>
          <el-select v-model="queryParams.standardType" :placeholder="$t('breedingStd.common.pleaseSelect')" clearable style="width: 160px">
            <el-option
              v-for="item in standardTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('breedingStd.common.search') }}</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('breedingStd.common.reset') }}</el-button>
          <el-button
            v-hasPermi="['epidemicTreatment:standard:add']"
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
          >{{ $t('breedingStd.common.add') }}</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <br />

    <el-card shadow="never">
      <el-table v-loading="loading" :data="tableList" border>
        <el-table-column :label="$t('breedingStd.common.colStdName')" prop="standardName" align="center" min-width="120" :show-overflow-tooltip="true" />
        <el-table-column :label="$t('breedingStd.common.colStdType')" align="center" width="112">
          <template slot-scope="scope">
            <span>{{ typeLabel(scope.row.standardType) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('breedingStd.common.colIntro')" prop="introduction" align="center" min-width="120" :show-overflow-tooltip="true" />
        <el-table-column :label="$t('breedingStd.common.colBodyFile')" align="center" min-width="130" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <el-link
              v-if="scope.row.contentFileUrl"
              type="primary"
              :href="scope.row.contentFileUrl"
              target="_blank"
            >{{ scope.row.contentFileName }}</el-link>
            <span v-else>{{ $t('breedingStd.status.dash') }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('breedingStd.common.colShelf')" align="center" width="92">
          <template slot-scope="scope">
            <span>{{ publishStatusText(scope.row.publishStatus) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('breedingStd.common.colKb')" align="center" width="100">
          <template slot-scope="scope">
            <span>{{ kbSyncStatusText(scope.row.kbSyncStatus) }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('breedingStd.common.colPub')" align="center" width="110">
          <template slot-scope="scope">
            <span>{{ scope.row.publishTime ? parseTime(scope.row.publishTime, '{y}-{m}-{d}') : $t('breedingStd.status.dash') }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('breedingStd.common.colCreate')" align="center" width="160">
          <template slot-scope="scope">
            <span>{{ scope.row.createTime ? parseTime(scope.row.createTime) : $t('breedingStd.status.dash') }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('breedingStd.common.colOp')" align="center" class-name="small-padding fixed-width" width="400">
          <template slot-scope="scope">
            <el-button
              v-hasPermi="['epidemicTreatment:standard:query']"
              type="text"
              size="mini"
              @click="handleView(scope.row)"
            >{{ $t('breedingStd.common.view') }}</el-button>
            <el-button
              v-hasPermi="['epidemicTreatment:standard:syncKb']"
              v-if="canSyncKb(scope.row)"
              type="text"
              size="mini"
              @click="handleSyncKb(scope.row)"
            >{{ $t('breedingStd.common.syncKb') }}</el-button>
            <el-button
              v-hasPermi="['epidemicTreatment:standard:removeKb']"
              v-if="canRemoveKb(scope.row)"
              type="text"
              size="mini"
              @click="handleRemoveKb(scope.row)"
            >{{ $t('breedingStd.common.removeKb') }}</el-button>
            <el-button
              v-hasPermi="['epidemicTreatment:standard:edit']"
              v-if="canEdit(scope.row)"
              type="text"
              size="mini"
              @click="handleEdit(scope.row)"
            >{{ $t('breedingStd.common.edit') }}</el-button>
            <el-button
              v-hasPermi="['epidemicTreatment:standard:remove']"
              v-if="canDelete(scope.row)"
              type="text"
              size="mini"
              @click="handleDelete(scope.row)"
            >{{ $t('breedingStd.common.delete') }}</el-button>
            <el-button
              v-hasPermi="['epidemicTreatment:standard:publish']"
              v-if="canPublish(scope.row)"
              type="text"
              size="mini"
              @click="handlePublish(scope.row)"
            >{{ $t('breedingStd.common.publish') }}</el-button>
            <el-button
              v-hasPermi="['epidemicTreatment:standard:offline']"
              v-if="canOffline(scope.row)"
              type="text"
              size="mini"
              @click="handleOffline(scope.row)"
            >{{ $t('breedingStd.common.offline') }}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>

    <el-dialog :title="dialogTitle" :visible.sync="open" width="580px" append-to-body @close="cancel">
      <el-form :key="formKey" ref="form" :model="form" label-width="100px">
        <el-form-item prop="standardName" :rules="formRules.standardName">
          <template slot="label">{{ $t('breedingStd.common.formStdName') }}</template>
          <el-input
            v-model="form.standardName"
            :placeholder="$t('breedingStd.common.phStdName')"
            maxlength="20"
            show-word-limit
            :disabled="dialogEdit && !canEditFormRow"
          />
        </el-form-item>
        <el-form-item prop="standardType" :rules="formRules.standardType">
          <template slot="label">{{ $t('breedingStd.common.formStdType') }}</template>
          <el-select
            v-model="form.standardType"
            :placeholder="$t('breedingStd.common.pleaseSelect')"
            style="width: 100%"
            :disabled="dialogEdit && !canEditFormRow"
          >
            <el-option
              v-for="item in standardTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item prop="introduction" :rules="formRules.introduction">
          <template slot="label">{{ $t('breedingStd.common.formIntro') }}</template>
          <el-input
            v-model="form.introduction"
            type="textarea"
            :rows="3"
            :placeholder="$t('breedingStd.common.phIntroOptional')"
            maxlength="50"
            show-word-limit
            :disabled="dialogEdit && !canEditFormRow"
          />
        </el-form-item>
        <el-form-item prop="contentFilePath" :rules="formRules.contentFilePath">
          <template slot="label">{{ $t('breedingStd.common.formBodyFile') }}</template>
          <el-upload
            class="upload-file-uploader"
            :action="uploadAction"
            :headers="uploadHeaders"
            :before-upload="beforeContentUpload"
            :on-success="handleContentUploadSuccess"
            :on-error="handleUploadHttpError"
            :show-file-list="false"
            :disabled="dialogEdit && !canEditFormRow"
          >
            <el-button size="mini" type="primary" :disabled="dialogEdit && !canEditFormRow">{{ $t('breedingStd.common.pickFile') }}</el-button>
          </el-upload>
          <div class="el-upload__tip">{{ $t('breedingStd.common.tipBody') }}</div>
          <ul v-if="form.contentFilePath" class="upload-file-list el-upload-list el-upload-list--text">
            <li class="el-upload-list__item ele-upload-list__item-content">
              <el-link :href="form.contentFileUrl || '#'" :underline="false" target="_blank">
                <span class="el-icon-document"> {{ form.contentFileName }} </span>
              </el-link>
              <div class="ele-upload-list__item-content-action">
                <el-link v-if="!(dialogEdit && !canEditFormRow)" type="danger" :underline="false" @click="clearContentFile">{{ $t('breedingStd.common.del') }}</el-link>
              </div>
            </li>
          </ul>
        </el-form-item>
        <el-form-item prop="coverFilePath">
          <template slot="label">{{ $t('breedingStd.common.formCover') }}</template>
          <el-upload
            list-type="picture-card"
            :class="{ hide: hideCoverUpload }"
            :action="uploadAction"
            :headers="uploadHeaders"
            :before-upload="beforeCoverUpload"
            :on-success="handleCoverUploadSuccess"
            :on-error="handleUploadHttpError"
            :on-remove="handleCoverRemove"
            :limit="1"
            :file-list="coverFileList"
            :disabled="dialogEdit && !canEditFormRow"
          >
            <i class="el-icon-plus"></i>
          </el-upload>
          <div class="el-upload__tip">{{ $t('breedingStd.common.tipCover') }}</div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">{{ $t('breedingStd.common.ok') }}</el-button>
        <el-button @click="cancel">{{ $t('breedingStd.common.cancel') }}</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="$t('breedingStd.common.viewTitle')" :visible.sync="viewOpen" width="560px" append-to-body>
      <el-form label-width="100px" size="small">
        <el-form-item :label="$t('breedingStd.common.formStdName')">
          <span>{{ viewRow.standardName }}</span>
        </el-form-item>
        <el-form-item :label="$t('breedingStd.common.formStdType')">
          <span>{{ typeLabel(viewRow.standardType) }}</span>
        </el-form-item>
        <el-form-item :label="$t('breedingStd.common.formIntro')">
          <span>{{ viewRow.introduction || $t('breedingStd.status.dash') }}</span>
        </el-form-item>
        <el-form-item :label="$t('breedingStd.common.formBodyFile')">
          <el-link
            v-if="viewRow.contentFileUrl"
            type="primary"
            :href="viewRow.contentFileUrl"
            target="_blank"
          >{{ viewRow.contentFileName }}</el-link>
          <span v-else>{{ $t('breedingStd.status.dash') }}</span>
        </el-form-item>
        <el-form-item :label="$t('breedingStd.common.formCover')">
          <image-preview v-if="viewRow.coverFileUrl" :src="viewRow.coverFileUrl" :width="200" :height="120" />
          <span v-else>{{ $t('breedingStd.status.dash') }}</span>
        </el-form-item>
        <el-form-item :label="$t('breedingStd.common.colShelf')">
          <span>{{ publishStatusText(viewRow.publishStatus) }}</span>
        </el-form-item>
        <el-form-item :label="$t('breedingStd.common.colKb')">
          <span>{{ kbSyncStatusText(viewRow.kbSyncStatus) }}</span>
        </el-form-item>
        <el-form-item :label="$t('breedingStd.common.viewPubTime')">
          <span>{{ viewRow.publishTime ? parseTime(viewRow.publishTime) : $t('breedingStd.status.dash') }}</span>
        </el-form-item>
        <el-form-item :label="$t('breedingStd.common.viewOfflineTime')">
          <span>{{ viewRow.offlineTime ? parseTime(viewRow.offlineTime) : $t('breedingStd.status.dash') }}</span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="viewOpen = false">{{ $t('breedingStd.common.close') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getToken } from "@/utils/auth"
import breedingStdLocaleMixin from "@/mixins/breedingStdLocaleMixin"
import {
  listEpidemicTreatmentStandard,
  getEpidemicTreatmentStandard,
  addEpidemicTreatmentStandard,
  updateEpidemicTreatmentStandard,
  delEpidemicTreatmentStandard,
  syncKbEpidemicTreatmentStandard,
  removeKbEpidemicTreatmentStandard,
  publishEpidemicTreatmentStandard,
  offlineEpidemicTreatmentStandard
} from "@/api/breedingStandards/epidemicTreatment"
import { listInformationCategoryChildren } from "@/api/category/informationCategory"

const PUBLISH_STATUS = { UNPUBLISHED: 0, PUBLISHED: 1 }
const KB_SYNC_STATUS = { UNSYNCED: 0, SYNCED: 1 }
/** 资讯类别：parentCode=001、categoryType=5（与后端 EpidemicTreatmentStandardTypeValidator 一致） */
const STD_TYPE_PARENT_CODE = "001"
const STD_TYPE_CATEGORY_TYPE = "5"
/** 存量数据迁移前可能仍为 1，展示用 */
const LEGACY_STANDARD_TYPE_LABELS = {
  1: "type1"
}

export default {
  name: "EpidemicTreatmentStandard",
  mixins: [breedingStdLocaleMixin],
  data() {
    return {
      stdNs: "ep",
      loading: false,
      open: false,
      viewOpen: false,
      viewRow: {},
      dialogEdit: false,
      canEditFormRow: true,
      formKey: 0,
      total: 0,
      tableList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        keyword: undefined,
        standardType: undefined
      },
      form: {},
      standardTypeOptions: [],
      contentFileExts: ["pdf", "doc", "docx", "xls", "xlsx", "pptx"],
      coverFileExts: ["jpg", "jpeg", "png"]
    }
  },
  computed: {
    dialogTitle() {
      return this.dialogEdit ? this.stdT("dialogEdit") : this.stdT("dialogAdd")
    },
    formRules() {
      return {
        standardName: [
          { required: true, message: this.$t("breedingStd.common.ruleStdNameRequired"), trigger: "blur" },
          { min: 1, max: 20, message: this.$t("breedingStd.common.ruleLen120"), trigger: "blur" }
        ],
        standardType: [{ required: true, message: this.$t("breedingStd.common.ruleStdTypeRequired"), trigger: "change" }],
        introduction: [{ max: 50, message: this.$t("breedingStd.common.ruleIntroMax50"), trigger: "blur" }],
        contentFilePath: [{ required: true, message: this.$t("breedingStd.common.ruleBodyRequired"), trigger: "change" }]
      }
    },
    uploadAction() {
      return process.env.VUE_APP_BASE_API + "/common/upload"
    },
    uploadHeaders() {
      return { Authorization: "Bearer " + getToken() }
    },
    coverFileList() {
      if (!this.form.coverFileUrl) {
        return []
      }
      return [{ name: "cover", url: this.form.coverFileUrl }]
    },
    hideCoverUpload() {
      return !!(this.form.coverFilePath || this.form.coverFileUrl)
    }
  },
  created() {
    this.loadStandardTypeOptions()
    this.getList()
  },
  methods: {
    mapCategoryItem(item) {
      if (!item) {
        return { value: "", label: "" }
      }
      return {
        value: item["code"] != null ? item["code"] : item.code,
        label: item["name"] != null ? item["name"] : item.name
      }
    },
    loadStandardTypeOptions() {
      return listInformationCategoryChildren(STD_TYPE_PARENT_CODE, STD_TYPE_CATEGORY_TYPE)
        .then((res) => {
          const list = res.data || []
          this.standardTypeOptions = list.map((item) => this.mapCategoryItem(item)).filter((o) => o.value)
        })
        .catch(() => {
          this.standardTypeOptions = []
          this.$modal.msgError(this.stdT("errStdTypeLoad"))
        })
    },
    typeLabel(val) {
      if (val == null || val === "") {
        return ""
      }
      const key = String(val)
      const item = this.standardTypeOptions.find((o) => String(o.value) === key)
      if (item) {
        return item.label
      }
      const legacyKey = LEGACY_STANDARD_TYPE_LABELS[val]
      if (legacyKey) {
        return this.stdT(legacyKey)
      }
      return key
    },
    canEdit(row) {
      return (
        Number(row.publishStatus) === PUBLISH_STATUS.UNPUBLISHED &&
        Number(row.kbSyncStatus) === KB_SYNC_STATUS.UNSYNCED
      )
    },
    canSyncKb(row) {
      return (
        Number(row.publishStatus) === PUBLISH_STATUS.UNPUBLISHED &&
        Number(row.kbSyncStatus) === KB_SYNC_STATUS.UNSYNCED
      )
    },
    canRemoveKb(row) {
      return (
        Number(row.publishStatus) === PUBLISH_STATUS.UNPUBLISHED &&
        Number(row.kbSyncStatus) === KB_SYNC_STATUS.SYNCED
      )
    },
    canPublish(row) {
      return (
        Number(row.publishStatus) === PUBLISH_STATUS.UNPUBLISHED &&
        Number(row.kbSyncStatus) === KB_SYNC_STATUS.SYNCED
      )
    },
    canOffline(row) {
      return Number(row.publishStatus) === PUBLISH_STATUS.PUBLISHED
    },
    /** 仅未发布且未同步可删；已同步须先移出 */
    canDelete(row) {
      return (
        Number(row.publishStatus) === PUBLISH_STATUS.UNPUBLISHED &&
        Number(row.kbSyncStatus) === KB_SYNC_STATUS.UNSYNCED
      )
    },
    getList() {
      this.loading = true
      listEpidemicTreatmentStandard(this.queryParams)
        .then((res) => {
          this.tableList = res.rows || []
          this.total = res.total != null ? res.total : 0
        })
        .finally(() => {
          this.loading = false
        })
    },
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.queryParams.keyword = undefined
      this.queryParams.standardType = undefined
      this.resetForm("queryForm")
      this.handleQuery()
    },
    resetFormModel() {
      this.form = {
        id: undefined,
        standardName: undefined,
        standardType: undefined,
        introduction: undefined,
        contentFileUrl: undefined,
        contentFilePath: undefined,
        contentFileName: undefined,
        coverFileUrl: undefined,
        coverFilePath: undefined
      }
    },
    handleAdd() {
      this.formKey += 1
      this.resetFormModel()
      this.dialogEdit = false
      this.canEditFormRow = true
      this.open = true
      this.$nextTick(() => this.resetForm("form"))
    },
    resolveCanEditFormRow(data) {
      return (
        Number(data.publishStatus) === PUBLISH_STATUS.UNPUBLISHED &&
        Number(data.kbSyncStatus) === KB_SYNC_STATUS.UNSYNCED
      )
    },
    handleEdit(row) {
      if (Number(row.publishStatus) === PUBLISH_STATUS.PUBLISHED) {
        this.$modal.msgWarning(this.stdT("rulePublishedNoEdit"))
        return
      }
      if (Number(row.kbSyncStatus) === KB_SYNC_STATUS.SYNCED) {
        this.$modal.msgWarning(this.stdT("ruleSyncedNoEdit"))
        return
      }
      if (!this.canEdit(row)) {
        return
      }
      const id = row.id
      getEpidemicTreatmentStandard(id).then((res) => {
        const data = res.data || {}
        this.formKey += 1
        this.dialogEdit = true
        this.canEditFormRow = this.resolveCanEditFormRow(data)
        this.form = {
          id: data.id,
          standardName: data.standardName,
          standardType: data.standardType,
          introduction: data.introduction,
          contentFileUrl: data.contentFileUrl,
          contentFilePath: data.contentFilePath,
          contentFileName: data.contentFileName,
          coverFileUrl: data.coverFileUrl,
          coverFilePath: data.coverFilePath
        }
        this.open = true
        this.$nextTick(() => {
          if (this.$refs.form) {
            this.$refs.form.clearValidate()
          }
        })
      })
    },
    handleView(row) {
      const id = row.id
      getEpidemicTreatmentStandard(id).then((res) => {
        this.viewRow = res.data || {}
        this.viewOpen = true
      })
    },
    handleSyncKb(row) {
      this.runSyncKbAfterConfirm(this.stdT("confirmSync"), () => syncKbEpidemicTreatmentStandard(row.id))
        .then(() => {
          this.$modal.msgSuccess(this.$t("breedingStd.common.msgSyncOk"))
          this.getList()
        })
        .catch(() => {})
    },
    handleRemoveKb(row) {
      this.runRemoveKbAfterConfirm(this.stdT("confirmRemoveKb"), () => removeKbEpidemicTreatmentStandard(row.id))
        .then(() => {
          this.$modal.msgSuccess(this.$t("breedingStd.common.msgOpOk"))
          this.getList()
        })
        .catch(() => {})
    },
    handleDelete(row) {
      if (!this.canDelete(row)) {
        this.$modal.msgWarning(this.stdT("ruleDeleteNeedRemoveKb"))
        return
      }
      this.$modal
        .confirm(this.stdT("confirmDelete", { id: row.id }))
        .then(() => delEpidemicTreatmentStandard(row.id))
        .then(() => {
          this.$modal.msgSuccess(this.$t("breedingStd.common.msgDelOk"))
          this.getList()
        })
        .catch(() => {})
    },
    handlePublish(row) {
      this.$modal
        .confirm(this.stdT("confirmPublish"))
        .then(() => publishEpidemicTreatmentStandard(row.id))
        .then(() => {
          this.$modal.msgSuccess(this.$t("breedingStd.common.msgPubOk"))
          this.getList()
        })
        .catch(() => {})
    },
    handleOffline(row) {
      this.$modal
        .confirm(this.stdT("confirmOffline"))
        .then(() => offlineEpidemicTreatmentStandard(row.id))
        .then(() => {
          this.$modal.msgSuccess(this.$t("breedingStd.common.msgOffOk"))
          this.getList()
        })
        .catch(() => {})
    },
    extOf(fileName) {
      if (!fileName || fileName.lastIndexOf(".") < 0) {
        return ""
      }
      return fileName.slice(fileName.lastIndexOf(".") + 1).toLowerCase()
    },
    beforeContentUpload(file) {
      const ext = this.extOf(file.name)
      if (!this.contentFileExts.includes(ext)) {
        this.$modal.msgError(this.$t("breedingStd.common.errBodyFmt"))
        return false
      }
      if (file.name.includes(",")) {
        this.$modal.msgError(this.$t("breedingStd.common.errComma"))
        return false
      }
      const isLt = file.size / 1024 / 1024 < 30
      if (!isLt) {
        this.$modal.msgError(this.$t("breedingStd.common.errBodyMb"))
        return false
      }
      this.$modal.loading(this.$t("breedingStd.common.uploadingFile"))
      return true
    },
    handleUploadHttpError() {
      this.$modal.closeLoading()
      this.$modal.msgError(this.$t("breedingStd.common.errUploadRetry"))
    },
    handleContentUploadSuccess(res, file) {
      this.$modal.closeLoading()
      if (res.code === 200) {
        this.form.contentFileUrl = res.url
        this.form.contentFilePath = res.fileName
        this.form.contentFileName = res.originalFilename || file.name
        this.$nextTick(() => {
          if (this.$refs.form) {
            this.$refs.form.validateField("contentFilePath")
          }
        })
      } else {
        this.$modal.msgError(res.msg || this.$t("breedingStd.common.errUploadFail"))
      }
    },
    clearContentFile() {
      this.form.contentFileUrl = undefined
      this.form.contentFilePath = undefined
      this.form.contentFileName = undefined
      this.$nextTick(() => {
        if (this.$refs.form) {
          this.$refs.form.validateField("contentFilePath")
        }
      })
    },
    beforeCoverUpload(file) {
      const ext = this.extOf(file.name)
      if (!this.coverFileExts.includes(ext)) {
        this.$modal.msgError(this.$t("breedingStd.common.errCoverFmt"))
        return false
      }
      if (file.name.includes(",")) {
        this.$modal.msgError(this.$t("breedingStd.common.errComma"))
        return false
      }
      const isLt = file.size / 1024 / 1024 < 10
      if (!isLt) {
        this.$modal.msgError(this.$t("breedingStd.common.errCoverMb"))
        return false
      }
      this.$modal.loading(this.$t("breedingStd.common.uploadingImg"))
      return true
    },
    handleCoverUploadSuccess(res) {
      this.$modal.closeLoading()
      if (res.code === 200) {
        this.form.coverFileUrl = res.url
        this.form.coverFilePath = res.fileName
      } else {
        this.$modal.msgError(res.msg || this.$t("breedingStd.common.errUploadFail"))
      }
    },
    handleCoverRemove() {
      this.form.coverFileUrl = undefined
      this.form.coverFilePath = undefined
    },
    submitForm() {
      this.$refs.form.validate((valid) => {
        if (!valid) {
          return
        }
        const payload = {
          standardName: this.form.standardName,
          standardType: this.form.standardType,
          introduction: this.form.introduction || undefined,
          contentFileUrl: this.form.contentFileUrl,
          contentFilePath: this.form.contentFilePath,
          contentFileName: this.form.contentFileName,
          coverFileUrl: this.form.coverFileUrl,
          coverFilePath: this.form.coverFilePath
        }
        if (this.dialogEdit) {
          payload.id = this.form.id
          updateEpidemicTreatmentStandard(payload).then(() => {
            this.$modal.msgSuccess(this.$t("breedingStd.common.msgModOk"))
            this.open = false
            this.getList()
          })
        } else {
          addEpidemicTreatmentStandard(payload).then(() => {
            this.$modal.msgSuccess(this.$t("breedingStd.common.msgAddOk"))
            this.open = false
            this.getList()
          })
        }
      })
    },
    cancel() {
      this.open = false
      this.resetFormModel()
    }
  }
}
</script>

<style scoped>
.upload-file-uploader {
  margin-bottom: 8px;
}
.upload-file-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
}
.upload-file-list .el-upload-list__item {
  border: 1px solid #e4e7ed;
  line-height: 2;
  padding: 0 8px;
}
.ele-upload-list__item-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.hide ::v-deep .el-upload--picture-card {
  display: none;
}
</style>
