userapp.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. :page.sync="page"
  7. :permission="permissionList"
  8. :before-open="beforeOpen"
  9. v-model="form"
  10. ref="crud"
  11. @row-update="rowUpdate"
  12. @row-save="rowSave"
  13. @row-del="rowDel"
  14. @search-change="searchChange"
  15. @search-reset="searchReset"
  16. @selection-change="selectionChange"
  17. @current-change="currentChange"
  18. @size-change="sizeChange"
  19. @refresh-change="refreshChange"
  20. @on-load="onLoad">
  21. <template slot="menuLeft">
  22. <el-button type="danger"
  23. size="small"
  24. icon="el-icon-delete"
  25. plain
  26. v-if="permission.userapp_delete"
  27. @click="handleDelete">删 除
  28. </el-button>
  29. </template>
  30. <template slot="isStore" slot-scope="scope">
  31. <el-tag v-if="scope.row.isStore === 1" type="success">{{ scope.row.$isStore }}</el-tag>
  32. <el-tag v-if="scope.row.isStore === 0" type="primary">{{ scope.row.$isStore }}</el-tag>
  33. </template>
  34. <template slot="livingHall" slot-scope="scope">
  35. <el-tag v-if="scope.row.livingHall === 0" type="warning">{{ scope.row.$livingHall }}</el-tag>
  36. <el-tag v-else-if="scope.row.livingHall === 1" type="success">{{ scope.row.$livingHall }}</el-tag>
  37. </template>
  38. <template slot-scope="{type,size,row}" slot="menu">
  39. <el-button v-if="row.state == 1" :size="size" :type="type" @click="forbidden(row, 2)">禁用</el-button>
  40. <el-button v-if="row.state == 2" :size="size" :type="type" @click="forbidden(row, 1)">启用</el-button>
  41. <el-button v-if="row.livingHall === 0" :size="size" :type="type" @click="setLeader(row)">设为团长</el-button>
  42. <el-button v-if="row.livingHall === 1" :size="size" :type="type" @click="removeLeader(row)">移除团长</el-button>
  43. <el-button v-if="row.isStore === 0" :size="size" :type="type" @click="handleAddTicket(row)">设为供应商</el-button>
  44. <el-button v-if="row.isStore === 1" :size="size" :type="type" @click="removeStore(row)">移除供应商</el-button>
  45. </template>
  46. </avue-crud>
  47. <el-dialog title="选择自提点" :visible.sync="dialogVisible" width="80%" :append-to-body="true" :before-close="handleClose" >
  48. <avue-crud :option="selfTakeOption"
  49. :table-loading="selfTakeLoading"
  50. :data="selfTakeData"
  51. :page.sync="selfTakePage"
  52. v-model="selfTakeForm"
  53. ref="selfTakeCrud"
  54. @search-change="selfTakeSearchChange"
  55. @search-reset="selfTakeSearchReset"
  56. @selection-change="selfTakeSelectionChange"
  57. @current-change="selfTakeCurrentChange"
  58. @size-change="selfTakeSizeChange"
  59. @refresh-change="selfTakeRefreshChange"
  60. @on-load="selfTakeOnLoad">
  61. </avue-crud>
  62. <span slot="footer" class="dialog-footer">
  63. <el-button @click="handleClose">取 消</el-button>
  64. <el-button type="primary" @click="addUserSelfTake">确 定</el-button>
  65. </span>
  66. </el-dialog>
  67. <el-dialog title="新增供应商" append-to-body :visible.sync="addUserTicketBox" width="450px" :before-close="handleClose">
  68. <el-form :model="store" ref="store" label-width="80px">
  69. <el-form-item label="会员名称" labelWidth="130" prop="userName">
  70. <el-input v-model="store.userName" disabled="false" />
  71. </el-form-item>
  72. <el-form-item label="供应商名称" labelWidth="130" prop="name" :rules="[{ required: true, message: '供应商名称不能为空'}]">
  73. <el-input v-model="store.name" placeholder="请输入供应商名称" />
  74. </el-form-item>
  75. <el-form-item label="供应商电话" labelWidth="130" prop="tel" :rules="[{ required: true, message: '电话不能为空'}]">
  76. <el-input v-model="store.tel" placeholder="请输入供应商名称电话" />
  77. </el-form-item>
  78. </el-form>
  79. <div slot="footer" class="dialog-footer">
  80. <el-button @click="addUserTicketBox = false">取 消</el-button>
  81. <el-button type="primary" @click="submitTicket" :loading="addTicketButLoading">确 定</el-button>
  82. </div>
  83. </el-dialog>
  84. </basic-container>
  85. </template>
  86. <style>
  87. .codeGeting{
  88. background: #cdcdcd;
  89. border-color: #cdcdcd;
  90. }
  91. </style>
  92. <script>
  93. import {getList, getDetail, add, update, remove, addStore, removeCommander, setUpCommander} from "../../api/platform/userapp";
  94. import {listByUserId,getList as getSelfTakeList,addUserSelfTake } from "../../api/groupon/selftake";
  95. import {mapGetters} from "vuex";
  96. import {selfTakeOption} from "../../option/platform/userapp"
  97. export default {
  98. data() {
  99. return {
  100. leaderUserId: 0,
  101. selfTakeOption: selfTakeOption,
  102. addTicketButLoading: false,
  103. dialogVisible: false,
  104. getCodeButName: '获取验证码',
  105. disable: false,
  106. isGeting: false,
  107. count: 60,
  108. addUserTicketBox: false,
  109. addUserTicketForm: {
  110. score: '',
  111. code: '',
  112. codeId: ''
  113. },
  114. store: {
  115. userId: '',
  116. userName: '',
  117. name: '',
  118. tel: ''
  119. },
  120. form: {},
  121. query: {},
  122. loading: true,
  123. page: {
  124. pageSize: 10,
  125. currentPage: 1,
  126. total: 0
  127. },
  128. selectionList: [],
  129. option: {
  130. height:'auto',
  131. calcHeight: 30,
  132. tip: false,
  133. searchShow: true,
  134. searchMenuSpan: 6,
  135. border: true,
  136. // index: true,
  137. viewBtn: true,
  138. viewBtnIcon: ' ',
  139. editBtnIcon: ' ',
  140. selection: false,
  141. dialogClickModal: false,
  142. menuAlign: 'left',
  143. searchLabelWidth:100,
  144. menuWidth: 265,
  145. searchIcon: true,
  146. searchIndex: 3,
  147. column: [
  148. {
  149. label: "主键ID",
  150. prop: "id",
  151. hide: true,
  152. display: false,
  153. },
  154. {
  155. label: "用户ID",
  156. prop: "userId",
  157. hide: true,
  158. display: false,
  159. },
  160. {
  161. label: "会员昵称",
  162. prop: "name",
  163. addDisplay: true,
  164. editDisplay: true,
  165. search: true,
  166. },
  167. {
  168. label: "会员姓名",
  169. prop: "realName",
  170. addDisplay: true,
  171. editDisplay: true,
  172. search: true,
  173. },
  174. {
  175. label: "手机号",
  176. prop: "phone",
  177. addDisplay: false,
  178. editDisplay: false,
  179. search: true,
  180. },
  181. {
  182. label: "供应商身份",
  183. prop: "isStore",
  184. type: "select",
  185. dicUrl: "/api/blade-system/dict-biz/dictionary?code=is_store",
  186. props: {
  187. label: "dictValue",
  188. value: "dictKey"
  189. },
  190. dataType: "number",
  191. hide: false,
  192. search: true,
  193. addDisplay: false,
  194. editDisplay: false,
  195. rules: [{
  196. required: true,
  197. message: "请选择状态",
  198. trigger: "blur"
  199. }]
  200. },
  201. {
  202. label: "团长身份",
  203. prop: "livingHall",
  204. type: "select",
  205. dicUrl: "/api/blade-system/dict-biz/dictionary?code=is_captain",
  206. props: {
  207. label: "dictValue",
  208. value: "dictKey"
  209. },
  210. dataType: "number",
  211. hide: false,
  212. search: true,
  213. addDisplay: false,
  214. editDisplay: false,
  215. rules: [{
  216. required: true,
  217. message: "请选择状态",
  218. trigger: "blur"
  219. }]
  220. },
  221. {
  222. label: "状态",
  223. prop: "state",
  224. type: "select",
  225. dicUrl: "/api/blade-system/dict-biz/dictionary?code=user_state",
  226. props: {
  227. label: "dictValue",
  228. value: "dictKey"
  229. },
  230. dataType: "number",
  231. hide: false,
  232. search: true,
  233. addDisplay: true,
  234. rules: [{
  235. required: true,
  236. message: "请选择状态",
  237. trigger: "blur"
  238. }]
  239. },
  240. {
  241. label: "注册时间",
  242. prop: "createTime",
  243. addDisplay: false,
  244. editDisplay: false,
  245. width: 150
  246. },
  247. ]
  248. },
  249. data: [],
  250. userExportShow: false,
  251. userExportForm: {},
  252. userExportLoading: false,
  253. selfTakeList:[],
  254. selfTakeListTotal:0,
  255. mySelfTakeList:[],
  256. mySelfTakeListTotal:0,
  257. row:{},
  258. selfTakePage: {
  259. pageSize: 10,
  260. currentPage: 1,
  261. total: 0
  262. },
  263. selfTakeData: [],
  264. selfTakeLoading: false,
  265. selfTakeForm: {},
  266. selfTakeQuery: {},
  267. selfTakeSelectionList: []
  268. };
  269. },
  270. computed: {
  271. ...mapGetters(["permission"]),
  272. permissionList() {
  273. return {
  274. addBtn: this.vaildData(this.permission.userapp_add, false),
  275. viewBtn: this.vaildData(this.permission.userapp_view, false),
  276. delBtn: this.vaildData(this.permission.userapp_delete, false),
  277. editBtn: this.vaildData(this.permission.userapp_edit, false)
  278. };
  279. },
  280. ids() {
  281. let ids = [];
  282. this.selectionList.forEach(ele => {
  283. ids.push(ele.id);
  284. });
  285. return ids.join(",");
  286. }
  287. },
  288. methods: {
  289. deleteRow(index,mySelfTakeList){
  290. console.log(index);
  291. console.log(mySelfTakeList);
  292. this.mySelfTakeList =[];
  293. },
  294. addUserSelfTake(){
  295. if (this.selfTakeSelectionList.length === 0) {
  296. this.$message.warning("请选择一条数据");
  297. return;
  298. }
  299. if (this.selfTakeSelectionList.length > 1) {
  300. this.$message.warning("只能选择一条数据");
  301. return;
  302. }
  303. setUpCommander({
  304. userId: this.leaderUserId,
  305. selfTakeId: this.selfTakeSelectionList[0].id
  306. }).then(res =>{
  307. this.$message({
  308. type: "success",
  309. message: "操作成功!"
  310. });
  311. this.onLoad(this.page, this.query)
  312. this.handleClose();
  313. })
  314. },
  315. handleCurrentChange(e){
  316. let arr = [];
  317. arr.push(e);
  318. this.mySelfTakeList = arr;
  319. },
  320. getCurrentChange(e){
  321. console.log(e)
  322. getSelfTakeList(e,10,{status:1}).then(res =>{
  323. console.log(res)
  324. this.selfTakeListTotal = res.data.data.total
  325. this.selfTakeList = res.data.data.records
  326. })
  327. },
  328. addSelftake(row){
  329. this.row =row;
  330. this.dialogVisible = true;
  331. getSelfTakeList(1,10,{status:1}).then(res =>{
  332. console.log(res)
  333. this.selfTakeListTotal = res.data.data.total
  334. this.selfTakeList = res.data.data.records
  335. })
  336. listByUserId(row.userId).then(res =>{
  337. this.mySelfTakeList = res.data.data
  338. })
  339. },
  340. /**
  341. * 移除团长
  342. * @param row
  343. */
  344. removeLeader(row) {
  345. removeCommander({
  346. userId: row.userId
  347. }).then(res =>{
  348. this.onLoad(this.page, this.query);
  349. this.$message({
  350. type: "success",
  351. message: "移除成功"
  352. });
  353. })
  354. },
  355. setLeader(row) {
  356. this.leaderUserId = row.userId;
  357. this.dialogVisible = true;
  358. },
  359. /**
  360. * 禁用用户
  361. * @param row
  362. * @param state
  363. */
  364. forbidden(row, state) {
  365. let title = state == 1 ? '启用' : '禁用';
  366. this.$confirm('此操作将会' + title+ '该用户, 是否继续?', '提示', {
  367. confirmButtonText: '确定',
  368. cancelButtonText: '取消',
  369. type: 'warning'
  370. }).then(() => {
  371. row.state = state;
  372. this.loading = true;
  373. update(row).then(res => {
  374. if(res.data.code !== 200){
  375. this.$message.error(res.data.msg);
  376. } else{
  377. this.$message.success(res.data.msg);
  378. }
  379. this.loading = false;
  380. })
  381. }).catch(() => {});
  382. },
  383. rowSave(row, done, loading) {
  384. add(row).then(() => {
  385. this.onLoad(this.page);
  386. this.$message({
  387. type: "success",
  388. message: "操作成功!"
  389. });
  390. done();
  391. }, error => {
  392. loading();
  393. window.console.log(error);
  394. });
  395. },
  396. rowUpdate(row, index, done, loading) {
  397. update(row).then(() => {
  398. this.onLoad(this.page);
  399. this.$message({
  400. type: "success",
  401. message: "操作成功!"
  402. });
  403. done();
  404. }, error => {
  405. loading();
  406. console.log(error);
  407. });
  408. },
  409. rowDel(row) {
  410. this.$confirm("确定将选择数据删除?", {
  411. confirmButtonText: "确定",
  412. cancelButtonText: "取消",
  413. type: "warning"
  414. })
  415. .then(() => {
  416. return remove(row.id);
  417. })
  418. .then(() => {
  419. this.onLoad(this.page);
  420. this.$message({
  421. type: "success",
  422. message: "操作成功!"
  423. });
  424. });
  425. },
  426. handleAddTicket(row) {
  427. this.store.userName = row.realName
  428. this.store.userId = row.userId
  429. this.store.tel = row.phone
  430. this.addUserTicketBox = true;
  431. },
  432. handleDelete() {
  433. if (this.selectionList.length === 0) {
  434. this.$message.warning("请选择至少一条数据");
  435. return;
  436. }
  437. this.$confirm("确定将选择数据删除?", {
  438. confirmButtonText: "确定",
  439. cancelButtonText: "取消",
  440. type: "warning"
  441. })
  442. .then(() => {
  443. return remove(this.ids);
  444. })
  445. .then(() => {
  446. this.onLoad(this.page);
  447. this.$message({
  448. type: "success",
  449. message: "操作成功!"
  450. });
  451. this.$refs.crud.toggleSelection();
  452. });
  453. },
  454. beforeOpen(done, type) {
  455. if (["edit", "view"].includes(type)) {
  456. getDetail(this.form.id).then(res => {
  457. this.form = res.data.data;
  458. });
  459. }
  460. done();
  461. },
  462. searchReset() {
  463. this.query = {};
  464. this.onLoad(this.page);
  465. },
  466. searchChange(params, done) {
  467. this.query = params;
  468. this.page.currentPage = 1;
  469. this.onLoad(this.page, params);
  470. done();
  471. },
  472. selectionChange(list) {
  473. this.selectionList = list;
  474. },
  475. selectionClear() {
  476. this.selectionList = [];
  477. this.$refs.crud.toggleSelection();
  478. },
  479. currentChange(currentPage){
  480. this.page.currentPage = currentPage;
  481. },
  482. sizeChange(pageSize){
  483. this.page.pageSize = pageSize;
  484. },
  485. refreshChange() {
  486. this.onLoad(this.page, this.query);
  487. },
  488. onLoad(page, params = {}) {
  489. this.loading = true;
  490. this.query.userType = 2;
  491. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  492. const data = res.data.data;
  493. this.page.total = data.total;
  494. this.data = data.records;
  495. this.loading = false;
  496. this.selectionClear();
  497. });
  498. },
  499. submitTicket() {
  500. this.$refs["store"].validate((valid) => {
  501. if (valid) {
  502. const loading = this.$loading({
  503. lock: true,
  504. text: '处理中,请稍等...',
  505. spinner: 'el-icon-loading',
  506. background: 'rgba(0, 0, 0, 0.7)'
  507. });
  508. this.addTicketButLoading = true;
  509. addStore(this.store).then(res => {
  510. loading.close();
  511. this.$message.success("增加成功");
  512. this.onLoad(this.page, this.query);
  513. }).catch(e => {
  514. this.addTicketButLoading = false;
  515. loading.close();
  516. })
  517. } else {
  518. return false;
  519. }
  520. });
  521. },
  522. selfTakeSearchReset() {
  523. this.selfTakeQuery = {};
  524. this.selfTakeOnLoad(this.selfTakePage);
  525. },
  526. selfTakeSearchChange(params, done) {
  527. this.selfTakeQuery = params;
  528. this.selfTakePage.currentPage = 1;
  529. this.selfTakeOnLoad(this.selfTakePage, params);
  530. done();
  531. },
  532. selfTakeSelectionChange(list) {
  533. this.selfTakeSelectionList = list;
  534. },
  535. selfTakeSelectionClear() {
  536. this.selfTakeSelectionList = [];
  537. this.$refs.selfTakeCrud.toggleSelection();
  538. },
  539. selfTakeCurrentChange(currentPage){
  540. this.selfTakePage.currentPage = currentPage;
  541. },
  542. selfTakeSizeChange(pageSize){
  543. this.selfTakePage.pageSize = pageSize;
  544. },
  545. selfTakeRefreshChange() {
  546. this.selfTakeOnLoad(this.selfTakePage, this.selfTakeQuery);
  547. },
  548. selfTakeOnLoad(page, params = {}) {
  549. this.selfTakeLoading = true;
  550. this.selfTakeQuery.status = 1;
  551. getSelfTakeList(page.currentPage, page.pageSize, Object.assign(params, this.selfTakeQuery)).then(res => {
  552. const data = res.data.data;
  553. this.selfTakePage.total = data.total;
  554. this.selfTakeData = data.records;
  555. this.selfTakeLoading = false;
  556. this.selfTakeSelectionClear();
  557. });
  558. },
  559. handleClose() {
  560. this.leaderUserId = 0;
  561. this.dialogVisible = false;
  562. this.addUserTicketBox = false
  563. this.store = {};
  564. this.addTicketButLoading = false;
  565. },
  566. /**
  567. * 移除供应商
  568. */
  569. removeStore(row) {
  570. }
  571. }
  572. };
  573. </script>
  574. <style>
  575. </style>