list.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true">
  6. <el-form-item label="工程专业列表">
  7. </el-form-item>
  8. <el-form-item >
  9. <div>
  10. <el-input style="float:left;" v-model="keyword" class="input-with-select" placeholder="请输入专业名称关键字" clearable="true">
  11. <el-button slot="append" @click="searchList" icon="el-icon-search"></el-button>
  12. </el-input>
  13. </div>
  14. </el-form-item>
  15. <el-form-item style="float:right;">
  16. <el-link type="primary" :underline="false" @click="handleAdd(-1,null)">新增专业</el-link>
  17. </el-form-item>
  18. </el-form>
  19. </el-col>
  20. <!--列表-->
  21. <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;">
  22. <el-table-column type="index" width="60">
  23. <template slot-scope="scope" >
  24. {{scope.$index+1+(page-1)*size}}
  25. </template>
  26. </el-table-column>
  27. <el-table-column prop="name" label="专业名称" >
  28. </el-table-column>
  29. <el-table-column label="操作" width="150">
  30. <template slot-scope="scope">
  31. <el-button size="mini" type="primary" @click="handleAdd(scope.$index, scope.row)">编辑</el-button>
  32. <el-button size="mini" @click="deletePro(scope.$index, scope.row)">删除</el-button>
  33. </template>
  34. </el-table-column>
  35. </el-table>
  36. <!--工具条-->
  37. <el-col :span="24" class="toolbar">
  38. <el-pagination
  39. @size-change="handleSizeChange"
  40. @current-change="handleCurrentChange"
  41. :page-sizes="[20 , 50 , 80 , 100]"
  42. :page-size="20"
  43. layout="total, sizes, prev, pager, next"
  44. :total="total"
  45. style="float:right;"
  46. ></el-pagination>
  47. </el-col>
  48. <!--新增界面-->
  49. <el-dialog :title="title" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass="customWidth" width="600px">
  50. <el-form ref="form1" :model="addForm" :rules="rules" label-width="120px">
  51. <el-form-item label="专业名称" prop="name">
  52. <el-input v-model="addForm.name" :max="20" placeholder="请输入专业名称" clearable></el-input>
  53. </el-form-item>
  54. </el-form>
  55. <div slot="footer" class="dialog-footer;">
  56. <el-button @click.native="addFormVisible = false">取消</el-button>
  57. <el-button type="primary" @click="submitInsert" :loading="addLoading">提交</el-button>
  58. </div>
  59. </el-dialog>
  60. </section>
  61. </template>
  62. <style scoped>
  63. .input-with-select .el-input-group__prepend {
  64. background-color: #fff;
  65. }
  66. .line {
  67. padding:10px;
  68. }
  69. .line span{
  70. font-size:15px;
  71. }
  72. .line span:nth-child(even){
  73. float:right;
  74. }
  75. </style>
  76. <script>
  77. import util from "../../common/js/util";
  78. export default {
  79. data() {
  80. return {
  81. keyword:null,
  82. user: JSON.parse(sessionStorage.getItem("user")),
  83. userDetailVisible: false,
  84. userDetail:{},
  85. date: new Date(),
  86. users: [],
  87. participator:[],
  88. tableHeight: 0,
  89. listLoading: false,
  90. total: 0,
  91. page: 1,
  92. size: 20,
  93. list: [],
  94. addFormVisible: false,
  95. addLoading: false,
  96. addUp: 0, // 合计
  97. title: "",
  98. addForm: {
  99. name: ''
  100. },
  101. rules: {
  102. name: [{ required: true, message: "请输入专业名称", trigger: "blur" }],
  103. }
  104. };
  105. },
  106. // 过滤器
  107. filters: {
  108. numberToCurrency(value) {
  109. if (!value) return '0.00'
  110. // 将数值截取,保留两位小数
  111. value = value.toFixed(2)
  112. // 获取整数部分
  113. const intPart = Math.trunc(value)
  114. // 整数部分处理,增加,
  115. const intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
  116. // 预定义小数部分
  117. let floatPart = '.00'
  118. // 将数值截取为小数部分和整数部分
  119. const valueArray = value.toString().split('.')
  120. if (valueArray.length === 2) { // 有小数部分
  121. floatPart = valueArray[1].toString() // 取得小数部分
  122. return intPartFormat + '.' + floatPart
  123. }
  124. return intPartFormat + floatPart
  125. }
  126. },
  127. methods: {
  128. number(){  
  129. //     this.addForm.budget = this.addForm.budget.replace(/[^\.\d]/g,'');
  130. // this.addForm.budget = this.addForm.budget.replace('.','');
  131.   },
  132. searchList() {
  133. this.page = 1;
  134. this.getList();
  135. },
  136. //分页
  137. handleCurrentChange(val) {
  138. this.page = val;
  139. this.getList();
  140. },
  141. handleSizeChange(val) {
  142. this.size = val;
  143. this.getList();
  144. },
  145. //获取项目列表
  146. getList() {
  147. this.listLoading = true;
  148. this.http.post('/profession/list', {
  149. pageIndex: this.page,
  150. pageSize: this.size,
  151. keyword:this.keyword
  152. },
  153. res => {
  154. this.listLoading = false;
  155. if (res.code == "ok") {
  156. var list = res.data.records;
  157. this.list = list;
  158. this.total = res.data.total;
  159. } else {
  160. this.$message({
  161. message: res.msg,
  162. type: "error"
  163. });
  164. }
  165. },
  166. error => {
  167. this.listLoading = false;
  168. this.$message({
  169. message: error,
  170. type: "error"
  171. });
  172. });
  173. },
  174. //显示新增界面
  175. handleAdd(i, item) {
  176. if(i == -1) {
  177. this.title = "新增专业";
  178. this.addForm = {
  179. }
  180. } else {
  181. this.title = "修改专业";
  182. this.addForm = JSON.parse(JSON.stringify(item));
  183. }
  184. this.addFormVisible = true;
  185. },
  186. submitInsert() {
  187. this.$refs.form1.validate(valid => {
  188. if (valid) {
  189. this.addLoading = true;
  190. this.http.post('/profession/addOrMod', this.addForm,
  191. res => {
  192. this.addLoading = false;
  193. if (res.code == "ok") {
  194. this.addFormVisible = false;
  195. this.getList();
  196. } else {
  197. this.$message({
  198. message: res.msg,
  199. type: "error"
  200. });
  201. }
  202. },
  203. error => {
  204. this.addLoading = false;
  205. this.$message({
  206. message: error,
  207. type: "error"
  208. });
  209. });
  210. }
  211. });
  212. },
  213. // 删除
  214. deletePro(i, item) {
  215. this.$confirm("确定要专业" + item.customerName + "吗?","删除专业", {
  216. confirmButtonText: "确定",
  217. cancelButtonText: "取消",
  218. type: "warning"
  219. })
  220. .then(() => {
  221. this.listLoading = true;
  222. this.http.post('/profession/delete',{
  223. id: item.id
  224. },
  225. res => {
  226. this.listLoading = false;
  227. if (res.code == "ok") {
  228. this.$message({
  229. message: "删除成功",
  230. type: "success"
  231. });
  232. this.getList();
  233. } else {
  234. this.$message({
  235. message: res.msg,
  236. type: "error"
  237. });
  238. }
  239. },
  240. error => {
  241. this.listLoading = false;
  242. this.$message({
  243. message: error,
  244. type: "error"
  245. });
  246. }
  247. );
  248. })
  249. .catch(() => {});
  250. },
  251. },
  252. created() {
  253. let height = window.innerHeight;
  254. this.tableHeight = height - 195;
  255. const that = this;
  256. window.onresize = function temp() {
  257. that.tableHeight = window.innerHeight - 195;
  258. };
  259. },
  260. mounted() {
  261. this.getList();
  262. }
  263. };
  264. </script>
  265. <style lang="scss" scoped>
  266. .rg_span{
  267. display: inline-block;
  268. }
  269. .rg_span span {
  270. text-align: right;
  271. box-sizing: border-box;
  272. padding-right: 10px;
  273. }
  274. .el-dialog__title {
  275. display: inline-table;
  276. margin-top: 20px;
  277. }
  278. </style>