index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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:events: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:events: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:events: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:events: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="eventsList" @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" width="180">
  82. <template slot-scope="scope">
  83. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  84. </template>
  85. </el-table-column>
  86. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  87. <template slot-scope="scope">
  88. <el-button
  89. size="mini"
  90. type="text"
  91. icon="el-icon-edit"
  92. @click="handleUpdate(scope.row)"
  93. v-hasPermi="['system:events:edit']"
  94. >修改</el-button>
  95. <el-button
  96. size="mini"
  97. type="text"
  98. icon="el-icon-delete"
  99. @click="handleDelete(scope.row)"
  100. v-hasPermi="['system:events:remove']"
  101. >删除</el-button>
  102. </template>
  103. </el-table-column>
  104. </el-table>
  105. <pagination
  106. v-show="total>0"
  107. :total="total"
  108. :page.sync="queryParams.pageNum"
  109. :limit.sync="queryParams.pageSize"
  110. @pagination="getList"
  111. />
  112. <!-- 添加或修改家族大事件对话框 -->
  113. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  114. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  115. <!-- <el-form-item label="家族" prop="familyId">
  116. <el-select v-model="form.familyId" placeholder="请选择家族">
  117. <el-option
  118. v-for="item in familyOptions"
  119. :key="'f'+item.id"
  120. :label="item.fullName"
  121. :value="item.id"
  122. />
  123. </el-select>
  124. </el-form-item> -->
  125. <el-form-item label="家族" prop="familyId">
  126. <el-tag v-model="form.familyId"><span v-if="family">{{ family.fullName }}</span></el-tag>
  127. </el-form-item>
  128. <el-form-item label="事件标题" prop="title">
  129. <el-input v-model="form.title" type="textarea" placeholder="请输入内容" />
  130. </el-form-item>
  131. <el-form-item label="事件内容" prop="contents">
  132. <el-input v-model="form.contents" type="textarea" placeholder="请输入内容" />
  133. </el-form-item>
  134. <el-form-item label="大事件发生日期" prop="createTime">
  135. <el-date-picker v-model="form.createTime" type="date" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期"></el-date-picker>
  136. </el-form-item>
  137. <el-form-item label="备注" prop="remark">
  138. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  139. </el-form-item>
  140. </el-form>
  141. <div slot="footer" class="dialog-footer">
  142. <el-button type="primary" @click="submitForm">确 定</el-button>
  143. <el-button @click="cancel">取 消</el-button>
  144. </div>
  145. </el-dialog>
  146. </div>
  147. </template>
  148. <script>
  149. import { listEvents, getEvents, delEvents, addEvents, updateEvents, exportEvents } from "@/api/system/events";
  150. import { listFamily, getFamily } from "@/api/system/family";
  151. export default {
  152. name: "Events",
  153. data() {
  154. var validatefamilyId = (rule, value, callback) => {
  155. if (value == '' || value<=0 || value == null || value == undefined) {
  156. callback(new Error('家族不能为空'));
  157. } else{
  158. callback();
  159. }
  160. };
  161. return {
  162. // 遮罩层
  163. loading: true,
  164. // 选中数组
  165. ids: [],
  166. // 非单个禁用
  167. single: true,
  168. // 非多个禁用
  169. multiple: true,
  170. // 显示搜索条件
  171. showSearch: true,
  172. // 总条数
  173. total: 0,
  174. // 家族大事件表格数据
  175. eventsList: [],
  176. // 弹出层标题
  177. title: "",
  178. // 是否显示弹出层
  179. open: false,
  180. // 查询参数
  181. queryParams: {
  182. pageNum: 1,
  183. pageSize: 10,
  184. familyId: null,
  185. title: null,
  186. },
  187. // 表单参数
  188. form: { id: undefined },
  189. // 表单校验
  190. rules: {
  191. title: [{ required: true, message: "标题不能为空", trigger: "blur" }],
  192. familyId: [{ validator:validatefamilyId, trigger: "blur" }],
  193. },
  194. familyId: undefined,
  195. family: undefined,
  196. familyOptions: [],
  197. };
  198. },
  199. activated() {
  200. this.init()
  201. },
  202. mounted () {
  203. this.init();
  204. this.getFamilyOptions();
  205. },
  206. methods: {
  207. init(){
  208. this.familyId = this.$route.query.fid;
  209. if (this.familyId) {
  210. this.queryParams.familyId = this.familyId;
  211. this.getFamilyById(this.familyId);
  212. this.getList();
  213. }else{
  214. this.loading = false;
  215. }
  216. },
  217. /**获取单个家族信息 */
  218. getFamilyById(_familyId) {
  219. getFamily(_familyId).then((res) => {
  220. this.family = res.data;
  221. });
  222. },
  223. //获取家族列表
  224. getFamilyOptions(){
  225. var _params= {
  226. pageNum: 1,
  227. pageSize: 10000000,
  228. }
  229. listFamily(_params).then(res=>{
  230. if(res.code == 200){
  231. this.familyOptions = res.rows
  232. }
  233. })
  234. },
  235. /** 查询家族大事件列表 */
  236. getList() {
  237. this.loading = true;
  238. const fid = this.$route.query.fid;
  239. this.queryParams.familyId = fid;
  240. listEvents(this.queryParams).then(response => {
  241. this.eventsList = response.rows;
  242. this.total = response.total;
  243. this.loading = false;
  244. });
  245. },
  246. // 取消按钮
  247. cancel() {
  248. this.open = false;
  249. this.reset();
  250. },
  251. // 表单重置
  252. reset() {
  253. this.form = {
  254. id: null,
  255. title: null,
  256. contents: null,
  257. createBy: null,
  258. createTime: null,
  259. updateBy: null,
  260. updateTime: null,
  261. remark: null
  262. };
  263. this.resetForm("form");
  264. },
  265. /** 搜索按钮操作 */
  266. handleQuery() {
  267. this.queryParams.pageNum = 1;
  268. this.getList();
  269. },
  270. /** 重置按钮操作 */
  271. resetQuery() {
  272. this.resetForm("queryForm");
  273. this.handleQuery();
  274. },
  275. // 多选框选中数据
  276. handleSelectionChange(selection) {
  277. this.ids = selection.map(item => item.id)
  278. this.single = selection.length!==1
  279. this.multiple = !selection.length
  280. },
  281. /** 新增按钮操作 */
  282. handleAdd() {
  283. this.reset();
  284. this.open = true;
  285. this.title = "添加家族大事件";
  286. this.$nextTick(()=>{
  287. this.form.familyId =this.familyId
  288. })
  289. },
  290. /** 修改按钮操作 */
  291. handleUpdate(row) {
  292. this.reset();
  293. const id = row.id || this.ids
  294. getEvents(id).then(response => {
  295. this.form = response.data;
  296. this.open = true;
  297. this.title = "修改家族大事件";
  298. });
  299. },
  300. /** 提交按钮 */
  301. submitForm() {
  302. this.$refs["form"].validate(valid => {
  303. if (valid) {
  304. if (this.form.id != null) {
  305. updateEvents(this.form).then(response => {
  306. if (response.code === 200) {
  307. this.msgSuccess("修改成功");
  308. this.open = false;
  309. this.getList();
  310. }
  311. });
  312. } else {
  313. addEvents(this.form).then(response => {
  314. if (response.code === 200) {
  315. this.msgSuccess("新增成功");
  316. this.open = false;
  317. this.getList();
  318. }
  319. });
  320. }
  321. }
  322. });
  323. },
  324. /** 删除按钮操作 */
  325. handleDelete(row) {
  326. const ids = row.id || this.ids;
  327. this.$confirm('是否确认删除家族大事件编号为"' + ids + '"的数据项?', "警告", {
  328. confirmButtonText: "确定",
  329. cancelButtonText: "取消",
  330. type: "warning"
  331. }).then(function() {
  332. return delEvents(ids);
  333. }).then(() => {
  334. this.getList();
  335. this.msgSuccess("删除成功");
  336. }).catch(function() {});
  337. },
  338. /** 导出按钮操作 */
  339. handleExport() {
  340. const queryParams = this.queryParams;
  341. this.$confirm('是否确认导出所有家族大事件数据项?', "警告", {
  342. confirmButtonText: "确定",
  343. cancelButtonText: "取消",
  344. type: "warning"
  345. }).then(function() {
  346. return exportEvents(queryParams);
  347. }).then(response => {
  348. this.download(response.msg);
  349. }).catch(function() {});
  350. }
  351. }
  352. };
  353. </script>