index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="小区名" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入小区名"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="负责工长" prop="userId">
  14. <el-select v-model="queryParams.userId" filterable placeholder="请选择负责工长" clearable size="small">
  15. <el-option v-for="item in workerList"
  16. :key="item.id"
  17. :label="item.name"
  18. :value="item.id"/>
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item label="行政区" prop="district">
  22. <el-select v-model="queryParams.district" placeholder="请选择行政区" clearable size="small">
  23. <el-option
  24. v-for="dict in dict.type.district"
  25. :key="dict.value"
  26. :label="dict.label"
  27. :value="dict.value"
  28. />
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item>
  32. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  33. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  34. </el-form-item>
  35. </el-form>
  36. <el-row :gutter="10" class="mb8">
  37. <el-col :span="1.5">
  38. <el-button
  39. type="primary"
  40. plain
  41. icon="el-icon-plus"
  42. size="mini"
  43. @click="handleAdd"
  44. v-hasPermi="['gsa:area:add']"
  45. >新增
  46. </el-button>
  47. </el-col>
  48. <el-col :span="1.5">
  49. <el-button
  50. type="success"
  51. plain
  52. icon="el-icon-edit"
  53. size="mini"
  54. :disabled="single"
  55. @click="handleUpdate"
  56. v-hasPermi="['gsa:area:edit']"
  57. >修改
  58. </el-button>
  59. </el-col>
  60. <el-col :span="1.5">
  61. <el-button
  62. type="danger"
  63. plain
  64. icon="el-icon-delete"
  65. size="mini"
  66. :disabled="multiple"
  67. @click="handleDelete"
  68. v-hasPermi="['gsa:area:remove']"
  69. >删除
  70. </el-button>
  71. </el-col>
  72. <el-col :span="1.5">
  73. <el-button
  74. type="warning"
  75. plain
  76. icon="el-icon-download"
  77. size="mini"
  78. :loading="exportLoading"
  79. @click="handleExport"
  80. v-hasPermi="['gsa:area:export']"
  81. >导出
  82. </el-button>
  83. </el-col>
  84. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  85. </el-row>
  86. <el-table v-loading="loading" :data="areaList" @selection-change="handleSelectionChange">
  87. <el-table-column type="selection" width="55" align="center"/>
  88. <el-table-column label="主键id" align="center" prop="id" v-if="true"/>
  89. <el-table-column label="小区名" align="center" prop="name"/>
  90. <el-table-column label="负责工长" align="center" prop="userName">
  91. <!-- <template slot-scope="scope">-->
  92. <!-- {{ getUserName(scope.row.userId) }}-->
  93. <!-- </template>-->
  94. </el-table-column>
  95. <el-table-column label="是否释放" align="center" prop="releaseIs">
  96. <template slot-scope="scope">
  97. <dict-tag :options="dict.type.release_status" :value="scope.row.releaseIs"/>
  98. </template>
  99. </el-table-column>
  100. <el-table-column label="释放人" align="center" prop="releaseBy"/>
  101. <el-table-column label="行政区" align="center" prop="district">
  102. <template slot-scope="scope">
  103. <dict-tag :options="dict.type.district" :value="scope.row.district"/>
  104. </template>
  105. </el-table-column>
  106. <el-table-column label="小区规模" align="center" prop="areaSize"/>
  107. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  108. <template slot-scope="scope">
  109. <el-button
  110. size="mini"
  111. type="text"
  112. icon="el-icon-edit"
  113. @click="handleUpdate(scope.row)"
  114. v-hasPermi="['gsa:area:edit']"
  115. >修改
  116. </el-button>
  117. <el-button
  118. size="mini"
  119. type="text"
  120. icon="el-icon-edit"
  121. @click="handleRelease(scope.row)"
  122. v-hasPermi="['gsa:area:edit']"
  123. >释放
  124. </el-button>
  125. <el-button
  126. size="mini"
  127. type="text"
  128. icon="el-icon-delete"
  129. @click="handleDelete(scope.row)"
  130. v-hasPermi="['gsa:area:remove']"
  131. >删除
  132. </el-button>
  133. </template>
  134. </el-table-column>
  135. </el-table>
  136. <pagination
  137. v-show="total>0"
  138. :total="total"
  139. :page.sync="queryParams.pageNum"
  140. :limit.sync="queryParams.pageSize"
  141. @pagination="getList"
  142. />
  143. <!-- 添加或修改小区对话框 -->
  144. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  145. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  146. <el-form-item label="小区名" prop="name">
  147. <el-input v-model="form.name" placeholder="请输入小区名"/>
  148. </el-form-item>
  149. <el-form-item label="负责工长" prop="userIds">
  150. <el-select v-model="userIds" multiple filterable placeholder="请选择负责工长" style="width: 100%">
  151. <el-option v-for="(item,index) in workerList"
  152. :key="index"
  153. :label="item.name"
  154. :value="item.id"/>
  155. </el-select>
  156. </el-form-item>
  157. <el-form-item label="行政区" prop="district">
  158. <el-select v-model="form.district" placeholder="请选择行政区" style="width: 100%">
  159. <el-option
  160. v-for="dict in dict.type.district"
  161. :key="dict.value"
  162. :label="dict.label"
  163. :value="dict.value"
  164. ></el-option>
  165. </el-select>
  166. </el-form-item>
  167. <el-form-item label="小区规模" prop="areaSize">
  168. <el-input-number v-model="form.areaSize" :min="1" label="请输入小区规模" style="width: 100%"/>
  169. </el-form-item>
  170. <el-form-item label="照片" prop="photoList">
  171. <imageUpload v-model="form.photoList"/>
  172. </el-form-item>
  173. </el-form>
  174. <div slot="footer" class="dialog-footer">
  175. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  176. <el-button @click="cancel">取 消</el-button>
  177. </div>
  178. </el-dialog>
  179. </div>
  180. </template>
  181. <script>
  182. import {listArea, getArea, delArea, addArea, updateArea, releaseIs} from "@/api/gas/area";
  183. import {getWorker} from "@/api/gas/user";
  184. import el from "element-ui/src/locale/lang/el";
  185. export default {
  186. name: "Area",
  187. dicts: ['release_status', 'district', 'district'],
  188. data() {
  189. return {
  190. // 按钮loading
  191. buttonLoading: false,
  192. // 遮罩层
  193. loading: true,
  194. // 导出遮罩层
  195. exportLoading: false,
  196. // 选中数组
  197. ids: [],
  198. userIds: [],
  199. // 非单个禁用
  200. single: true,
  201. // 非多个禁用
  202. multiple: true,
  203. // 显示搜索条件
  204. showSearch: true,
  205. // 总条数
  206. total: 0,
  207. // 小区表格数据
  208. areaList: [],
  209. // 弹出层标题
  210. title: "",
  211. // 是否显示弹出层
  212. open: false,
  213. // 查询参数
  214. queryParams: {
  215. pageNum: 1,
  216. pageSize: 10,
  217. name: undefined,
  218. userId: undefined,
  219. district: undefined,
  220. },
  221. // 表单参数
  222. form: {},
  223. // 表单校验
  224. rules: {
  225. name: [
  226. {required: true, message: "小区名不能为空", trigger: "blur"}
  227. ],
  228. userIds: [
  229. {required: false, message: "负责工长不能为空", trigger: "change"}
  230. ],
  231. releaseIs: [
  232. {required: true, message: "是否释放不能为空", trigger: "change"}
  233. ],
  234. district: [
  235. {required: true, message: "行政区不能为空", trigger: "change"}
  236. ],
  237. },
  238. workerList: []
  239. };
  240. },
  241. created() {
  242. this.getWorkerList();
  243. this.getList();
  244. },
  245. methods: {
  246. //释放
  247. handleRelease(row) {
  248. this.$modal.confirm('请确认照片是否下载!释放过程不可逆!是否释放?').then(() => {
  249. this.loading = true
  250. return releaseIs(row.id)
  251. }).then(() => {
  252. this.loading = false
  253. this.getList()
  254. this.getArea()
  255. this.$modal.msgSuccess('释放成功')
  256. }).finally(() => {
  257. this.loading = false
  258. })
  259. },
  260. getUserName(userId) {
  261. let name = ''
  262. if (userId == undefined || userId == null || userId == '') {
  263. return ''
  264. }
  265. for (let i = 0; i < userId.split(",").length; i++) {
  266. if (i === 0) name = this.workerList.filter(item => item.id == userId.split(",")[i])[0].name
  267. else name = name + "," + this.workerList.filter(item => item.id == userId.split(",")[i])[0].name
  268. }
  269. return name
  270. },
  271. getWorkerList() {
  272. getWorker().then(req => {
  273. this.workerList = req.data
  274. })
  275. },
  276. /** 查询小区列表 */
  277. getList() {
  278. this.loading = true;
  279. if (this.queryParams.userId == '') {
  280. this.queryParams.userId = undefined
  281. }
  282. if (this.queryParams.userId != undefined)
  283. this.queryParams.userId = this.queryParams.userId + ""
  284. listArea(this.queryParams).then(response => {
  285. this.areaList = []
  286. this.areaList = response.rows;
  287. this.total = response.total;
  288. this.loading = false;
  289. });
  290. if (this.queryParams.userId != undefined)
  291. this.queryParams.userId = this.queryParams.userId * 1
  292. },
  293. // 取消按钮
  294. cancel() {
  295. this.open = false;
  296. this.reset();
  297. },
  298. // 表单重置
  299. reset() {
  300. this.userIds = []
  301. this.form = {
  302. id: undefined,
  303. name: undefined,
  304. userId: undefined,
  305. userIds: [],
  306. releaseIs: undefined,
  307. releaseBy: undefined,
  308. district: undefined,
  309. calculateDistrictId: undefined,
  310. areaSize: 1,
  311. affiliatedPackage: undefined,
  312. delFlag: undefined,
  313. createBy: undefined,
  314. createTime: undefined,
  315. updateBy: undefined,
  316. updateTime: undefined,
  317. photoList: ""
  318. };
  319. this.resetForm("form");
  320. },
  321. /** 搜索按钮操作 */
  322. handleQuery() {
  323. this.queryParams.pageNum = 1;
  324. this.getList();
  325. },
  326. /** 重置按钮操作 */
  327. resetQuery() {
  328. this.resetForm("queryForm");
  329. this.handleQuery();
  330. },
  331. // 多选框选中数据
  332. handleSelectionChange(selection) {
  333. this.ids = selection.map(item => item.id)
  334. this.single = selection.length !== 1
  335. this.multiple = !selection.length
  336. },
  337. /** 新增按钮操作 */
  338. handleAdd() {
  339. this.reset();
  340. this.open = true;
  341. this.title = "添加小区";
  342. },
  343. /** 修改按钮操作 */
  344. handleUpdate(row) {
  345. this.loading = true;
  346. this.reset();
  347. const id = row.id || this.ids
  348. getArea(id).then(response => {
  349. this.loading = false;
  350. this.form = response.data;
  351. this.userIds = response.data.userId == '' || response.data.userId == null ? [] : response.data.userId.split(",").map(Number);
  352. this.form.userId = response.data.userId;
  353. this.open = true;
  354. this.title = "修改小区";
  355. });
  356. },
  357. /** 提交按钮 */
  358. submitForm() {
  359. this.$refs["form"].validate(valid => {
  360. if (valid) {
  361. this.buttonLoading = true;
  362. this.form.userId = this.userIds.join(",")
  363. if (this.form.releaseIs === 'Y') {
  364. this.form.releaseBy = this.$store.state.user.userId
  365. }
  366. if (this.form.id != null) {
  367. if (typeof this.form.photoList === 'string') {
  368. this.form.photoList = this.form.photoList.split(',')
  369. }
  370. updateArea(this.form).then(response => {
  371. this.$modal.msgSuccess("修改成功");
  372. this.open = false;
  373. this.getList();
  374. }).finally(() => {
  375. this.buttonLoading = false;
  376. });
  377. } else {
  378. this.form.photoList = this.form.photoList.split(',')
  379. addArea(this.form).then(response => {
  380. this.$modal.msgSuccess("新增成功");
  381. this.open = false;
  382. this.getList();
  383. }).finally(() => {
  384. this.buttonLoading = false;
  385. });
  386. }
  387. }
  388. });
  389. },
  390. /** 删除按钮操作 */
  391. handleDelete(row) {
  392. const ids = row.id || this.ids;
  393. this.$modal.confirm('是否确认删除小区编号为"' + ids + '"的数据项?').then(() => {
  394. this.loading = true;
  395. return delArea(ids);
  396. }).then(() => {
  397. this.loading = false;
  398. this.getList();
  399. this.$modal.msgSuccess("删除成功");
  400. }).finally(() => {
  401. this.loading = false;
  402. });
  403. },
  404. /** 导出按钮操作 */
  405. handleExport() {
  406. this.$download.excel('/gas/area/export', this.queryParams);
  407. }
  408. }
  409. };
  410. </script>