index.vue 21 KB

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