agentList.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <!-- -->
  2. <template>
  3. <div class="m-container">
  4. <h2>
  5. <div class="squrt"></div>
  6. 代理商管理
  7. </h2>
  8. <div class="m-core">
  9. <save-form
  10. :inline="true"
  11. :model="searchForm"
  12. @submit="search"
  13. @reset="onReSet"
  14. >
  15. <el-form-item prop="search">
  16. <el-input
  17. v-model.trim="searchForm.search"
  18. clearable
  19. @keyup.enter.native="search"
  20. placeholder="姓名/手机号"
  21. ></el-input>
  22. </el-form-item>
  23. <el-form-item prop="state">
  24. <el-select placeholder="状态" v-model="searchForm.state" clearable>
  25. <el-option label="正常" value="0"></el-option>
  26. <el-option label="冻结" value="1"></el-option>
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item>
  30. <el-button native-type="submit" type="primary">搜索</el-button>
  31. <el-button native-type="reset" type="danger">重置</el-button>
  32. </el-form-item>
  33. </save-form>
  34. <div class="btnList">
  35. <el-button type="primary" style="margin-bottom: 20px" @click="addAgent">
  36. 新建代理商
  37. </el-button>
  38. <el-button type="primary" style="margin-bottom: 20px" @click="lookH5">
  39. 代理商H5
  40. </el-button>
  41. </div>
  42. <div class="tableWrap">
  43. <el-table
  44. style="width: 100%"
  45. :header-cell-style="{ background: '#EDEEF0', color: '#444' }"
  46. :data="tableList"
  47. row-key="userId"
  48. ref="table1"
  49. type="expand"
  50. lazy
  51. :load="getStaffList"
  52. @expand-change="hasExpandChange"
  53. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  54. >
  55. <!-- -->
  56. <el-table-column
  57. align="center"
  58. prop="userId"
  59. label="代理商编号"
  60. ></el-table-column>
  61. <el-table-column
  62. align="center"
  63. prop="proxyName"
  64. label="代理商名称"
  65. ></el-table-column>
  66. <el-table-column
  67. align="center"
  68. prop="name"
  69. label="姓名"
  70. ></el-table-column>
  71. <el-table-column
  72. align="center"
  73. prop="phone"
  74. label="手机号"
  75. ></el-table-column>
  76. <el-table-column
  77. align="center"
  78. prop="role"
  79. label="角色"
  80. ></el-table-column>
  81. <el-table-column align="center" prop="state" label="状态">
  82. <template slot-scope="scope">
  83. {{ scope.row.state == "0" ? "正常" : "冻结" }}
  84. </template>
  85. </el-table-column>
  86. <el-table-column
  87. align="center"
  88. fixed="right"
  89. label="操作"
  90. width="300"
  91. >
  92. <template slot-scope="scope">
  93. <div>
  94. <el-button type="text" @click="onJoinQrCode(scope.row)"
  95. >入驻二维码</el-button
  96. >
  97. <el-button
  98. type="text"
  99. v-if="!scope.row.parentId"
  100. @click="addAgentStaff(scope.row)"
  101. >添加员工</el-button
  102. >
  103. <!-- permission -->
  104. <el-button
  105. type="text"
  106. v-if="!scope.row.parentId"
  107. @click="addAgent(scope.row)"
  108. >修改</el-button
  109. >
  110. <el-button
  111. type="text"
  112. v-if="scope.row.parentId"
  113. @click="addAgentStaff(scope.row)"
  114. >修改</el-button
  115. >
  116. <el-button
  117. type="text"
  118. v-if="scope.row.state == '0' && !scope.row.parentId"
  119. @click="freezeProxy(scope.row)"
  120. >冻结</el-button
  121. >
  122. <el-button
  123. type="text"
  124. v-if="scope.row.state != '0' && !scope.row.parentId"
  125. @click="freezeProxy(scope.row)"
  126. >启用</el-button
  127. >
  128. </div>
  129. </template>
  130. </el-table-column>
  131. </el-table>
  132. <pagination
  133. sync
  134. :total.sync="rules.total"
  135. :page.sync="rules.page"
  136. :limit.sync="rules.limit"
  137. :page-sizes="rules.page_size"
  138. @pagination="getList"
  139. />
  140. </div>
  141. </div>
  142. <eidtAgentMager ref="eidtAgentMagerRef" @getList="getList" />
  143. <eidthStaff ref="eidthStaffRef" @getList="resetTreedata" />
  144. <qr-code
  145. v-model="codeStatus"
  146. :isDown="true"
  147. :title="title"
  148. :codeUrl="qrCodeUrl"
  149. />
  150. </div>
  151. </template>
  152. <script>
  153. import axios from "axios";
  154. import { getToken } from "@/utils/auth";
  155. import pagination from "@/components/Pagination/index";
  156. import load from "@/utils/loading";
  157. import { permission } from "@/utils/directivePage";
  158. import {
  159. getProxyUserList,
  160. freezeProxyUser,
  161. getProxyUserStaffList,
  162. } from "./api";
  163. import eidtAgentMager from "./modals/eidtAgentMager";
  164. import eidthStaff from "./modals/eidthStaff";
  165. import qrCode from "@/components/QrCode/index";
  166. import {
  167. isvalidPhone,
  168. vaildStudentUrl,
  169. vaildTeachingUrl,
  170. } from "@/utils/validate";
  171. export default {
  172. components: { pagination, eidtAgentMager, qrCode, eidthStaff },
  173. data() {
  174. return {
  175. searchForm: {
  176. search: null,
  177. state: "",
  178. },
  179. tableList: [],
  180. organList: [],
  181. rules: {
  182. // 分页规则
  183. limit: 10, // 限制显示条数
  184. page: 1, // 当前页
  185. total: 0, // 总条数
  186. page_size: [10, 20, 40, 50], // 选择限制显示条数
  187. },
  188. codeStatus: false,
  189. qrCodeUrl: null,
  190. title: "入驻二维码",
  191. hasLoad: false,
  192. currentLoadTreeData: null,
  193. resolveObj: null,
  194. treeIds: [],
  195. };
  196. },
  197. //生命周期 - 创建完成(可以访问当前this实例)
  198. created() {},
  199. //生命周期 - 挂载完成(可以访问DOM元素)
  200. mounted() {
  201. // 获取分部
  202. this.init();
  203. },
  204. methods: {
  205. init() {
  206. this.getList();
  207. },
  208. async getList() {
  209. try {
  210. const res = await getProxyUserList({
  211. ...this.searchForm,
  212. page: this.rules.page,
  213. rows: this.rules.limit,
  214. });
  215. this.tableList = res.data.rows.map((item, index) => {
  216. // console.log(this.$refs.table1["store"].states.treeData)
  217. return {
  218. ...item,
  219. hasChildren: true,
  220. };
  221. });
  222. this.refreshRow();
  223. this.rules.total = res.data.total;
  224. } catch (e) {}
  225. },
  226. search() {
  227. this.rules.page = 1;
  228. this.getList();
  229. // this.$set(this.$refs.table1.store.states.lazyTreeNodeMap,parentId,this.childrenData)
  230. },
  231. onReSet() {
  232. this.$nextTick(() => {
  233. this.search();
  234. });
  235. },
  236. permission(str) {
  237. return permission(str);
  238. },
  239. addAgent(row) {
  240. this.$refs.eidtAgentMagerRef.openDialog(row);
  241. },
  242. addAgentStaff(row) {
  243. this.$refs.eidthStaffRef.openDialog(row);
  244. },
  245. onJoinQrCode(row) {
  246. this.qrCodeUrl =
  247. vaildStudentUrl() +
  248. "/project/questionAsk/index.html?recommender=" +
  249. row.userId;
  250. this.title = "入驻二维码";
  251. this.codeStatus = true;
  252. },
  253. lookH5() {
  254. this.qrCodeUrl = vaildTeachingUrl() + "/#/saas-home";
  255. this.title = "代理商H5";
  256. this.codeStatus = true;
  257. },
  258. async freezeProxy(row) {
  259. let str = "";
  260. let state = "";
  261. if (row.state == 0) {
  262. state = 1;
  263. str = "冻结";
  264. } else {
  265. state = 0;
  266. str = "启用";
  267. }
  268. try {
  269. await this.$confirm(`是否${str}代理商"${row.proxyName}"?`, "提示", {
  270. type: "warning",
  271. });
  272. await freezeProxyUser({ state, id: row.userId });
  273. this.$message.success(`${str}成功`);
  274. this.getList();
  275. } catch (e) {}
  276. },
  277. async getStaffList(tree, treeNode, resolve) {
  278. this.hasLoad = true;
  279. this.currentLoadTreeData = tree;
  280. this.resolveObj = resolve;
  281. if (!this.treeIds.includes(tree.userId)) {
  282. this.treeIds.push(tree.userId);
  283. }
  284. try {
  285. const res = await getProxyUserStaffList({ id: tree.userId });
  286. console.log(res.data);
  287. resolve(res.data || []);
  288. } catch (e) {
  289. // resolve([])
  290. }
  291. },
  292. hasExpandChange(row, expanded) {
  293. if (expanded) {
  294. // 当前是展开状态
  295. if (this.hasLoad) {
  296. // 已执行过load,则去掉执行过的标记
  297. this.hasLoad = false;
  298. } else {
  299. // 不然,则执行load。因为load只会执行一次,所以需要在expand事件触发再次执行
  300. this.getStaffList(this.currentLoadTreeData, "", this.resolveObj);
  301. }
  302. }
  303. },
  304. refreshRow() {
  305. for (let i in this.treeIds) {
  306. this.$refs.table1["store"].states.treeData[
  307. this.treeIds[i]
  308. ].loaded = false;
  309. this.$refs.table1["store"].states.treeData[
  310. this.treeIds[i]
  311. ].expanded = false;
  312. }
  313. },
  314. async resetTreedata(parentId) {
  315. try {
  316. const res = await getProxyUserStaffList({ id: parentId });
  317. this.$set(
  318. this.$refs.table1.store.states.lazyTreeNodeMap,
  319. parentId,
  320. res.data
  321. );
  322. } catch (e) {
  323. // resolve([])
  324. }
  325. },
  326. },
  327. };
  328. </script>
  329. <style lang='scss' scoped>
  330. </style>