index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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="warning"
  114. plain
  115. icon="el-icon-download"
  116. size="mini"
  117. :loading="exportLoading"
  118. @click="handleExport"
  119. v-hasPermi="['his:user:export']"
  120. >导出</el-button>
  121. </el-col>
  122. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  123. </el-row>
  124. <el-table height="660" v-loading="loading" border :data="userList" @selection-change="handleSelectionChange" >
  125. <el-table-column type="selection" width="55" align="center" />
  126. <el-table-column label="会员id" align="center" prop="userId" width="150px"/>
  127. <el-table-column label="用户昵称" align="center" prop="nickName" width="150px"/>
  128. <el-table-column label="会员头像" align="center" width="80">
  129. <template slot-scope="scope">
  130. <el-popover
  131. placement="right"
  132. title=""
  133. trigger="hover"
  134. >
  135. <img slot="reference" :src="scope.row.avatar" width="50" >
  136. <img :src="scope.row.avatar" style="max-width: 120px;">
  137. </el-popover>
  138. </template>
  139. </el-table-column>
  140. <el-table-column label="手机号码" align="center" prop="phone" width="150px" />
  141. <el-table-column label="用户积分" align="center" prop="integral" />
  142. <el-table-column label="用户状态" align="center" prop="status" >
  143. <template slot-scope="scope">
  144. <dict-tag :options="userOptions" :value="scope.row.status"/>
  145. </template>
  146. </el-table-column>
  147. <el-table-column label="所属公司" align="center" prop="companyName" />
  148. <el-table-column label="所属销售" align="center" prop="companyUserNickName" />
  149. <el-table-column label="用户备注" align="center" prop="remark" />
  150. <el-table-column label="上级昵称" align="center" prop="tuiName" />
  151. <el-table-column label="app来源" align="center" prop="source" />
  152. <el-table-column label="登陆设备" align="center" prop="loginDevice" />
  153. <el-table-column label="上级手机号码" align="center" prop="tuiPhone" width="150px"/>
  154. <el-table-column label="下级人数" align="center" prop="tuiUserCount" />
  155. <el-table-column label="最后一次登录ip" align="center" prop="lastIp" width="130px"/>
  156. <el-table-column label="余额" align="center" prop="balance" />
  157. <el-table-column label="注册时间" align="center" prop="createTime" width="150px" />
  158. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="150px">
  159. <template slot-scope="scope">
  160. <el-button
  161. size="mini"
  162. type="text"
  163. icon="el-icon-edit"
  164. @click="handleUpdate(scope.row)"
  165. v-hasPermi="['his:user:edit']"
  166. >修改</el-button>
  167. <el-button
  168. size="mini"
  169. type="text"
  170. @click="handledetails(scope.row)"
  171. >详情</el-button>
  172. <el-button
  173. size="mini"
  174. type="text"
  175. @click="handleDelete(scope.row)"
  176. v-hasPermi="['his:user:remove']"
  177. >删除</el-button>
  178. <el-button
  179. size="mini"
  180. type="text"
  181. @click="handleAddPoint(scope.row)"
  182. v-hasPermi="['his:user:addPoint']"
  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. <el-dialog :title="addPointDialog.title" :visible.sync="addPointDialog.open" width="500px" append-to-body>
  227. <el-form ref="addPointForm" :model="addPointDialog.form" :rules="addPointDialog.rules" label-width="100px">
  228. <el-form-item label="积分" prop="point">
  229. <el-input-number :min="0" :step="1" :precision="0" v-model="addPointDialog.form.point" placeholder="请输入积分" />
  230. <div style="color: #a95812">积分不能为小数</div>
  231. </el-form-item>
  232. <el-form-item label="备注" prop="remark">
  233. <el-input type="textarea" v-model="addPointDialog.form.remark" placeholder="请输入备注说明" />
  234. </el-form-item>
  235. </el-form>
  236. <div slot="footer" class="dialog-footer">
  237. <el-button type="primary" @click="submitAddPointForm">确 定</el-button>
  238. <el-button @click="cancelAddPoint">取 消</el-button>
  239. </div>
  240. </el-dialog>
  241. </div>
  242. </template>
  243. <script>
  244. import { listUser, getUser, delUser, addUser, updateUser, exportUser, addPoint } from "@/api/his/user";
  245. import { getCompanyUserList, changeCompanyUser, getCompanyList } from '@/api/company/companyUser';
  246. import userDetails from '../../components/his/userDetails.vue';
  247. import userDetailsByNew from './userDetails.vue';
  248. export default {
  249. name: "User",
  250. components: {userDetails,userDetailsByNew},
  251. data() {
  252. return {
  253. companyQueryOptions:[],
  254. companyQueryUserOptions:[],
  255. queryCompanyId:null,
  256. queryCompanyUserId:null,
  257. companyName: null,
  258. companyUserNickName: null,
  259. companyOptions: [],
  260. companyUserOptions: [],
  261. show:{
  262. title:"用户详情",
  263. open:false,
  264. },
  265. userOptions: [],
  266. // 遮罩层
  267. loading: true,
  268. // 导出遮罩层
  269. exportLoading: false,
  270. // 选中数组
  271. ids: [],
  272. orOptions:[],
  273. // 非单个禁用
  274. single: true,
  275. // 非多个禁用
  276. multiple: true,
  277. // 显示搜索条件
  278. showSearch: true,
  279. // 总条数
  280. total: 0,
  281. // 用户表格数据
  282. userList: [],
  283. // 弹出层标题
  284. title: "",
  285. // 是否显示弹出层
  286. open: false,
  287. createTime:null,
  288. // 查询参数
  289. queryParams: {
  290. pageNum: 1,
  291. pageSize: 10,
  292. nickName: null,
  293. avatar: null,
  294. phone: null,
  295. phoneMk: null,
  296. integral: null,
  297. status: null,
  298. tuiUserId: null,
  299. tuiTime: null,
  300. tuiUserCount: null,
  301. maOpenId: null,
  302. mpOpenId: null,
  303. unionId: null,
  304. isDel: null,
  305. userCode: null,
  306. lastIp: null,
  307. balance: null,
  308. sTime:null,
  309. eTime:null,
  310. isBuy:null,
  311. source:null,
  312. companyName: null,
  313. },
  314. // 表单参数
  315. form: {},
  316. // 表单校验
  317. rules: {
  318. nickName: [
  319. { required: true, message: "昵称不能为空", trigger: "blur" }
  320. ],
  321. status: [
  322. { required: true, message: "用户状态不能为空", trigger: "blur" }
  323. ],
  324. integral: [
  325. { required: true, message: "用户积分不能为空", trigger: "blur" }
  326. ],
  327. },
  328. addPointDialog: {
  329. open: false,
  330. title: "添加积分",
  331. form: {
  332. userId: null,
  333. point: null,
  334. remark: null
  335. },
  336. rules: {
  337. point: [
  338. { required: true, message: "请输入积分", trigger: "blur" },
  339. { validator: (rule, value, callback) => {
  340. if (Number(value) > 0) {
  341. callback(); // 验证通过
  342. } else {
  343. callback(new Error("积分必须大于0"));
  344. }
  345. },
  346. trigger: "blur" }
  347. ]
  348. }
  349. }
  350. };
  351. },
  352. created() {
  353. this.getList();
  354. this.getDicts("sys_user_status").then(response => {
  355. this.userOptions = response.data;
  356. });
  357. this.getDicts("sys_company_or").then(response => {
  358. this.orOptions = response.data;
  359. });
  360. getCompanyList().then(response => {
  361. if (response.code === 200) {
  362. this.companyQueryOptions = response.data;
  363. }});
  364. },
  365. methods: {
  366. /** 销售选择变化 */
  367. handleCompanyUserChange(userId) {
  368. if (!this.changeCompanyUserForm.companyId) {
  369. this.$message.warning('请先选择公司');
  370. this.changeCompanyUserForm.companyUserId = null;
  371. return;
  372. }
  373. },
  374. change(){
  375. if(this.createTime!=null){
  376. this.queryParams.sTime=this.createTime[0];
  377. this.queryParams.eTime=this.createTime[1];
  378. }else{
  379. this.queryParams.sTime=null;
  380. this.queryParams.eTime=null;
  381. }
  382. },
  383. handledetails(row){
  384. this.show.open=true;
  385. setTimeout(() => {
  386. this.$refs.userDetailsByNew.getDetails(row.userId);
  387. }, 1);
  388. },
  389. handleQueryCompanyChange(companyId){
  390. // 清空已选择的销售
  391. this.queryCompanyUserId = null;
  392. // 根据公司ID获取对应的销售列表
  393. if (companyId) {
  394. getCompanyUserList({ companyId: companyId }).then(response => {
  395. if (response.code === 200) {
  396. this.companyQueryUserOptions = response.data;
  397. } else {
  398. this.$message.error(response.msg || '获取销售列表失败');
  399. this.companyQueryUserOptions = [];
  400. }
  401. }).catch(() => {
  402. this.$message.error('获取销售列表失败');
  403. this.companyQueryUserOptions = [];
  404. });
  405. } else {
  406. this.companyQueryUserOptions = [];
  407. }
  408. },
  409. /** 查询用户列表 */
  410. getList() {
  411. this.loading = true;
  412. listUser(this.queryParams).then(response => {
  413. this.userList = response.rows;
  414. this.total = response.total;
  415. this.loading = false;
  416. });
  417. },
  418. // 取消按钮
  419. cancel() {
  420. this.open = false;
  421. this.reset();
  422. },
  423. // 表单重置
  424. reset() {
  425. this.form = {
  426. userId: null,
  427. nickName: null,
  428. avatar: null,
  429. phone: null,
  430. integral: null,
  431. status: null,
  432. tuiUserId: null,
  433. tuiTime: null,
  434. tuiUserCount: null,
  435. maOpenId: null,
  436. mpOpenId: null,
  437. unionId: null,
  438. isDel: null,
  439. userCode: null,
  440. remark: null,
  441. createTime: null,
  442. updateTime: null,
  443. lastIp: null,
  444. balance: null
  445. };
  446. this.resetForm("form");
  447. },
  448. /** 搜索按钮操作 */
  449. handleQuery() {
  450. this.queryParams.pageNum = 1;
  451. this.queryParams.companyId = this.queryCompanyId;
  452. this.queryParams.companyUserId = this.queryCompanyUserId;
  453. this.getList();
  454. },
  455. /** 重置按钮操作 */
  456. resetQuery() {
  457. this.resetForm("queryForm");
  458. this.createTime=null;
  459. this.queryParams.sTime=null;
  460. this.queryParams.eTime=null;
  461. this.queryParams.companyName = null;
  462. this.queryParams.companyUserNickName = null;
  463. this.queryParams.companyId = null;
  464. this.queryParams.companyUserId = null;
  465. this.handleQuery();
  466. },
  467. // 多选框选中数据
  468. handleSelectionChange(selection) {
  469. this.ids = selection.map(item => item.userId)
  470. this.single = selection.length!==1
  471. this.multiple = !selection.length
  472. },
  473. /** 新增按钮操作 */
  474. handleAdd() {
  475. this.reset();
  476. this.open = true;
  477. this.title = "添加用户";
  478. },
  479. /** 修改按钮操作 */
  480. handleUpdate(row) {
  481. this.reset();
  482. const userId = row.userId || this.ids
  483. getUser(userId).then(response => {
  484. this.form = response.data;
  485. this.open = true;
  486. this.title = "修改用户";
  487. this.form.status = String(this.form.status)
  488. });
  489. },
  490. /** 提交按钮 */
  491. submitForm() {
  492. this.$refs["form"].validate(valid => {
  493. if (valid) {
  494. if (this.form.userId != null) {
  495. updateUser(this.form).then(response => {
  496. this.msgSuccess("修改成功");
  497. this.open = false;
  498. this.getList();
  499. });
  500. } else {
  501. addUser(this.form).then(response => {
  502. this.msgSuccess("新增成功");
  503. this.open = false;
  504. this.getList();
  505. });
  506. }
  507. }
  508. });
  509. },
  510. /** 删除按钮操作 */
  511. handleDelete(row) {
  512. const userIds = row.userId || this.ids;
  513. this.$confirm('是否确认删除用户编号为"' + userIds + '"的数据项?', "警告", {
  514. confirmButtonText: "确定",
  515. cancelButtonText: "取消",
  516. type: "warning"
  517. }).then(function() {
  518. return delUser(userIds);
  519. }).then(() => {
  520. this.getList();
  521. this.msgSuccess("删除成功");
  522. }).catch(() => {});
  523. },
  524. handleAddPoint(row) {
  525. console.log(row)
  526. this.resetForm("addPointForm");
  527. this.addPointDialog.form = {
  528. userId: row.userId,
  529. point: 0,
  530. remark: ''
  531. }
  532. this.addPointDialog.open = true
  533. },
  534. submitAddPointForm() {
  535. this.$refs["addPointForm"].validate(valid => {
  536. if (valid) {
  537. addPoint(this.addPointDialog.form).then(response => {
  538. const {code} = response
  539. if (code !== 200) {
  540. this.msgError(response.msg || '添加失败');
  541. return
  542. }
  543. this.msgSuccess("添加成功");
  544. this.addPointDialog.open = false;
  545. this.getList();
  546. });
  547. }
  548. });
  549. },
  550. cancelAddPoint() {
  551. this.addPointDialog.open = false;
  552. },
  553. /** 导出按钮操作 */
  554. handleExport() {
  555. const queryParams = this.queryParams;
  556. this.$confirm('是否确认导出当前用户数据项?', "警告", {
  557. confirmButtonText: "确定",
  558. cancelButtonText: "取消",
  559. type: "warning"
  560. }).then(() => {
  561. this.exportLoading = true;
  562. return exportUser(queryParams);
  563. }).then(response => {
  564. this.download(response.msg);
  565. this.exportLoading = false;
  566. }).catch(() => {});
  567. },
  568. }
  569. };
  570. </script>