index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <div class="app-container">
  3. <el-form
  4. :model="queryParams"
  5. ref="queryForm"
  6. :inline="true"
  7. v-show="showSearch"
  8. label-width="68px"
  9. onSubmit="return false"
  10. >
  11. <!-- <el-form-item label="家族" prop="familyId" v-if="!familyName">
  12. <el-select v-model="queryParams.familyId" placeholder="请选择家族" clearable size="small">
  13. <el-option
  14. v-for="item in familyOptions"
  15. :key="'f'+item.id"
  16. :label="item.fullName"
  17. :value="item.id"
  18. />
  19. </el-select>
  20. </el-form-item> -->
  21. <el-form-item label="家族名称" prop="familyId">
  22. <span v-if="family">{{ family.fullName }}</span>
  23. </el-form-item>
  24. <el-form-item label="园地标题" prop="title"><el-input v-model="queryParams.title" placeholder="请输入标题" clearable @keyup.enter.native="handleQuery" /></el-form-item>
  25. <el-form-item>
  26. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  27. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  28. </el-form-item>
  29. </el-form>
  30. <el-row :gutter="10" class="mb8">
  31. <el-col :span="1.5">
  32. <el-button
  33. type="primary"
  34. icon="el-icon-plus"
  35. size="mini"
  36. @click="handleAdd"
  37. v-hasPermi="['system:garden:add']"
  38. >新增</el-button>
  39. </el-col>
  40. <el-col :span="1.5">
  41. <el-button
  42. type="success"
  43. icon="el-icon-edit"
  44. size="mini"
  45. :disabled="single"
  46. @click="handleUpdate"
  47. v-hasPermi="['system:garden:edit']"
  48. >修改</el-button>
  49. </el-col>
  50. <el-col :span="1.5">
  51. <el-button
  52. type="danger"
  53. icon="el-icon-delete"
  54. size="mini"
  55. :disabled="multiple"
  56. @click="handleDelete"
  57. v-hasPermi="['system:garden:remove']"
  58. >删除</el-button>
  59. </el-col>
  60. <el-col :span="1.5">
  61. <el-button
  62. type="warning"
  63. icon="el-icon-download"
  64. size="mini"
  65. @click="handleExport"
  66. v-hasPermi="['system:garden:export']"
  67. >导出</el-button>
  68. </el-col>
  69. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  70. </el-row>
  71. <el-table v-loading="loading" :data="gardenList" @selection-change="handleSelectionChange">
  72. <el-table-column type="selection" width="55" align="center" />
  73. <el-table-column label="ID" align="center" prop="id" v-if="false"/>
  74. <el-table-column label="家族" align="center" prop="familyId" >
  75. <template slot-scope="scope">
  76. <span>{{scope.row.family.fullName}}</span>
  77. </template>
  78. </el-table-column>
  79. <el-table-column label="园地标题" align="center" prop="title" />
  80. <!-- <el-table-column label="园地内容" align="center" prop="contents" /> -->
  81. <el-table-column label="创建时间" align="center" prop="createTime" />
  82. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  83. <template slot-scope="scope">
  84. <el-button
  85. size="mini"
  86. type="text"
  87. icon="el-icon-edit"
  88. @click="handleUpdate(scope.row)"
  89. v-hasPermi="['system:garden:edit']"
  90. >修改</el-button>
  91. <el-button
  92. size="mini"
  93. type="text"
  94. icon="el-icon-delete"
  95. @click="handleDelete(scope.row)"
  96. v-hasPermi="['system:garden:remove']"
  97. >删除</el-button>
  98. </template>
  99. </el-table-column>
  100. </el-table>
  101. <pagination
  102. v-show="total>0"
  103. :total="total"
  104. :page.sync="queryParams.pageNum"
  105. :limit.sync="queryParams.pageSize"
  106. @pagination="getList"
  107. />
  108. <!-- 添加或修改家族园地对话框 -->
  109. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  110. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  111. <!-- <el-form-item label="家族" prop="familyId">
  112. <el-select v-model="form.familyId" placeholder="请选择家族">
  113. <el-option
  114. v-for="item in familyOptions"
  115. :key="'f'+item.id"
  116. :label="item.fullName"
  117. :value="item.id"
  118. />
  119. </el-select>
  120. </el-form-item> -->
  121. <el-form-item label="家族" prop="familyId">
  122. <el-tag v-model="form.familyId"><span v-if="family">{{ family.fullName }}</span></el-tag>
  123. </el-form-item>
  124. <el-form-item label="园地标题" prop="title">
  125. <el-input v-model="form.title" type="textarea" placeholder="请输入内容" />
  126. </el-form-item>
  127. <el-form-item label="园地内容" prop="contents">
  128. <editor v-model="form.contents" :min-height="192"/>
  129. </el-form-item>
  130. <el-form-item label="排序号" prop="sort">
  131. <el-input v-model="form.sort" placeholder="请输入排序号" />
  132. </el-form-item>
  133. <el-form-item label="备注" prop="remark">
  134. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  135. </el-form-item>
  136. </el-form>
  137. <div slot="footer" class="dialog-footer">
  138. <el-button type="primary" @click="submitForm">确 定</el-button>
  139. <el-button @click="cancel">取 消</el-button>
  140. </div>
  141. </el-dialog>
  142. </div>
  143. </template>
  144. <script>
  145. import { listGarden, getGarden, delGarden, addGarden, updateGarden, exportGarden } from "@/api/system/garden";
  146. import { listFamily, getFamily } from "@/api/system/family";
  147. import Editor from '@/components/Editor';
  148. export default {
  149. name: "Garden",
  150. components: { Editor },
  151. data() {
  152. var validatefamilyId = (rule, value, callback) => {
  153. if (value == '' || value<=0 || value == null || value == undefined) {
  154. callback(new Error('家族不能为空'));
  155. } else{
  156. callback();
  157. }
  158. };
  159. return {
  160. // 遮罩层
  161. loading: true,
  162. // 选中数组
  163. ids: [],
  164. // 非单个禁用
  165. single: true,
  166. // 非多个禁用
  167. multiple: true,
  168. // 显示搜索条件
  169. showSearch: true,
  170. // 总条数
  171. total: 0,
  172. // 家族园地表格数据
  173. gardenList: [],
  174. // 弹出层标题
  175. title: "",
  176. // 是否显示弹出层
  177. open: false,
  178. // 查询参数
  179. queryParams: {
  180. pageNum: 1,
  181. pageSize: 10,
  182. familyId: null,
  183. title: null,
  184. },
  185. // 表单参数
  186. form: { id: undefined },
  187. // 表单校验
  188. rules: {
  189. title: [{ required: true, message: "标题不能为空", trigger: "blur" }],
  190. familyId: [{ validator:validatefamilyId, trigger: "blur" }],
  191. },
  192. familyId:undefined,
  193. familyName:undefined,
  194. familyOptions:[],
  195. };
  196. },
  197. activated() {
  198. this.init()
  199. },
  200. mounted () {
  201. this.init();
  202. this.getFamilyOptions();
  203. },
  204. methods: {
  205. init(){
  206. this.familyId = this.$route.query.fid;
  207. if (this.familyId) {
  208. this.queryParams.familyId = this.familyId;
  209. this.getFamilyById(this.familyId);
  210. this.getList();
  211. }else{
  212. this.loading = false;
  213. }
  214. },
  215. /**获取单个家族信息 */
  216. getFamilyById(_familyId) {
  217. getFamily(_familyId).then((res) => {
  218. this.family = res.data;
  219. });
  220. },
  221. //获取家族列表
  222. getFamilyOptions(){
  223. var _params= {
  224. pageNum: 1,
  225. pageSize: 10000000,
  226. }
  227. listFamily(_params).then(res=>{
  228. if(res.code == 200){
  229. this.familyOptions = res.rows
  230. }
  231. })
  232. },
  233. /** 查询家族园地列表 */
  234. getList() {
  235. this.loading = true;
  236. const fid = this.$route.query.fid;
  237. this.queryParams.familyId = fid;
  238. listGarden(this.queryParams).then(response => {
  239. this.gardenList = response.rows;
  240. this.total = response.total;
  241. this.loading = false;
  242. });
  243. },
  244. // 取消按钮
  245. cancel() {
  246. this.open = false;
  247. this.reset();
  248. },
  249. // 表单重置
  250. reset() {
  251. this.form = {
  252. id: null,
  253. title: null,
  254. contents: null,
  255. sort: null,
  256. createBy: null,
  257. createTime: null,
  258. updateBy: null,
  259. updateTime: null,
  260. remark: null
  261. };
  262. this.resetForm("form");
  263. },
  264. /** 搜索按钮操作 */
  265. handleQuery() {
  266. this.queryParams.pageNum = 1;
  267. this.getList();
  268. },
  269. /** 重置按钮操作 */
  270. resetQuery() {
  271. this.resetForm("queryForm");
  272. this.handleQuery();
  273. },
  274. // 多选框选中数据
  275. handleSelectionChange(selection) {
  276. this.ids = selection.map(item => item.id)
  277. this.single = selection.length!==1
  278. this.multiple = !selection.length
  279. },
  280. /** 新增按钮操作 */
  281. handleAdd() {
  282. this.reset();
  283. this.open = true;
  284. this.title = "添加家族园地";
  285. this.$nextTick(()=>{
  286. this.form.familyId =this.familyId
  287. })
  288. },
  289. /** 修改按钮操作 */
  290. handleUpdate(row) {
  291. this.reset();
  292. const id = row.id || this.ids
  293. getGarden(id).then(response => {
  294. this.form = response.data;
  295. this.open = true;
  296. this.title = "修改家族园地";
  297. });
  298. },
  299. /** 提交按钮 */
  300. submitForm() {
  301. this.$refs["form"].validate(valid => {
  302. if (valid) {
  303. if (this.form.id != null) {
  304. updateGarden(this.form).then(response => {
  305. if (response.code === 200) {
  306. this.msgSuccess("修改成功");
  307. this.open = false;
  308. this.getList();
  309. }
  310. });
  311. } else {
  312. addGarden(this.form).then(response => {
  313. if (response.code === 200) {
  314. this.msgSuccess("新增成功");
  315. this.open = false;
  316. this.getList();
  317. }
  318. });
  319. }
  320. }
  321. });
  322. },
  323. /** 删除按钮操作 */
  324. handleDelete(row) {
  325. const ids = row.id || this.ids;
  326. this.$confirm('是否确认删除家族园地编号为"' + ids + '"的数据项?', "警告", {
  327. confirmButtonText: "确定",
  328. cancelButtonText: "取消",
  329. type: "warning"
  330. }).then(function() {
  331. return delGarden(ids);
  332. }).then(() => {
  333. this.getList();
  334. this.msgSuccess("删除成功");
  335. }).catch(function() {});
  336. },
  337. /** 导出按钮操作 */
  338. handleExport() {
  339. const queryParams = this.queryParams;
  340. this.$confirm('是否确认导出所有家族园地数据项?', "警告", {
  341. confirmButtonText: "确定",
  342. cancelButtonText: "取消",
  343. type: "warning"
  344. }).then(function() {
  345. return exportGarden(queryParams);
  346. }).then(response => {
  347. this.download(response.msg);
  348. }).catch(function() {});
  349. }
  350. }
  351. };
  352. </script>