index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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. />
  126. <farmer-management
  127. :visible.sync="farmerManageShow"
  128. :detailsData="detailsData"
  129. />
  130. <irrigation-record
  131. :visible.sync="irrigationShow"
  132. :irrigationDetail="irrigationDetail"
  133. />
  134. </el-row>
  135. </template>
  136. <script>
  137. import { getToken } from "@/utils/auth";
  138. import { Message } from 'element-ui'
  139. import { getTree } from '@/api/tree.js'
  140. import { getWaterrightList } from '@/api/waterright/index.js'
  141. import { getFarmerList,deleteFarmer,getFarmerDetail } from '@/api/farmer/list.js'
  142. import BTable from '@/components/Table/index.vue';
  143. import DataReportLeft from '@/components/DataReportLeft/index.vue'
  144. import AddedFarmers from './components/addedFarmers.vue'
  145. import FarmerManagement from './components/farmerManagement.vue';
  146. import IrrigationRecord from './components/IrrigationRecord.vue';
  147. import { assign, omit } from 'lodash-es';
  148. export default {
  149. name: 'peasantHouseholdManage',
  150. components: { BTable,DataReportLeft,AddedFarmers,FarmerManagement,IrrigationRecord },
  151. data() {
  152. return {
  153. uploadUrl: process.env.VUE_APP_BASE_API + "/wpr/farmer/import", // 上传的图片服务器地址
  154. headers: {
  155. Authorization: "Bearer " + getToken()
  156. },
  157. visibles: false,
  158. farmerName: '',
  159. detailsData: {},
  160. treeData: [],
  161. treeDatas: [],
  162. currentClick:{},
  163. irrigationDetail: {},
  164. isEdit: false,
  165. loading: false,
  166. associationManageShow: false,
  167. farmerManageShow: false,
  168. irrigationShow: false,
  169. editFarmerData: {},
  170. farmerId: '',
  171. requestData: {},
  172. currentClickId:'',
  173. columns: [
  174. {
  175. label: '农户姓名',
  176. prop: 'farmerName',
  177. customRender: '',
  178. align: 'center'
  179. },
  180. {
  181. label: '农户身份证',
  182. prop: 'farmerIdcard',
  183. customRender: '',
  184. align: 'center',
  185. width: 160
  186. },
  187. {
  188. label: '联系电话',
  189. prop: 'farmerPhone',
  190. customRender: '',
  191. align: 'center'
  192. },{
  193. label: '种植面积(亩)',
  194. prop: 'farmerAreasize',
  195. customRender: '',
  196. align: 'center'
  197. },{
  198. label: '水权数量(立方)',
  199. prop: 'farmerWramount',
  200. customRender: '',
  201. align: 'center'
  202. },{
  203. label: '剩余水权(立方)',
  204. prop: 'farmerWrbalance',
  205. customRender: '',
  206. align: 'center'
  207. },
  208. {
  209. label: '操作',
  210. customRender: 'operate',
  211. width: 200,
  212. align: 'center'
  213. }
  214. ],
  215. };
  216. },
  217. methods: {
  218. handleAvatarSuccess(res, file) {
  219. if (res.code !== '000000') {
  220. Message.error(res?.msg)
  221. return
  222. } else {
  223. Message.success('导入成功')
  224. }
  225. },
  226. handleUploadError() {
  227. Message.error("图片插入失败");
  228. },
  229. beforeAvatarUpload(file) {
  230. this.requestData = {
  231. areaId: this.currentClickId
  232. }
  233. },
  234. downloadExcel() {
  235. const href = process.env.NODE_ENV === 'production' ? "../../../wpr/static/template.xlsx" : "../../../static/template.xlsx"
  236. let a = document.createElement("a");
  237. a.href = href;
  238. a.download = "农户信息统计表.xlsx";
  239. a.style.display = "none";
  240. document.body.appendChild(a);
  241. a.click();
  242. a.remove();
  243. },
  244. editFarmerHandler(row) {
  245. this.associationManageShow = true
  246. this.isEdit = true
  247. this.editFarmerData = row
  248. },
  249. async getDetail(farmerId) {
  250. const res = await getFarmerDetail({
  251. farmerId
  252. })
  253. this.detailsData = res?.data
  254. },
  255. async getWaterrighTreetList(currentClickId) {
  256. const date = new Date()
  257. const waterrightYear = date.getFullYear()
  258. const res = await getWaterrightList({
  259. waterrightYear
  260. })
  261. this.treeDatas = res?.data ?? []
  262. },
  263. async loadData(parameter) {
  264. if(!this.currentClickId ) {
  265. const treeList = this.$store.state.tree.treeList
  266. let res = []
  267. if (treeList.code === '000000') {
  268. res = treeList
  269. } else {
  270. res = await getTree()
  271. this.$store.dispatch('tree/setTree', res)
  272. }
  273. this.treeData = res?.data
  274. this.currentClick = res?.data[0]
  275. this.currentClickId = this.currentClick?.cusareaId
  276. this.getWaterrighTreetList(this.currentClickId)
  277. }
  278. const params = {
  279. farmerName: this.farmerName,
  280. areaId: this.currentClickId
  281. }
  282. const payload = omit(assign({}, parameter, params), []);
  283. return getFarmerList(payload)
  284. },
  285. setCurrentData(areaId) {
  286. this.currentClickId = areaId
  287. this.$refs.tableRef.refresh(false);
  288. },
  289. irrigationShowHistory(row) {
  290. this.irrigationDetail = row
  291. this.irrigationShow = true
  292. },
  293. // 详情
  294. showDetails(row){
  295. this.farmerManageShow = true
  296. this.farmerId = row.farmerId
  297. this.getDetail(row.farmerId)
  298. },
  299. addAssociation() {
  300. this.isEdit = false
  301. this.editFarmerData = {}
  302. this.associationManageShow = true
  303. },
  304. handleSearch() {
  305. this.$refs.tableRef.refresh(true);
  306. },
  307. handlerChange() {
  308. this.$refs.tableRef.refresh(false);
  309. },
  310. deleteRow(row) {
  311. this.$modal
  312. .confirm(`是否确认删除农户${row.farmerName}`)
  313. .then(()=> {
  314. deleteFarmer({
  315. farmerIds: row.farmerId
  316. }).then(() => {
  317. Message({ message: "删除成功", type: 'success' });
  318. this.handlerChange()
  319. })
  320. })
  321. }
  322. }
  323. };
  324. </script>
  325. <style lang="scss" scoped>
  326. .el-row-container{
  327. height: 100%;
  328. }
  329. .elrow-main__col-top {
  330. display: flex;
  331. align-items: center;
  332. justify-content: space-between;
  333. margin-bottom: 15px;
  334. .top-left {
  335. height: 100%;
  336. display: flex;
  337. align-items: center;
  338. i {
  339. background-color: #40d5ec;
  340. height: 45%;
  341. width: 5px;
  342. margin-right: 5px;
  343. }
  344. }
  345. }
  346. .status{
  347. display: inline-block;
  348. width: 8px;
  349. height: 8px;
  350. border-radius: 50%;
  351. background: red;
  352. margin-right: 5px;
  353. }
  354. </style>