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.

248 lines
8.0 KiB

5 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}}
  56. {{- if .DictType}}
  57. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
  58. <template slot-scope="scope">
  59. {{"{{"}}filterDict(scope.row.{{.FieldJson}},"{{.DictType}}"){{"}}"}}
  60. </template>
  61. </el-table-column>
  62. {{- else if eq .FieldType "bool" }}
  63. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120">
  64. <template slot-scope="scope">{{ "{{scope.row."}}{{.FieldJson}}{{"|formatBoolean}}" }}</template>
  65. </el-table-column> {{- else }}
  66. <el-table-column label="{{.FieldDesc}}" prop="{{.FieldJson}}" width="120"></el-table-column> {{ end }}
  67. {{ end }}
  68. <el-table-column label="按钮组">
  69. <template slot-scope="scope">
  70. <el-button @click="update{{.StructName}}(scope.row)" size="small" type="primary">变更</el-button>
  71. <el-popover placement="top" width="160" v-model="scope.row.visible">
  72. <p>确定要删除吗?</p>
  73. <div style="text-align: right; margin: 0">
  74. <el-button size="mini" type="text" @click="scope.row.visible = false">取消</el-button>
  75. <el-button type="primary" size="mini" @click="delete{{.StructName}}(scope.row)">确定</el-button>
  76. </div>
  77. <el-button type="danger" icon="el-icon-delete" size="mini" slot="reference">删除</el-button>
  78. </el-popover>
  79. </template>
  80. </el-table-column>
  81. </el-table>
  82. <el-pagination
  83. :current-page="page"
  84. :page-size="pageSize"
  85. :page-sizes="[10, 30, 50, 100]"
  86. :style="{float:'right',padding:'20px'}"
  87. :total="total"
  88. @current-change="handleCurrentChange"
  89. @size-change="handleSizeChange"
  90. layout="total, sizes, prev, pager, next, jumper"
  91. ></el-pagination>
  92. <el-dialog :before-close="closeDialog" :visible.sync="dialogFormVisible" title="弹窗操作">
  93. 此处请使用表单生成器生成form填充 表单默认绑定 formData 如手动修改过请自行修改key
  94. <div class="dialog-footer" slot="footer">
  95. <el-button @click="closeDialog">取 消</el-button>
  96. <el-button @click="enterDialog" type="primary">确 定</el-button>
  97. </div>
  98. </el-dialog>
  99. </div>
  100. </template>
  101. <script>
  102. import {
  103. create{{.StructName}},
  104. delete{{.StructName}},
  105. delete{{.StructName}}ByIds,
  106. update{{.StructName}},
  107. find{{.StructName}},
  108. get{{.StructName}}List
  109. } from "@/api/{{.PackageName}}"; // 此处请自行替换地址
  110. import { formatTimeToStr } from "@/utils/data";
  111. import infoList from "@/components/mixins/infoList";
  112. export default {
  113. name: "{{.StructName}}",
  114. mixins: [infoList],
  115. data() {
  116. return {
  117. listApi: get{{.StructName}}List,
  118. dialogFormVisible: false,
  119. visible: false,
  120. type: "",
  121. deleteVisible: false,
  122. multipleSelection: [],
  123. {{- range .Fields}}
  124. {{- if .DictType }}
  125. {{.DictType}}Options:[],
  126. {{ end -}}
  127. {{end -}}
  128. formData: {
  129. {{range .Fields}}{{.FieldJson}}:null,{{ end }}
  130. }
  131. };
  132. },
  133. filters: {
  134. formatDate: function(time) {
  135. if (time != null && time != "") {
  136. var date = new Date(time);
  137. return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss");
  138. } else {
  139. return "";
  140. }
  141. },
  142. formatBoolean: function(bool) {
  143. if (bool != null) {
  144. return bool ? "是" :"否";
  145. } else {
  146. return "";
  147. }
  148. }
  149. },
  150. methods: {
  151. //条件搜索前端看此方法
  152. onSubmit() {
  153. this.page = 1
  154. this.pageSize = 10
  155. {{- range .Fields}} {{- if eq .FieldType "bool" }}
  156. if (this.searchInfo.{{.FieldJson}}==""){
  157. this.searchInfo.{{.FieldJson}}=null
  158. } {{ end }} {{ end }}
  159. this.getTableData()
  160. },
  161. handleSelectionChange(val) {
  162. this.multipleSelection = val
  163. },
  164. async onDelete() {
  165. const ids = []
  166. this.multipleSelection &&
  167. this.multipleSelection.map(item => {
  168. ids.push(item.ID)
  169. })
  170. const res = await delete{{.StructName}}ByIds({ ids })
  171. if (res.code == 0) {
  172. this.$message({
  173. type: 'success',
  174. message: '删除成功'
  175. })
  176. this.deleteVisible = false
  177. this.getTableData()
  178. }
  179. },
  180. async update{{.StructName}}(row) {
  181. const res = await find{{.StructName}}({ ID: row.ID });
  182. this.type = "update";
  183. if (res.code == 0) {
  184. this.formData = res.data.re{{.Abbreviation}};
  185. this.dialogFormVisible = true;
  186. }
  187. },
  188. closeDialog() {
  189. this.dialogFormVisible = false;
  190. this.formData = {
  191. {{range .Fields}}
  192. {{.FieldJson}}:null,{{ end }}
  193. };
  194. },
  195. async delete{{.StructName}}(row) {
  196. this.visible = false;
  197. const res = await delete{{.StructName}}({ ID: row.ID });
  198. if (res.code == 0) {
  199. this.$message({
  200. type: "success",
  201. message: "删除成功"
  202. });
  203. this.getTableData();
  204. }
  205. },
  206. async enterDialog() {
  207. let res;
  208. switch (this.type) {
  209. case "create":
  210. res = await create{{.StructName}}(this.formData);
  211. break;
  212. case "update":
  213. res = await update{{.StructName}}(this.formData);
  214. break;
  215. default:
  216. res = await create{{.StructName}}(this.formData);
  217. break;
  218. }
  219. if (res.code == 0) {
  220. this.$message({
  221. type:"success",
  222. message:"创建/更改成功"
  223. })
  224. this.closeDialog();
  225. this.getTableData();
  226. }
  227. },
  228. openDialog() {
  229. this.type = "create";
  230. this.dialogFormVisible = true;
  231. }
  232. },
  233. async created() {
  234. await this.getTableData();
  235. {{- range .Fields -}}
  236. {{- if .DictType -}}
  237. await this.getDict("{{.DictType}}")
  238. {{- end -}}
  239. {{- end -}}
  240. }
  241. };
  242. </script>
  243. <style>
  244. </style>