西藏巴青项目

index.vue 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. <template>
  2. <div class="app-container">
  3. <el-card shadow="never">
  4. <el-form ref="queryForm" :model="queryParams" size="small" :inline="true">
  5. <el-form-item prop="statYear">
  6. <template slot="label">{{ dmT("queryStatYear") }}</template>
  7. <el-select v-model="queryParams.statYear" :placeholder="dmCommon('pleaseSelect')" clearable style="width: 120px">
  8. <el-option v-for="y in yearOptions" :key="y" :label="String(y)" :value="y" />
  9. </el-select>
  10. </el-form-item>
  11. <el-form-item prop="statMonth">
  12. <template slot="label">{{ dmT("queryStatMonth") }}</template>
  13. <el-select v-model="queryParams.statMonth" :placeholder="dmCommon('pleaseSelect')" clearable style="width: 120px">
  14. <el-option v-for="m in monthOptions" :key="'q-' + m" :label="formatStatMonth(m)" :value="m" />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item prop="townDeptId">
  18. <template slot="label">{{ dmT("queryTown") }}</template>
  19. <el-select v-model="queryParams.townDeptId" :placeholder="dmCommon('pleaseSelect')" clearable filterable style="width: 180px">
  20. <el-option v-for="item in townOptions" :key="item.deptId" :label="item.deptName" :value="item.deptId" />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item prop="villageDeptId">
  24. <template slot="label">{{ dmT("queryVillage") }}</template>
  25. <el-select
  26. v-model="queryParams.villageDeptId"
  27. :placeholder="dmT('phVillageSearch')"
  28. clearable
  29. filterable
  30. style="width: 220px"
  31. >
  32. <el-option
  33. v-for="item in villageOptions"
  34. :key="'q-v-' + item.deptId"
  35. :label="item.label"
  36. :value="item.deptId"
  37. />
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item>
  41. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ dmCommon("search") }}</el-button>
  42. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ dmCommon("reset") }}</el-button>
  43. <el-button
  44. v-hasPermi="['dataModel:livestockProductOutput:add']"
  45. type="primary"
  46. plain
  47. icon="el-icon-plus"
  48. size="mini"
  49. @click="handleAdd"
  50. >{{ dmCommon("add") }}</el-button>
  51. <el-button
  52. v-hasPermi="['dataModel:livestockProductOutput:import']"
  53. type="info"
  54. plain
  55. icon="el-icon-upload2"
  56. size="mini"
  57. @click="handleImportOpen"
  58. >{{ dmT("btnImport") }}</el-button>
  59. <el-button
  60. v-hasPermi="['dataModel:livestockProductOutput:export']"
  61. type="warning"
  62. plain
  63. icon="el-icon-download"
  64. size="mini"
  65. @click="handleExportOpen"
  66. >{{ dmCommon("export") }}</el-button>
  67. </el-form-item>
  68. </el-form>
  69. </el-card>
  70. <br />
  71. <el-card shadow="never">
  72. <el-table v-loading="loading" :data="tableList" border>
  73. <template slot="empty">
  74. <span>{{ dmT("emptyList") }}</span>
  75. </template>
  76. <el-table-column :label="dmT('colStatYear')" prop="statYear" align="center" width="100" />
  77. <el-table-column :label="dmT('colStatMonth')" align="center" width="90">
  78. <template slot-scope="scope">{{ formatStatMonth(scope.row.statMonth) }}</template>
  79. </el-table-column>
  80. <el-table-column :label="dmT('colTownName')" prop="townName" align="center" min-width="110" :show-overflow-tooltip="true" />
  81. <el-table-column :label="dmT('colVillageName')" prop="villageName" align="center" min-width="110" :show-overflow-tooltip="true" />
  82. <el-table-column :label="dmT('colMeatOutput')" align="center" min-width="120">
  83. <template slot-scope="scope">{{ formatOutput(scope.row.meatOutput) }}</template>
  84. </el-table-column>
  85. <el-table-column :label="dmT('colMilkOutput')" align="center" min-width="120">
  86. <template slot-scope="scope">{{ formatOutput(scope.row.milkOutput) }}</template>
  87. </el-table-column>
  88. <el-table-column :label="dmCommon('colOp')" align="center" class-name="small-padding fixed-width" width="180" fixed="right">
  89. <template slot-scope="scope">
  90. <el-button v-hasPermi="['dataModel:livestockProductOutput:query']" type="text" size="mini" @click="handleView(scope.row)">{{ dmCommon("view") }}</el-button>
  91. <el-button v-hasPermi="['dataModel:livestockProductOutput:edit']" type="text" size="mini" @click="handleEdit(scope.row)">{{ dmCommon("edit") }}</el-button>
  92. <el-button v-hasPermi="['dataModel:livestockProductOutput:remove']" type="text" size="mini" @click="handleDelete(scope.row)">{{ dmCommon("delete") }}</el-button>
  93. </template>
  94. </el-table-column>
  95. </el-table>
  96. <pagination
  97. v-show="total > 0"
  98. :total="total"
  99. :page.sync="queryParams.pageNum"
  100. :limit.sync="queryParams.pageSize"
  101. @pagination="getList"
  102. />
  103. </el-card>
  104. <el-dialog :title="dialogTitle" :visible.sync="open" width="640px" append-to-body @close="cancel">
  105. <el-form :key="formKey" ref="form" :model="form" label-width="120px" size="small">
  106. <el-form-item prop="statYear" :rules="formRules.statYear">
  107. <template slot="label">{{ dmT("formStatYear") }}</template>
  108. <el-select v-model="form.statYear" :placeholder="dmCommon('pleaseSelect')" style="width: 100%">
  109. <el-option v-for="y in yearOptions" :key="'f-' + y" :label="String(y)" :value="y" />
  110. </el-select>
  111. </el-form-item>
  112. <el-form-item prop="statMonth" :rules="formRules.statMonth">
  113. <template slot="label">{{ dmT("formStatMonth") }}</template>
  114. <el-select v-model="form.statMonth" :placeholder="dmCommon('pleaseSelect')" style="width: 100%">
  115. <el-option v-for="m in monthOptions" :key="'fm-' + m" :label="formatStatMonth(m)" :value="m" />
  116. </el-select>
  117. </el-form-item>
  118. <el-form-item prop="villageDeptId" :rules="formRules.villageDeptId">
  119. <template slot="label">{{ dmT("formVillage") }}</template>
  120. <el-select
  121. v-model="form.villageDeptId"
  122. :placeholder="dmT('phVillageSearch')"
  123. filterable
  124. clearable
  125. style="width: 100%"
  126. >
  127. <el-option
  128. v-for="item in villageOptions"
  129. :key="'f-v-' + item.deptId"
  130. :label="item.label"
  131. :value="item.deptId"
  132. />
  133. </el-select>
  134. </el-form-item>
  135. <el-form-item prop="meatOutput" :rules="formRules.decimal">
  136. <template slot="label">{{ dmT("formMeatOutput") }}</template>
  137. <div class="dm-input-with-unit">
  138. <el-input-number
  139. v-model="form.meatOutput"
  140. :min="0"
  141. :precision="4"
  142. :controls="true"
  143. controls-position="right"
  144. class="dm-input-with-unit__input"
  145. />
  146. <span class="dm-input-with-unit__suffix">{{ dmT("unitWanTon") }}</span>
  147. </div>
  148. </el-form-item>
  149. <el-form-item prop="milkOutput" :rules="formRules.decimal">
  150. <template slot="label">{{ dmT("formMilkOutput") }}</template>
  151. <div class="dm-input-with-unit">
  152. <el-input-number
  153. v-model="form.milkOutput"
  154. :min="0"
  155. :precision="4"
  156. :controls="true"
  157. controls-position="right"
  158. class="dm-input-with-unit__input"
  159. />
  160. <span class="dm-input-with-unit__suffix">{{ dmT("unitWanTon") }}</span>
  161. </div>
  162. </el-form-item>
  163. <el-form-item prop="remark" :rules="formRules.remark">
  164. <template slot="label">{{ dmT("formRemark") }}</template>
  165. <el-input v-model="form.remark" type="textarea" :rows="2" :placeholder="dmT('phRemark')" maxlength="500" show-word-limit />
  166. </el-form-item>
  167. </el-form>
  168. <div slot="footer" class="dialog-footer">
  169. <el-button type="primary" @click="submitForm">{{ dmCommon("ok") }}</el-button>
  170. <el-button @click="cancel">{{ dmCommon("cancel") }}</el-button>
  171. </div>
  172. </el-dialog>
  173. <el-dialog :title="dmCommon('viewTitle')" :visible.sync="viewOpen" width="640px" append-to-body>
  174. <el-form label-width="120px" size="small">
  175. <el-form-item :label="dmT('formStatYear')">
  176. <span>{{ viewRow.statYear || dash }}</span>
  177. </el-form-item>
  178. <el-form-item :label="dmT('formStatMonth')">
  179. <span>{{ formatStatMonth(viewRow.statMonth) }}</span>
  180. </el-form-item>
  181. <el-form-item :label="dmT('formTown')">
  182. <span>{{ viewRow.townName || dash }}</span>
  183. </el-form-item>
  184. <el-form-item :label="dmT('formVillage')">
  185. <span>{{ viewRow.villageName || dash }}</span>
  186. </el-form-item>
  187. <el-form-item :label="dmT('formMeatOutput')">
  188. <span>{{ formatWithUnit(formatOutput(viewRow.meatOutput), "unitWanTon") }}</span>
  189. </el-form-item>
  190. <el-form-item :label="dmT('formMilkOutput')">
  191. <span>{{ formatWithUnit(formatOutput(viewRow.milkOutput), "unitWanTon") }}</span>
  192. </el-form-item>
  193. <el-form-item :label="dmT('formRemark')">
  194. <span class="lpo-view-text">{{ viewRow.remark || dash }}</span>
  195. </el-form-item>
  196. </el-form>
  197. <div slot="footer" class="dialog-footer">
  198. <el-button
  199. v-hasPermi="['dataModel:livestockProductOutput:edit']"
  200. type="primary"
  201. @click="handleEditFromView"
  202. >{{ dmCommon("edit") }}</el-button>
  203. <el-button @click="viewOpen = false">{{ dmCommon("close") }}</el-button>
  204. </div>
  205. </el-dialog>
  206. <el-dialog :title="dmT('importTitle')" :visible.sync="importOpen" width="480px" append-to-body @close="resetImport">
  207. <el-form ref="importFormRef" :model="importForm" label-width="100px" size="small">
  208. <el-form-item prop="statYear" :rules="importRules.statYear">
  209. <template slot="label">{{ dmT("importStatYear") }}</template>
  210. <el-select v-model="importForm.statYear" :placeholder="dmT('importStatYearPh')" style="width: 100%">
  211. <el-option v-for="y in yearOptions" :key="'iy-' + y" :label="String(y)" :value="y" />
  212. </el-select>
  213. </el-form-item>
  214. <el-form-item prop="statMonth" :rules="importRules.statMonth">
  215. <template slot="label">{{ dmT("importStatMonth") }}</template>
  216. <el-select v-model="importForm.statMonth" :placeholder="dmT('importStatMonthPh')" style="width: 100%">
  217. <el-option v-for="m in monthOptions" :key="'im-' + m" :label="formatStatMonth(m)" :value="m" />
  218. </el-select>
  219. </el-form-item>
  220. <p class="lpo-import-tip">{{ dmT("importTip") }}</p>
  221. <el-upload
  222. ref="importUpload"
  223. drag
  224. :limit="1"
  225. accept=".xlsx,.xls"
  226. :auto-upload="false"
  227. action="#"
  228. >
  229. <i class="el-icon-upload" />
  230. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  231. <div slot="tip" class="el-upload__tip">
  232. <el-link type="primary" :underline="false" @click="handleDownloadTemplate">{{ dmT("btnDownloadTemplate") }}</el-link>
  233. </div>
  234. </el-upload>
  235. </el-form>
  236. <div slot="footer" class="dialog-footer">
  237. <el-button type="primary" :loading="importing" @click="handleImportSubmit">{{ dmCommon("ok") }}</el-button>
  238. <el-button @click="importOpen = false">{{ dmCommon("cancel") }}</el-button>
  239. </div>
  240. </el-dialog>
  241. <el-dialog :title="dmT('exportTitle')" :visible.sync="exportOpen" width="480px" append-to-body @close="resetExport">
  242. <el-form ref="exportFormRef" :model="exportForm" label-width="100px" size="small">
  243. <el-form-item prop="statYear" :rules="exportRules.statYear">
  244. <template slot="label">{{ dmT("exportStatYear") }}</template>
  245. <el-select v-model="exportForm.statYear" :placeholder="dmT('exportStatYearPh')" style="width: 100%">
  246. <el-option v-for="y in yearOptions" :key="'ey-' + y" :label="String(y)" :value="y" />
  247. </el-select>
  248. </el-form-item>
  249. <el-form-item prop="statMonth" :rules="exportRules.statMonth">
  250. <template slot="label">{{ dmT("exportStatMonth") }}</template>
  251. <el-select v-model="exportForm.statMonth" :placeholder="dmT('exportStatMonthPh')" style="width: 100%">
  252. <el-option v-for="m in monthOptions" :key="'em-' + m" :label="formatStatMonth(m)" :value="m" />
  253. </el-select>
  254. </el-form-item>
  255. <el-form-item>
  256. <template slot="label">{{ dmT("exportTown") }}</template>
  257. <el-select
  258. v-model="exportForm.townDeptId"
  259. :placeholder="dmT('exportTownPh')"
  260. clearable
  261. filterable
  262. style="width: 100%"
  263. >
  264. <el-option v-for="item in townOptions" :key="'et-' + item.deptId" :label="item.deptName" :value="item.deptId" />
  265. </el-select>
  266. </el-form-item>
  267. </el-form>
  268. <div slot="footer" class="dialog-footer">
  269. <el-button type="primary" :loading="exporting" @click="handleExportSubmit">{{ dmCommon("ok") }}</el-button>
  270. <el-button @click="exportOpen = false">{{ dmCommon("cancel") }}</el-button>
  271. </div>
  272. </el-dialog>
  273. </div>
  274. </template>
  275. <script>
  276. import dataModelLocaleMixin from "@/mixins/dataModelLocaleMixin"
  277. import {
  278. listLivestockProductOutput,
  279. getLivestockProductOutput,
  280. addLivestockProductOutput,
  281. updateLivestockProductOutput,
  282. delLivestockProductOutput,
  283. listLivestockProductOutputYearOptions,
  284. listLivestockProductOutputMonthOptions,
  285. listLivestockProductOutputTownOptions,
  286. listLivestockProductOutputVillageTree,
  287. importLivestockProductOutput,
  288. downloadLivestockProductOutputTemplate,
  289. exportLivestockProductOutput
  290. } from "@/api/dataModel/livestockProductOutput"
  291. import { blobValidate } from "@/utils/ruoyi"
  292. import { saveAs } from "file-saver"
  293. function getCurrentYearMonth() {
  294. const now = new Date()
  295. return {
  296. statYear: now.getFullYear(),
  297. statMonth: now.getMonth() + 1
  298. }
  299. }
  300. function createEmptyForm() {
  301. return {
  302. id: undefined,
  303. statYear: undefined,
  304. statMonth: undefined,
  305. villageDeptId: undefined,
  306. meatOutput: undefined,
  307. milkOutput: undefined,
  308. remark: undefined
  309. }
  310. }
  311. function normalizeForm(data) {
  312. const row = Object.assign(createEmptyForm(), data || {})
  313. ;["meatOutput", "milkOutput"].forEach((prop) => {
  314. const val = row[prop]
  315. row[prop] = val == null || val === "" ? undefined : Number(val)
  316. })
  317. return row
  318. }
  319. function flattenVillageOptions(tree) {
  320. const list = []
  321. ;(tree || []).forEach((county) => {
  322. ;(county.children || []).forEach((town) => {
  323. ;(town.children || []).forEach((village) => {
  324. if (village == null || village.id == null) {
  325. return
  326. }
  327. const townName = town.label || ""
  328. const villageName = village.label || ""
  329. list.push({
  330. deptId: village.id,
  331. deptName: villageName,
  332. townName,
  333. label: townName ? `${townName} / ${villageName}` : villageName
  334. })
  335. })
  336. })
  337. })
  338. return list
  339. }
  340. export default {
  341. name: "LivestockProductOutput",
  342. mixins: [dataModelLocaleMixin],
  343. data() {
  344. return {
  345. dmNs: "livestockProductOutput",
  346. loading: false,
  347. importing: false,
  348. exporting: false,
  349. open: false,
  350. viewOpen: false,
  351. importOpen: false,
  352. exportOpen: false,
  353. dialogEdit: false,
  354. formKey: 0,
  355. total: 0,
  356. tableList: [],
  357. yearOptions: [],
  358. monthOptions: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
  359. townOptions: [],
  360. villageOptions: [],
  361. viewRow: {},
  362. importForm: {
  363. statYear: undefined,
  364. statMonth: undefined
  365. },
  366. exportForm: {
  367. statYear: undefined,
  368. statMonth: undefined,
  369. townDeptId: undefined
  370. },
  371. queryParams: {
  372. pageNum: 1,
  373. pageSize: 20,
  374. statYear: undefined,
  375. statMonth: undefined,
  376. townDeptId: undefined,
  377. villageDeptId: undefined
  378. },
  379. form: createEmptyForm()
  380. }
  381. },
  382. computed: {
  383. dash() {
  384. return this.$t("dataModel.status.dash")
  385. },
  386. dialogTitle() {
  387. return this.dialogEdit ? this.dmT("dialogEdit") : this.dmT("dialogAdd")
  388. },
  389. formRules() {
  390. return {
  391. statYear: [{ required: true, message: this.dmT("ruleStatYearRequired"), trigger: "change" }],
  392. statMonth: [
  393. { required: true, message: this.dmT("ruleStatMonthRequired"), trigger: "change" },
  394. { validator: this.validateFormStatMonth, trigger: "change" }
  395. ],
  396. villageDeptId: [{ required: true, message: this.dmT("ruleVillageRequired"), trigger: "change" }],
  397. decimal: [{ validator: this.validateOptionalDecimal, trigger: "change" }],
  398. remark: [{ max: 500, message: this.dmCommon("ruleLen500"), trigger: "blur" }]
  399. }
  400. },
  401. importRules() {
  402. return {
  403. statYear: [{ required: true, message: this.dmT("ruleStatYearRequired"), trigger: "change" }],
  404. statMonth: [
  405. { required: true, message: this.dmT("ruleStatMonthRequired"), trigger: "change" },
  406. { validator: this.validateImportStatMonth, trigger: "change" }
  407. ]
  408. }
  409. },
  410. exportRules() {
  411. return {
  412. statYear: [{ required: true, message: this.dmT("exportStatYearRequired"), trigger: "change" }],
  413. statMonth: [
  414. { required: true, message: this.dmT("exportStatMonthRequired"), trigger: "change" },
  415. { validator: this.validateExportStatMonth, trigger: "change" }
  416. ]
  417. }
  418. }
  419. },
  420. created() {
  421. this.loadOptions()
  422. this.getList()
  423. },
  424. methods: {
  425. loadOptions() {
  426. listLivestockProductOutputYearOptions().then((res) => {
  427. this.yearOptions = Array.isArray(res.data) ? res.data : []
  428. })
  429. listLivestockProductOutputMonthOptions().then((res) => {
  430. if (Array.isArray(res.data) && res.data.length) {
  431. this.monthOptions = res.data
  432. }
  433. })
  434. listLivestockProductOutputTownOptions().then((res) => {
  435. this.townOptions = Array.isArray(res.data) ? res.data : []
  436. })
  437. this.loadVillageTree()
  438. },
  439. loadVillageTree() {
  440. return listLivestockProductOutputVillageTree()
  441. .then((res) => {
  442. const raw = res && res.data !== undefined ? res.data : res
  443. const tree = Array.isArray(raw) ? raw : []
  444. this.villageOptions = flattenVillageOptions(tree)
  445. if (!this.villageOptions.length) {
  446. this.$modal.msgWarning(this.dmT("villageTreeEmpty"))
  447. }
  448. })
  449. .catch(() => {
  450. this.villageOptions = []
  451. })
  452. },
  453. formatStatMonth(month) {
  454. if (month == null || month === "") {
  455. return this.dash
  456. }
  457. return this.dmT("statMonthLabel", { month })
  458. },
  459. formatOutput(val) {
  460. if (val == null || val === "") {
  461. return this.dash
  462. }
  463. const n = Number(val)
  464. if (!Number.isFinite(n)) {
  465. return this.dash
  466. }
  467. return n
  468. },
  469. isFutureStatPeriod(statYear, statMonth) {
  470. if (statYear == null || statMonth == null) {
  471. return false
  472. }
  473. const now = new Date()
  474. const currentYear = now.getFullYear()
  475. const currentMonth = now.getMonth() + 1
  476. if (statYear > currentYear) {
  477. return true
  478. }
  479. return statYear === currentYear && statMonth > currentMonth
  480. },
  481. validateFormStatMonth(rule, value, callback) {
  482. if (this.isFutureStatPeriod(this.form.statYear, value)) {
  483. callback(new Error(this.dmT("ruleStatMonthFuture")))
  484. return
  485. }
  486. callback()
  487. },
  488. validateImportStatMonth(rule, value, callback) {
  489. if (this.isFutureStatPeriod(this.importForm.statYear, value)) {
  490. callback(new Error(this.dmT("ruleStatMonthFuture")))
  491. return
  492. }
  493. callback()
  494. },
  495. validateExportStatMonth(rule, value, callback) {
  496. if (this.isFutureStatPeriod(this.exportForm.statYear, value)) {
  497. callback(new Error(this.dmT("ruleStatMonthFuture")))
  498. return
  499. }
  500. callback()
  501. },
  502. validateOptionalDecimal(rule, value, callback) {
  503. if (value == null || value === "") {
  504. callback()
  505. return
  506. }
  507. if (typeof value !== "number" || Number.isNaN(value) || value < 0) {
  508. callback(new Error(this.dmT("ruleDecimalNonNegative")))
  509. return
  510. }
  511. callback()
  512. },
  513. buildListQuery() {
  514. const q = {
  515. pageNum: this.queryParams.pageNum,
  516. pageSize: this.queryParams.pageSize
  517. }
  518. if (this.queryParams.statYear != null) {
  519. q.statYear = this.queryParams.statYear
  520. }
  521. if (this.queryParams.statMonth != null) {
  522. q.statMonth = this.queryParams.statMonth
  523. }
  524. if (this.queryParams.townDeptId != null) {
  525. q.townDeptId = this.queryParams.townDeptId
  526. }
  527. if (this.queryParams.villageDeptId != null) {
  528. q.villageDeptId = this.queryParams.villageDeptId
  529. }
  530. return q
  531. },
  532. buildPayload() {
  533. const remarkText = this.form.remark != null ? String(this.form.remark).trim() : ""
  534. return {
  535. statYear: this.form.statYear,
  536. statMonth: this.form.statMonth,
  537. villageDeptId: this.form.villageDeptId,
  538. meatOutput: this.form.meatOutput == null || this.form.meatOutput === "" ? undefined : this.form.meatOutput,
  539. milkOutput: this.form.milkOutput == null || this.form.milkOutput === "" ? undefined : this.form.milkOutput,
  540. remark: remarkText !== "" ? remarkText : undefined
  541. }
  542. },
  543. getList() {
  544. this.loading = true
  545. listLivestockProductOutput(this.buildListQuery())
  546. .then((res) => {
  547. this.tableList = res.rows || []
  548. this.total = res.total != null ? res.total : 0
  549. })
  550. .finally(() => {
  551. this.loading = false
  552. })
  553. },
  554. handleQuery() {
  555. this.queryParams.pageNum = 1
  556. this.getList()
  557. },
  558. resetQuery() {
  559. this.queryParams.statYear = undefined
  560. this.queryParams.statMonth = undefined
  561. this.queryParams.townDeptId = undefined
  562. this.queryParams.villageDeptId = undefined
  563. this.resetForm("queryForm")
  564. this.handleQuery()
  565. },
  566. handleAdd() {
  567. const openDialog = () => {
  568. this.formKey += 1
  569. const current = getCurrentYearMonth()
  570. this.form = createEmptyForm()
  571. this.form.statYear = current.statYear
  572. this.form.statMonth = current.statMonth
  573. this.dialogEdit = false
  574. this.open = true
  575. this.$nextTick(() => {
  576. if (this.$refs.form) {
  577. this.$refs.form.clearValidate()
  578. }
  579. })
  580. }
  581. if (!this.villageOptions.length) {
  582. this.loadVillageTree().finally(openDialog)
  583. } else {
  584. openDialog()
  585. }
  586. },
  587. handleEdit(row) {
  588. const openWithData = (data) => {
  589. this.formKey += 1
  590. this.dialogEdit = true
  591. this.form = normalizeForm(data)
  592. this.open = true
  593. this.viewOpen = false
  594. this.$nextTick(() => {
  595. if (this.$refs.form) {
  596. this.$refs.form.clearValidate()
  597. }
  598. })
  599. }
  600. getLivestockProductOutput(row.id).then((res) => {
  601. const data = res.data || {}
  602. if (!this.villageOptions.length) {
  603. this.loadVillageTree().finally(() => openWithData(data))
  604. } else {
  605. openWithData(data)
  606. }
  607. })
  608. },
  609. handleEditFromView() {
  610. this.handleEdit(this.viewRow)
  611. },
  612. handleView(row) {
  613. getLivestockProductOutput(row.id).then((res) => {
  614. this.viewRow = res.data || {}
  615. this.viewOpen = true
  616. })
  617. },
  618. handleDelete(row) {
  619. this.$modal
  620. .confirm(this.dmT("confirmDelete"))
  621. .then(() => delLivestockProductOutput(row.id))
  622. .then(() => {
  623. this.$modal.msgSuccess(this.dmCommon("msgDelOk"))
  624. this.viewOpen = false
  625. this.getList()
  626. })
  627. .catch(() => {})
  628. },
  629. submitForm() {
  630. this.$refs.form.validate((valid) => {
  631. if (!valid) {
  632. return
  633. }
  634. const payload = this.buildPayload()
  635. if (this.dialogEdit) {
  636. payload.id = this.form.id
  637. updateLivestockProductOutput(payload).then(() => {
  638. this.$modal.msgSuccess(this.dmCommon("msgModOk"))
  639. this.open = false
  640. this.getList()
  641. })
  642. } else {
  643. addLivestockProductOutput(payload).then(() => {
  644. this.$modal.msgSuccess(this.dmCommon("msgAddOk"))
  645. this.open = false
  646. this.getList()
  647. })
  648. }
  649. })
  650. },
  651. cancel() {
  652. this.open = false
  653. this.form = createEmptyForm()
  654. },
  655. handleImportOpen() {
  656. const current = getCurrentYearMonth()
  657. this.importForm.statYear = current.statYear
  658. this.importForm.statMonth = current.statMonth
  659. this.importOpen = true
  660. this.$nextTick(() => {
  661. this.resetImportFiles()
  662. })
  663. },
  664. resetImportFiles() {
  665. if (this.$refs.importUpload) {
  666. this.$refs.importUpload.clearFiles()
  667. }
  668. },
  669. resetImport() {
  670. this.importing = false
  671. this.importForm.statYear = undefined
  672. this.importForm.statMonth = undefined
  673. this.resetImportFiles()
  674. },
  675. handleDownloadTemplate() {
  676. const filename = `livestock_product_output_template_${new Date().getTime()}.xlsx`
  677. this.$modal.loading("正在下载模板,请稍候")
  678. downloadLivestockProductOutputTemplate()
  679. .then(async (data) => {
  680. if (blobValidate(data)) {
  681. saveAs(new Blob([data], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }), filename)
  682. } else {
  683. const resText = await data.text()
  684. const rspObj = JSON.parse(resText)
  685. this.$modal.msgError(rspObj.msg || "下载模板失败")
  686. }
  687. })
  688. .catch(() => {
  689. this.$modal.msgError("下载模板失败")
  690. })
  691. .finally(() => {
  692. this.$modal.closeLoading()
  693. })
  694. },
  695. handleExportOpen() {
  696. const current = getCurrentYearMonth()
  697. this.exportForm.statYear = current.statYear
  698. this.exportForm.statMonth = current.statMonth
  699. this.exportForm.townDeptId = undefined
  700. this.exportOpen = true
  701. this.$nextTick(() => {
  702. if (this.$refs.exportFormRef) {
  703. this.$refs.exportFormRef.clearValidate()
  704. }
  705. })
  706. },
  707. resetExport() {
  708. this.exporting = false
  709. this.exportForm.statYear = undefined
  710. this.exportForm.statMonth = undefined
  711. this.exportForm.townDeptId = undefined
  712. },
  713. handleExportSubmit() {
  714. this.$refs.exportFormRef.validate((valid) => {
  715. if (!valid) {
  716. return
  717. }
  718. const statYear = this.exportForm.statYear
  719. const statMonth = this.exportForm.statMonth
  720. if (!this.yearOptions.includes(statYear) || !this.monthOptions.includes(statMonth)) {
  721. this.$modal.msgError(this.dmT("exportStatYearInvalid"))
  722. return
  723. }
  724. const filename = `${statYear}年${statMonth}月畜牧产品产量数据.xlsx`
  725. this.exporting = true
  726. this.$modal.loading(this.dmT("exportLoading"))
  727. exportLivestockProductOutput(statYear, statMonth, this.exportForm.townDeptId)
  728. .then(async (data) => {
  729. if (blobValidate(data)) {
  730. saveAs(new Blob([data], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }), filename)
  731. this.exportOpen = false
  732. } else {
  733. const resText = await data.text()
  734. const rspObj = JSON.parse(resText)
  735. this.$modal.msgError(rspObj.msg || this.dmT("exportFail"))
  736. }
  737. })
  738. .catch(() => {
  739. this.$modal.msgError(this.dmT("exportFail"))
  740. })
  741. .finally(() => {
  742. this.exporting = false
  743. this.$modal.closeLoading()
  744. })
  745. })
  746. },
  747. handleImportSubmit() {
  748. this.$refs.importFormRef.validate((valid) => {
  749. if (!valid) {
  750. return
  751. }
  752. const upload = this.$refs.importUpload
  753. const files = upload && upload.uploadFiles
  754. if (!files || !files.length) {
  755. this.$modal.msgError("请选择要上传的文件")
  756. return
  757. }
  758. const raw = files[0].raw
  759. const name = (raw.name || "").toLowerCase()
  760. if (!name.endsWith(".xlsx") && !name.endsWith(".xls")) {
  761. this.$modal.msgError('请选择后缀为 "xls" 或 "xlsx" 的文件')
  762. return
  763. }
  764. this.importing = true
  765. this.$modal.loading(this.dmT("importLoading"))
  766. importLivestockProductOutput(raw, this.importForm.statYear, this.importForm.statMonth)
  767. .then((res) => {
  768. this.importOpen = false
  769. this.showImportResult(res.data || {})
  770. this.getList()
  771. })
  772. .finally(() => {
  773. this.importing = false
  774. this.$modal.closeLoading()
  775. this.resetImportFiles()
  776. })
  777. })
  778. },
  779. showImportResult(data) {
  780. const insert = data.insertCount != null ? data.insertCount : 0
  781. const update = data.updateCount != null ? data.updateCount : 0
  782. const fail = data.failCount != null ? data.failCount : 0
  783. let html = this.dmT("importSummary", { insert, update, fail })
  784. if (data.warnMessages && data.warnMessages.length) {
  785. html += `<p><strong>${this.dmT("importWarnTitle")}</strong></p><p>${data.warnMessages.join("<br/>")}</p>`
  786. }
  787. if (data.failMessages && data.failMessages.length) {
  788. html += `<p><strong>${this.dmT("importFailTitle")}</strong></p><p>${data.failMessages.join("<br/>")}</p>`
  789. }
  790. this.$alert(
  791. `<div style='overflow:auto;overflow-x:hidden;max-height:70vh;padding:10px 20px 0;'>${html}</div>`,
  792. this.dmT("importTitle"),
  793. { dangerouslyUseHTMLString: true }
  794. )
  795. }
  796. }
  797. }
  798. </script>
  799. <style scoped>
  800. .lpo-import-tip {
  801. margin: 0 0 12px;
  802. color: #909399;
  803. font-size: 12px;
  804. line-height: 1.5;
  805. }
  806. .lpo-view-text {
  807. white-space: pre-wrap;
  808. word-break: break-all;
  809. }
  810. .dm-input-with-unit {
  811. display: flex;
  812. align-items: center;
  813. width: 100%;
  814. }
  815. .dm-input-with-unit__input {
  816. flex: 1;
  817. width: 100%;
  818. }
  819. .dm-input-with-unit__suffix {
  820. margin-left: 8px;
  821. color: #909399;
  822. white-space: nowrap;
  823. }
  824. .dm-input-with-unit >>> .el-input-number {
  825. width: 100%;
  826. }
  827. </style>