index.vue 19 KB

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