西藏巴青项目

index.vue 40KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  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>
  24. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ dmCommon("search") }}</el-button>
  25. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ dmCommon("reset") }}</el-button>
  26. <el-button
  27. v-hasPermi="['dataModel:farmerHousehold:add']"
  28. type="primary"
  29. plain
  30. icon="el-icon-plus"
  31. size="mini"
  32. @click="handleAdd"
  33. >{{ dmCommon("add") }}</el-button>
  34. <el-button
  35. v-hasPermi="['dataModel:farmerHousehold:import']"
  36. type="info"
  37. plain
  38. icon="el-icon-upload2"
  39. size="mini"
  40. @click="handleImportOpen"
  41. >{{ dmT("btnImport") }}</el-button>
  42. <el-button
  43. v-hasPermi="['dataModel:farmerHousehold:export']"
  44. type="warning"
  45. plain
  46. icon="el-icon-download"
  47. size="mini"
  48. @click="handleExportOpen"
  49. >{{ dmCommon("export") }}</el-button>
  50. </el-form-item>
  51. </el-form>
  52. </el-card>
  53. <br />
  54. <el-card shadow="never">
  55. <el-table v-loading="loading" :data="tableList" border>
  56. <template slot="empty">
  57. <span>{{ dmT("emptyList") }}</span>
  58. </template>
  59. <el-table-column :label="dmT('colStatYear')" prop="statYear" align="center" width="90" />
  60. <el-table-column :label="dmT('colStatMonth')" align="center" width="80">
  61. <template slot-scope="scope">{{ formatStatMonth(scope.row.statMonth) }}</template>
  62. </el-table-column>
  63. <el-table-column :label="dmT('colTownName')" prop="townName" align="center" min-width="110" :show-overflow-tooltip="true" />
  64. <el-table-column :label="dmT('colVillageName')" prop="villageName" align="center" min-width="110" :show-overflow-tooltip="true" />
  65. <el-table-column :label="dmT('colHouseholdCount')" align="center" width="90">
  66. <template slot-scope="scope">{{ formatCount(scope.row.householdCount) }}</template>
  67. </el-table-column>
  68. <el-table-column :label="dmT('colPopulationCount')" align="center" width="90">
  69. <template slot-scope="scope">{{ formatCount(scope.row.populationCount) }}</template>
  70. </el-table-column>
  71. <el-table-column :label="dmT('colPastureContractArea')" align="center" width="130">
  72. <template slot-scope="scope">{{ formatDecimal(scope.row.pastureContractArea) }}</template>
  73. </el-table-column>
  74. <el-table-column :label="dmCommon('colOp')" align="center" class-name="small-padding fixed-width" width="180" fixed="right">
  75. <template slot-scope="scope">
  76. <el-button v-hasPermi="['dataModel:farmerHousehold:query']" type="text" size="mini" @click="handleView(scope.row)">{{ dmCommon("view") }}</el-button>
  77. <el-button v-hasPermi="['dataModel:farmerHousehold:edit']" type="text" size="mini" @click="handleEdit(scope.row)">{{ dmCommon("edit") }}</el-button>
  78. <el-button v-hasPermi="['dataModel:farmerHousehold:remove']" type="text" size="mini" @click="handleDelete(scope.row)">{{ dmCommon("delete") }}</el-button>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. <pagination
  83. v-show="total > 0"
  84. :total="total"
  85. :page.sync="queryParams.pageNum"
  86. :limit.sync="queryParams.pageSize"
  87. @pagination="getList"
  88. />
  89. </el-card>
  90. <el-dialog :title="dialogTitle" :visible.sync="open" width="980px" append-to-body @close="cancel">
  91. <el-form :key="formKey" ref="form" :model="form" class="fh-form" label-width="200px" size="small">
  92. <div class="fh-section-title">{{ dmT("sectionBasic") }}</div>
  93. <el-row :gutter="16">
  94. <el-col :span="12">
  95. <el-form-item prop="statYear" :rules="formRules.statYear">
  96. <template slot="label">{{ dmT("formStatYear") }}</template>
  97. <el-select v-model="form.statYear" :placeholder="dmCommon('pleaseSelect')" style="width: 100%">
  98. <el-option v-for="y in yearOptions" :key="'f-' + y" :label="String(y)" :value="y" />
  99. </el-select>
  100. </el-form-item>
  101. </el-col>
  102. <el-col :span="12">
  103. <el-form-item prop="statMonth" :rules="formRules.statMonth">
  104. <template slot="label">{{ dmT("formStatMonth") }}</template>
  105. <el-select v-model="form.statMonth" :placeholder="dmCommon('pleaseSelect')" style="width: 100%">
  106. <el-option v-for="m in monthOptions" :key="'fm-' + m" :label="formatStatMonth(m)" :value="m" />
  107. </el-select>
  108. </el-form-item>
  109. </el-col>
  110. <el-col :span="24">
  111. <el-form-item prop="villageDeptId" :rules="formRules.villageDeptId">
  112. <template slot="label">{{ dmT("formVillage") }}</template>
  113. <el-select
  114. v-model="form.villageDeptId"
  115. :placeholder="dmT('phVillageSearch')"
  116. filterable
  117. clearable
  118. style="width: 100%"
  119. >
  120. <el-option
  121. v-for="item in villageOptions"
  122. :key="'f-v-' + item.deptId"
  123. :label="item.label"
  124. :value="item.deptId"
  125. />
  126. </el-select>
  127. </el-form-item>
  128. </el-col>
  129. <el-col :span="12">
  130. <el-form-item prop="householdCount" :rules="formRules.count">
  131. <template slot="label">{{ dmT("formHouseholdCount") }}</template>
  132. <div class="dm-input-with-unit">
  133. <el-input-number v-model="form.householdCount" :min="0" :precision="0" controls-position="right" class="dm-input-with-unit__input" />
  134. <span class="dm-input-with-unit__suffix">{{ dmT("unitHousehold") }}</span>
  135. </div>
  136. </el-form-item>
  137. </el-col>
  138. <el-col :span="12">
  139. <el-form-item prop="populationCount" :rules="formRules.count">
  140. <template slot="label">{{ dmT("formPopulationCount") }}</template>
  141. <div class="dm-input-with-unit">
  142. <el-input-number v-model="form.populationCount" :min="0" :precision="0" controls-position="right" class="dm-input-with-unit__input" />
  143. <span class="dm-input-with-unit__suffix">{{ dmT("unitPerson") }}</span>
  144. </div>
  145. </el-form-item>
  146. </el-col>
  147. </el-row>
  148. <div class="fh-section-title">{{ dmT("sectionPasture") }}</div>
  149. <el-row :gutter="16">
  150. <el-col v-for="field in pastureAreaFields" :key="field.prop" :span="12">
  151. <el-form-item :prop="field.prop" :rules="formRules.decimal">
  152. <template slot="label">{{ dmT(field.labelKey) }}</template>
  153. <div class="dm-input-with-unit">
  154. <el-input-number v-model="form[field.prop]" :min="0" :precision="4" controls-position="right" class="dm-input-with-unit__input" />
  155. <span class="dm-input-with-unit__suffix">{{ dmT(field.unitKey) }}</span>
  156. </div>
  157. </el-form-item>
  158. </el-col>
  159. <el-col :span="12">
  160. <el-form-item>
  161. <template slot="label">{{ dmT("formPastureContractArea") }}</template>
  162. <div class="dm-input-with-unit">
  163. <el-input-number :value="pastureContractAreaDisplay" :controls="false" disabled class="dm-input-with-unit__input" />
  164. <span class="dm-input-with-unit__suffix">{{ dmT("unitMu") }}</span>
  165. </div>
  166. </el-form-item>
  167. </el-col>
  168. <el-col v-for="field in carryingFields" :key="field.prop" :span="12">
  169. <el-form-item :prop="field.prop" :rules="formRules.decimal">
  170. <template slot="label">{{ dmT(field.labelKey) }}</template>
  171. <div class="dm-input-with-unit">
  172. <el-input-number v-model="form[field.prop]" :min="0" :precision="4" controls-position="right" class="dm-input-with-unit__input" />
  173. <span class="dm-input-with-unit__suffix">{{ dmT(field.unitKey) }}</span>
  174. </div>
  175. </el-form-item>
  176. </el-col>
  177. </el-row>
  178. <div class="fh-section-title">{{ dmT("sectionCapFloor") }}</div>
  179. <el-row :gutter="16">
  180. <el-col v-for="field in yesNoFields" :key="field.prop" :span="12">
  181. <el-form-item :prop="field.prop">
  182. <template slot="label">{{ dmT(field.labelKey) }}</template>
  183. <el-radio-group v-model="form[field.prop]">
  184. <el-radio v-for="item in yesNoOptions" :key="field.prop + '-' + item" :label="item">{{ item }}</el-radio>
  185. </el-radio-group>
  186. </el-form-item>
  187. </el-col>
  188. </el-row>
  189. <div class="fh-section-title">{{ dmT("sectionSubsidy") }}</div>
  190. <el-row :gutter="16">
  191. <el-col v-for="field in subsidyRewardFields" :key="field.prop" :span="12">
  192. <el-form-item :prop="field.prop" :rules="formRules.decimal">
  193. <template slot="label">{{ dmT(field.labelKey) }}</template>
  194. <div class="dm-input-with-unit">
  195. <el-input-number v-model="form[field.prop]" :min="0" :precision="4" controls-position="right" class="dm-input-with-unit__input" />
  196. <span class="dm-input-with-unit__suffix">{{ dmT(field.unitKey) }}</span>
  197. </div>
  198. </el-form-item>
  199. </el-col>
  200. <el-col :span="12">
  201. <el-form-item>
  202. <template slot="label">{{ dmT("formSubsidyRewardSubtotal") }}</template>
  203. <div class="dm-input-with-unit">
  204. <el-input-number :value="subsidyRewardSubtotalDisplay" :controls="false" disabled class="dm-input-with-unit__input" />
  205. <span class="dm-input-with-unit__suffix">{{ dmT("unitYuan") }}</span>
  206. </div>
  207. </el-form-item>
  208. </el-col>
  209. <el-col v-for="field in subsidyExtraFields" :key="field.prop" :span="12">
  210. <el-form-item :prop="field.prop" :rules="formRules.decimal">
  211. <template slot="label">{{ dmT(field.labelKey) }}</template>
  212. <div class="dm-input-with-unit">
  213. <el-input-number v-model="form[field.prop]" :min="0" :precision="4" controls-position="right" class="dm-input-with-unit__input" />
  214. <span class="dm-input-with-unit__suffix">{{ dmT(field.unitKey) }}</span>
  215. </div>
  216. </el-form-item>
  217. </el-col>
  218. <el-col :span="12">
  219. <el-form-item>
  220. <template slot="label">{{ dmT("formSubsidyTotal") }}</template>
  221. <div class="dm-input-with-unit">
  222. <el-input-number :value="subsidyTotalDisplay" :controls="false" disabled class="dm-input-with-unit__input" />
  223. <span class="dm-input-with-unit__suffix">{{ dmT("unitYuan") }}</span>
  224. </div>
  225. </el-form-item>
  226. </el-col>
  227. <el-col :span="24">
  228. <el-form-item prop="remark" :rules="formRules.remark">
  229. <template slot="label">{{ dmT("formRemark") }}</template>
  230. <el-input v-model="form.remark" type="textarea" :rows="2" :placeholder="dmT('phRemark')" maxlength="500" show-word-limit />
  231. </el-form-item>
  232. </el-col>
  233. </el-row>
  234. </el-form>
  235. <div slot="footer" class="dialog-footer">
  236. <el-button type="primary" @click="submitForm">{{ dmCommon("ok") }}</el-button>
  237. <el-button @click="cancel">{{ dmCommon("cancel") }}</el-button>
  238. </div>
  239. </el-dialog>
  240. <el-dialog :title="dmCommon('viewTitle')" :visible.sync="viewOpen" width="980px" append-to-body>
  241. <el-form class="dm-view-form fh-form" label-width="200px" size="small">
  242. <div class="fh-section-title">{{ dmT("sectionBasic") }}</div>
  243. <el-row :gutter="16">
  244. <el-col :span="12">
  245. <el-form-item :label="dmT('formStatYear')"><span>{{ viewRow.statYear || dash }}</span></el-form-item>
  246. </el-col>
  247. <el-col :span="12">
  248. <el-form-item :label="dmT('formStatMonth')"><span>{{ formatStatMonth(viewRow.statMonth) }}</span></el-form-item>
  249. </el-col>
  250. <el-col :span="12">
  251. <el-form-item :label="dmT('formTown')"><span>{{ viewRow.townName || dash }}</span></el-form-item>
  252. </el-col>
  253. <el-col :span="12">
  254. <el-form-item :label="dmT('formVillage')"><span>{{ viewRow.villageName || dash }}</span></el-form-item>
  255. </el-col>
  256. <el-col :span="12">
  257. <el-form-item :label="dmT('formHouseholdCount')">
  258. <span>{{ formatWithUnit(formatCount(viewRow.householdCount), "unitHousehold") }}</span>
  259. </el-form-item>
  260. </el-col>
  261. <el-col :span="12">
  262. <el-form-item :label="dmT('formPopulationCount')">
  263. <span>{{ formatWithUnit(formatCount(viewRow.populationCount), "unitPerson") }}</span>
  264. </el-form-item>
  265. </el-col>
  266. </el-row>
  267. <div class="fh-section-title">{{ dmT("sectionPasture") }}</div>
  268. <el-row :gutter="16">
  269. <el-col v-for="field in pastureAreaFields" :key="'vp-' + field.prop" :span="12">
  270. <el-form-item :label="dmT(field.labelKey)">
  271. <span>{{ formatWithUnit(formatDecimal(viewRow[field.prop]), field.unitKey) }}</span>
  272. </el-form-item>
  273. </el-col>
  274. <el-col :span="12">
  275. <el-form-item :label="dmT('formPastureContractArea')">
  276. <span>{{ formatWithUnit(formatDecimal(pastureContractAreaOf(viewRow)), "unitMu") }}</span>
  277. </el-form-item>
  278. </el-col>
  279. <el-col v-for="field in carryingFields" :key="'vc-' + field.prop" :span="12">
  280. <el-form-item :label="dmT(field.labelKey)">
  281. <span>{{ formatWithUnit(formatDecimal(viewRow[field.prop]), field.unitKey) }}</span>
  282. </el-form-item>
  283. </el-col>
  284. </el-row>
  285. <div class="fh-section-title">{{ dmT("sectionCapFloor") }}</div>
  286. <el-row :gutter="16">
  287. <el-col v-for="field in yesNoFields" :key="'vy-' + field.prop" :span="12">
  288. <el-form-item :label="dmT(field.labelKey)"><span>{{ viewRow[field.prop] || dash }}</span></el-form-item>
  289. </el-col>
  290. </el-row>
  291. <div class="fh-section-title">{{ dmT("sectionSubsidy") }}</div>
  292. <el-row :gutter="16">
  293. <el-col v-for="field in subsidyRewardFields" :key="'vsr-' + field.prop" :span="12">
  294. <el-form-item :label="dmT(field.labelKey)">
  295. <span>{{ formatWithUnit(formatDecimal(viewRow[field.prop]), field.unitKey) }}</span>
  296. </el-form-item>
  297. </el-col>
  298. <el-col :span="12">
  299. <el-form-item :label="dmT('formSubsidyRewardSubtotal')">
  300. <span>{{ formatWithUnit(formatDecimal(subsidyRewardSubtotalOf(viewRow)), "unitYuan") }}</span>
  301. </el-form-item>
  302. </el-col>
  303. <el-col v-for="field in subsidyExtraFields" :key="'vse-' + field.prop" :span="12">
  304. <el-form-item :label="dmT(field.labelKey)">
  305. <span>{{ formatWithUnit(formatDecimal(viewRow[field.prop]), field.unitKey) }}</span>
  306. </el-form-item>
  307. </el-col>
  308. <el-col :span="12">
  309. <el-form-item :label="dmT('formSubsidyTotal')">
  310. <span>{{ formatWithUnit(formatDecimal(subsidyTotalOf(viewRow)), "unitYuan") }}</span>
  311. </el-form-item>
  312. </el-col>
  313. <el-col :span="24">
  314. <el-form-item :label="dmT('formRemark')">
  315. <span class="fh-view-text">{{ viewRow.remark || dash }}</span>
  316. </el-form-item>
  317. </el-col>
  318. </el-row>
  319. </el-form>
  320. <div slot="footer" class="dialog-footer">
  321. <el-button v-hasPermi="['dataModel:farmerHousehold:edit']" type="primary" @click="handleEditFromView">{{ dmCommon("edit") }}</el-button>
  322. <el-button @click="viewOpen = false">{{ dmCommon("close") }}</el-button>
  323. </div>
  324. </el-dialog>
  325. <el-dialog :title="dmT('importTitle')" :visible.sync="importOpen" width="480px" append-to-body @close="resetImport">
  326. <el-form ref="importFormRef" :model="importForm" label-width="100px" size="small">
  327. <el-form-item prop="statYear" :rules="importRules.statYear">
  328. <template slot="label">{{ dmT("importStatYear") }}</template>
  329. <el-select v-model="importForm.statYear" :placeholder="dmT('importStatYearPh')" style="width: 100%">
  330. <el-option v-for="y in yearOptions" :key="'iy-' + y" :label="String(y)" :value="y" />
  331. </el-select>
  332. </el-form-item>
  333. <el-form-item prop="statMonth" :rules="importRules.statMonth">
  334. <template slot="label">{{ dmT("importStatMonth") }}</template>
  335. <el-select v-model="importForm.statMonth" :placeholder="dmT('importStatMonthPh')" style="width: 100%">
  336. <el-option v-for="m in monthOptions" :key="'im-' + m" :label="formatStatMonth(m)" :value="m" />
  337. </el-select>
  338. </el-form-item>
  339. <p class="fh-import-tip">{{ dmT("importTip") }}</p>
  340. <el-upload ref="importUpload" drag :limit="1" accept=".xlsx,.xls" :auto-upload="false" action="#">
  341. <i class="el-icon-upload" />
  342. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  343. <div slot="tip" class="el-upload__tip">
  344. <el-link type="primary" :underline="false" @click="handleDownloadTemplate">{{ dmT("btnDownloadTemplate") }}</el-link>
  345. </div>
  346. </el-upload>
  347. </el-form>
  348. <div slot="footer" class="dialog-footer">
  349. <el-button type="primary" :loading="importing" @click="handleImportSubmit">{{ dmCommon("ok") }}</el-button>
  350. <el-button @click="importOpen = false">{{ dmCommon("cancel") }}</el-button>
  351. </div>
  352. </el-dialog>
  353. <el-dialog :title="dmT('exportTitle')" :visible.sync="exportOpen" width="480px" append-to-body @close="resetExport">
  354. <el-form ref="exportFormRef" :model="exportForm" label-width="100px" size="small">
  355. <el-form-item prop="statYear" :rules="exportRules.statYear">
  356. <template slot="label">{{ dmT("exportStatYear") }}</template>
  357. <el-select v-model="exportForm.statYear" :placeholder="dmT('exportStatYearPh')" style="width: 100%">
  358. <el-option v-for="y in yearOptions" :key="'ey-' + y" :label="String(y)" :value="y" />
  359. </el-select>
  360. </el-form-item>
  361. <el-form-item prop="statMonth" :rules="exportRules.statMonth">
  362. <template slot="label">{{ dmT("exportStatMonth") }}</template>
  363. <el-select v-model="exportForm.statMonth" :placeholder="dmT('exportStatMonthPh')" style="width: 100%">
  364. <el-option v-for="m in monthOptions" :key="'em-' + m" :label="formatStatMonth(m)" :value="m" />
  365. </el-select>
  366. </el-form-item>
  367. <el-form-item>
  368. <template slot="label">{{ dmT("exportTown") }}</template>
  369. <el-select
  370. v-model="exportForm.townDeptId"
  371. :placeholder="dmT('exportTownPh')"
  372. clearable
  373. filterable
  374. style="width: 100%"
  375. >
  376. <el-option v-for="item in townOptions" :key="'et-' + item.deptId" :label="item.deptName" :value="item.deptId" />
  377. </el-select>
  378. </el-form-item>
  379. </el-form>
  380. <div slot="footer" class="dialog-footer">
  381. <el-button type="primary" :loading="exporting" @click="handleExportSubmit">{{ dmCommon("ok") }}</el-button>
  382. <el-button @click="exportOpen = false">{{ dmCommon("cancel") }}</el-button>
  383. </div>
  384. </el-dialog>
  385. </div>
  386. </template>
  387. <script>
  388. import dataModelLocaleMixin from "@/mixins/dataModelLocaleMixin"
  389. import {
  390. listFarmerHousehold,
  391. getFarmerHousehold,
  392. addFarmerHousehold,
  393. updateFarmerHousehold,
  394. delFarmerHousehold,
  395. listFarmerHouseholdYearOptions,
  396. listFarmerHouseholdMonthOptions,
  397. listFarmerHouseholdTownOptions,
  398. listFarmerHouseholdVillageTree,
  399. importFarmerHousehold,
  400. downloadFarmerHouseholdTemplate,
  401. exportFarmerHousehold
  402. } from "@/api/dataModel/farmerHousehold"
  403. import { blobValidate } from "@/utils/ruoyi"
  404. import { saveAs } from "file-saver"
  405. const YES_NO_OPTIONS = ["是", "否"]
  406. const PASTURE_AREA_FIELDS = [
  407. { prop: "grazingBanArea", labelKey: "formGrazingBanArea", unitKey: "unitMu" },
  408. { prop: "grassBalanceArea", labelKey: "formGrassBalanceArea", unitKey: "unitMu" }
  409. ]
  410. const CARRYING_FIELDS = [
  411. { prop: "approvedCarryingCapacity", labelKey: "formApprovedCarryingCapacity", unitKey: "unitSheepUnit" },
  412. { prop: "yearEndStockSheepUnit", labelKey: "formYearEndStockSheepUnit", unitKey: "unitSheepUnit" }
  413. ]
  414. const YES_NO_FIELDS = [
  415. { prop: "isPureHerder", labelKey: "formIsPureHerder" },
  416. { prop: "isNoLivestock", labelKey: "formIsNoLivestock" },
  417. { prop: "isExtinctHousehold", labelKey: "formIsExtinctHousehold" },
  418. { prop: "isOverloadHerder", labelKey: "formIsOverloadHerder" },
  419. { prop: "needCap", labelKey: "formNeedCap" },
  420. { prop: "needFloor", labelKey: "formNeedFloor" }
  421. ]
  422. const SUBSIDY_REWARD_FIELDS = [
  423. { prop: "grazingBanSubsidy", labelKey: "formGrazingBanSubsidy", unitKey: "unitYuan" },
  424. { prop: "grassBalanceReward", labelKey: "formGrassBalanceReward", unitKey: "unitYuan" }
  425. ]
  426. const SUBSIDY_EXTRA_FIELDS = [
  427. { prop: "afterCapFloorSubsidy", labelKey: "formAfterCapFloorSubsidy", unitKey: "unitYuan" },
  428. { prop: "villageSupervisorSubsidy", labelKey: "formVillageSupervisorSubsidy", unitKey: "unitYuan" }
  429. ]
  430. const COUNT_PROPS = ["householdCount", "populationCount"]
  431. const DECIMAL_PROPS = [
  432. ...PASTURE_AREA_FIELDS.map((f) => f.prop),
  433. ...CARRYING_FIELDS.map((f) => f.prop),
  434. ...SUBSIDY_REWARD_FIELDS.map((f) => f.prop),
  435. ...SUBSIDY_EXTRA_FIELDS.map((f) => f.prop)
  436. ]
  437. const YES_NO_PROPS = YES_NO_FIELDS.map((f) => f.prop)
  438. function safeNum(val) {
  439. const n = Number(val)
  440. return Number.isFinite(n) ? n : 0
  441. }
  442. function getCurrentYearMonth() {
  443. const now = new Date()
  444. return { statYear: now.getFullYear(), statMonth: now.getMonth() + 1 }
  445. }
  446. function createEmptyForm() {
  447. const form = {
  448. id: undefined,
  449. statYear: undefined,
  450. statMonth: undefined,
  451. villageDeptId: undefined,
  452. remark: undefined
  453. }
  454. COUNT_PROPS.forEach((p) => {
  455. form[p] = undefined
  456. })
  457. DECIMAL_PROPS.forEach((p) => {
  458. form[p] = undefined
  459. })
  460. YES_NO_PROPS.forEach((p) => {
  461. form[p] = undefined
  462. })
  463. return form
  464. }
  465. function normalizeForm(data) {
  466. const row = Object.assign(createEmptyForm(), data || {})
  467. COUNT_PROPS.concat(DECIMAL_PROPS).forEach((prop) => {
  468. const val = row[prop]
  469. row[prop] = val == null || val === "" ? undefined : Number(val)
  470. })
  471. YES_NO_PROPS.forEach((prop) => {
  472. if (row[prop] === "") {
  473. row[prop] = undefined
  474. }
  475. })
  476. return row
  477. }
  478. function flattenVillageOptions(tree) {
  479. const list = []
  480. ;(tree || []).forEach((county) => {
  481. ;(county.children || []).forEach((town) => {
  482. ;(town.children || []).forEach((village) => {
  483. if (village == null || village.id == null) {
  484. return
  485. }
  486. const townName = town.label || ""
  487. const villageName = village.label || ""
  488. list.push({
  489. deptId: village.id,
  490. label: townName ? `${townName} / ${villageName}` : villageName
  491. })
  492. })
  493. })
  494. })
  495. return list
  496. }
  497. export default {
  498. name: "FarmerHousehold",
  499. mixins: [dataModelLocaleMixin],
  500. data() {
  501. return {
  502. dmNs: "farmerHousehold",
  503. loading: false,
  504. importing: false,
  505. exporting: false,
  506. open: false,
  507. viewOpen: false,
  508. importOpen: false,
  509. exportOpen: false,
  510. dialogEdit: false,
  511. formKey: 0,
  512. total: 0,
  513. tableList: [],
  514. yearOptions: [],
  515. monthOptions: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
  516. townOptions: [],
  517. villageOptions: [],
  518. yesNoOptions: YES_NO_OPTIONS,
  519. pastureAreaFields: PASTURE_AREA_FIELDS,
  520. carryingFields: CARRYING_FIELDS,
  521. yesNoFields: YES_NO_FIELDS,
  522. subsidyRewardFields: SUBSIDY_REWARD_FIELDS,
  523. subsidyExtraFields: SUBSIDY_EXTRA_FIELDS,
  524. viewRow: {},
  525. importForm: { statYear: undefined, statMonth: undefined },
  526. exportForm: { statYear: undefined, statMonth: undefined, townDeptId: undefined },
  527. queryParams: {
  528. pageNum: 1,
  529. pageSize: 20,
  530. statYear: undefined,
  531. statMonth: undefined,
  532. townDeptId: undefined
  533. },
  534. form: createEmptyForm()
  535. }
  536. },
  537. computed: {
  538. dash() {
  539. return this.$t("dataModel.status.dash")
  540. },
  541. dialogTitle() {
  542. return this.dialogEdit ? this.dmT("dialogEdit") : this.dmT("dialogAdd")
  543. },
  544. // 草场承包总面积 = 禁牧面积 + 草畜平衡面积
  545. pastureContractAreaDisplay() {
  546. return Number((safeNum(this.form.grazingBanArea) + safeNum(this.form.grassBalanceArea)).toFixed(4))
  547. },
  548. // 补助奖励总资金 = 禁牧补助 + 草畜平衡奖励
  549. subsidyRewardSubtotalDisplay() {
  550. return Number((safeNum(this.form.grazingBanSubsidy) + safeNum(this.form.grassBalanceReward)).toFixed(4))
  551. },
  552. // 补助合计金额 = 封顶保底后享受补助奖励总资金 + 村级草原监督员补助
  553. subsidyTotalDisplay() {
  554. return Number((safeNum(this.form.afterCapFloorSubsidy) + safeNum(this.form.villageSupervisorSubsidy)).toFixed(4))
  555. },
  556. formRules() {
  557. return {
  558. statYear: [{ required: true, message: this.dmT("ruleStatYearRequired"), trigger: "change" }],
  559. statMonth: [
  560. { required: true, message: this.dmT("ruleStatMonthRequired"), trigger: "change" },
  561. { validator: this.validateFormStatMonth, trigger: "change" }
  562. ],
  563. villageDeptId: [{ required: true, message: this.dmT("ruleVillageRequired"), trigger: "change" }],
  564. count: [{ validator: this.validateOptionalCount, trigger: "change" }],
  565. decimal: [{ validator: this.validateOptionalDecimal, trigger: "change" }],
  566. remark: [{ max: 500, message: this.dmCommon("ruleLen500"), trigger: "blur" }]
  567. }
  568. },
  569. importRules() {
  570. return {
  571. statYear: [{ required: true, message: this.dmT("ruleStatYearRequired"), trigger: "change" }],
  572. statMonth: [
  573. { required: true, message: this.dmT("ruleStatMonthRequired"), trigger: "change" },
  574. { validator: this.validateImportStatMonth, trigger: "change" }
  575. ]
  576. }
  577. },
  578. exportRules() {
  579. return {
  580. statYear: [{ required: true, message: this.dmT("exportStatYearRequired"), trigger: "change" }],
  581. statMonth: [
  582. { required: true, message: this.dmT("exportStatMonthRequired"), trigger: "change" },
  583. { validator: this.validateExportStatMonth, trigger: "change" }
  584. ]
  585. }
  586. }
  587. },
  588. created() {
  589. this.loadOptions()
  590. this.getList()
  591. },
  592. methods: {
  593. loadOptions() {
  594. listFarmerHouseholdYearOptions().then((res) => {
  595. this.yearOptions = Array.isArray(res.data) ? res.data : []
  596. })
  597. listFarmerHouseholdMonthOptions().then((res) => {
  598. if (Array.isArray(res.data) && res.data.length) {
  599. this.monthOptions = res.data
  600. }
  601. })
  602. listFarmerHouseholdTownOptions().then((res) => {
  603. this.townOptions = Array.isArray(res.data) ? res.data : []
  604. })
  605. this.loadVillageTree()
  606. },
  607. loadVillageTree() {
  608. return listFarmerHouseholdVillageTree()
  609. .then((res) => {
  610. const raw = res && res.data !== undefined ? res.data : res
  611. this.villageOptions = flattenVillageOptions(Array.isArray(raw) ? raw : [])
  612. if (!this.villageOptions.length) {
  613. this.$modal.msgWarning(this.dmT("villageTreeEmpty"))
  614. }
  615. })
  616. .catch(() => {
  617. this.villageOptions = []
  618. })
  619. },
  620. formatStatMonth(month) {
  621. if (month == null || month === "") {
  622. return this.dash
  623. }
  624. return this.dmT("statMonthLabel", { month })
  625. },
  626. formatCount(val) {
  627. return val == null || val === "" ? this.dash : val
  628. },
  629. formatDecimal(val) {
  630. return val == null || val === "" ? this.dash : val
  631. },
  632. pastureContractAreaOf(row) {
  633. if (!row) {
  634. return undefined
  635. }
  636. if (row.pastureContractArea != null && row.pastureContractArea !== "") {
  637. return row.pastureContractArea
  638. }
  639. if (row.grazingBanArea == null && row.grassBalanceArea == null) {
  640. return undefined
  641. }
  642. return Number((safeNum(row.grazingBanArea) + safeNum(row.grassBalanceArea)).toFixed(4))
  643. },
  644. subsidyRewardSubtotalOf(row) {
  645. if (!row) {
  646. return undefined
  647. }
  648. if (row.subsidyRewardSubtotal != null && row.subsidyRewardSubtotal !== "") {
  649. return row.subsidyRewardSubtotal
  650. }
  651. if (row.grazingBanSubsidy == null && row.grassBalanceReward == null) {
  652. return undefined
  653. }
  654. return Number((safeNum(row.grazingBanSubsidy) + safeNum(row.grassBalanceReward)).toFixed(4))
  655. },
  656. subsidyTotalOf(row) {
  657. if (!row) {
  658. return undefined
  659. }
  660. // 前端展示公式:封顶保底后 + 村级监督员(与本次需求一致)
  661. if (row.afterCapFloorSubsidy == null && row.villageSupervisorSubsidy == null) {
  662. if (row.subsidyTotal != null && row.subsidyTotal !== "") {
  663. return row.subsidyTotal
  664. }
  665. return undefined
  666. }
  667. return Number((safeNum(row.afterCapFloorSubsidy) + safeNum(row.villageSupervisorSubsidy)).toFixed(4))
  668. },
  669. isFutureStatPeriod(statYear, statMonth) {
  670. if (statYear == null || statMonth == null) {
  671. return false
  672. }
  673. const now = new Date()
  674. const y = now.getFullYear()
  675. const m = now.getMonth() + 1
  676. return statYear > y || (statYear === y && statMonth > m)
  677. },
  678. validateFormStatMonth(rule, value, callback) {
  679. if (this.isFutureStatPeriod(this.form.statYear, value)) {
  680. callback(new Error(this.dmT("ruleStatMonthFuture")))
  681. return
  682. }
  683. callback()
  684. },
  685. validateImportStatMonth(rule, value, callback) {
  686. if (this.isFutureStatPeriod(this.importForm.statYear, value)) {
  687. callback(new Error(this.dmT("ruleStatMonthFuture")))
  688. return
  689. }
  690. callback()
  691. },
  692. validateExportStatMonth(rule, value, callback) {
  693. if (this.isFutureStatPeriod(this.exportForm.statYear, value)) {
  694. callback(new Error(this.dmT("ruleStatMonthFuture")))
  695. return
  696. }
  697. callback()
  698. },
  699. validateOptionalCount(rule, value, callback) {
  700. if (value == null || value === "") {
  701. callback()
  702. return
  703. }
  704. if (typeof value !== "number" || Number.isNaN(value) || value < 0 || !Number.isInteger(value)) {
  705. callback(new Error(this.dmT("ruleCountNonNegative")))
  706. return
  707. }
  708. callback()
  709. },
  710. validateOptionalDecimal(rule, value, callback) {
  711. if (value == null || value === "") {
  712. callback()
  713. return
  714. }
  715. if (typeof value !== "number" || Number.isNaN(value) || value < 0) {
  716. callback(new Error(this.dmT("ruleDecimalNonNegative")))
  717. return
  718. }
  719. callback()
  720. },
  721. buildListQuery() {
  722. const q = {
  723. pageNum: this.queryParams.pageNum,
  724. pageSize: this.queryParams.pageSize
  725. }
  726. if (this.queryParams.statYear != null) {
  727. q.statYear = this.queryParams.statYear
  728. }
  729. if (this.queryParams.statMonth != null) {
  730. q.statMonth = this.queryParams.statMonth
  731. }
  732. if (this.queryParams.townDeptId != null) {
  733. q.townDeptId = this.queryParams.townDeptId
  734. }
  735. return q
  736. },
  737. getList() {
  738. this.loading = true
  739. listFarmerHousehold(this.buildListQuery())
  740. .then((res) => {
  741. this.tableList = res.rows || []
  742. this.total = res.total || 0
  743. })
  744. .finally(() => {
  745. this.loading = false
  746. })
  747. },
  748. handleQuery() {
  749. this.queryParams.pageNum = 1
  750. this.getList()
  751. },
  752. resetQuery() {
  753. this.queryParams = {
  754. pageNum: 1,
  755. pageSize: 20,
  756. statYear: undefined,
  757. statMonth: undefined,
  758. townDeptId: undefined
  759. }
  760. this.getList()
  761. },
  762. handleAdd() {
  763. this.dialogEdit = false
  764. this.formKey += 1
  765. this.form = createEmptyForm()
  766. const ym = getCurrentYearMonth()
  767. this.form.statYear = ym.statYear
  768. this.form.statMonth = ym.statMonth
  769. this.open = true
  770. this.$nextTick(() => {
  771. if (this.$refs.form) {
  772. this.$refs.form.clearValidate()
  773. }
  774. })
  775. },
  776. handleEdit(row) {
  777. getFarmerHousehold(row.id).then((res) => {
  778. this.dialogEdit = true
  779. this.formKey += 1
  780. this.form = normalizeForm(res.data)
  781. this.open = true
  782. this.viewOpen = false
  783. this.$nextTick(() => {
  784. if (this.$refs.form) {
  785. this.$refs.form.clearValidate()
  786. }
  787. })
  788. })
  789. },
  790. handleView(row) {
  791. getFarmerHousehold(row.id).then((res) => {
  792. this.viewRow = res.data || {}
  793. this.viewOpen = true
  794. })
  795. },
  796. handleEditFromView() {
  797. if (!this.viewRow || this.viewRow.id == null) {
  798. return
  799. }
  800. this.handleEdit(this.viewRow)
  801. },
  802. handleDelete(row) {
  803. this.$modal
  804. .confirm(this.dmT("confirmDelete"))
  805. .then(() => delFarmerHousehold(row.id))
  806. .then(() => {
  807. this.$modal.msgSuccess(this.dmCommon("msgDelOk"))
  808. this.getList()
  809. })
  810. .catch(() => {})
  811. },
  812. buildSubmitPayload() {
  813. const payload = {
  814. id: this.form.id,
  815. statYear: this.form.statYear,
  816. statMonth: this.form.statMonth,
  817. villageDeptId: this.form.villageDeptId,
  818. remark: this.form.remark
  819. }
  820. COUNT_PROPS.concat(DECIMAL_PROPS).forEach((prop) => {
  821. const val = this.form[prop]
  822. payload[prop] = val == null || val === "" ? null : val
  823. })
  824. YES_NO_PROPS.forEach((prop) => {
  825. payload[prop] = this.form[prop] || null
  826. })
  827. return payload
  828. },
  829. submitForm() {
  830. this.$refs.form.validate((valid) => {
  831. if (!valid) {
  832. return
  833. }
  834. const payload = this.buildSubmitPayload()
  835. if (this.dialogEdit) {
  836. updateFarmerHousehold(payload).then(() => {
  837. this.$modal.msgSuccess(this.dmCommon("msgModOk"))
  838. this.open = false
  839. this.getList()
  840. })
  841. } else {
  842. addFarmerHousehold(payload).then(() => {
  843. this.$modal.msgSuccess(this.dmCommon("msgAddOk"))
  844. this.open = false
  845. this.getList()
  846. })
  847. }
  848. })
  849. },
  850. cancel() {
  851. this.open = false
  852. this.form = createEmptyForm()
  853. },
  854. handleImportOpen() {
  855. const ym = getCurrentYearMonth()
  856. this.importForm = {
  857. statYear: this.queryParams.statYear != null ? this.queryParams.statYear : ym.statYear,
  858. statMonth: this.queryParams.statMonth != null ? this.queryParams.statMonth : ym.statMonth
  859. }
  860. this.importOpen = true
  861. this.$nextTick(() => {
  862. if (this.$refs.importFormRef) {
  863. this.$refs.importFormRef.clearValidate()
  864. }
  865. if (this.$refs.importUpload) {
  866. this.$refs.importUpload.clearFiles()
  867. }
  868. })
  869. },
  870. resetImport() {
  871. this.importForm = { statYear: undefined, statMonth: undefined }
  872. if (this.$refs.importUpload) {
  873. this.$refs.importUpload.clearFiles()
  874. }
  875. },
  876. handleDownloadTemplate() {
  877. downloadFarmerHouseholdTemplate().then(async (data) => {
  878. const isBlob = blobValidate(data)
  879. if (isBlob) {
  880. saveAs(data, `farmer_household_import_template_${new Date().getTime()}.xlsx`)
  881. } else {
  882. this.$modal.msgError(this.dmT("exportFail"))
  883. }
  884. })
  885. },
  886. handleImportSubmit() {
  887. this.$refs.importFormRef.validate((valid) => {
  888. if (!valid) {
  889. return
  890. }
  891. const files = this.$refs.importUpload ? this.$refs.importUpload.uploadFiles : []
  892. if (!files || !files.length) {
  893. this.$modal.msgError(this.dmCommon("pleaseSelect"))
  894. return
  895. }
  896. const raw = files[0].raw
  897. this.importing = true
  898. this.$modal.loading(this.dmT("importLoading"))
  899. importFarmerHousehold(raw, this.importForm.statYear, this.importForm.statMonth)
  900. .then((res) => {
  901. const data = res.data || {}
  902. const msg = this.dmT("importSummary", {
  903. insert: data.insertCount != null ? data.insertCount : 0,
  904. update: data.updateCount != null ? data.updateCount : 0,
  905. fail: data.failCount != null ? data.failCount : 0
  906. })
  907. this.$modal.msgSuccess(msg)
  908. if (data.warnMessages && data.warnMessages.length) {
  909. this.$alert(data.warnMessages.join("<br/>"), this.dmT("importWarnTitle"), { dangerouslyUseHTMLString: true })
  910. }
  911. if (data.failMessages && data.failMessages.length) {
  912. this.$alert(data.failMessages.join("<br/>"), this.dmT("importFailTitle"), { dangerouslyUseHTMLString: true })
  913. }
  914. this.importOpen = false
  915. this.getList()
  916. })
  917. .finally(() => {
  918. this.importing = false
  919. this.$modal.closeLoading()
  920. })
  921. })
  922. },
  923. handleExportOpen() {
  924. const ym = getCurrentYearMonth()
  925. this.exportForm = {
  926. statYear: this.queryParams.statYear != null ? this.queryParams.statYear : ym.statYear,
  927. statMonth: this.queryParams.statMonth != null ? this.queryParams.statMonth : ym.statMonth,
  928. townDeptId: this.queryParams.townDeptId
  929. }
  930. this.exportOpen = true
  931. this.$nextTick(() => {
  932. if (this.$refs.exportFormRef) {
  933. this.$refs.exportFormRef.clearValidate()
  934. }
  935. })
  936. },
  937. resetExport() {
  938. this.exportForm = { statYear: undefined, statMonth: undefined, townDeptId: undefined }
  939. },
  940. handleExportSubmit() {
  941. this.$refs.exportFormRef.validate((valid) => {
  942. if (!valid) {
  943. return
  944. }
  945. this.exporting = true
  946. const filename = `${this.exportForm.statYear}年${this.exportForm.statMonth}月农牧户数据.xlsx`
  947. this.$modal.loading(this.dmT("exportLoading"))
  948. exportFarmerHousehold(this.exportForm.statYear, this.exportForm.statMonth, this.exportForm.townDeptId)
  949. .then(async (data) => {
  950. const isBlob = blobValidate(data)
  951. if (isBlob) {
  952. saveAs(data, filename)
  953. this.exportOpen = false
  954. } else {
  955. this.$modal.msgError(this.dmT("exportFail"))
  956. }
  957. })
  958. .finally(() => {
  959. this.exporting = false
  960. this.$modal.closeLoading()
  961. })
  962. })
  963. }
  964. }
  965. }
  966. </script>
  967. <style scoped>
  968. .fh-section-title {
  969. margin: 4px 0 12px;
  970. font-weight: 600;
  971. color: #303133;
  972. }
  973. .fh-form >>> .el-form-item__label {
  974. white-space: nowrap;
  975. line-height: 32px;
  976. }
  977. .fh-import-tip {
  978. margin: 0 0 12px;
  979. color: #909399;
  980. font-size: 12px;
  981. line-height: 1.5;
  982. }
  983. .fh-view-text {
  984. white-space: pre-wrap;
  985. word-break: break-all;
  986. }
  987. .dm-input-with-unit {
  988. display: flex;
  989. align-items: center;
  990. width: 100%;
  991. }
  992. .dm-input-with-unit__input {
  993. flex: 1;
  994. width: 100%;
  995. }
  996. .dm-input-with-unit__suffix {
  997. margin-left: 8px;
  998. color: #909399;
  999. white-space: nowrap;
  1000. }
  1001. .dm-input-with-unit >>> .el-input-number {
  1002. width: 100%;
  1003. }
  1004. </style>