index.vue 22 KB

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