| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845 |
- <template>
- <div class="app-container">
- <el-card shadow="never">
- <el-form ref="queryForm" :model="queryParams" size="small" :inline="true">
- <el-form-item prop="statYear">
- <template slot="label">{{ dmT("queryStatYear") }}</template>
- <el-select v-model="queryParams.statYear" :placeholder="dmCommon('pleaseSelect')" clearable style="width: 120px">
- <el-option v-for="y in yearOptions" :key="y" :label="String(y)" :value="y" />
- </el-select>
- </el-form-item>
- <el-form-item prop="statMonth">
- <template slot="label">{{ dmT("queryStatMonth") }}</template>
- <el-select v-model="queryParams.statMonth" :placeholder="dmCommon('pleaseSelect')" clearable style="width: 120px">
- <el-option v-for="m in monthOptions" :key="'q-' + m" :label="formatStatMonth(m)" :value="m" />
- </el-select>
- </el-form-item>
- <el-form-item prop="townDeptId">
- <template slot="label">{{ dmT("queryTown") }}</template>
- <el-select v-model="queryParams.townDeptId" :placeholder="dmCommon('pleaseSelect')" clearable filterable style="width: 180px">
- <el-option v-for="item in townOptions" :key="item.deptId" :label="item.deptName" :value="item.deptId" />
- </el-select>
- </el-form-item>
- <el-form-item prop="villageDeptId">
- <template slot="label">{{ dmT("queryVillage") }}</template>
- <el-select
- v-model="queryParams.villageDeptId"
- :placeholder="dmT('phVillageSearch')"
- clearable
- filterable
- style="width: 220px"
- >
- <el-option
- v-for="item in villageOptions"
- :key="'q-v-' + item.deptId"
- :label="item.label"
- :value="item.deptId"
- />
- </el-select>
- </el-form-item>
- <el-form-item>
- <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ dmCommon("search") }}</el-button>
- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ dmCommon("reset") }}</el-button>
- <el-button
- v-hasPermi="['dataModel:livestockOwnershipHousehold:add']"
- type="primary"
- plain
- icon="el-icon-plus"
- size="mini"
- @click="handleAdd"
- >{{ dmCommon("add") }}</el-button>
- <el-button
- v-hasPermi="['dataModel:livestockOwnershipHousehold:import']"
- type="info"
- plain
- icon="el-icon-upload2"
- size="mini"
- @click="handleImportOpen"
- >{{ dmT("btnImport") }}</el-button>
- <el-button
- v-hasPermi="['dataModel:livestockOwnershipHousehold:export']"
- type="warning"
- plain
- icon="el-icon-download"
- size="mini"
- @click="handleExportOpen"
- >{{ dmCommon("export") }}</el-button>
- </el-form-item>
- </el-form>
- </el-card>
- <br />
- <el-card shadow="never">
- <el-table v-loading="loading" :data="tableList" border>
- <template slot="empty">
- <span>{{ dmT("emptyList") }}</span>
- </template>
- <el-table-column :label="dmT('colStatYear')" prop="statYear" align="center" width="90" fixed />
- <el-table-column :label="dmT('colStatMonth')" align="center" width="80" fixed>
- <template slot-scope="scope">{{ formatStatMonth(scope.row.statMonth) }}</template>
- </el-table-column>
- <el-table-column :label="dmT('colTownName')" prop="townName" align="center" min-width="100" :show-overflow-tooltip="true" />
- <el-table-column :label="dmT('colVillageName')" prop="villageName" align="center" min-width="100" :show-overflow-tooltip="true" />
- <el-table-column :label="dmT('colWithHousehold')" align="center" width="100">
- <template slot-scope="scope">{{ formatCount(scope.row.withLivestockHouseholdCount) }}</template>
- </el-table-column>
- <el-table-column :label="dmT('colWithPopulation')" align="center" width="100">
- <template slot-scope="scope">{{ formatCount(scope.row.withLivestockPopulationCount) }}</template>
- </el-table-column>
- <el-table-column :label="dmT('colWithLabor')" align="center" width="100">
- <template slot-scope="scope">{{ formatCount(scope.row.withLivestockLaborCount) }}</template>
- </el-table-column>
- <el-table-column :label="dmT('colWithAnimal')" align="center" width="110">
- <template slot-scope="scope">{{ formatCount(scope.row.withLivestockAnimalCount) }}</template>
- </el-table-column>
- <el-table-column :label="dmT('colWithoutHousehold')" align="center" width="100">
- <template slot-scope="scope">{{ formatCount(scope.row.withoutLivestockHouseholdCount) }}</template>
- </el-table-column>
- <el-table-column :label="dmT('colWithoutPopulation')" align="center" width="100">
- <template slot-scope="scope">{{ formatCount(scope.row.withoutLivestockPopulationCount) }}</template>
- </el-table-column>
- <el-table-column :label="dmT('colWithoutLabor')" align="center" width="100">
- <template slot-scope="scope">{{ formatCount(scope.row.withoutLivestockLaborCount) }}</template>
- </el-table-column>
- <el-table-column :label="dmCommon('colOp')" align="center" class-name="small-padding fixed-width" width="180" fixed="right">
- <template slot-scope="scope">
- <el-button v-hasPermi="['dataModel:livestockOwnershipHousehold:query']" type="text" size="mini" @click="handleView(scope.row)">{{ dmCommon("view") }}</el-button>
- <el-button v-hasPermi="['dataModel:livestockOwnershipHousehold:edit']" type="text" size="mini" @click="handleEdit(scope.row)">{{ dmCommon("edit") }}</el-button>
- <el-button v-hasPermi="['dataModel:livestockOwnershipHousehold:remove']" type="text" size="mini" @click="handleDelete(scope.row)">{{ dmCommon("delete") }}</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="680px" append-to-body @close="cancel">
- <el-form :key="formKey" ref="form" :model="form" class="loh-form" label-width="120px" size="small">
- <div class="loh-section-title">{{ dmT("sectionBasic") }}</div>
- <el-form-item prop="statYear" :rules="formRules.statYear">
- <template slot="label">{{ dmT("formStatYear") }}</template>
- <el-select v-model="form.statYear" :placeholder="dmCommon('pleaseSelect')" style="width: 100%">
- <el-option v-for="y in yearOptions" :key="'f-' + y" :label="String(y)" :value="y" />
- </el-select>
- </el-form-item>
- <el-form-item prop="statMonth" :rules="formRules.statMonth">
- <template slot="label">{{ dmT("formStatMonth") }}</template>
- <el-select v-model="form.statMonth" :placeholder="dmCommon('pleaseSelect')" style="width: 100%">
- <el-option v-for="m in monthOptions" :key="'fm-' + m" :label="formatStatMonth(m)" :value="m" />
- </el-select>
- </el-form-item>
- <el-form-item prop="villageDeptId" :rules="formRules.villageDeptId">
- <template slot="label">{{ dmT("formVillage") }}</template>
- <el-select
- v-model="form.villageDeptId"
- :placeholder="dmT('phVillageSearch')"
- filterable
- clearable
- style="width: 100%"
- >
- <el-option
- v-for="item in villageOptions"
- :key="'f-v-' + item.deptId"
- :label="item.label"
- :value="item.deptId"
- />
- </el-select>
- </el-form-item>
- <div class="loh-section-title">{{ dmT("sectionWith") }}</div>
- <el-form-item prop="withLivestockHouseholdCount" :rules="formRules.count">
- <template slot="label">{{ dmT("formHouseholdCount") }}</template>
- <div class="dm-input-with-unit">
- <el-input-number v-model="form.withLivestockHouseholdCount" :min="0" :precision="0" controls-position="right" class="dm-input-with-unit__input" />
- <span class="dm-input-with-unit__suffix">{{ dmT("unitHousehold") }}</span>
- </div>
- </el-form-item>
- <el-form-item prop="withLivestockPopulationCount" :rules="formRules.count">
- <template slot="label">{{ dmT("formPopulationCount") }}</template>
- <div class="dm-input-with-unit">
- <el-input-number v-model="form.withLivestockPopulationCount" :min="0" :precision="0" controls-position="right" class="dm-input-with-unit__input" />
- <span class="dm-input-with-unit__suffix">{{ dmT("unitPerson") }}</span>
- </div>
- </el-form-item>
- <el-form-item prop="withLivestockLaborCount" :rules="formRules.count">
- <template slot="label">{{ dmT("formLaborCount") }}</template>
- <div class="dm-input-with-unit">
- <el-input-number v-model="form.withLivestockLaborCount" :min="0" :precision="0" controls-position="right" class="dm-input-with-unit__input" />
- <span class="dm-input-with-unit__suffix">{{ dmT("unitPerson") }}</span>
- </div>
- </el-form-item>
- <el-form-item prop="withLivestockAnimalCount" :rules="formRules.count">
- <template slot="label">{{ dmT("formAnimalCount") }}</template>
- <div class="dm-input-with-unit">
- <el-input-number v-model="form.withLivestockAnimalCount" :min="0" :precision="0" controls-position="right" class="dm-input-with-unit__input" />
- <span class="dm-input-with-unit__suffix">{{ dmT("unitHeadPiece") }}</span>
- </div>
- </el-form-item>
- <div class="loh-section-title">{{ dmT("sectionWithout") }}</div>
- <el-form-item prop="withoutLivestockHouseholdCount" :rules="formRules.count">
- <template slot="label">{{ dmT("formHouseholdCount") }}</template>
- <div class="dm-input-with-unit">
- <el-input-number v-model="form.withoutLivestockHouseholdCount" :min="0" :precision="0" controls-position="right" class="dm-input-with-unit__input" />
- <span class="dm-input-with-unit__suffix">{{ dmT("unitHousehold") }}</span>
- </div>
- </el-form-item>
- <el-form-item prop="withoutLivestockPopulationCount" :rules="formRules.count">
- <template slot="label">{{ dmT("formPopulationCount") }}</template>
- <div class="dm-input-with-unit">
- <el-input-number v-model="form.withoutLivestockPopulationCount" :min="0" :precision="0" controls-position="right" class="dm-input-with-unit__input" />
- <span class="dm-input-with-unit__suffix">{{ dmT("unitPerson") }}</span>
- </div>
- </el-form-item>
- <el-form-item prop="withoutLivestockLaborCount" :rules="formRules.count">
- <template slot="label">{{ dmT("formLaborCount") }}</template>
- <div class="dm-input-with-unit">
- <el-input-number v-model="form.withoutLivestockLaborCount" :min="0" :precision="0" controls-position="right" class="dm-input-with-unit__input" />
- <span class="dm-input-with-unit__suffix">{{ dmT("unitPerson") }}</span>
- </div>
- </el-form-item>
- <el-form-item prop="remark" :rules="formRules.remark">
- <template slot="label">{{ dmT("formRemark") }}</template>
- <el-input v-model="form.remark" type="textarea" :rows="2" :placeholder="dmT('phRemark')" maxlength="500" show-word-limit />
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button type="primary" @click="submitForm">{{ dmCommon("ok") }}</el-button>
- <el-button @click="cancel">{{ dmCommon("cancel") }}</el-button>
- </div>
- </el-dialog>
- <el-dialog :title="dmCommon('viewTitle')" :visible.sync="viewOpen" width="680px" append-to-body>
- <el-form class="dm-view-form loh-form" label-width="120px" size="small">
- <div class="loh-section-title">{{ dmT("sectionBasic") }}</div>
- <el-form-item :label="dmT('formStatYear')"><span>{{ viewRow.statYear || dash }}</span></el-form-item>
- <el-form-item :label="dmT('formStatMonth')"><span>{{ formatStatMonth(viewRow.statMonth) }}</span></el-form-item>
- <el-form-item :label="dmT('formTown')"><span>{{ viewRow.townName || dash }}</span></el-form-item>
- <el-form-item :label="dmT('formVillage')"><span>{{ viewRow.villageName || dash }}</span></el-form-item>
- <div class="loh-section-title">{{ dmT("sectionWith") }}</div>
- <el-form-item :label="dmT('formHouseholdCount')">
- <span>{{ formatWithUnit(formatCount(viewRow.withLivestockHouseholdCount), "unitHousehold") }}</span>
- </el-form-item>
- <el-form-item :label="dmT('formPopulationCount')">
- <span>{{ formatWithUnit(formatCount(viewRow.withLivestockPopulationCount), "unitPerson") }}</span>
- </el-form-item>
- <el-form-item :label="dmT('formLaborCount')">
- <span>{{ formatWithUnit(formatCount(viewRow.withLivestockLaborCount), "unitPerson") }}</span>
- </el-form-item>
- <el-form-item :label="dmT('formAnimalCount')">
- <span>{{ formatWithUnit(formatCount(viewRow.withLivestockAnimalCount), "unitHeadPiece") }}</span>
- </el-form-item>
- <div class="loh-section-title">{{ dmT("sectionWithout") }}</div>
- <el-form-item :label="dmT('formHouseholdCount')">
- <span>{{ formatWithUnit(formatCount(viewRow.withoutLivestockHouseholdCount), "unitHousehold") }}</span>
- </el-form-item>
- <el-form-item :label="dmT('formPopulationCount')">
- <span>{{ formatWithUnit(formatCount(viewRow.withoutLivestockPopulationCount), "unitPerson") }}</span>
- </el-form-item>
- <el-form-item :label="dmT('formLaborCount')">
- <span>{{ formatWithUnit(formatCount(viewRow.withoutLivestockLaborCount), "unitPerson") }}</span>
- </el-form-item>
- <el-form-item :label="dmT('formRemark')">
- <span class="loh-view-text">{{ viewRow.remark || dash }}</span>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button v-hasPermi="['dataModel:livestockOwnershipHousehold:edit']" type="primary" @click="handleEditFromView">{{ dmCommon("edit") }}</el-button>
- <el-button @click="viewOpen = false">{{ dmCommon("close") }}</el-button>
- </div>
- </el-dialog>
- <el-dialog :title="dmT('importTitle')" :visible.sync="importOpen" width="480px" append-to-body @close="resetImport">
- <el-form ref="importFormRef" :model="importForm" label-width="100px" size="small">
- <el-form-item prop="statYear" :rules="importRules.statYear">
- <template slot="label">{{ dmT("importStatYear") }}</template>
- <el-select v-model="importForm.statYear" :placeholder="dmT('importStatYearPh')" style="width: 100%">
- <el-option v-for="y in yearOptions" :key="'iy-' + y" :label="String(y)" :value="y" />
- </el-select>
- </el-form-item>
- <el-form-item prop="statMonth" :rules="importRules.statMonth">
- <template slot="label">{{ dmT("importStatMonth") }}</template>
- <el-select v-model="importForm.statMonth" :placeholder="dmT('importStatMonthPh')" style="width: 100%">
- <el-option v-for="m in monthOptions" :key="'im-' + m" :label="formatStatMonth(m)" :value="m" />
- </el-select>
- </el-form-item>
- <p class="loh-import-tip">{{ dmT("importTip") }}</p>
- <el-upload ref="importUpload" drag :limit="1" accept=".xlsx,.xls" :auto-upload="false" action="#">
- <i class="el-icon-upload" />
- <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
- <div slot="tip" class="el-upload__tip">
- <el-link type="primary" :underline="false" @click="handleDownloadTemplate">{{ dmT("btnDownloadTemplate") }}</el-link>
- </div>
- </el-upload>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button type="primary" :loading="importing" @click="handleImportSubmit">{{ dmCommon("ok") }}</el-button>
- <el-button @click="importOpen = false">{{ dmCommon("cancel") }}</el-button>
- </div>
- </el-dialog>
- <el-dialog :title="dmT('exportTitle')" :visible.sync="exportOpen" width="480px" append-to-body @close="resetExport">
- <el-form ref="exportFormRef" :model="exportForm" label-width="100px" size="small">
- <el-form-item prop="statYear" :rules="exportRules.statYear">
- <template slot="label">{{ dmT("exportStatYear") }}</template>
- <el-select v-model="exportForm.statYear" :placeholder="dmT('exportStatYearPh')" style="width: 100%">
- <el-option v-for="y in yearOptions" :key="'ey-' + y" :label="String(y)" :value="y" />
- </el-select>
- </el-form-item>
- <el-form-item prop="statMonth" :rules="exportRules.statMonth">
- <template slot="label">{{ dmT("exportStatMonth") }}</template>
- <el-select v-model="exportForm.statMonth" :placeholder="dmT('exportStatMonthPh')" style="width: 100%">
- <el-option v-for="m in monthOptions" :key="'em-' + m" :label="formatStatMonth(m)" :value="m" />
- </el-select>
- </el-form-item>
- <el-form-item>
- <template slot="label">{{ dmT("exportTown") }}</template>
- <el-select
- v-model="exportForm.townDeptId"
- :placeholder="dmT('exportTownPh')"
- clearable
- filterable
- style="width: 100%"
- >
- <el-option v-for="item in townOptions" :key="'et-' + item.deptId" :label="item.deptName" :value="item.deptId" />
- </el-select>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button type="primary" :loading="exporting" @click="handleExportSubmit">{{ dmCommon("ok") }}</el-button>
- <el-button @click="exportOpen = false">{{ dmCommon("cancel") }}</el-button>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import dataModelLocaleMixin from "@/mixins/dataModelLocaleMixin"
- import {
- listLivestockOwnershipHousehold,
- getLivestockOwnershipHousehold,
- addLivestockOwnershipHousehold,
- updateLivestockOwnershipHousehold,
- delLivestockOwnershipHousehold,
- listLivestockOwnershipHouseholdYearOptions,
- listLivestockOwnershipHouseholdMonthOptions,
- listLivestockOwnershipHouseholdTownOptions,
- listLivestockOwnershipHouseholdVillageTree,
- importLivestockOwnershipHousehold,
- downloadLivestockOwnershipHouseholdTemplate,
- exportLivestockOwnershipHousehold
- } from "@/api/dataModel/livestockOwnershipHousehold"
- import { blobValidate } from "@/utils/ruoyi"
- import { saveAs } from "file-saver"
- const COUNT_PROPS = [
- "withLivestockHouseholdCount",
- "withLivestockPopulationCount",
- "withLivestockLaborCount",
- "withLivestockAnimalCount",
- "withoutLivestockHouseholdCount",
- "withoutLivestockPopulationCount",
- "withoutLivestockLaborCount"
- ]
- function getCurrentYearMonth() {
- const now = new Date()
- return { statYear: now.getFullYear(), statMonth: now.getMonth() + 1 }
- }
- function createEmptyForm() {
- const form = {
- id: undefined,
- statYear: undefined,
- statMonth: undefined,
- villageDeptId: undefined,
- remark: undefined
- }
- COUNT_PROPS.forEach((prop) => {
- form[prop] = undefined
- })
- return form
- }
- function normalizeForm(data) {
- const row = Object.assign(createEmptyForm(), data || {})
- COUNT_PROPS.forEach((prop) => {
- const val = row[prop]
- row[prop] = val == null || val === "" ? undefined : Number(val)
- })
- return row
- }
- function flattenVillageOptions(tree) {
- const list = []
- ;(tree || []).forEach((county) => {
- ;(county.children || []).forEach((town) => {
- ;(town.children || []).forEach((village) => {
- if (village == null || village.id == null) {
- return
- }
- const townName = town.label || ""
- const villageName = village.label || ""
- list.push({
- deptId: village.id,
- label: townName ? `${townName} / ${villageName}` : villageName
- })
- })
- })
- })
- return list
- }
- export default {
- name: "LivestockOwnershipHousehold",
- mixins: [dataModelLocaleMixin],
- data() {
- return {
- dmNs: "livestockOwnershipHousehold",
- loading: false,
- importing: false,
- exporting: false,
- open: false,
- viewOpen: false,
- importOpen: false,
- exportOpen: false,
- dialogEdit: false,
- formKey: 0,
- total: 0,
- tableList: [],
- yearOptions: [],
- monthOptions: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
- townOptions: [],
- villageOptions: [],
- viewRow: {},
- importForm: { statYear: undefined, statMonth: undefined },
- exportForm: { statYear: undefined, statMonth: undefined, townDeptId: undefined },
- queryParams: {
- pageNum: 1,
- pageSize: 20,
- statYear: undefined,
- statMonth: undefined,
- townDeptId: undefined,
- villageDeptId: undefined
- },
- form: createEmptyForm()
- }
- },
- computed: {
- dash() {
- return this.$t("dataModel.status.dash")
- },
- dialogTitle() {
- return this.dialogEdit ? this.dmT("dialogEdit") : this.dmT("dialogAdd")
- },
- formRules() {
- return {
- statYear: [{ required: true, message: this.dmT("ruleStatYearRequired"), trigger: "change" }],
- statMonth: [
- { required: true, message: this.dmT("ruleStatMonthRequired"), trigger: "change" },
- { validator: this.validateFormStatMonth, trigger: "change" }
- ],
- villageDeptId: [{ required: true, message: this.dmT("ruleVillageRequired"), trigger: "change" }],
- count: [{ validator: this.validateOptionalCount, trigger: "change" }],
- remark: [{ max: 500, message: this.dmCommon("ruleLen500"), trigger: "blur" }]
- }
- },
- importRules() {
- return {
- statYear: [{ required: true, message: this.dmT("ruleStatYearRequired"), trigger: "change" }],
- statMonth: [
- { required: true, message: this.dmT("ruleStatMonthRequired"), trigger: "change" },
- { validator: this.validateImportStatMonth, trigger: "change" }
- ]
- }
- },
- exportRules() {
- return {
- statYear: [{ required: true, message: this.dmT("exportStatYearRequired"), trigger: "change" }],
- statMonth: [
- { required: true, message: this.dmT("exportStatMonthRequired"), trigger: "change" },
- { validator: this.validateExportStatMonth, trigger: "change" }
- ]
- }
- }
- },
- created() {
- this.loadOptions()
- this.getList()
- },
- methods: {
- loadOptions() {
- listLivestockOwnershipHouseholdYearOptions().then((res) => {
- this.yearOptions = Array.isArray(res.data) ? res.data : []
- })
- listLivestockOwnershipHouseholdMonthOptions().then((res) => {
- if (Array.isArray(res.data) && res.data.length) {
- this.monthOptions = res.data
- }
- })
- listLivestockOwnershipHouseholdTownOptions().then((res) => {
- this.townOptions = Array.isArray(res.data) ? res.data : []
- })
- this.loadVillageTree()
- },
- loadVillageTree() {
- return listLivestockOwnershipHouseholdVillageTree()
- .then((res) => {
- const raw = res && res.data !== undefined ? res.data : res
- this.villageOptions = flattenVillageOptions(Array.isArray(raw) ? raw : [])
- if (!this.villageOptions.length) {
- this.$modal.msgWarning(this.dmT("villageTreeEmpty"))
- }
- })
- .catch(() => {
- this.villageOptions = []
- })
- },
- formatStatMonth(month) {
- if (month == null || month === "") {
- return this.dash
- }
- return this.dmT("statMonthLabel", { month })
- },
- formatCount(val) {
- return val == null || val === "" ? this.dash : val
- },
- isFutureStatPeriod(statYear, statMonth) {
- if (statYear == null || statMonth == null) {
- return false
- }
- const now = new Date()
- const y = now.getFullYear()
- const m = now.getMonth() + 1
- return statYear > y || (statYear === y && statMonth > m)
- },
- validateFormStatMonth(rule, value, callback) {
- if (this.isFutureStatPeriod(this.form.statYear, value)) {
- callback(new Error(this.dmT("ruleStatMonthFuture")))
- return
- }
- callback()
- },
- validateImportStatMonth(rule, value, callback) {
- if (this.isFutureStatPeriod(this.importForm.statYear, value)) {
- callback(new Error(this.dmT("ruleStatMonthFuture")))
- return
- }
- callback()
- },
- validateExportStatMonth(rule, value, callback) {
- if (this.isFutureStatPeriod(this.exportForm.statYear, value)) {
- callback(new Error(this.dmT("ruleStatMonthFuture")))
- return
- }
- callback()
- },
- validateOptionalCount(rule, value, callback) {
- if (value == null || value === "") {
- callback()
- return
- }
- if (typeof value !== "number" || Number.isNaN(value) || value < 0 || !Number.isInteger(value)) {
- callback(new Error(this.dmT("ruleCountNonNegative")))
- return
- }
- callback()
- },
- buildListQuery() {
- const q = {
- pageNum: this.queryParams.pageNum,
- pageSize: this.queryParams.pageSize
- }
- if (this.queryParams.statYear != null) {
- q.statYear = this.queryParams.statYear
- }
- if (this.queryParams.statMonth != null) {
- q.statMonth = this.queryParams.statMonth
- }
- if (this.queryParams.townDeptId != null) {
- q.townDeptId = this.queryParams.townDeptId
- }
- if (this.queryParams.villageDeptId != null) {
- q.villageDeptId = this.queryParams.villageDeptId
- }
- return q
- },
- getList() {
- this.loading = true
- listLivestockOwnershipHousehold(this.buildListQuery())
- .then((res) => {
- this.tableList = res.rows || []
- this.total = res.total || 0
- })
- .finally(() => {
- this.loading = false
- })
- },
- handleQuery() {
- this.queryParams.pageNum = 1
- this.getList()
- },
- resetQuery() {
- this.queryParams = {
- pageNum: 1,
- pageSize: 20,
- statYear: undefined,
- statMonth: undefined,
- townDeptId: undefined,
- villageDeptId: undefined
- }
- this.getList()
- },
- handleAdd() {
- this.dialogEdit = false
- this.formKey += 1
- this.form = createEmptyForm()
- const ym = getCurrentYearMonth()
- this.form.statYear = ym.statYear
- this.form.statMonth = ym.statMonth
- this.open = true
- this.$nextTick(() => {
- if (this.$refs.form) {
- this.$refs.form.clearValidate()
- }
- })
- },
- handleEdit(row) {
- getLivestockOwnershipHousehold(row.id).then((res) => {
- this.dialogEdit = true
- this.formKey += 1
- this.form = normalizeForm(res.data)
- this.open = true
- this.viewOpen = false
- this.$nextTick(() => {
- if (this.$refs.form) {
- this.$refs.form.clearValidate()
- }
- })
- })
- },
- handleView(row) {
- getLivestockOwnershipHousehold(row.id).then((res) => {
- this.viewRow = res.data || {}
- this.viewOpen = true
- })
- },
- handleEditFromView() {
- if (!this.viewRow || this.viewRow.id == null) {
- return
- }
- this.handleEdit(this.viewRow)
- },
- handleDelete(row) {
- this.$modal
- .confirm(this.dmT("confirmDelete"))
- .then(() => delLivestockOwnershipHousehold(row.id))
- .then(() => {
- this.$modal.msgSuccess(this.dmCommon("msgDelOk"))
- this.getList()
- })
- .catch(() => {})
- },
- normalizeCount(val) {
- return val == null || val === "" ? null : val
- },
- buildSubmitPayload() {
- const payload = {
- id: this.form.id,
- statYear: this.form.statYear,
- statMonth: this.form.statMonth,
- villageDeptId: this.form.villageDeptId,
- remark: this.form.remark
- }
- COUNT_PROPS.forEach((prop) => {
- payload[prop] = this.normalizeCount(this.form[prop])
- })
- return payload
- },
- submitForm() {
- this.$refs.form.validate((valid) => {
- if (!valid) {
- return
- }
- const payload = this.buildSubmitPayload()
- if (this.dialogEdit) {
- updateLivestockOwnershipHousehold(payload).then(() => {
- this.$modal.msgSuccess(this.dmCommon("msgModOk"))
- this.open = false
- this.getList()
- })
- } else {
- addLivestockOwnershipHousehold(payload).then(() => {
- this.$modal.msgSuccess(this.dmCommon("msgAddOk"))
- this.open = false
- this.getList()
- })
- }
- })
- },
- cancel() {
- this.open = false
- this.form = createEmptyForm()
- },
- handleImportOpen() {
- const ym = getCurrentYearMonth()
- this.importForm = {
- statYear: this.queryParams.statYear != null ? this.queryParams.statYear : ym.statYear,
- statMonth: this.queryParams.statMonth != null ? this.queryParams.statMonth : ym.statMonth
- }
- this.importOpen = true
- this.$nextTick(() => {
- if (this.$refs.importFormRef) {
- this.$refs.importFormRef.clearValidate()
- }
- if (this.$refs.importUpload) {
- this.$refs.importUpload.clearFiles()
- }
- })
- },
- resetImport() {
- this.importForm = { statYear: undefined, statMonth: undefined }
- if (this.$refs.importUpload) {
- this.$refs.importUpload.clearFiles()
- }
- },
- handleDownloadTemplate() {
- downloadLivestockOwnershipHouseholdTemplate().then(async (data) => {
- const isBlob = blobValidate(data)
- if (isBlob) {
- saveAs(data, `livestock_ownership_household_import_template_${new Date().getTime()}.xlsx`)
- } else {
- this.$modal.msgError(this.dmT("exportFail"))
- }
- })
- },
- handleImportSubmit() {
- this.$refs.importFormRef.validate((valid) => {
- if (!valid) {
- return
- }
- const files = this.$refs.importUpload ? this.$refs.importUpload.uploadFiles : []
- if (!files || !files.length) {
- this.$modal.msgError(this.dmCommon("pleaseSelect"))
- return
- }
- const raw = files[0].raw
- this.importing = true
- this.$modal.loading(this.dmT("importLoading"))
- importLivestockOwnershipHousehold(raw, this.importForm.statYear, this.importForm.statMonth)
- .then((res) => {
- const data = res.data || {}
- const msg = this.dmT("importSummary", {
- insert: data.insertCount != null ? data.insertCount : 0,
- update: data.updateCount != null ? data.updateCount : 0,
- fail: data.failCount != null ? data.failCount : 0
- })
- this.$modal.msgSuccess(msg)
- if (data.warnMessages && data.warnMessages.length) {
- this.$alert(data.warnMessages.join("<br/>"), this.dmT("importWarnTitle"), { dangerouslyUseHTMLString: true })
- }
- if (data.failMessages && data.failMessages.length) {
- this.$alert(data.failMessages.join("<br/>"), this.dmT("importFailTitle"), { dangerouslyUseHTMLString: true })
- }
- this.importOpen = false
- this.getList()
- })
- .finally(() => {
- this.importing = false
- this.$modal.closeLoading()
- })
- })
- },
- handleExportOpen() {
- const ym = getCurrentYearMonth()
- this.exportForm = {
- statYear: this.queryParams.statYear != null ? this.queryParams.statYear : ym.statYear,
- statMonth: this.queryParams.statMonth != null ? this.queryParams.statMonth : ym.statMonth,
- townDeptId: this.queryParams.townDeptId
- }
- this.exportOpen = true
- this.$nextTick(() => {
- if (this.$refs.exportFormRef) {
- this.$refs.exportFormRef.clearValidate()
- }
- })
- },
- resetExport() {
- this.exportForm = { statYear: undefined, statMonth: undefined, townDeptId: undefined }
- },
- handleExportSubmit() {
- this.$refs.exportFormRef.validate((valid) => {
- if (!valid) {
- return
- }
- this.exporting = true
- const filename = `${this.exportForm.statYear}年${this.exportForm.statMonth}月有无畜户数据.xlsx`
- this.$modal.loading(this.dmT("exportLoading"))
- exportLivestockOwnershipHousehold(this.exportForm.statYear, this.exportForm.statMonth, this.exportForm.townDeptId)
- .then(async (data) => {
- const isBlob = blobValidate(data)
- if (isBlob) {
- saveAs(
- data,
- filename
- )
- this.exportOpen = false
- } else {
- this.$modal.msgError(this.dmT("exportFail"))
- }
- })
- .finally(() => {
- this.exporting = false
- this.$modal.closeLoading()
- })
- })
- }
- }
- }
- </script>
- <style scoped>
- .loh-section-title {
- margin: 4px 0 12px;
- font-weight: 600;
- color: #303133;
- }
- .loh-import-tip {
- margin: 0 0 12px;
- color: #909399;
- font-size: 12px;
- line-height: 1.5;
- }
- .loh-view-text {
- white-space: pre-wrap;
- word-break: break-all;
- }
- .dm-input-with-unit {
- display: flex;
- align-items: center;
- width: 100%;
- }
- .dm-input-with-unit__input {
- flex: 1;
- width: 100%;
- }
- .dm-input-with-unit__suffix {
- margin-left: 8px;
- color: #909399;
- white-space: nowrap;
- }
- .dm-input-with-unit >>> .el-input-number {
- width: 100%;
- }
- </style>
|