studentList.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <div class="m-container">
  3. <h2>
  4. <div class="squrt"></div>学员列表
  5. </h2>
  6. <div class="m-core">
  7. <div class="newBand"
  8. v-permission="'studentManage/register'"
  9. @click="addStudent">新增学员</div>
  10. <div class="newBand"
  11. @click="onCreateQRCode">学员激活列表</div>
  12. <!-- 搜索标题 -->
  13. <el-form :inline="true"
  14. class="searchForm"
  15. v-model="searchForm">
  16. <el-form-item>
  17. <el-input placeholder="学生姓名或电话"
  18. @keyup.enter.native='onSearch'
  19. v-model="searchForm.search"></el-input>
  20. </el-form-item>
  21. <el-form-item prop='organId'>
  22. <el-select class='multiple'
  23. filterable
  24. v-model="searchForm.organId"
  25. clearable
  26. placeholder="请选择分部">
  27. <el-option v-for="(item,index) in organList"
  28. :key="index"
  29. :label="item.name"
  30. :value="item.id"></el-option>
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item prop='isActive'>
  34. <el-select class='multiple'
  35. v-model="searchForm.isActive"
  36. clearable
  37. placeholder="是否激活">
  38. <el-option label="是"
  39. value="true"></el-option>
  40. <el-option label="否"
  41. value="false"></el-option>
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item prop='hasCourse'>
  45. <el-select class='multiple'
  46. v-model="searchForm.hasCourse"
  47. clearable
  48. placeholder="是否有课">
  49. <el-option label="是"
  50. value="1"></el-option>
  51. <el-option label="否"
  52. value="0"></el-option>
  53. </el-select>
  54. </el-form-item>
  55. <!-- <el-form-item>
  56. <el-input placeholder="学生姓名"
  57. @keyup.enter.native='onSearch'
  58. v-model="searchForm.studentName"></el-input>
  59. </el-form-item> -->
  60. <el-form-item>
  61. <el-button @click="onSearch"
  62. type="danger">搜索</el-button>
  63. <el-button @click="onReSet"
  64. type="primary">重置</el-button>
  65. <el-button type="primary"
  66. v-permission="'export/studentHasCourse'"
  67. @click="downLoadStudent">导出名单</el-button>
  68. </el-form-item>
  69. </el-form>
  70. <!-- 列表 -->
  71. <div class="tableWrap">
  72. <el-table :data='tableList'
  73. :header-cell-style="{background:'#EDEEF0',color:'#444'}">
  74. <el-table-column align='center'
  75. prop="userId"
  76. label="学员编号">
  77. </el-table-column>
  78. <el-table-column align='center'
  79. prop="username"
  80. label="学员姓名">
  81. </el-table-column>
  82. <el-table-column align='center'
  83. label="性别">
  84. <template slot-scope="scope">
  85. {{ scope.row.gender ? '男': '女' }}
  86. </template>
  87. </el-table-column>
  88. <el-table-column align='center'
  89. prop="realName"
  90. label="家长姓名">
  91. </el-table-column>
  92. <el-table-column align='center'
  93. prop="parentsPhone"
  94. label="家长联系电话">
  95. </el-table-column>
  96. <el-table-column align='center'
  97. label="是否激活">
  98. <template slot-scope="scope">
  99. {{ scope.row.isActive ? '是' : '否' }}
  100. </template>
  101. </el-table-column>
  102. <el-table-column align='center'
  103. label="是否有课">
  104. <template slot-scope="scope">
  105. {{ scope.row.hasCourse ? '是' : '否' }}
  106. </template>
  107. </el-table-column>
  108. <el-table-column align='center'
  109. label="预约陪练课">
  110. <template slot-scope="scope">
  111. {{ scope.row.isMake ? '是' : '否' }}
  112. </template>
  113. </el-table-column>
  114. <el-table-column align='center'
  115. prop="courseBalance"
  116. label="课程余额(元)">
  117. </el-table-column>
  118. <el-table-column align='center'
  119. label="操作">
  120. <template slot-scope="scope">
  121. <router-link style="color:#409EFF"
  122. v-permission="'/studentDetail'"
  123. :to="{path:`/business/studentDetail?userId=${scope.row.userId}`,query:{search:JSON.stringify(searchForm),rules:JSON.stringify(pageInfo)}}">查看</router-link>
  124. <el-button type="text"
  125. v-permission="'studentManage/studentUpdate'"
  126. @click="resetStudent(scope.row)">修改</el-button>
  127. </template>
  128. </el-table-column>
  129. </el-table>
  130. <pagination :total="pageInfo.total"
  131. :page.sync="pageInfo.page"
  132. :limit.sync="pageInfo.limit"
  133. :page-sizes="pageInfo.page_size"
  134. @pagination="getList" />
  135. </div>
  136. </div>
  137. <el-dialog :title="maskName"
  138. width="700px"
  139. label-width='100px'
  140. label-position="right"
  141. :visible.sync="studentVisible">
  142. <el-divider>基本信息</el-divider>
  143. <el-form :model="studentForm"
  144. :inline='true'
  145. label-width="80px"
  146. label-position="right"
  147. ref='studentForm'
  148. :rules="studentRules">
  149. <el-form-item label="联系电话"
  150. :rules="[{ required: true, message: '请输入手机号' }, { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }]">
  151. <!-- @blur="checkPhone(studentForm.phone)" -->
  152. <el-input v-model="studentForm.phone"></el-input>
  153. </el-form-item>
  154. <el-form-item label="所属分部"
  155. v-if="isNew"
  156. prop="organId">
  157. <el-select class='multiple'
  158. v-model="studentForm.organId"
  159. filterable
  160. clearable
  161. placeholder="请选择分部">
  162. <el-option v-for="(item,index) in organList"
  163. :key="index"
  164. :label="item.name"
  165. :value="item.id"></el-option>
  166. </el-select>
  167. </el-form-item>
  168. <el-form-item label="学生姓名"
  169. prop="name">
  170. <el-input v-model="studentForm.name"></el-input>
  171. </el-form-item>
  172. <el-form-item label="学生性别"
  173. prop="sex">
  174. <el-select class='multiple'
  175. filterable
  176. v-model="studentForm.sex"
  177. clearable
  178. placeholder="请选择性别">
  179. <el-option :value="0"
  180. label="女"></el-option>
  181. <el-option :value="1"
  182. label="男"></el-option>
  183. </el-select>
  184. </el-form-item>
  185. <el-form-item label="家长姓名">
  186. <el-input v-model="studentForm.parseName"></el-input>
  187. </el-form-item>
  188. <el-form-item label="出生日期">
  189. <el-date-picker v-model="studentForm.date"
  190. value-format="yyyy-MM-dd"
  191. type="date"
  192. placeholder="选择日期">
  193. </el-date-picker>
  194. </el-form-item>
  195. </el-form>
  196. <div slot="footer"
  197. class="dialog-footer">
  198. <el-button @click="studentVisible = false">取 消</el-button>
  199. <el-button type="primary"
  200. v-if="isNew"
  201. @click="submitAddStudent">确 定</el-button>
  202. <el-button type="primary"
  203. v-if="!isNew"
  204. @click="resetStudentSubmie">确 定</el-button>
  205. </div>
  206. </el-dialog>
  207. <el-dialog :visible.sync="qrcodeStatus"
  208. center
  209. width="300px">
  210. <div class="right-code">
  211. <h2 class="title">学员激活列表</h2>
  212. <div id="qrcode"
  213. class="qrcode code"
  214. ref="qrCodeUrl"></div>
  215. <!-- <p class="code-url"
  216. v-if="codeUrl2">{{ codeUrl2 }}</p> -->
  217. </div>
  218. </el-dialog>
  219. </div>
  220. </template>
  221. <script>
  222. import pagination from '@/components/Pagination/index'
  223. import { queryStudentList, getStudentInfoByPhone, registerStudent, updateStudent, studentHasCourse } from '@/api/studentManager'
  224. import { vaildStudentUrl } from '@/utils/validate'
  225. import { getEmployeeOrgan } from '@/api/buildTeam'
  226. import QRCode from 'qrcodejs2'
  227. import store from '@/store'
  228. import axios from 'axios'
  229. import { getToken } from '@/utils/auth'
  230. export default {
  231. name: 'studentList',
  232. components: { pagination },
  233. data () {
  234. return {
  235. studentVisible: false,
  236. searchForm: {
  237. organId: null,
  238. search: null,
  239. studentName: null,
  240. isActive: null,
  241. hasCourse: null
  242. },
  243. searchList: [],
  244. tableList: [],
  245. organList: [],
  246. pageInfo: {
  247. // 分页规则
  248. limit: 10, // 限制显示条数
  249. page: 1, // 当前页
  250. total: 0, // 总条数
  251. page_size: [10, 20, 40, 50] // 选择限制显示条数
  252. },
  253. studentForm: {
  254. phone: '',
  255. organId: '',
  256. name: '',
  257. sex: '',
  258. parseName: '',
  259. date: '',
  260. nation: ''
  261. },
  262. studentRules: {
  263. name: [{ required: true, message: '请输入学生姓名' },],
  264. sex: [{ required: true, message: '请选择学生姓名' },],
  265. date: [{ required: true, message: '请选择出生日期' },],
  266. organId: [{ required: true, message: '请选择分部' }],
  267. nation: [{ required: true, message: '请输入名族' }]
  268. },
  269. isNew: false,
  270. active: null,
  271. maskName: '新增学员',
  272. qrcodeStatus: false,
  273. qrcodes: true,
  274. activeRow: null
  275. }
  276. },
  277. mounted () {
  278. if (this.$route.query.search) {
  279. this.$route.query.search instanceof Object ? this.searchForm = this.$route.query.search : this.searchForm = JSON.parse(this.$route.query.search);
  280. }
  281. if (this.$route.query.rules) {
  282. this.$route.query.rules instanceof Object ? this.pageInfo = this.$route.query.rules : this.pageInfo = JSON.parse(this.$route.query.rules);
  283. }
  284. getEmployeeOrgan().then(res => {
  285. if (res.code == 200) {
  286. this.organList = res.data;
  287. }
  288. })
  289. this.getList();
  290. },
  291. methods: {
  292. onSearch () {
  293. this.pageInfo.page = 1;
  294. this.getList()
  295. },
  296. onCreateQRCode () { // 生成报名二维码
  297. this.qrcodeStatus = true
  298. // let id = this.$route.query.id
  299. // let teamName = this.$route.query.name
  300. setTimeout(() => {
  301. if (this.qrcodes) {
  302. this.qrcodes = false
  303. this.qrcode = new QRCode('qrcode', {
  304. width: 250,
  305. height: 250,
  306. colorDark: '#000000',
  307. colorLight: '#ffffff',
  308. correctLevel: QRCode.CorrectLevel.H
  309. })
  310. }
  311. // vaildStudentUrl() + `/#/sporadicLogin?id=${刷刷刷}`
  312. this.qrcode.clear();
  313. this.qrcode.makeCode(vaildStudentUrl() + `/#/queryStudentPer`)
  314. // this.codeUrl = vaildStudentUrl() + '/#/login?musicGroupId=' + id
  315. }, 500)
  316. },
  317. getList () {
  318. let params = this.searchForm
  319. params.rows = this.pageInfo.limit
  320. params.page = this.pageInfo.page
  321. params.organId ? params.organId : params.organId = null;
  322. queryStudentList(params).then(res => {
  323. if (res.code == 200) {
  324. this.tableList = res.data.rows
  325. this.pageInfo.total = res.data.total
  326. }
  327. })
  328. },
  329. onReSet () {
  330. this.searchForm = {
  331. organId: null,
  332. search: null,
  333. studentName: null,
  334. isActive: null
  335. }
  336. },
  337. downLoadStudent () {
  338. let url = '/api-web/export/studentHasCourse'
  339. const options = {
  340. method: 'POST',
  341. headers: {
  342. 'Authorization': getToken()
  343. },
  344. url,
  345. responseType: 'blob'
  346. }
  347. this.$confirm('确定导出?', '提示', {
  348. confirmButtonText: '确定',
  349. cancelButtonText: '取消',
  350. type: 'warning'
  351. }).then(() => {
  352. axios(options).then(res => {
  353. let blob = new Blob([res.data], {
  354. // type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8',
  355. type: 'application/vnd.ms-excel;charset=utf-8'
  356. // word文档为application/msword,pdf文档为application/pdf,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8
  357. })
  358. let objectUrl = URL.createObjectURL(blob)
  359. let link = document.createElement("a")
  360. let nowTime = new Date()
  361. let ymd = nowTime.getFullYear() + (nowTime.getMonth() + 1) + nowTime.getDate()
  362. let fname = `导出学员名单` + ymd //下载文件的名字
  363. link.href = objectUrl
  364. link.setAttribute("download", fname)
  365. document.body.appendChild(link)
  366. link.click()
  367. })
  368. }).catch(() => { })
  369. },
  370. checkPhone (val) {
  371. var regu = /^1[3456789]\d{9}$/;
  372. var re = new RegExp(regu);
  373. if (re.test(val)) {
  374. getStudentInfoByPhone({ mobile: this.studentForm.phone }).then(res => {
  375. if (res.code == 200) {
  376. if (res.data) {
  377. this.studentForm = {
  378. name: res.data.name,
  379. sex: res.data.gender,
  380. parseName: res.data.parentsName,
  381. // sound: parseInt(res.data.subjectId),
  382. phone: val,
  383. date: res.data.birthdate
  384. }
  385. }
  386. }
  387. })
  388. }
  389. },
  390. submitAddStudent () {
  391. // 效验 然后组数据提交
  392. this.$refs['studentForm'].validate(item => {
  393. if (item) {
  394. let obj = {
  395. phone: this.studentForm.phone,
  396. username: this.studentForm.name,
  397. gender: this.studentForm.sex,
  398. realName: this.studentForm.parseName,
  399. birthdate: this.studentForm.date,
  400. organId: this.studentForm.organId,
  401. nation: this.studentForm.nation
  402. }
  403. registerStudent(obj).then(res => {
  404. if (res.code == 200) {
  405. this.$message.success('添加成功');
  406. this.studentVisible = false;
  407. this.getList()
  408. }
  409. })
  410. }
  411. })
  412. },
  413. // 修改学生信息
  414. resetStudentSubmie () {
  415. this.$refs['studentForm'].validate(item => {
  416. if (item) {
  417. let obj = {
  418. phone: this.studentForm.phone,
  419. username: this.studentForm.name,
  420. gender: this.studentForm.sex,
  421. realName: this.studentForm.parseName,
  422. birthdate: this.studentForm.date,
  423. organId: this.studentForm.organId,
  424. id: this.active.userId,
  425. nation: this.studentForm.nation
  426. }
  427. updateStudent(obj).then(res => {
  428. if (res.code == 200) {
  429. this.$message.success('修改成功');
  430. this.studentVisible = false;
  431. this.getList()
  432. }
  433. })
  434. }
  435. })
  436. },
  437. addStudent () {
  438. this.isNew = true;
  439. this.studentVisible = true;
  440. this.maskName = '新增学员'
  441. },
  442. resetStudent (row) {
  443. this.isNew = false;
  444. this.active = row;
  445. this.studentVisible = true;
  446. this.maskName = '修改学员'
  447. this.studentForm = {
  448. phone: row.parentsPhone,
  449. name: row.username,
  450. sex: row.gender,
  451. parseName: row.realName,
  452. date: row.birthdate,
  453. nation: row.nation
  454. }
  455. },
  456. },
  457. watch: {
  458. studentVisible (val) {
  459. if (!val) {
  460. this.studentForm = {
  461. phone: '',
  462. organId: '',
  463. name: '',
  464. sex: '',
  465. parseName: '',
  466. date: '',
  467. nation: ''
  468. }
  469. this.$refs['studentForm'].resetFields()
  470. }
  471. }
  472. }
  473. }
  474. </script>
  475. <style lang="scss" scoped>
  476. .newBand {
  477. display: inline-block;
  478. margin-right: 10px;
  479. }
  480. .right-code {
  481. // width: 50%;
  482. // float: left;
  483. .title {
  484. font-size: 18px;
  485. text-align: center;
  486. padding-bottom: 8px;
  487. }
  488. }
  489. </style>