index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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="companyName">
  5. <el-select
  6. v-model="queryCompanyId"
  7. placeholder="请选择所属公司"
  8. clearable
  9. filterable
  10. size="small"
  11. @change="handleQueryCompanyChange"
  12. >
  13. <el-option
  14. v-for="item in companyQueryOptions"
  15. :key="item.companyId"
  16. :label="item.companyName"
  17. :value="item.companyId">
  18. </el-option>
  19. </el-select>
  20. </el-form-item>
  21. <el-form-item label="所属销售" prop="companyUserId">
  22. <el-select
  23. v-model="queryCompanyUserId"
  24. placeholder="请选择所属销售"
  25. clearable
  26. filterable
  27. size="small"
  28. >
  29. <el-option
  30. v-for="item in companyQueryUserOptions"
  31. :key="item.userId"
  32. :label="item.nickName"
  33. :value="item.userId">
  34. </el-option>
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item label="会员ID" prop="userId">
  38. <el-input
  39. v-model="queryParams.userId"
  40. placeholder="请输入会员ID"
  41. clearable
  42. size="small"
  43. @keyup.enter.native="handleQuery"
  44. />
  45. </el-form-item>
  46. <el-form-item label="用户昵称" prop="nickName">
  47. <el-input
  48. v-model="queryParams.nickName"
  49. placeholder="请输入用户昵称"
  50. clearable
  51. size="small"
  52. @keyup.enter.native="handleQuery"
  53. />
  54. </el-form-item>
  55. <el-form-item label="手机号码" prop="phone">
  56. <el-input
  57. v-model="queryParams.phone"
  58. placeholder="请输入手机号码"
  59. clearable
  60. size="small"
  61. @keyup.enter.native="handleQuery"
  62. />
  63. </el-form-item>
  64. <el-form-item label="加密号码" prop="phoneMk">
  65. <el-input
  66. v-model="queryParams.phoneMk"
  67. placeholder="请输入手机号码"
  68. clearable
  69. size="small"
  70. @keyup.enter.native="handleQuery"
  71. />
  72. </el-form-item>
  73. <el-form-item label="app来源" prop="source">
  74. <el-input
  75. v-model="queryParams.source"
  76. placeholder="请输入手机号码"
  77. clearable
  78. size="small"
  79. @keyup.enter.native="handleQuery"
  80. />
  81. </el-form-item>
  82. <el-form-item label="用户状态" prop="status">
  83. <el-select v-model="queryParams.status" placeholder="请选择用户状态" clearable size="small">
  84. <el-option
  85. v-for="dict in userOptions"
  86. :key="dict.dictValue"
  87. :label="dict.dictLabel"
  88. :value="dict.dictValue"
  89. />
  90. </el-select>
  91. </el-form-item>
  92. <el-form-item label="是否购药" prop="isBuy">
  93. <el-select v-model="queryParams.isBuy" placeholder="请选择用户状态" clearable size="small">
  94. <el-option
  95. v-for="dict in orOptions"
  96. :key="dict.dictValue"
  97. :label="dict.dictLabel"
  98. :value="dict.dictValue"
  99. />
  100. </el-select>
  101. </el-form-item>
  102. <el-form-item label="注册时间" prop="createTime">
  103. <el-date-picker v-model="createTime" size="small" style="width: 230px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" @change="change"></el-date-picker>
  104. </el-form-item>
  105. <el-form-item>
  106. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  107. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  108. </el-form-item>
  109. </el-form>
  110. <el-row :gutter="10" class="mb8">
  111. <el-col :span="1.5">
  112. <el-button
  113. type="primary"
  114. icon="el-icon-user"
  115. size="mini"
  116. @click="handleChangeCompanyUser"
  117. :disabled="multiple"
  118. v-hasPermi="['company:companyUser:change']"
  119. >更换会员归属</el-button>
  120. </el-col>
  121. <el-col :span="1.5">
  122. <el-button
  123. type="warning"
  124. plain
  125. icon="el-icon-download"
  126. size="mini"
  127. :loading="exportLoading"
  128. @click="handleExport"
  129. v-hasPermi="['his:user:export']"
  130. >导出</el-button>
  131. </el-col>
  132. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  133. </el-row>
  134. <el-table height="660" v-loading="loading" border :data="userList" @selection-change="handleSelectionChange" >
  135. <el-table-column type="selection" width="55" align="center" />
  136. <el-table-column label="用户昵称" align="center" prop="nickName" width="150px"/>
  137. <el-table-column label="用户头像" align="center" prop="avatar" >
  138. <template slot-scope="scope">
  139. <el-image v-if="scope.row.avatar!=null"
  140. style="width: 50px;"
  141. :src="scope.row.avatar"
  142. >
  143. </el-image>
  144. </template>
  145. </el-table-column>
  146. <el-table-column label="手机号码" align="center" prop="phone" width="150px" />
  147. <el-table-column label="用户积分" align="center" prop="integral" />
  148. <el-table-column label="用户状态" align="center" prop="status" >
  149. <template slot-scope="scope">
  150. <dict-tag :options="userOptions" :value="scope.row.status"/>
  151. </template>
  152. </el-table-column>
  153. <el-table-column label="所属公司" align="center" prop="companyName" />
  154. <el-table-column label="所属销售" align="center" prop="companyUserNickName" />
  155. <el-table-column label="上级昵称" align="center" prop="tuiName" />
  156. <el-table-column label="app来源" align="center" prop="source" />
  157. <el-table-column label="登陆设备" align="center" prop="loginDevice" />
  158. <el-table-column label="上级手机号码" align="center" prop="tuiPhone" width="150px"/>
  159. <el-table-column label="下级人数" align="center" prop="tuiUserCount" />
  160. <el-table-column label="最后一次登录ip" align="center" prop="lastIp" width="130px"/>
  161. <el-table-column label="余额" align="center" prop="balance" />
  162. <el-table-column label="注册时间" align="center" prop="createTime" width="150px" />
  163. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150px">
  164. <template slot-scope="scope">
  165. <el-button
  166. size="mini"
  167. type="text"
  168. icon="el-icon-edit"
  169. @click="handleUpdate(scope.row)"
  170. v-hasPermi="['his:user:edit']"
  171. >修改</el-button>
  172. <el-button
  173. size="mini"
  174. type="text"
  175. @click="handledetails(scope.row)"
  176. >详情</el-button>
  177. <el-button
  178. size="mini"
  179. type="text"
  180. @click="handleDelete(scope.row)"
  181. v-hasPermi="['his:user:remove']"
  182. >删除</el-button>
  183. </template>
  184. </el-table-column>
  185. </el-table>
  186. <pagination
  187. v-show="total>0"
  188. :total="total"
  189. :page.sync="queryParams.pageNum"
  190. :limit.sync="queryParams.pageSize"
  191. @pagination="getList"
  192. />
  193. <!-- 添加或修改用户对话框 -->
  194. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  195. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  196. <el-form-item label="用户昵称" prop="nickName">
  197. <el-input v-model="form.nickName" placeholder="请输入用户昵称" />
  198. </el-form-item>
  199. <el-form-item label="用户状态" prop="status">
  200. <el-select v-model="form.status" placeholder="请选择状态" clearable size="small">
  201. <el-option
  202. v-for="dict in userOptions"
  203. :key="dict.dictValue"
  204. :label="dict.dictLabel"
  205. :value="dict.dictValue"
  206. />
  207. </el-select>
  208. </el-form-item>
  209. <el-form-item label="用户备注" prop="remark" >
  210. <el-input v-model="form.remark" placeholder="请输入用户备注" type="textarea"/>
  211. </el-form-item>
  212. </el-form>
  213. <div slot="footer" class="dialog-footer">
  214. <el-button type="primary" @click="submitForm">确 定</el-button>
  215. <el-button @click="cancel">取 消</el-button>
  216. </div>
  217. </el-dialog>
  218. <el-drawer
  219. :with-header="false"
  220. size="75%"
  221. :title="show.title" :visible.sync="show.open">
  222. <userDetails ref="userDetails" />
  223. </el-drawer>
  224. <!-- 更换会员归属对话框 -->
  225. <el-dialog title="更换会员归属" :visible.sync="changeCompanyUserOpen" width="500px" append-to-body>
  226. <el-form ref="changeCompanyUserForm" :model="changeCompanyUserForm" :rules="changeCompanyUserRules" label-width="100px">
  227. <el-form-item label="选择公司" prop="companyId">
  228. <el-select v-model="changeCompanyUserForm.companyId" placeholder="请选择公司" style="width: 100%" @change="handleCompanyChange">
  229. <el-option
  230. v-for="item in companyOptions"
  231. :key="item.companyId"
  232. :label="item.companyName"
  233. :value="item.companyId"
  234. />
  235. </el-select>
  236. </el-form-item>
  237. <el-form-item label="选择销售" prop="companyUserId">
  238. <el-select v-model="changeCompanyUserForm.companyUserId" placeholder="请选择销售" style="width: 100%" @change="handleCompanyUserChange">
  239. <el-option
  240. v-for="item in companyUserOptions"
  241. :key="item.userId"
  242. :label="item.nickName + '_' + item.userName"
  243. :value="item.userId"
  244. />
  245. </el-select>
  246. </el-form-item>
  247. </el-form>
  248. <div slot="footer" class="dialog-footer">
  249. <el-button type="primary" @click="submitChangeCompanyUserForm">确 定</el-button>
  250. <el-button @click="cancelChangeCompanyUser">取 消</el-button>
  251. </div>
  252. </el-dialog>
  253. </div>
  254. </template>
  255. <script>
  256. import { listUser, getUser, delUser, addUser, updateUser, exportUser } from "@/api/his/user";
  257. import { getCompanyUserList, changeCompanyUser, getCompanyList } from '@/api/company/companyUser';
  258. import userDetails from '../../components/his/userDetails.vue';
  259. export default {
  260. name: "User",
  261. components: {userDetails},
  262. data() {
  263. return {
  264. companyQueryOptions:[],
  265. companyQueryUserOptions:[],
  266. queryCompanyId:null,
  267. queryCompanyUserId:null,
  268. companyName: null,
  269. companyUserNickName: null,
  270. // 更换会员归属表单校验
  271. changeCompanyUserRules: {
  272. companyId: [
  273. { required: true, message: '请选择公司', trigger: 'change' }
  274. ],
  275. companyUserId: [
  276. { required: true, message: '请选择销售', trigger: 'change' }
  277. ]
  278. },
  279. companyOptions: [],
  280. companyUserOptions: [],
  281. // 更换会员归属对话框
  282. changeCompanyUserOpen: false,
  283. // 更换会员归属表单
  284. changeCompanyUserForm: {
  285. companyId: null,
  286. companyUserId: null,
  287. userIds: []
  288. },
  289. show:{
  290. title:"用户详情",
  291. open:false,
  292. },
  293. userOptions: [],
  294. // 遮罩层
  295. loading: true,
  296. // 导出遮罩层
  297. exportLoading: false,
  298. // 选中数组
  299. ids: [],
  300. orOptions:[],
  301. // 非单个禁用
  302. single: true,
  303. // 非多个禁用
  304. multiple: true,
  305. // 显示搜索条件
  306. showSearch: true,
  307. // 总条数
  308. total: 0,
  309. // 用户表格数据
  310. userList: [],
  311. // 弹出层标题
  312. title: "",
  313. // 是否显示弹出层
  314. open: false,
  315. createTime:null,
  316. // 查询参数
  317. queryParams: {
  318. pageNum: 1,
  319. pageSize: 10,
  320. nickName: null,
  321. avatar: null,
  322. phone: null,
  323. phoneMk: null,
  324. integral: null,
  325. status: null,
  326. tuiUserId: null,
  327. tuiTime: null,
  328. tuiUserCount: null,
  329. maOpenId: null,
  330. mpOpenId: null,
  331. unionId: null,
  332. isDel: null,
  333. userCode: null,
  334. lastIp: null,
  335. balance: null,
  336. sTime:null,
  337. eTime:null,
  338. isBuy:null,
  339. source:null
  340. },
  341. // 表单参数
  342. form: {},
  343. // 表单校验
  344. rules: {
  345. nickName: [
  346. { required: true, message: "昵称不能为空", trigger: "blur" }
  347. ],
  348. status: [
  349. { required: true, message: "用户状态不能为空", trigger: "blur" }
  350. ],
  351. integral: [
  352. { required: true, message: "用户积分不能为空", trigger: "blur" }
  353. ],
  354. }
  355. };
  356. },
  357. created() {
  358. this.getList();
  359. this.getDicts("sys_user_status").then(response => {
  360. this.userOptions = response.data;
  361. });
  362. this.getDicts("sys_company_or").then(response => {
  363. this.orOptions = response.data;
  364. });
  365. getCompanyList().then(response => {
  366. if (response.code === 200) {
  367. this.companyQueryOptions = response.data;
  368. }});
  369. },
  370. methods: {
  371. /** 销售选择变化 */
  372. handleCompanyUserChange(userId) {
  373. if (!this.changeCompanyUserForm.companyId) {
  374. this.$message.warning('请先选择公司');
  375. this.changeCompanyUserForm.companyUserId = null;
  376. return;
  377. }
  378. },
  379. change(){
  380. if(this.createTime!=null){
  381. this.queryParams.sTime=this.createTime[0];
  382. this.queryParams.eTime=this.createTime[1];
  383. }else{
  384. this.queryParams.sTime=null;
  385. this.queryParams.eTime=null;
  386. }
  387. },
  388. handledetails(row){
  389. this.show.open=true;
  390. setTimeout(() => {
  391. this.$refs.userDetails.getDetails(row.userId);
  392. }, 1);
  393. },
  394. handleQueryCompanyChange(companyId){
  395. // 清空已选择的销售
  396. this.queryCompanyUserId = null;
  397. // 根据公司ID获取对应的销售列表
  398. if (companyId) {
  399. getCompanyUserList({ companyId: companyId }).then(response => {
  400. if (response.code === 200) {
  401. this.companyQueryUserOptions = response.data;
  402. } else {
  403. this.$message.error(response.msg || '获取销售列表失败');
  404. this.companyQueryUserOptions = [];
  405. }
  406. }).catch(() => {
  407. this.$message.error('获取销售列表失败');
  408. this.companyQueryUserOptions = [];
  409. });
  410. } else {
  411. this.companyQueryUserOptions = [];
  412. }
  413. },
  414. handleCompanyChange(companyId) {
  415. // 清空已选择的销售
  416. this.changeCompanyUserForm.companyUserId = null;
  417. // 根据公司ID获取对应的销售列表
  418. if (companyId) {
  419. getCompanyUserList({ companyId: companyId }).then(response => {
  420. if (response.code === 200) {
  421. this.companyUserOptions = response.data;
  422. } else {
  423. this.$message.error(response.msg || '获取销售列表失败');
  424. this.companyUserOptions = [];
  425. }
  426. }).catch(() => {
  427. this.$message.error('获取销售列表失败');
  428. this.companyUserOptions = [];
  429. });
  430. } else {
  431. this.companyUserOptions = [];
  432. }
  433. },
  434. /** 查询用户列表 */
  435. getList() {
  436. this.loading = true;
  437. listUser(this.queryParams).then(response => {
  438. this.userList = response.rows;
  439. this.total = response.total;
  440. this.loading = false;
  441. });
  442. },
  443. // 取消按钮
  444. cancel() {
  445. this.open = false;
  446. this.reset();
  447. },
  448. // 表单重置
  449. reset() {
  450. this.form = {
  451. userId: null,
  452. nickName: null,
  453. avatar: null,
  454. phone: null,
  455. integral: null,
  456. status: null,
  457. tuiUserId: null,
  458. tuiTime: null,
  459. tuiUserCount: null,
  460. maOpenId: null,
  461. mpOpenId: null,
  462. unionId: null,
  463. isDel: null,
  464. userCode: null,
  465. remark: null,
  466. createTime: null,
  467. updateTime: null,
  468. lastIp: null,
  469. balance: null
  470. };
  471. this.resetForm("form");
  472. },
  473. /** 搜索按钮操作 */
  474. handleQuery() {
  475. this.queryParams.pageNum = 1;
  476. this.queryParams.companyId = this.queryCompanyId;
  477. this.queryParams.companyUserId = this.queryCompanyUserId;
  478. this.getList();
  479. },
  480. /** 重置按钮操作 */
  481. resetQuery() {
  482. this.resetForm("queryForm");
  483. this.createTime=null;
  484. this.queryParams.sTime=null;
  485. this.queryParams.eTime=null;
  486. this.queryParams.companyName = null;
  487. this.queryParams.companyUserNickName = null;
  488. this.queryParams.companyId = null;
  489. this.queryParams.companyUserId = null;
  490. this.handleQuery();
  491. },
  492. // 多选框选中数据
  493. handleSelectionChange(selection) {
  494. this.ids = selection.map(item => item.userId)
  495. this.single = selection.length!==1
  496. this.multiple = !selection.length
  497. },
  498. /** 新增按钮操作 */
  499. handleAdd() {
  500. this.reset();
  501. this.open = true;
  502. this.title = "添加用户";
  503. },
  504. /** 修改按钮操作 */
  505. handleUpdate(row) {
  506. this.reset();
  507. const userId = row.userId || this.ids
  508. getUser(userId).then(response => {
  509. this.form = response.data;
  510. this.open = true;
  511. this.title = "修改用户";
  512. this.form.status = String(this.form.status)
  513. });
  514. },
  515. /** 提交按钮 */
  516. submitForm() {
  517. this.$refs["form"].validate(valid => {
  518. if (valid) {
  519. if (this.form.userId != null) {
  520. updateUser(this.form).then(response => {
  521. this.msgSuccess("修改成功");
  522. this.open = false;
  523. this.getList();
  524. });
  525. } else {
  526. addUser(this.form).then(response => {
  527. this.msgSuccess("新增成功");
  528. this.open = false;
  529. this.getList();
  530. });
  531. }
  532. }
  533. });
  534. },
  535. /** 删除按钮操作 */
  536. handleDelete(row) {
  537. const userIds = row.userId || this.ids;
  538. this.$confirm('是否确认删除用户编号为"' + userIds + '"的数据项?', "警告", {
  539. confirmButtonText: "确定",
  540. cancelButtonText: "取消",
  541. type: "warning"
  542. }).then(function() {
  543. return delUser(userIds);
  544. }).then(() => {
  545. this.getList();
  546. this.msgSuccess("删除成功");
  547. }).catch(() => {});
  548. },
  549. /** 导出按钮操作 */
  550. handleExport() {
  551. const queryParams = this.queryParams;
  552. this.$confirm('是否确认导出所有用户数据项?', "警告", {
  553. confirmButtonText: "确定",
  554. cancelButtonText: "取消",
  555. type: "warning"
  556. }).then(() => {
  557. this.exportLoading = true;
  558. return exportUser(queryParams);
  559. }).then(response => {
  560. this.download(response.msg);
  561. this.exportLoading = false;
  562. }).catch(() => {});
  563. },
  564. /** 更换会员归属按钮操作 */
  565. handleChangeCompanyUser() {
  566. // 获取公司下拉列表
  567. getCompanyList().then(response => {
  568. if (response.code === 200) {
  569. this.companyOptions = response.data;
  570. // 重置表单和销售列表
  571. this.resetCompanyUserForm();
  572. this.companyUserOptions = [];
  573. this.changeCompanyUserOpen = true;
  574. } else {
  575. this.$message.error(response.msg || '获取公司列表失败');
  576. }
  577. }).catch(() => {
  578. this.$message.error('获取公司列表失败');
  579. });
  580. },
  581. /** 取消更换会员归属 */
  582. cancelChangeCompanyUser() {
  583. this.changeCompanyUserOpen = false;
  584. this.resetCompanyUserForm();
  585. },
  586. /** 重置更换会员归属表单 */
  587. resetCompanyUserForm() {
  588. this.changeCompanyUserForm = {
  589. companyId: null,
  590. companyUserId: null,
  591. userIds: []
  592. };
  593. this.resetForm("changeCompanyUserForm");
  594. },
  595. /** 提交更换会员归属 */
  596. submitChangeCompanyUserForm() {
  597. this.$refs["changeCompanyUserForm"].validate(valid => {
  598. if (valid) {
  599. // 调用更换会员归属接口
  600. // 检查companyId是否已设置
  601. if (!this.changeCompanyUserForm.companyId) {
  602. this.$message.error('请选择公司');
  603. return;
  604. }
  605. changeCompanyUser(this.ids, {
  606. companyUserId: this.changeCompanyUserForm.companyUserId,
  607. companyId: this.changeCompanyUserForm.companyId
  608. }).then(response => {
  609. if (response.code === 200) {
  610. this.msgSuccess("操作成功");
  611. this.changeCompanyUserOpen = false;
  612. this.getList();
  613. } else {
  614. this.$message.error(response.msg || '操作失败');
  615. }
  616. }).catch(() => {
  617. this.$message.error('操作失败');
  618. });
  619. }
  620. });
  621. }
  622. }
  623. };
  624. </script>