index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <div class="app-container">
  3. <!-- 搜索区域 -->
  4. <div class="filter-container">
  5. <div class="filter-control">
  6. <span>机构名称:</span>
  7. <el-input v-model="listQuery.name" placeholder="机构名称" @keyup.enter.native="getList" />
  8. </div>
  9. <div class="filter-control">
  10. <span>手机号:</span>
  11. <el-input v-model="listQuery.mobile" placeholder="手机号" @keyup.enter.native="getList" />
  12. </div>
  13. <div class="filter-control">
  14. <span>状态:</span>
  15. <el-select v-model="listQuery.status" clearable @change="getList">
  16. <el-option label="全部" value="" />
  17. <el-option label="启用" :value="1" />
  18. <el-option label="停用" :value="0" />
  19. </el-select>
  20. </div>
  21. <div class="filter-control">
  22. <permission-button type="primary" @click="getList">查询</permission-button>
  23. <permission-button type="primary" @click="handleCreate">添加账号</permission-button>
  24. </div>
  25. </div>
  26. <!-- 搜索区域END -->
  27. <!-- 表格区域 -->
  28. <el-table
  29. v-loading="listLoading"
  30. :data="list"
  31. style="width: 100%"
  32. border
  33. fit
  34. highlight-current-row
  35. cell-class-name="table-cell"
  36. header-row-class-name="tableHeader"
  37. >
  38. <el-table-column label="序号" :index="indexMethod" type="index" width="80px" align="center" />
  39. <el-table-column label="机构名称" prop="name" align="center">
  40. <template slot-scope="{ row }">
  41. <span v-if="row.name">{{ row.name }}</span>
  42. <span v-else>—</span>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="手机号" width="140" align="center">
  46. <template slot-scope="{ row }">
  47. <span v-if="row.mobile">{{ row.mobile }}</span>
  48. <span v-else>—</span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="注册时间" width="160px" align="center">
  52. <template slot-scope="{ row }">
  53. <span>{{ row.addTime | formatTime }}</span>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="微信昵称" align="center">
  57. <template slot-scope="{ row }">
  58. <span v-if="row.nickName">{{ row.nickName }}</span>
  59. <span v-else>—</span>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="openID" width="280" align="center">
  63. <template slot-scope="{ row }">
  64. <span v-if="row.openId">{{ row.openId }}</span>
  65. <span v-else>—</span>
  66. </template>
  67. </el-table-column>
  68. <el-table-column label="状态" width="160px" align="center">
  69. <template slot-scope="{ row }">
  70. <template v-if="row.status === 0">
  71. <span style="margin-right: 10px" class="status danger">停用</span>
  72. <permission-button type="primary" size="mini" @click="handleChangeStatus(row)">启用</permission-button>
  73. </template>
  74. <template v-else>
  75. <span style="margin-right: 10px" class="status success">启用</span>
  76. <permission-button type="info" size="mini" @click="handleChangeStatus(row)">停用</permission-button>
  77. </template>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="操作" width="280px" align="center">
  81. <template slot-scope="{ row }">
  82. <permission-button
  83. type="primary"
  84. size="mini"
  85. style="margin-right: 5px"
  86. @click="handleResetPwd(row)"
  87. >重置密码</permission-button>
  88. <permission-button type="primary" size="mini" @click="handleEdit(row)">编辑</permission-button>
  89. <permission-button type="primary" size="mini" @click="onChangeClub(row)">更换机构</permission-button>
  90. </template>
  91. </el-table-column>
  92. </el-table>
  93. <!-- 表格区域END -->
  94. <pagination
  95. :total="total"
  96. :page.sync="listQuery.pageNum"
  97. :limit.sync="listQuery.pageSize"
  98. @pagination="fetchUserList"
  99. />
  100. <el-dialog title="添加用户" width="30%" :visible.sync="dialogVisible" @close="onDialogClose">
  101. <el-form ref="form" label-width="80px" :model="formData" :rules="rules">
  102. <el-form-item label="手机号:" prop="mobile">
  103. <el-input v-model="formData.mobile" placeholder="请输入手机号" maxlength="11" show-word-limit />
  104. </el-form-item>
  105. </el-form>
  106. <span slot="footer" class="dialog-footer">
  107. <el-button @click="dialogVisible = false">取 消</el-button>
  108. <el-button type="primary" @click="onSave">确 定</el-button>
  109. </span>
  110. </el-dialog>
  111. <!-- 绑定/更换机构 -->
  112. <el-dialog title="绑定/更换机构" :visible.sync="dialogChangeClubVisible" width="30%" :show-close="false">
  113. <el-form ref="changeClubForm" :model="changeClubForm" :rules="changeClubRules" label-width="70px">
  114. <el-form-item prop="authId" label="机构:">
  115. <el-select v-model="changeClubForm.authId" placeholder="请选择机构" style="width: 100%" clearable>
  116. <template v-for="item in bindClubList">
  117. <el-option :key="item.authId" :label="item.authParty" :value="item.authId" />
  118. </template>
  119. </el-select>
  120. </el-form-item>
  121. </el-form>
  122. <div slot="footer" class="dialog-footer">
  123. <el-button type="primary" @click="dialogChangeClubVisible = false">取 消</el-button>
  124. <el-button type="primary" @click="onBindClubConfirm">确 定</el-button>
  125. </div>
  126. </el-dialog>
  127. </div>
  128. </template>
  129. <script>
  130. import { mapGetters } from 'vuex'
  131. import {
  132. authUserStatusChange,
  133. clubUserBindSave,
  134. createClubUser,
  135. fetchClubBindList,
  136. getAuthUserList,
  137. resetClubUserPassword
  138. } from '@/api/auth'
  139. import { isMobile } from '@/utils/validate'
  140. const resetFormData = () => ({
  141. clubUserId: '',
  142. authUserId: '',
  143. mobile: ''
  144. })
  145. export default {
  146. name: 'SupplierUserList',
  147. data() {
  148. const validateMobile = (rule, value, callback) => {
  149. console.log(value)
  150. if (isMobile(value)) {
  151. callback()
  152. } else {
  153. callback(new Error('手机号格式不正确'))
  154. }
  155. }
  156. return {
  157. total: 0,
  158. authId: '', // 机构id
  159. editType: 'add',
  160. dialogChangeClubVisible: false,
  161. listLoading: false,
  162. listQuery: {
  163. authUserId: '', // 机构id
  164. name: '', // 用户名
  165. status: '',
  166. mobile: '', // 手机号
  167. pageNum: 0, // 页码
  168. pageSize: 10 // 分页大小
  169. },
  170. list: [],
  171. srcList: [],
  172. dialogVisible: false,
  173. formData: resetFormData(),
  174. rules: {
  175. // name: [{ required: true, message: '请输入用户姓名', trigger: ['blur'] }],
  176. mobile: [
  177. { required: true, message: '请输入手机号', trigger: ['blur'] },
  178. { validator: validateMobile, message: '手机号格式不正确', trigger: ['blur'] }
  179. ]
  180. },
  181. changeClubForm: {
  182. clubUserId: '',
  183. authId: '',
  184. authParty: ''
  185. },
  186. changeClubRules: {
  187. authId: [{ required: true, message: '请选择机构', trigger: ['change'] }]
  188. },
  189. bindClubList: []
  190. }
  191. },
  192. computed: {
  193. ...mapGetters(['authUserId'])
  194. },
  195. created() {
  196. this.getList()
  197. },
  198. methods: {
  199. // 更换机构
  200. async onChangeClub(row) {
  201. try {
  202. this.changeClubForm.clubUserId = row.clubUserId
  203. const res = await fetchClubBindList()
  204. console.log(res)
  205. this.bindClubList = res.data
  206. this.dialogChangeClubVisible = true
  207. } catch (error) {
  208. console.log(error)
  209. }
  210. },
  211. // 绑定机构确定
  212. async onBindClubConfirm() {
  213. try {
  214. const bindClub = this.bindClubList.find((item) => item.authId === this.changeClubForm.authId)
  215. if (bindClub) {
  216. this.changeClubForm.authParty = bindClub.authParty
  217. }
  218. await this.$refs.changeClubForm.validate()
  219. this.onBindClub()
  220. } catch (error) {
  221. console.log(error)
  222. }
  223. },
  224. // 绑定机构
  225. async onBindClub() {
  226. try {
  227. await clubUserBindSave(this.changeClubForm)
  228. this.dialogChangeClubVisible = false
  229. this.getList()
  230. this.$message.success('机构绑定成功!')
  231. } catch (error) {
  232. console.log(error)
  233. } finally {
  234. this.$refs.changeClubForm.resetFields()
  235. }
  236. },
  237. // 更新列表
  238. getList() {
  239. this.listQuery.pageNum = 1
  240. this.fetchUserList()
  241. },
  242. // 获取列表数据
  243. async fetchUserList() {
  244. this.listLoading = true
  245. this.listQuery.authUserId = this.authUserId
  246. try {
  247. const res = await getAuthUserList(this.listQuery)
  248. this.list = res.data.list
  249. this.total = res.data.total
  250. } catch (error) {
  251. console.log(error)
  252. } finally {
  253. this.listLoading = false
  254. }
  255. },
  256. // 创建用户
  257. handleCreate() {
  258. this.dialogVisible = true
  259. this.editType = 'add'
  260. },
  261. // 修改用户
  262. handleEdit(row) {
  263. this.formData.clubUserId = row.clubUserId
  264. this.formData.authUserId = row.authUserId
  265. this.formData.mobile = row.mobile
  266. this.dialogVisible = true
  267. this.editType = 'edit'
  268. },
  269. async handleChangeStatus(row) {
  270. try {
  271. const status = row.status === 0 ? 1 : 0
  272. await authUserStatusChange({
  273. clubUserId: row.clubUserId,
  274. status
  275. })
  276. this.getList()
  277. this.$message.success('用户状态修改成功')
  278. } catch (error) {
  279. console.log(error)
  280. this.$message.error('用户状态修改失败')
  281. }
  282. },
  283. // 保存用户信息
  284. async onSave() {
  285. let valide = false
  286. try {
  287. valide = await this.$refs.form.validate()
  288. } catch (error) {
  289. console.log(error)
  290. }
  291. if (!valide) return
  292. this.formData.authUserId = this.authUserId
  293. try {
  294. await createClubUser(this.formData)
  295. this.$message.success(`${this.editType === 'add' ? '添加' : '修改'}用户成功`)
  296. this.fetchUserList()
  297. this.dialogVisible = false
  298. } catch (error) {
  299. console.log(error)
  300. }
  301. },
  302. // 删除用户
  303. // async handleRemove(row) {
  304. // let confirmType = ''
  305. // try {
  306. // confirmType = await this.$confirm('确认删除改用户?', '提示', {
  307. // confirmButtonText: '确认',
  308. // cancelButtonText: '取消',
  309. // type: 'warning'
  310. // })
  311. // } catch (error) {
  312. // console.log(error)
  313. // }
  314. // if (!confirmType) return
  315. // try {
  316. // await removeClubUser({ clubUserId: row.clubUserId })
  317. // this.$message.success('删除用户成功')
  318. // this.fetchUserList()
  319. // } catch (error) {
  320. // console.log(error)
  321. // }
  322. // },
  323. // 重置密码
  324. async handleResetPwd(row) {
  325. try {
  326. await resetClubUserPassword({ clubUserId: row.clubUserId })
  327. this.$message.success('重置密码成功')
  328. } catch (error) {
  329. console.log(error)
  330. }
  331. },
  332. onDialogClose() {
  333. this.$refs.form.resetFields()
  334. this.formData = resetFormData()
  335. },
  336. indexMethod(index) {
  337. return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
  338. }
  339. }
  340. }
  341. </script>
  342. <style lang="scss" scoped>
  343. .app-container {
  344. ::v-deep {
  345. .el-dialog__body {
  346. padding-bottom: 0;
  347. }
  348. }
  349. }
  350. .el-table .cell {
  351. overflow: visible;
  352. }
  353. .el-badge {
  354. margin: 0 6px;
  355. }
  356. </style>