index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="级别名称" prop="name">
  5. <el-input
  6. v-model="queryParams.name"
  7. placeholder="请输入级别名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item>
  14. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  15. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-row :gutter="10" class="mb8">
  19. <el-col :span="1.5">
  20. <el-button
  21. type="primary"
  22. icon="el-icon-plus"
  23. size="mini"
  24. @click="handleAdd"
  25. v-hasPermi="['crm:customerLevel:add']"
  26. >新增</el-button>
  27. </el-col>
  28. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  29. </el-row>
  30. <el-table border height="500" v-loading="loading" :data="customerLevelList">
  31. <el-table-column label="ID" align="center" prop="id" />
  32. <el-table-column label="级别名称" align="center" prop="name" />
  33. <el-table-column label="状态" align="center" prop="status">
  34. <template slot-scope="scope">
  35. <el-tag :type="getStatusType(scope.row.status)">{{getStatusLabel(scope.row.status)}}</el-tag>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="序号" align="center" prop="sort" />
  39. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  40. <template slot-scope="scope">
  41. <el-button
  42. size="mini"
  43. type="text"
  44. icon="el-icon-edit"
  45. @click="handleUpdate(scope.row)"
  46. v-hasPermi="['crm:customerLevel:edit']"
  47. >修改</el-button>
  48. <el-button
  49. size="mini"
  50. type="text"
  51. icon="el-icon-delete"
  52. @click="handleDelete(scope.row)"
  53. v-hasPermi="['crm:customerLevel:remove']"
  54. >删除</el-button>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. <pagination
  59. v-show="total>0"
  60. :total="total"
  61. :page-sizes="pageSizes"
  62. :page.sync="queryParams.pageNum"
  63. :limit.sync="queryParams.pageSize"
  64. @pagination="getList"
  65. />
  66. <el-dialog :title="customLevelDialog.title" :visible.sync="customLevelDialog.open" width="500px" append-to-body>
  67. <el-form ref="form" :model="customLevelDialog.form" :rules="customLevelDialog.rules" label-width="80px">
  68. <el-form-item label="级别名称" prop="name">
  69. <el-input v-model="customLevelDialog.form.name" placeholder="请输入级别名称" />
  70. </el-form-item>
  71. <el-form-item label="状态" prop="status">
  72. <el-radio v-model="customLevelDialog.form.status" label="0">正常</el-radio>
  73. <el-radio v-model="customLevelDialog.form.status" label="1">停用</el-radio>
  74. </el-form-item>
  75. <el-form-item label="排序" prop="sort">
  76. <el-input-number v-model="customLevelDialog.form.sort" placeholder="请输入排序" />
  77. </el-form-item>
  78. </el-form>
  79. <div slot="footer" class="dialog-footer">
  80. <el-button type="primary" @click="submitForm">确 定</el-button>
  81. <el-button @click="cancel">取 消</el-button>
  82. </div>
  83. </el-dialog>
  84. </div>
  85. </template>
  86. <script>
  87. import {add, del, get, edit, list} from '@/api/crm/customerLevel'
  88. const initForm = {
  89. id: null,
  90. name: null,
  91. status: '0',
  92. sort: 0
  93. }
  94. const statusOptions = [
  95. {
  96. dictLabel: "正常",
  97. dictValue: 0,
  98. type: 'success'
  99. },
  100. {
  101. dictLabel: "停用",
  102. dictValue: 1,
  103. type: 'danger'
  104. }
  105. ]
  106. export default {
  107. name: "index",
  108. data() {
  109. return {
  110. queryParams: {
  111. pageNum: 1,
  112. pageSize: 10,
  113. name: null
  114. },
  115. loading: false,
  116. customerLevelList: [],
  117. statusOptions: statusOptions,
  118. total: 0,
  119. pageSizes:[10, 20, 30, 50, 100],
  120. showSearch: true,
  121. customLevelDialog: {
  122. title: "新增",
  123. open: false,
  124. form: initForm,
  125. rules: {
  126. name: [
  127. { required: true, message: "级别名称不能为空", trigger: "blur" }
  128. ]
  129. }
  130. }
  131. }
  132. },
  133. created() {
  134. this.handleQuery()
  135. },
  136. methods: {
  137. handleQuery() {
  138. this.queryParams.pageNum = 1
  139. this.getList()
  140. },
  141. resetQuery() {
  142. this.resetForm("queryForm");
  143. this.handleQuery();
  144. },
  145. getList() {
  146. this.loading = true
  147. list(this.queryParams).then(response => {
  148. this.customerLevelList = response.rows
  149. this.total = response.total
  150. this.loading = false
  151. })
  152. },
  153. getStatusType(status) {
  154. return this.statusOptions.find(val => val.dictValue === status)?.type || ''
  155. },
  156. getStatusLabel(status) {
  157. return this.statusOptions.find(val => val.dictValue === status)?.dictLabel || ''
  158. },
  159. handleAdd() {
  160. this.reset()
  161. this.customLevelDialog.open = true
  162. this.customLevelDialog.title = "新增级别"
  163. },
  164. handleUpdate(row) {
  165. this.reset()
  166. get(row.id).then(response => {
  167. this.customLevelDialog.form = response.data
  168. this.customLevelDialog.form.status = response.data.status.toString()
  169. this.customLevelDialog.open = true
  170. this.customLevelDialog.title = "修改级别"
  171. })
  172. },
  173. handleDelete(row) {
  174. this.$confirm('是否确认删除级别编号为"' + row.id + '"的数据项?', "警告", {
  175. confirmButtonText: "确定",
  176. cancelButtonText: "取消",
  177. type: "warning"
  178. }).then(function() {
  179. return del(row.id)
  180. }).then(() => {
  181. this.getList()
  182. this.msgSuccess("删除成功")
  183. })
  184. },
  185. submitForm() {
  186. this.$refs["form"].validate(valid => {
  187. if (valid) {
  188. if (this.customLevelDialog.form.id != null) {
  189. edit(this.customLevelDialog.form).then(response => {
  190. const {code} = response
  191. if (code === 200) {
  192. this.msgSuccess("修改成功");
  193. this.customLevelDialog.open = false;
  194. this.getList();
  195. }
  196. })
  197. } else {
  198. add(this.customLevelDialog.form).then(response => {
  199. const {code} = response
  200. if (code === 200) {
  201. this.msgSuccess("新增成功");
  202. this.customLevelDialog.open = false;
  203. this.getList();
  204. }
  205. })
  206. }
  207. }
  208. });
  209. },
  210. cancel() {
  211. this.customLevelDialog.open = false
  212. this.reset();
  213. },
  214. reset() {
  215. this.customLevelDialog.form = initForm
  216. this.resetForm("form")
  217. },
  218. }
  219. }
  220. </script>
  221. <style scoped>
  222. </style>