index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch"
  4. @submit.native.prevent>
  5. <el-form-item label="名称" prop="plantName">
  6. <el-input
  7. v-model="queryParams.plantName"
  8. placeholder="请输入名称"
  9. clearable
  10. size="small"
  11. @keyup.enter.native="handleQuery"
  12. />
  13. </el-form-item>
  14. <el-form-item label="编号" prop="plantNumber">
  15. <el-input
  16. v-model="queryParams.plantNumber"
  17. placeholder="请输入编号"
  18. clearable
  19. size="small"
  20. @keyup.enter.native="handleQuery"
  21. />
  22. </el-form-item>
  23. <el-form-item prop="deptId">
  24. <template slot="label">
  25. <span @click="changeQueryType" v-if="queryParams.deptName === 0">本级及下级</span>
  26. <span @click="changeQueryType" v-if="queryParams.deptName === 1">只查询本级</span>
  27. </template>
  28. <treeselect v-model="queryParams.deptId" :options="deptOptions" multiple:false :show-count="true"
  29. placeholder="请选择部门" @select="hx" :noResultsText="'空'" :noOptionsText="'空'" style="width: 240px"/>
  30. <el-input v-model="queryParams.deptName" v-if="false"/>
  31. </el-form-item>
  32. <el-form-item>
  33. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  34. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  35. </el-form-item>
  36. </el-form>
  37. <el-row :gutter="10" class="mb8">
  38. <el-col :span="1.5">
  39. <el-button
  40. type="primary"
  41. plain
  42. icon="el-icon-plus"
  43. size="mini"
  44. @click="handleAdd"
  45. v-hasPermi="['forest:plant:add']"
  46. >新增
  47. </el-button>
  48. </el-col>
  49. <el-col :span="1.5">
  50. <el-button
  51. type="success"
  52. plain
  53. icon="el-icon-edit"
  54. size="mini"
  55. :disabled="single"
  56. @click="handleUpdate"
  57. v-hasPermi="['forest:plant:edit']"
  58. >修改
  59. </el-button>
  60. </el-col>
  61. <el-col :span="1.5">
  62. <el-button
  63. type="danger"
  64. plain
  65. icon="el-icon-delete"
  66. size="mini"
  67. :disabled="multiple"
  68. @click="handleDelete"
  69. v-hasPermi="['forest:plant:remove']"
  70. >删除
  71. </el-button>
  72. </el-col>
  73. <el-col :span="1.5">
  74. <el-button
  75. type="warning"
  76. plain
  77. icon="el-icon-download"
  78. size="mini"
  79. @click="handleExport"
  80. v-hasPermi="['forest:plant: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="plantList" @selection-change="handleSelectionChange">
  87. <el-table-column type="selection" width="55" align="center"/>
  88. <el-table-column label="名称" align="center" prop="plantName"/>
  89. <el-table-column label="编号" align="center" prop="plantNumber"/>
  90. <el-table-column label="植物类型" align="center" prop="plantType"/>
  91. <el-table-column label="所属部门" align="center" prop="deptName"/>
  92. <el-table-column label="创建人" align="center" prop="createName"/>
  93. <el-table-column label="创建时间" align="center" prop="createTime"/>
  94. <el-table-column label="修改人" align="center" prop="updateName"/>
  95. <el-table-column label="修改时间" align="center" prop="updateTime"/>
  96. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  97. <template slot-scope="scope">
  98. <el-button
  99. size="mini"
  100. type="text"
  101. icon="el-icon-edit"
  102. @click="handleUpdate(scope.row)"
  103. v-hasPermi="['forest:plant:edit']"
  104. >修改
  105. </el-button>
  106. <el-button
  107. size="mini"
  108. type="text"
  109. icon="el-icon-delete"
  110. @click="handleDelete(scope.row)"
  111. v-hasPermi="['forest:plant:remove']"
  112. >删除
  113. </el-button>
  114. </template>
  115. </el-table-column>
  116. </el-table>
  117. <pagination
  118. v-show="total>0"
  119. :total="total"
  120. :page.sync="queryParams.pageNum"
  121. :limit.sync="queryParams.pageSize"
  122. @pagination="getList"
  123. />
  124. <!-- 添加或修改野生植物对话框 -->
  125. <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
  126. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  127. <el-form-item label="名称" prop="plantName">
  128. <el-input v-model="form.plantName" placeholder="请输入名称" maxlength = "18"/>
  129. </el-form-item>
  130. <el-form-item label="编号" prop="plantNumber">
  131. <el-input v-model="form.plantNumber" placeholder="请输入编号" maxlength = "18"/>
  132. </el-form-item>
  133. <el-form-item label="植物类型" prop="plantType">
  134. <el-input v-model="form.plantType" placeholder="请输入植物类型" maxlength = "18"/>
  135. </el-form-item>
  136. <el-form-item label="经度" prop="longitude" @dblclick.native="showMap">
  137. <el-input v-model="form.longitude" placeholder="鼠标双击选择经纬度"/>
  138. </el-form-item>
  139. <el-form-item label="纬度" prop="latitude" @dblclick.native="showMap">
  140. <el-input v-model="form.latitude" placeholder="鼠标双击选择经纬度"/>
  141. </el-form-item>
  142. <el-form-item label="所属部门" prop="deptId">
  143. <treeselect v-model="form.deptId" :options="deptOptions" multiple:false :show-count="true"
  144. placeholder="请选择部门" @select="hx" :noResultsText="'空'" :noOptionsText="'空'"/>
  145. </el-form-item>
  146. <el-form-item label="备注" prop="remarks">
  147. <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容" maxlength="255"/>
  148. </el-form-item>
  149. </el-form>
  150. <div slot="footer" class="dialog-footer">
  151. <el-button type="primary" @click="submitForm">确 定</el-button>
  152. <el-button @click="cancel">取 消</el-button>
  153. </div>
  154. </el-dialog>
  155. </div>
  156. </template>
  157. <script>
  158. import {listPlant, getPlant, delPlant, addPlant, updatePlant} from "@/api/data/digitalforest/plant/plant";
  159. import Treeselect from "@riophae/vue-treeselect";
  160. import {treeselect} from "@/api/system/dept";
  161. import {checkLat, checkLon} from "@/api/rules/rules";
  162. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  163. import {format_date} from "@/views/data/common/dateExport";
  164. export default {
  165. name: "Plant",
  166. components: {Treeselect},
  167. data() {
  168. return {
  169. // 部门树选项
  170. deptOptions: undefined,
  171. // 遮罩层
  172. loading: true,
  173. // 选中数组
  174. ids: [],
  175. // 非单个禁用
  176. single: true,
  177. // 非多个禁用
  178. multiple: true,
  179. // 显示搜索条件
  180. showSearch: true,
  181. // 总条数
  182. total: 0,
  183. // 野生植物表格数据
  184. plantList: [],
  185. // 弹出层标题
  186. title: "",
  187. // 是否显示弹出层
  188. open: false,
  189. // 查询参数
  190. queryParams: {
  191. pageNum: 1,
  192. pageSize: 10,
  193. deptId: null,
  194. deptName: 0,
  195. createName: null,
  196. updateName: null,
  197. longitude: null,
  198. latitude: null,
  199. plantName: null,
  200. plantNumber: null,
  201. plantType: null,
  202. remarks: null
  203. },
  204. // 表单参数
  205. form: {},
  206. // 表单校验
  207. rules: {
  208. plantName: [
  209. {required: true, message: "名称不能为空", trigger: "change"}
  210. ],
  211. plantNumber: [
  212. {required: true, message: "编号不能为空", trigger: "change"}
  213. ],
  214. plantType: [
  215. {required: true, message: "植物类型不能为空", trigger: "change"}
  216. ],
  217. deptId: [
  218. {required: true, message: "所属部门不能为空", trigger: "change"},
  219. ],
  220. longitude: [
  221. {required: true, message: '经度不能为空', trigger: 'change'},
  222. {validator: checkLon, trigger: 'blur'}
  223. ],
  224. latitude: [
  225. {required: true, message: '纬度不能为空', trigger: 'change'},
  226. {validator: checkLat, trigger: 'blur'}
  227. ],
  228. }
  229. };
  230. },
  231. created() {
  232. this.getList();
  233. this.getTreeselect();
  234. },
  235. methods: {
  236. hx(node) {
  237. this.form.dataDeptId = node.id
  238. this.form.deptId = node.id
  239. this.form.deptName = node.label
  240. this.$refs.form.validateField("deptId")
  241. },
  242. showMap() {
  243. this.ISuperMapvisible = true;
  244. this.$nextTick(() => {
  245. this.$refs.ISuperMap.init(this.sign, {
  246. id: this.form.id,
  247. longitude: this.form.longitude,
  248. latitude: this.form.latitude,
  249. xiantude: this.form.longitude//this.form.longitude换成每个页面对应线或者面对应的字段
  250. })
  251. })
  252. },
  253. /** 查询野生植物列表 */
  254. getList() {
  255. this.loading = true;
  256. listPlant(this.queryParams).then(response => {
  257. this.plantList = response.rows;
  258. this.total = response.total;
  259. this.loading = false;
  260. });
  261. },
  262. // 取消按钮
  263. cancel() {
  264. this.open = false;
  265. this.reset();
  266. },
  267. // 表单重置
  268. reset() {
  269. this.form = {
  270. id: null,
  271. deptId: null,
  272. deptName: null,
  273. createBy: null,
  274. createName: null,
  275. createTime: null,
  276. updateBy: null,
  277. updateName: null,
  278. updateTime: null,
  279. longitude: null,
  280. latitude: null,
  281. plantName: null,
  282. plantNumber: null,
  283. plantType: null,
  284. remarks: null
  285. };
  286. this.resetForm("form");
  287. },
  288. showLatLng: function (lat, lng) {
  289. this.form.latitude = lat
  290. this.form.longitude = lng
  291. },
  292. setDataDeptId(e) {
  293. this.form.deptId = e.deptId
  294. this.form.deptName = e.deptName
  295. },
  296. /** 查询部门下拉树结构 */
  297. getTreeselect() {
  298. treeselect().then(response => {
  299. this.deptOptions = response.data;
  300. });
  301. },
  302. /** 搜索按钮操作 */
  303. handleQuery() {
  304. this.queryParams.pageNum = 1;
  305. this.getList();
  306. },
  307. /** 重置按钮操作 */
  308. resetQuery() {
  309. this.queryParams.deptName = 0;
  310. this.resetForm("queryForm");
  311. this.handleQuery();
  312. },
  313. // 多选框选中数据
  314. handleSelectionChange(selection) {
  315. this.ids = selection.map(item => item.id)
  316. this.single = selection.length !== 1
  317. this.multiple = !selection.length
  318. },
  319. /** 新增按钮操作 */
  320. handleAdd() {
  321. this.reset();
  322. this.open = true;
  323. this.title = "添加野生植物";
  324. },
  325. /** 修改按钮操作 */
  326. handleUpdate(row) {
  327. this.reset();
  328. const id = row.id || this.ids
  329. getPlant(id).then(response => {
  330. this.form = response.data;
  331. this.open = true;
  332. this.title = "修改野生植物";
  333. });
  334. },
  335. /** 提交按钮 */
  336. submitForm() {
  337. this.$refs["form"].validate(valid => {
  338. if (valid) {
  339. if (this.form.id != null) {
  340. updatePlant(this.form).then(response => {
  341. this.$modal.msgSuccess("修改成功");
  342. this.open = false;
  343. this.getList();
  344. });
  345. } else {
  346. addPlant(this.form).then(response => {
  347. this.$modal.msgSuccess("新增成功");
  348. this.open = false;
  349. this.getList();
  350. });
  351. }
  352. }
  353. });
  354. },
  355. /** 删除按钮操作 */
  356. handleDelete(row) {
  357. const ids = row.id || this.ids;
  358. this.$modal.confirm('是否删除选中的数据?').then(function () {
  359. return delPlant(ids);
  360. }).then(() => {
  361. this.getList();
  362. this.$modal.msgSuccess("删除成功");
  363. }).catch(() => {
  364. });
  365. },
  366. // 点击按钮修改是否只查询本级部门用户
  367. changeQueryType() {
  368. this.queryParams.deptName = this.queryParams.deptName === 0 ? 1 : 0;
  369. },
  370. /** 导出按钮操作 */
  371. handleExport() {
  372. this.download('center-data/plant/export', {
  373. ...this.queryParams
  374. }, `野生植物_${format_date(new Date())}.xlsx`)
  375. }
  376. }
  377. };
  378. </script>