index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <el-row class="el-row-container" style="height: 100%" v-loading="loading">
  3. <el-col
  4. :span="4"
  5. style="height:100%;padding-bottom:32px;"
  6. >
  7. <el-card style="margin:16px;height: 100%; overflow-y: auto">
  8. <data-report-left
  9. @setCurrentData="setCurrentData"
  10. :treeData="treeData"
  11. ></data-report-left>
  12. </el-card>
  13. </el-col>
  14. <el-col
  15. :span="20"
  16. style="padding: 16px 16px 16px 0; height: 100%"
  17. >
  18. <el-card style="height: 100%; overflow-y: auto">
  19. <el-col :span="24" class="elrow-main__col-top">
  20. <div style="display:flex">
  21. <el-input
  22. v-model="farmerName"
  23. style="width: 250px;"
  24. placeholder="请输入姓名/电话"
  25. @keyup.enter.native="handleSearch"
  26. clearable
  27. />
  28. <el-button
  29. type="primary"
  30. size="small"
  31. style="margin: 0 16px;"
  32. @click="handleSearch"
  33. >查询</el-button
  34. >
  35. <el-upload
  36. class="avatar-uploader"
  37. :action="uploadUrl"
  38. :show-file-list="false"
  39. :on-success="handleAvatarSuccess"
  40. :on-error="handleUploadError"
  41. name="file"
  42. :headers="headers"
  43. :data="{areaId: this.currentClickId}"
  44. :before-upload="beforeAvatarUpload"
  45. ><el-button
  46. size="small"
  47. type="primary"
  48. style="height:36px;margin-right:16px"
  49. >导入</el-button>
  50. </el-upload>
  51. <el-button
  52. class="filter-item"
  53. size="mini"
  54. type="primary"
  55. icon="el-icon-download"
  56. @click="downloadExcel()"
  57. >下载模板</el-button>
  58. </div>
  59. <div class="top-left">
  60. <el-button
  61. type="primary"
  62. size="small"
  63. @click="addAssociation"
  64. >新增农户
  65. </el-button
  66. ></div>
  67. </el-col>
  68. <el-col :span="24" class="elrow-main__col-bottom">
  69. <b-table
  70. ref="tableRef"
  71. :args="{ 'highlight-current-row': true }"
  72. :data="loadData"
  73. :columns="columns"
  74. isShowIndex
  75. >
  76. <template #status="scope">
  77. <span style="display:flex;align-items:center;justify-content:center">
  78. <span class="status"></span>
  79. {{ scope.row.name }}
  80. </span>
  81. </template>
  82. <template #operate="scope">
  83. <el-link
  84. size="small"
  85. :underline="false"
  86. type="primary"
  87. style="margin-right: 10px"
  88. @click="irrigationShowHistory(scope.row)"
  89. >灌溉记录</el-link
  90. >
  91. <el-link
  92. size="small"
  93. :underline="false"
  94. type="primary"
  95. style="margin-right: 10px"
  96. @click="editFarmerHandler(scope.row)"
  97. >修改</el-link>
  98. <el-link
  99. size="small"
  100. :underline="false"
  101. type="primary"
  102. style="margin-right: 10px"
  103. @click="showDetails(scope.row)"
  104. >详情</el-link>
  105. <el-link
  106. slot="reference"
  107. size="small"
  108. :underline="false"
  109. type="danger"
  110. style="margin-right: 10px"
  111. @click="deleteRow(scope.row)"
  112. >删除</el-link>
  113. </template>
  114. </b-table>
  115. </el-col>
  116. </el-card>
  117. </el-col>
  118. <added-farmers
  119. :visible.sync="associationManageShow"
  120. :treeData="treeDatas"
  121. :editFarmerData="editFarmerData"
  122. :isEdit="isEdit"
  123. :currentClickId="currentClickId"
  124. @refresh="handleSearch"
  125. @closeHandler="closeHandler"
  126. />
  127. <farmer-management
  128. :visible.sync="farmerManageShow"
  129. :detailsData="detailsData"
  130. />
  131. <irrigation-record
  132. :visible.sync="irrigationShow"
  133. :irrigationDetail="irrigationDetail"
  134. />
  135. </el-row>
  136. </template>
  137. <script>
  138. import { getToken } from "@/utils/auth";
  139. import { Message } from 'element-ui'
  140. import { getTree } from '@/api/tree.js'
  141. import { getWaterrightList } from '@/api/waterright/index.js'
  142. import { getFarmerList,deleteFarmer,getFarmerDetail } from '@/api/farmer/list.js'
  143. import BTable from '@/components/Table/index.vue';
  144. import DataReportLeft from '@/components/DataReportLeft/index.vue'
  145. import AddedFarmers from './components/addedFarmers.vue'
  146. import FarmerManagement from './components/farmerManagement.vue';
  147. import IrrigationRecord from './components/IrrigationRecord.vue';
  148. import { assign, omit } from 'lodash-es';
  149. export default {
  150. name: 'peasantHouseholdManage',
  151. components: { BTable,DataReportLeft,AddedFarmers,FarmerManagement,IrrigationRecord },
  152. data() {
  153. return {
  154. uploadUrl: process.env.VUE_APP_BASE_API + "/wpr/farmer/import", // 上传的图片服务器地址
  155. headers: {
  156. Authorization: "Bearer " + getToken()
  157. },
  158. currentData: {},
  159. visibles: false,
  160. farmerName: '',
  161. detailsData: {},
  162. treeData: [],
  163. treeDatas: [],
  164. currentClick:{},
  165. irrigationDetail: {},
  166. isEdit: false,
  167. loading: false,
  168. associationManageShow: false,
  169. farmerManageShow: false,
  170. irrigationShow: false,
  171. editFarmerData: {},
  172. farmerId: '',
  173. requestData: {},
  174. currentClickId:'',
  175. columns: [
  176. {
  177. label: '农户姓名',
  178. prop: 'farmerName',
  179. customRender: '',
  180. align: 'center'
  181. },
  182. {
  183. label: '农户身份证',
  184. prop: 'farmerIdcard',
  185. width: 200,
  186. customRender: '',
  187. align: 'center',
  188. },
  189. {
  190. label: '联系电话',
  191. prop: 'farmerPhone',
  192. customRender: '',
  193. align: 'center'
  194. },{
  195. label: '种植面积(亩)',
  196. prop: 'farmerAreasize',
  197. customRender: '',
  198. align: 'center'
  199. },{
  200. label: '水权数量(m³)',
  201. prop: 'farmerWramount',
  202. customRender: '',
  203. align: 'center'
  204. },{
  205. label: '剩余水权(m³)',
  206. prop: 'farmerWrbalance',
  207. customRender: '',
  208. align: 'center'
  209. },
  210. {
  211. label: '操作',
  212. customRender: 'operate',
  213. width: 200,
  214. align: 'center'
  215. }
  216. ],
  217. };
  218. },
  219. methods: {
  220. closeHandler() {
  221. this.editFarmerData = {}
  222. },
  223. handleAvatarSuccess(res, file) {
  224. if (res.code !== '000000') {
  225. Message.error(res?.msg)
  226. return
  227. } else {
  228. Message.success('导入成功')
  229. }
  230. },
  231. handleUploadError() {
  232. Message.error("图片插入失败");
  233. },
  234. beforeAvatarUpload() {
  235. if (this.currentData?.children?.length > 0) {
  236. Message.warning('请选择最小行政区块')
  237. return false
  238. }
  239. this.requestData = {
  240. areaId: this.currentClickId
  241. }
  242. },
  243. downloadExcel() {
  244. const href = process.env.NODE_ENV === 'production' ? "../../../wpr/static/template.xlsx" : "../../../static/template.xlsx"
  245. let a = document.createElement("a");
  246. a.href = href;
  247. a.download = "农户信息统计表.xlsx";
  248. a.style.display = "none";
  249. document.body.appendChild(a);
  250. a.click();
  251. a.remove();
  252. },
  253. editFarmerHandler(row) {
  254. this.associationManageShow = true
  255. this.isEdit = true
  256. this.editFarmerData = row
  257. },
  258. async getDetail(farmerId) {
  259. const res = await getFarmerDetail({
  260. farmerId
  261. })
  262. this.detailsData = res?.data
  263. },
  264. async getWaterrighTreetList(currentClickId) {
  265. const date = new Date()
  266. const waterrightYear = date.getFullYear()
  267. const res = await getWaterrightList({
  268. waterrightYear
  269. })
  270. this.treeDatas = res?.data ?? []
  271. },
  272. async loadData(parameter) {
  273. if(!this.currentClickId ) {
  274. const treeList = this.$store.state.tree.treeList
  275. let res = []
  276. if (treeList.code === '000000') {
  277. res = treeList
  278. } else {
  279. res = await getTree()
  280. this.$store.dispatch('tree/setTree', res)
  281. }
  282. this.treeData = res?.data
  283. let tflag = true
  284. this.treeData.forEach(t => {
  285. if (t?.cusareaName == '全部') {
  286. tflag = false
  287. }
  288. })
  289. if (tflag) {
  290. this.treeData.unshift({
  291. id: '',
  292. cusareaId: '',
  293. cusareaName: '全部'
  294. })
  295. }
  296. this.currentClick = res?.data[0]
  297. this.currentClickId = this.currentClick?.cusareaId
  298. this.currentData = this.currentClick
  299. this.getWaterrighTreetList(this.currentClickId)
  300. }
  301. const params = {
  302. farmerName: this.farmerName,
  303. areaId: this.currentClickId
  304. }
  305. const payload = omit(assign({}, parameter, params), []);
  306. return getFarmerList(payload)
  307. },
  308. setCurrentData(areaId, data) {
  309. this.currentData = data
  310. this.currentClickId = areaId
  311. this.$refs.tableRef.refresh(false);
  312. },
  313. irrigationShowHistory(row) {
  314. this.irrigationDetail = row
  315. this.irrigationShow = true
  316. },
  317. // 详情
  318. showDetails(row){
  319. this.farmerManageShow = true
  320. this.farmerId = row.farmerId
  321. this.getDetail(row.farmerId)
  322. },
  323. addAssociation() {
  324. this.isEdit = false
  325. this.editFarmerData = {}
  326. this.associationManageShow = true
  327. },
  328. handleSearch() {
  329. this.$refs.tableRef.refresh(true);
  330. },
  331. handlerChange() {
  332. this.$refs.tableRef.refresh(false);
  333. },
  334. deleteRow(row) {
  335. this.$modal
  336. .confirm(`是否确认删除农户${row.farmerName}`)
  337. .then(()=> {
  338. deleteFarmer({
  339. farmerIds: row.farmerId
  340. }).then(() => {
  341. Message({ message: "删除成功", type: 'success' });
  342. this.handlerChange()
  343. })
  344. })
  345. }
  346. }
  347. };
  348. </script>
  349. <style lang="scss" scoped>
  350. .el-row-container{
  351. height: 100%;
  352. }
  353. .elrow-main__col-top {
  354. display: flex;
  355. align-items: center;
  356. justify-content: space-between;
  357. margin-bottom: 15px;
  358. .top-left {
  359. height: 100%;
  360. display: flex;
  361. align-items: center;
  362. i {
  363. background-color: #40d5ec;
  364. height: 45%;
  365. width: 5px;
  366. margin-right: 5px;
  367. }
  368. }
  369. }
  370. .status{
  371. display: inline-block;
  372. width: 8px;
  373. height: 8px;
  374. border-radius: 50%;
  375. background: red;
  376. margin-right: 5px;
  377. }
  378. </style>