index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" @submit.native.prevent>
  4. <el-form-item label="计划使用量(吨)" prop="planUsage" label-width="125px">
  5. <el-input v-model="queryParams.planUsage" placeholder="请输入计划使用量(吨)" maxlength="15"/>
  6. </el-form-item>
  7. <el-form-item label="实际使用量(吨)" prop="realityUsage" label-width="125px">
  8. <el-input v-model="queryParams.realityUsage" placeholder="请输入实际使用量(吨)" maxlength="15"/>
  9. </el-form-item>
  10. <el-form-item>
  11. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  12. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  13. </el-form-item>
  14. </el-form>
  15. <el-row :gutter="10" class="mb8">
  16. <el-col :span="1.5">
  17. <el-button
  18. type="primary"
  19. plain
  20. icon="el-icon-plus"
  21. size="mini"
  22. @click="handleAdd"
  23. v-hasPermi="['digitalagriculture:information:add']"
  24. >新增
  25. </el-button>
  26. </el-col>
  27. <el-col :span="1.5">
  28. <el-button
  29. type="success"
  30. plain
  31. icon="el-icon-edit"
  32. size="mini"
  33. :disabled="single"
  34. @click="handleUpdate"
  35. v-hasPermi="['digitalagriculture:information:edit']"
  36. >修改
  37. </el-button>
  38. </el-col>
  39. <el-col :span="1.5">
  40. <el-button
  41. type="danger"
  42. plain
  43. icon="el-icon-delete"
  44. size="mini"
  45. :disabled="multiple"
  46. @click="handleDelete"
  47. v-hasPermi="['digitalagriculture:information:remove']"
  48. >删除
  49. </el-button>
  50. </el-col>
  51. <el-col :span="1.5">
  52. <el-button
  53. type="warning"
  54. plain
  55. icon="el-icon-download"
  56. size="mini"
  57. @click="handleExport"
  58. v-hasPermi="['digitalagriculture:information:export']"
  59. >导出
  60. </el-button>
  61. </el-col>
  62. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  63. </el-row>
  64. <el-table v-loading="loading" :data="informationList" @selection-change="handleSelectionChange">
  65. <el-table-column type="selection" width="55" align="center"/>
  66. <el-table-column label="所属部门" align="center" prop="deptName"/>
  67. <el-table-column label="计划使用量(吨)" align="center" prop="planUsage"/>
  68. <el-table-column label="实际使用量(吨)" align="center" prop="realityUsage"/>
  69. <el-table-column label="创建人" align="center" prop="createName" />
  70. <el-table-column label="创建时间" align="center" prop="createTime" />
  71. <el-table-column label="修改人" align="center" prop="updateName" />
  72. <el-table-column label="修改时间" align="center" prop="updateTime" />
  73. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  74. <template slot-scope="scope">
  75. <el-button
  76. size="mini"
  77. type="text"
  78. icon="el-icon-edit"
  79. @click="handleUpdate(scope.row)"
  80. v-hasPermi="['digitalagriculture:information:edit']"
  81. >修改
  82. </el-button>
  83. <el-button
  84. size="mini"
  85. type="text"
  86. icon="el-icon-delete"
  87. @click="handleDelete(scope.row)"
  88. v-hasPermi="['digitalagriculture:information:remove']"
  89. >删除
  90. </el-button>
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. <pagination
  95. v-show="total>0"
  96. :total="total"
  97. :page.sync="queryParams.pageNum"
  98. :limit.sync="queryParams.pageSize"
  99. @pagination="getList"
  100. />
  101. <!-- 添加或修改农药信息对话框 -->
  102. <el-dialog :title="title" :visible.sync="open" width="500px" class="form-style">
  103. <el-form ref="form" :model="form" :rules="rules" label-width="125px">
  104. <el-form-item label="所属部门" prop="deptId" class="form-style">
  105. <!-- <Deptselector :setValue=setDataDeptId :dataDeptId="form.deptId"/>-->
  106. <treeselect v-model="form.deptId" :options="deptOptions" multiple:false :show-count="true" :noResultsText="'空'" :noOptionsText="'空'"
  107. placeholder="请选择部门" @select="hx"/>
  108. </el-form-item>
  109. <el-form-item label="计划使用量(吨)" prop="planUsage">
  110. <el-input v-model="form.planUsage" placeholder="请输入计划使用量(吨)" maxlength="15"/>
  111. </el-form-item>
  112. <el-form-item label="实际使用量(吨)" prop="realityUsage">
  113. <el-input v-model="form.realityUsage" placeholder="请输入实际使用量(吨)" maxlength="15"/>
  114. </el-form-item>
  115. <el-col :span="24">
  116. <el-form-item label="展示图片" prop="attachPaths">
  117. <DataImageUpload ref="ImageUpload" :fileType="['png', 'jpg', 'jpeg']" :value="form.attachPaths"
  118. @input="getUrl"></DataImageUpload>
  119. </el-form-item>
  120. </el-col>
  121. </el-form>
  122. <div slot="footer" class="dialog-footer">
  123. <el-button type="primary" @click="submitForm">确 定</el-button>
  124. <el-button @click="cancel">取 消</el-button>
  125. </div>
  126. </el-dialog>
  127. </div>
  128. </template>
  129. <script>
  130. import {
  131. listInformation,
  132. getInformation,
  133. delInformation,
  134. addInformation,
  135. updateInformation
  136. } from "@/api/data/digitalagriculture/information";
  137. import Deptselector from '@/views/components/deptselector';
  138. import {checkPositiveDecimal} from "@/api/rules/rules";
  139. import {format_date} from "@/views/data/common/dateExport";
  140. import { treeselect } from "@/api/system/dept";
  141. import Treeselect from '@riophae/vue-treeselect'
  142. import '@riophae/vue-treeselect/dist/vue-treeselect.css'
  143. import DataImageUpload from "@/components/ImageUpload/dataUpload.vue";
  144. export default {
  145. name: "Information",
  146. dicts: ['sys_dept_type'],
  147. components: {DataImageUpload, Treeselect, Deptselector},
  148. data() {
  149. return {
  150. // 部门名称
  151. deptName: undefined,
  152. // 部门树选项
  153. deptOptions: undefined,
  154. // 遮罩层
  155. loading: true,
  156. // 选中数组
  157. ids: [],
  158. // 非单个禁用
  159. single: true,
  160. // 非多个禁用
  161. multiple: true,
  162. // 显示搜索条件
  163. showSearch: true,
  164. // 总条数
  165. total: 0,
  166. // 农药信息表格数据
  167. informationList: [],
  168. // 弹出层标题
  169. title: "",
  170. // 是否显示弹出层
  171. open: false,
  172. // 查询参数
  173. queryParams: {
  174. pageNum: 1,
  175. pageSize: 10,
  176. deptName: null,
  177. longitude: null,
  178. latitude: null,
  179. planUsage: null,
  180. realityUsage: null
  181. },
  182. // 表单参数
  183. form: {},
  184. // 表单校验
  185. rules: {
  186. deptId: [
  187. {required: true, message: "所属部门不能为空", trigger: "change"}
  188. ],
  189. planUsage: [
  190. {validator: checkPositiveDecimal, trigger: 'blur'}
  191. ],
  192. realityUsage: [
  193. {validator: checkPositiveDecimal, trigger: 'blur'}
  194. ],
  195. }
  196. };
  197. },
  198. created() {
  199. this.getList();
  200. this.getTreeselect();
  201. },
  202. methods: {
  203. /** 上传 */
  204. getUrl(url) {
  205. this.form.attachPaths=url
  206. },
  207. /** 查询部门下拉树结构 */
  208. getTreeselect() {
  209. treeselect().then(response => {
  210. this.deptOptions = response.data;
  211. });
  212. },
  213. hx(node) {
  214. this.form.dataDeptId = node.id
  215. this.form.deptId = node.id
  216. this.form.deptName = node.label
  217. this.$refs.form.validate()
  218. },
  219. /** 查询农药信息列表 */
  220. getList() {
  221. this.loading = true;
  222. listInformation(this.queryParams).then(response => {
  223. this.informationList = response.rows;
  224. this.total = response.total;
  225. this.loading = false;
  226. });
  227. },
  228. setDataDeptId(e) {
  229. this.form.deptId = e.deptId;
  230. this.form.deptName = e.deptName;
  231. },
  232. // 取消按钮
  233. cancel() {
  234. this.open = false;
  235. this.reset();
  236. },
  237. // 表单重置
  238. reset() {
  239. this.form = {
  240. id: null,
  241. createBy: null,
  242. createName: null,
  243. createTime: null,
  244. updateBy: null,
  245. updateName: null,
  246. updateTime: null,
  247. deptId: null,
  248. deptName: null,
  249. longitude: null,
  250. latitude: null,
  251. planUsage: null,
  252. realityUsage: null
  253. };
  254. this.resetForm("form");
  255. },
  256. /** 搜索按钮操作 */
  257. handleQuery() {
  258. this.queryParams.pageNum = 1;
  259. this.getList();
  260. },
  261. /** 重置按钮操作 */
  262. resetQuery() {
  263. this.resetForm("queryForm");
  264. this.handleQuery();
  265. },
  266. // 多选框选中数据
  267. handleSelectionChange(selection) {
  268. this.ids = selection.map(item => item.id)
  269. this.single = selection.length !== 1
  270. this.multiple = !selection.length
  271. },
  272. /** 新增按钮操作 */
  273. handleAdd() {
  274. this.reset();
  275. this.open = true;
  276. this.title = "添加农药信息";
  277. },
  278. /** 修改按钮操作 */
  279. handleUpdate(row) {
  280. this.reset();
  281. const id = row.id || this.ids
  282. getInformation(id).then(response => {
  283. this.form = response.data;
  284. this.open = true;
  285. this.title = "修改农药信息";
  286. });
  287. },
  288. /** 提交按钮 */
  289. submitForm() {
  290. this.$refs["form"].validate(valid => {
  291. if (valid) {
  292. if (this.form.id != null) {
  293. updateInformation(this.form).then(response => {
  294. this.$modal.msgSuccess("修改成功");
  295. this.open = false;
  296. this.getList();
  297. });
  298. } else {
  299. addInformation(this.form).then(response => {
  300. this.$modal.msgSuccess("新增成功");
  301. this.open = false;
  302. this.getList();
  303. });
  304. }
  305. }
  306. });
  307. },
  308. /** 删除按钮操作 */
  309. handleDelete(row) {
  310. const ids = row.id || this.ids;
  311. this.$modal.confirm('是否确认删除已选择的数据项?').then(function () {
  312. return delInformation(ids);
  313. }).then(() => {
  314. this.getList();
  315. this.$modal.msgSuccess("删除成功");
  316. }).catch(() => {
  317. });
  318. },
  319. /** 导出按钮操作 */
  320. handleExport() {
  321. this.download('center-data/information/export', {
  322. ...this.queryParams
  323. }, `农药信息_${format_date(new Date())}.xlsx`)
  324. }
  325. }
  326. };
  327. </script>