index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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. <userDetailsByNew ref="userDetailsByNew" />
  224. </el-drawer>
  225. <!-- 更换会员归属对话框 -->
  226. <el-dialog title="更换会员归属" :visible.sync="changeCompanyUserOpen" width="500px" append-to-body>
  227. <el-form ref="changeCompanyUserForm" :model="changeCompanyUserForm" :rules="changeCompanyUserRules" label-width="100px">
  228. <el-form-item label="选择公司" prop="companyId">
  229. <el-select v-model="changeCompanyUserForm.companyId" placeholder="请选择公司" style="width: 100%" @change="handleCompanyChange">
  230. <el-option
  231. v-for="item in companyOptions"
  232. :key="item.companyId"
  233. :label="item.companyName"
  234. :value="item.companyId"
  235. />
  236. </el-select>
  237. </el-form-item>
  238. <el-form-item label="选择销售" prop="companyUserId">
  239. <el-select v-model="changeCompanyUserForm.companyUserId" placeholder="请选择销售" style="width: 100%" @change="handleCompanyUserChange">
  240. <el-option
  241. v-for="item in companyUserOptions"
  242. :key="item.userId"
  243. :label="item.nickName + '_' + item.userName"
  244. :value="item.userId"
  245. />
  246. </el-select>
  247. </el-form-item>
  248. </el-form>
  249. <div slot="footer" class="dialog-footer">
  250. <el-button type="primary" @click="submitChangeCompanyUserForm">确 定</el-button>
  251. <el-button @click="cancelChangeCompanyUser">取 消</el-button>
  252. </div>
  253. </el-dialog>
  254. </div>
  255. </template>
  256. <script>
  257. import { listUser, getUser, delUser, addUser, updateUser, exportUser } from "@/api/his/user";
  258. import { getCompanyUserList, changeCompanyUser, getCompanyList } from '@/api/company/companyUser';
  259. import userDetails from '../../components/his/userDetails.vue';
  260. import userDetailsByNew from './userDetails.vue';
  261. export default {
  262. name: "User",
  263. components: {userDetails,userDetailsByNew},
  264. data() {
  265. return {
  266. companyQueryOptions:[],
  267. companyQueryUserOptions:[],
  268. queryCompanyId:null,
  269. queryCompanyUserId:null,
  270. companyName: null,
  271. companyUserNickName: null,
  272. // 更换会员归属表单校验
  273. changeCompanyUserRules: {
  274. companyId: [
  275. { required: true, message: '请选择公司', trigger: 'change' }
  276. ],
  277. companyUserId: [
  278. { required: true, message: '请选择销售', trigger: 'change' }
  279. ]
  280. },
  281. companyOptions: [],
  282. companyUserOptions: [],
  283. // 更换会员归属对话框
  284. changeCompanyUserOpen: false,
  285. // 更换会员归属表单
  286. changeCompanyUserForm: {
  287. companyId: null,
  288. companyUserId: null,
  289. userIds: []
  290. },
  291. show:{
  292. title:"用户详情",
  293. open:false,
  294. },
  295. userOptions: [],
  296. // 遮罩层
  297. loading: true,
  298. // 导出遮罩层
  299. exportLoading: false,
  300. // 选中数组
  301. ids: [],
  302. orOptions:[],
  303. // 非单个禁用
  304. single: true,
  305. // 非多个禁用
  306. multiple: true,
  307. // 显示搜索条件
  308. showSearch: true,
  309. // 总条数
  310. total: 0,
  311. // 用户表格数据
  312. userList: [],
  313. // 弹出层标题
  314. title: "",
  315. // 是否显示弹出层
  316. open: false,
  317. createTime:null,
  318. // 查询参数
  319. queryParams: {
  320. pageNum: 1,
  321. pageSize: 10,
  322. nickName: null,
  323. avatar: null,
  324. phone: null,
  325. phoneMk: null,
  326. integral: null,
  327. status: null,
  328. tuiUserId: null,
  329. tuiTime: null,
  330. tuiUserCount: null,
  331. maOpenId: null,
  332. mpOpenId: null,
  333. unionId: null,
  334. isDel: null,
  335. userCode: null,
  336. lastIp: null,
  337. balance: null,
  338. sTime:null,
  339. eTime:null,
  340. isBuy:null,
  341. source:null
  342. },
  343. // 表单参数
  344. form: {},
  345. // 表单校验
  346. rules: {
  347. nickName: [
  348. { required: true, message: "昵称不能为空", trigger: "blur" }
  349. ],
  350. status: [
  351. { required: true, message: "用户状态不能为空", trigger: "blur" }
  352. ],
  353. integral: [
  354. { required: true, message: "用户积分不能为空", trigger: "blur" }
  355. ],
  356. }
  357. };
  358. },
  359. created() {
  360. this.getList();
  361. this.getDicts("sys_user_status").then(response => {
  362. this.userOptions = response.data;
  363. });
  364. this.getDicts("sys_company_or").then(response => {
  365. this.orOptions = response.data;
  366. });
  367. getCompanyList().then(response => {
  368. if (response.code === 200) {
  369. this.companyQueryOptions = response.data;
  370. }});
  371. },
  372. methods: {
  373. /** 销售选择变化 */
  374. handleCompanyUserChange(userId) {
  375. if (!this.changeCompanyUserForm.companyId) {
  376. this.$message.warning('请先选择公司');
  377. this.changeCompanyUserForm.companyUserId = null;
  378. return;
  379. }
  380. },
  381. change(){
  382. if(this.createTime!=null){
  383. this.queryParams.sTime=this.createTime[0];
  384. this.queryParams.eTime=this.createTime[1];
  385. }else{
  386. this.queryParams.sTime=null;
  387. this.queryParams.eTime=null;
  388. }
  389. },
  390. handledetails(row){
  391. this.show.open=true;
  392. setTimeout(() => {
  393. this.$refs.userDetailsByNew.getDetails(row.userId);
  394. }, 1);
  395. },
  396. handleQueryCompanyChange(companyId){
  397. // 清空已选择的销售
  398. this.queryCompanyUserId = null;
  399. // 根据公司ID获取对应的销售列表
  400. if (companyId) {
  401. getCompanyUserList({ companyId: companyId }).then(response => {
  402. if (response.code === 200) {
  403. this.companyQueryUserOptions = response.data;
  404. } else {
  405. this.$message.error(response.msg || '获取销售列表失败');
  406. this.companyQueryUserOptions = [];
  407. }
  408. }).catch(() => {
  409. this.$message.error('获取销售列表失败');
  410. this.companyQueryUserOptions = [];
  411. });
  412. } else {
  413. this.companyQueryUserOptions = [];
  414. }
  415. },
  416. handleCompanyChange(companyId) {
  417. // 清空已选择的销售
  418. this.changeCompanyUserForm.companyUserId = null;
  419. // 根据公司ID获取对应的销售列表
  420. if (companyId) {
  421. getCompanyUserList({ companyId: companyId }).then(response => {
  422. if (response.code === 200) {
  423. this.companyUserOptions = response.data;
  424. } else {
  425. this.$message.error(response.msg || '获取销售列表失败');
  426. this.companyUserOptions = [];
  427. }
  428. }).catch(() => {
  429. this.$message.error('获取销售列表失败');
  430. this.companyUserOptions = [];
  431. });
  432. } else {
  433. this.companyUserOptions = [];
  434. }
  435. },
  436. /** 查询用户列表 */
  437. getList() {
  438. this.loading = true;
  439. listUser(this.queryParams).then(response => {
  440. this.userList = response.rows;
  441. this.total = response.total;
  442. this.loading = false;
  443. });
  444. },
  445. // 取消按钮
  446. cancel() {
  447. this.open = false;
  448. this.reset();
  449. },
  450. // 表单重置
  451. reset() {
  452. this.form = {
  453. userId: null,
  454. nickName: null,
  455. avatar: null,
  456. phone: null,
  457. integral: null,
  458. status: null,
  459. tuiUserId: null,
  460. tuiTime: null,
  461. tuiUserCount: null,
  462. maOpenId: null,
  463. mpOpenId: null,
  464. unionId: null,
  465. isDel: null,
  466. userCode: null,
  467. remark: null,
  468. createTime: null,
  469. updateTime: null,
  470. lastIp: null,
  471. balance: null
  472. };
  473. this.resetForm("form");
  474. },
  475. /** 搜索按钮操作 */
  476. handleQuery() {
  477. this.queryParams.pageNum = 1;
  478. this.queryParams.companyId = this.queryCompanyId;
  479. this.queryParams.companyUserId = this.queryCompanyUserId;
  480. this.getList();
  481. },
  482. /** 重置按钮操作 */
  483. resetQuery() {
  484. this.resetForm("queryForm");
  485. this.createTime=null;
  486. this.queryParams.sTime=null;
  487. this.queryParams.eTime=null;
  488. this.queryParams.companyName = null;
  489. this.queryParams.companyUserNickName = null;
  490. this.queryParams.companyId = null;
  491. this.queryParams.companyUserId = null;
  492. this.handleQuery();
  493. },
  494. // 多选框选中数据
  495. handleSelectionChange(selection) {
  496. this.ids = selection.map(item => item.userId)
  497. this.single = selection.length!==1
  498. this.multiple = !selection.length
  499. },
  500. /** 新增按钮操作 */
  501. handleAdd() {
  502. this.reset();
  503. this.open = true;
  504. this.title = "添加用户";
  505. },
  506. /** 修改按钮操作 */
  507. handleUpdate(row) {
  508. this.reset();
  509. const userId = row.userId || this.ids
  510. getUser(userId).then(response => {
  511. this.form = response.data;
  512. this.open = true;
  513. this.title = "修改用户";
  514. this.form.status = String(this.form.status)
  515. });
  516. },
  517. /** 提交按钮 */
  518. submitForm() {
  519. this.$refs["form"].validate(valid => {
  520. if (valid) {
  521. if (this.form.userId != null) {
  522. updateUser(this.form).then(response => {
  523. this.msgSuccess("修改成功");
  524. this.open = false;
  525. this.getList();
  526. });
  527. } else {
  528. addUser(this.form).then(response => {
  529. this.msgSuccess("新增成功");
  530. this.open = false;
  531. this.getList();
  532. });
  533. }
  534. }
  535. });
  536. },
  537. /** 删除按钮操作 */
  538. handleDelete(row) {
  539. const userIds = row.userId || this.ids;
  540. this.$confirm('是否确认删除用户编号为"' + userIds + '"的数据项?', "警告", {
  541. confirmButtonText: "确定",
  542. cancelButtonText: "取消",
  543. type: "warning"
  544. }).then(function() {
  545. return delUser(userIds);
  546. }).then(() => {
  547. this.getList();
  548. this.msgSuccess("删除成功");
  549. }).catch(() => {});
  550. },
  551. /** 导出按钮操作 */
  552. handleExport() {
  553. const queryParams = this.queryParams;
  554. this.$confirm('是否确认导出所有用户数据项?', "警告", {
  555. confirmButtonText: "确定",
  556. cancelButtonText: "取消",
  557. type: "warning"
  558. }).then(() => {
  559. this.exportLoading = true;
  560. return exportUser(queryParams);
  561. }).then(response => {
  562. this.download(response.msg);
  563. this.exportLoading = false;
  564. }).catch(() => {});
  565. },
  566. /** 更换会员归属按钮操作 */
  567. handleChangeCompanyUser() {
  568. // 获取公司下拉列表
  569. getCompanyList().then(response => {
  570. if (response.code === 200) {
  571. this.companyOptions = response.data;
  572. // 重置表单和销售列表
  573. this.resetCompanyUserForm();
  574. this.companyUserOptions = [];
  575. this.changeCompanyUserOpen = true;
  576. } else {
  577. this.$message.error(response.msg || '获取公司列表失败');
  578. }
  579. }).catch(() => {
  580. this.$message.error('获取公司列表失败');
  581. });
  582. },
  583. /** 取消更换会员归属 */
  584. cancelChangeCompanyUser() {
  585. this.changeCompanyUserOpen = false;
  586. this.resetCompanyUserForm();
  587. },
  588. /** 重置更换会员归属表单 */
  589. resetCompanyUserForm() {
  590. this.changeCompanyUserForm = {
  591. companyId: null,
  592. companyUserId: null,
  593. userIds: []
  594. };
  595. this.resetForm("changeCompanyUserForm");
  596. },
  597. /** 提交更换会员归属 */
  598. submitChangeCompanyUserForm() {
  599. this.$refs["changeCompanyUserForm"].validate(valid => {
  600. if (valid) {
  601. // 调用更换会员归属接口
  602. // 检查companyId是否已设置
  603. if (!this.changeCompanyUserForm.companyId) {
  604. this.$message.error('请选择公司');
  605. return;
  606. }
  607. changeCompanyUser(this.ids, {
  608. companyUserId: this.changeCompanyUserForm.companyUserId,
  609. companyId: this.changeCompanyUserForm.companyId
  610. }).then(response => {
  611. if (response.code === 200) {
  612. this.msgSuccess("操作成功");
  613. this.changeCompanyUserOpen = false;
  614. this.getList();
  615. } else {
  616. this.$message.error(response.msg || '操作失败');
  617. }
  618. }).catch(() => {
  619. this.$message.error('操作失败');
  620. });
  621. }
  622. });
  623. }
  624. }
  625. };
  626. </script>