You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

231 lines
7.5 KiB

4 years ago
  1. <template>
  2. <div>
  3. <div class="search-term">
  4. <el-form :inline="true" :model="searchInfo" class="demo-form-inline">
  5. {{- range .Fields}} {{- if .FieldSearchType}} {{- if eq .FieldType "bool" }}
  6. <el-form-item label="{{.FieldDesc}}" prop="{{.FieldJson}}">
  7. <el-select v-model="searchInfo.{{.FieldJson}}" clear placeholder="请选择">
  8. <el-option
  9. key="true"
  10. label="是"
  11. value="true">
  12. </el-option>
  13. <el-option
  14. key="false"
  15. label="否"
  16. value="false">
  17. </el-option>
  18. </el-select>
  19. </el-form-item>
  20. {{- else }}
  21. <el-form-item label="{{.FieldDesc}}">
  22. <el-input placeholder="搜索条件" v-model="searchInfo.{{.FieldJson}}"></el-input>
  23. </el-form-item> {{ end }} {{ end }} {{ end }}
  24. <el-form-item>
  25. <el-button @click="onSubmit" type="primary">查询</el-button>
  26. </el-form-item>
  27. <el-form-item>
  28. <el-button @click="openDialog" type="primary">新增{{.Description}}</el-button>
  29. </el-form-item>
  30. <el-form-item>
  31. <el-popover placement="top" v-model="deleteVisible" width="160">
  32. <p>确定要删除吗?</p>
  33. <div style="text-align: right; margin: 0">
  34. <el-button @click="deleteVisible = false" size="mini" type="text">取消</el-button>
  35. <el-button @click="onDelete" size="mini" type="primary">确定</el-button>
  36. </div>
  37. <el-button icon="el-icon-delete" size="mini" slot="reference" type="danger">批量删除</el-button>
  38. </el-popover>
  39. </el-form-item>
  40. </el-form>
  41. </div>
  42. <el-table
  43. :data="tableData"
  44. @selection-change="handleSelectionChange"
  45. border
  46. ref="multipleTable"
  47. stripe
  48. style="width: 100%"
  49. tooltip-effect="dark"
  50. >
  51. <el-table-column type="selection" width="55"></el-table-column>
  52. <el-table-column label="日期" width="180">
  53. <template slot-scope="scope">{{ "{{scope.row.CreatedAt|formatDate}}" }}</template>
  54. </el-table-column>
  55. {{range .Fields}} {{- if eq .FieldType "bool" }}
  56. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
  57. <template slot-scope="scope">{{ "{{scope.row."}}{{.FieldJson}}{{"|formatBoolean}}" }}</template>
  58. </el-table-column> {{- else }}
  59. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120"></el-table-column> {{ end }}
  60. {{ end }}
  61. <el-table-column label="按钮组">
  62. <template slot-scope="scope">
  63. <el-button @click="update{{.StructName}}(scope.row)" size="small" type="primary">变更</el-button>
  64. <el-popover placement="top" width="160" v-model="scope.row.visible">
  65. <p>确定要删除吗?</p>
  66. <div style="text-align: right; margin: 0">
  67. <el-button size="mini" type="text" @click="scope.row.visible = false">取消</el-button>
  68. <el-button type="primary" size="mini" @click="delete{{.StructName}}(scope.row)">确定</el-button>
  69. </div>
  70. <el-button type="danger" icon="el-icon-delete" size="mini" slot="reference">删除</el-button>
  71. </el-popover>
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. <el-pagination
  76. :current-page="page"
  77. :page-size="pageSize"
  78. :page-sizes="[10, 30, 50, 100]"
  79. :style="{float:'right',padding:'20px'}"
  80. :total="total"
  81. @current-change="handleCurrentChange"
  82. @size-change="handleSizeChange"
  83. layout="total, sizes, prev, pager, next, jumper"
  84. ></el-pagination>
  85. <el-dialog :before-close="closeDialog" :visible.sync="dialogFormVisible" title="弹窗操作">
  86. 此处请使用表单生成器生成form填充 表单默认绑定 formData 如手动修改过请自行修改key
  87. <div class="dialog-footer" slot="footer">
  88. <el-button @click="closeDialog">取 消</el-button>
  89. <el-button @click="enterDialog" type="primary">确 定</el-button>
  90. </div>
  91. </el-dialog>
  92. </div>
  93. </template>
  94. <script>
  95. import {
  96. create{{.StructName}},
  97. delete{{.StructName}},
  98. delete{{.StructName}}ByIds,
  99. update{{.StructName}},
  100. find{{.StructName}},
  101. get{{.StructName}}List
  102. } from "@/api/{{.PackageName}}"; // 此处请自行替换地址
  103. import { formatTimeToStr } from "@/utils/data";
  104. import infoList from "@/components/mixins/infoList";
  105. export default {
  106. name: "{{.StructName}}",
  107. mixins: [infoList],
  108. data() {
  109. return {
  110. listApi: get{{.StructName}}List,
  111. dialogFormVisible: false,
  112. visible: false,
  113. type: "",
  114. deleteVisible: false,
  115. multipleSelection: [],
  116. formData: {
  117. {{range .Fields}}{{.FieldJson}}:null,{{ end }}
  118. }
  119. };
  120. },
  121. filters: {
  122. formatDate: function(time) {
  123. if (time != null && time != "") {
  124. var date = new Date(time);
  125. return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");
  126. } else {
  127. return "";
  128. }
  129. },
  130. formatBoolean: function(bool) {
  131. if (bool != null) {
  132. return bool ? "是" :"否";
  133. } else {
  134. return "";
  135. }
  136. }
  137. },
  138. methods: {
  139. //条件搜索前端看此方法
  140. onSubmit() {
  141. this.page = 1
  142. this.pageSize = 10
  143. {{- range .Fields}} {{- if eq .FieldType "bool" }}
  144. if (this.searchInfo.{{.FieldJson}}==""){
  145. this.searchInfo.{{.FieldJson}}=null
  146. } {{ end }} {{ end }}
  147. this.getTableData()
  148. },
  149. handleSelectionChange(val) {
  150. this.multipleSelection = val
  151. },
  152. async onDelete() {
  153. const ids = []
  154. this.multipleSelection &&
  155. this.multipleSelection.map(item => {
  156. ids.push(item.ID)
  157. })
  158. const res = await delete{{.StructName}}ByIds({ ids })
  159. if (res.code == 0) {
  160. this.$message({
  161. type: 'success',
  162. message: '删除成功'
  163. })
  164. this.deleteVisible = false
  165. this.getTableData()
  166. }
  167. },
  168. async update{{.StructName}}(row) {
  169. const res = await find{{.StructName}}({ ID: row.ID });
  170. this.type = "update";
  171. if (res.code == 0) {
  172. this.formData = res.data.re{{.Abbreviation}};
  173. this.dialogFormVisible = true;
  174. }
  175. },
  176. closeDialog() {
  177. this.dialogFormVisible = false;
  178. this.formData = {
  179. {{range .Fields}}
  180. {{.FieldJson}}:null,{{ end }}
  181. };
  182. },
  183. async delete{{.StructName}}(row) {
  184. this.visible = false;
  185. const res = await delete{{.StructName}}({ ID: row.ID });
  186. if (res.code == 0) {
  187. this.$message({
  188. type: "success",
  189. message: "删除成功"
  190. });
  191. this.getTableData();
  192. }
  193. },
  194. async enterDialog() {
  195. let res;
  196. switch (this.type) {
  197. case "create":
  198. res = await create{{.StructName}}(this.formData);
  199. break;
  200. case "update":
  201. res = await update{{.StructName}}(this.formData);
  202. break;
  203. default:
  204. res = await create{{.StructName}}(this.formData);
  205. break;
  206. }
  207. if (res.code == 0) {
  208. this.$message({
  209. type:"success",
  210. message:"创建/更改成功"
  211. })
  212. this.closeDialog();
  213. this.getTableData();
  214. }
  215. },
  216. openDialog() {
  217. this.type = "create";
  218. this.dialogFormVisible = true;
  219. }
  220. },
  221. created() {
  222. this.getTableData();
  223. }
  224. };
  225. </script>
  226. <style>
  227. </style>