index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :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. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  14. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  15. </el-form-item>
  16. </el-form>
  17. <el-row :gutter="10" class="mb8">
  18. <el-col :span="1.5">
  19. <el-button
  20. type="primary"
  21. plain
  22. icon="el-icon-plus"
  23. size="mini"
  24. @click="handleAdd"
  25. v-hasPermi="['system1:teacher:add']"
  26. >新增</el-button>
  27. </el-col>
  28. <el-col :span="1.5">
  29. <el-button
  30. type="success"
  31. plain
  32. icon="el-icon-edit"
  33. size="mini"
  34. :disabled="single"
  35. @click="handleUpdate"
  36. v-hasPermi="['system1:teacher:edit']"
  37. >修改</el-button>
  38. </el-col>
  39. <el-col :span="1.5">
  40. <el-button
  41. type="danger"
  42. plain
  43. icon="el-icon-delete"
  44. size="mini"
  45. :disabled="multiple"
  46. @click="handleDelete"
  47. v-hasPermi="['system1:teacher:remove']"
  48. >删除</el-button>
  49. </el-col>
  50. <el-col :span="1.5">
  51. <el-button
  52. type="warning"
  53. plain
  54. icon="el-icon-download"
  55. size="mini"
  56. @click="handleExport"
  57. v-hasPermi="['system1:teacher:export']"
  58. >导出</el-button>
  59. </el-col>
  60. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  61. </el-row>
  62. <el-table v-loading="loading" :data="teacherList" @selection-change="handleSelectionChange">
  63. <el-table-column type="selection" width="55" align="center" />
  64. <el-table-column label="老师ID" align="center" prop="id" />
  65. <el-table-column label="老师姓名" align="center" prop="name" />
  66. <el-table-column label="头像URL" align="center" prop="avatar" width="100">
  67. <template slot-scope="scope">
  68. <image-preview :src="scope.row.avatar" :width="50" :height="50"/>
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="职称/头衔" align="center" prop="title" />
  72. <el-table-column label="老师简介" align="center" prop="intro" />
  73. <el-table-column label="所属店铺" align="center" prop="shopId" />
  74. <el-table-column label="关联的用户ID" align="center" prop="userId" />
  75. <el-table-column label="状态" align="center" prop="status" />
  76. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  77. <template slot-scope="scope">
  78. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  79. </template>
  80. </el-table-column>
  81. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  82. <template slot-scope="scope">
  83. <el-button
  84. size="mini"
  85. type="text"
  86. icon="el-icon-edit"
  87. @click="handleUpdate(scope.row)"
  88. v-hasPermi="['system1:teacher:edit']"
  89. >修改</el-button>
  90. <el-button
  91. size="mini"
  92. type="text"
  93. icon="el-icon-delete"
  94. @click="handleDelete(scope.row)"
  95. v-hasPermi="['system1:teacher:remove']"
  96. >删除</el-button>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. <pagination
  101. v-show="total>0"
  102. :total="total"
  103. :page.sync="queryParams.pageNum"
  104. :limit.sync="queryParams.pageSize"
  105. @pagination="getList"
  106. />
  107. <!-- 添加或修改教师对话框 -->
  108. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  109. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  110. <el-form-item label="老师姓名" prop="name">
  111. <el-input v-model="form.name" placeholder="请输入老师姓名" />
  112. </el-form-item>
  113. <el-form-item label="头像URL" prop="avatar">
  114. <image-upload v-model="form.avatar"/>
  115. </el-form-item>
  116. <el-form-item label="职称/头衔" prop="title">
  117. <el-input v-model="form.title" placeholder="请输入职称/头衔" />
  118. </el-form-item>
  119. <el-form-item label="老师简介" prop="intro">
  120. <el-input v-model="form.intro" type="textarea" placeholder="请输入内容" />
  121. </el-form-item>
  122. <el-form-item label="所属店铺" prop="shopId">
  123. <el-select
  124. v-model="form.shopId"
  125. placeholder="请选择店铺"
  126. size="large"
  127. style="width: 240px"
  128. >
  129. <el-option
  130. v-for="user1 in course"
  131. :key="user1.id"
  132. :label="user1.name"
  133. :value="user1.id"
  134. />
  135. </el-select>
  136. </el-form-item>
  137. <el-form-item label="用户ID" prop="userId">
  138. <el-select
  139. v-model="form.userId"
  140. placeholder="请选择用户"
  141. size="large"
  142. style="width: 240px"
  143. >
  144. <el-option
  145. v-for="user1 in user"
  146. :key="user1.id"
  147. :label="user1.nickname"
  148. :value="user1.id"
  149. />
  150. </el-select>
  151. </el-form-item>
  152. <el-form-item label="状态" prop="status">
  153. <el-radio-group v-model="form.status">
  154. <el-radio :label="0">待审核</el-radio>
  155. <el-radio :label="1">已上架</el-radio>
  156. <el-radio :label="2">已禁用</el-radio>
  157. </el-radio-group>
  158. </el-form-item>
  159. </el-form>
  160. <div slot="footer" class="dialog-footer">
  161. <el-button type="primary" @click="submitForm">确 定</el-button>
  162. <el-button @click="cancel">取 消</el-button>
  163. </div>
  164. </el-dialog>
  165. </div>
  166. </template>
  167. <script>
  168. import { listTeacher, getTeacher, delTeacher, addTeacher, updateTeacher } from "@/api/system1/teacher"
  169. import {listUserAll} from "../../../api/system1/user";
  170. import {listAll} from "../../../api/system1/shop";
  171. export default {
  172. name: "Teacher",
  173. data() {
  174. return {
  175. course: [],
  176. // 遮罩层
  177. loading: true,
  178. // 选中数组
  179. ids: [],
  180. // 非单个禁用
  181. single: true,
  182. // 非多个禁用
  183. multiple: true,
  184. // 显示搜索条件
  185. showSearch: true,
  186. // 总条数
  187. total: 0,
  188. // 教师表格数据
  189. teacherList: [],
  190. user: [],
  191. // 弹出层标题
  192. title: "",
  193. // 是否显示弹出层
  194. open: false,
  195. // 查询参数
  196. queryParams: {
  197. pageNum: 1,
  198. pageSize: 10,
  199. name: null,
  200. },
  201. // 表单参数
  202. form: {},
  203. // 表单校验
  204. rules: {
  205. name: [
  206. { required: true, message: "老师姓名不能为空", trigger: "blur" }
  207. ],
  208. }
  209. }
  210. },
  211. created() {
  212. this.getList()
  213. this.All()
  214. this.All1()
  215. },
  216. methods: {
  217. All(){
  218. this.loading=true
  219. listUserAll().then(response => {
  220. this.user=response.rows
  221. console.log(this.user)
  222. })
  223. },
  224. All1(){
  225. listAll().then(response=>{
  226. this.course=response.rows
  227. })
  228. },
  229. /** 查询教师列表 */
  230. getList() {
  231. this.loading = true
  232. listTeacher(this.queryParams).then(response => {
  233. this.teacherList = response.rows
  234. this.total = response.total
  235. this.loading = false
  236. })
  237. },
  238. // 取消按钮
  239. cancel() {
  240. this.open = false
  241. this.reset()
  242. },
  243. // 表单重置
  244. reset() {
  245. this.form = {
  246. id: null,
  247. name: null,
  248. avatar: null,
  249. title: null,
  250. intro: null,
  251. shopId: null,
  252. userId: null,
  253. status: null,
  254. createTime: null
  255. }
  256. this.resetForm("form")
  257. },
  258. /** 搜索按钮操作 */
  259. handleQuery() {
  260. this.queryParams.pageNum = 1
  261. this.getList()
  262. },
  263. /** 重置按钮操作 */
  264. resetQuery() {
  265. this.resetForm("queryForm")
  266. this.handleQuery()
  267. },
  268. // 多选框选中数据
  269. handleSelectionChange(selection) {
  270. this.ids = selection.map(item => item.id)
  271. this.single = selection.length!==1
  272. this.multiple = !selection.length
  273. },
  274. /** 新增按钮操作 */
  275. handleAdd() {
  276. this.reset()
  277. this.open = true
  278. this.title = "添加教师"
  279. },
  280. /** 修改按钮操作 */
  281. handleUpdate(row) {
  282. this.reset()
  283. const id = row.id || this.ids
  284. getTeacher(id).then(response => {
  285. this.form = response.data
  286. this.open = true
  287. this.title = "修改教师"
  288. })
  289. },
  290. /** 提交按钮 */
  291. submitForm() {
  292. this.$refs["form"].validate(valid => {
  293. if (valid) {
  294. if (this.form.id != null) {
  295. updateTeacher(this.form).then(response => {
  296. this.$modal.msgSuccess("修改成功")
  297. this.open = false
  298. this.getList()
  299. })
  300. } else {
  301. addTeacher(this.form).then(response => {
  302. this.$modal.msgSuccess("新增成功")
  303. this.open = false
  304. this.getList()
  305. })
  306. }
  307. }
  308. })
  309. },
  310. /** 删除按钮操作 */
  311. handleDelete(row) {
  312. const ids = row.id || this.ids
  313. this.$modal.confirm('是否确认删除教师编号为"' + ids + '"的数据项?').then(function() {
  314. return delTeacher(ids)
  315. }).then(() => {
  316. this.getList()
  317. this.$modal.msgSuccess("删除成功")
  318. }).catch(() => {})
  319. },
  320. /** 导出按钮操作 */
  321. handleExport() {
  322. this.download('system1/teacher/export', {
  323. ...this.queryParams
  324. }, `teacher_${new Date().getTime()}.xlsx`)
  325. }
  326. }
  327. }
  328. </script>