Label_AddUser.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <PermissionContainer
  3. :jiBieArr="[2]"
  4. :type="4"
  5. :tipArr="[, '标签配置只对站点级别开放', '', , '您没有开启标签功能']"
  6. >
  7. <div>
  8. <div class="Label_AddUser" v-if="labelList.labelFlag == 1">
  9. <div v-if="(labelList.labelArr || []).length == 0">
  10. 你未添加标签,请先添加标签后再来设置规则
  11. </div>
  12. <el-collapse
  13. v-model="activeNames"
  14. @change="openLabel"
  15. class=""
  16. accordion
  17. >
  18. <el-collapse-item
  19. :name="ele.id"
  20. v-for="(ele, index) in labelList.labelArr"
  21. :key="ele.id"
  22. >
  23. <template slot="title">
  24. 标签{{ index + 1 }} <i class="header-icon el-icon-info"></i>
  25. <b>{{ ele.labelName }}</b>
  26. </template>
  27. <el-col :span="11">
  28. <div>
  29. <el-input
  30. v-model="leftQuery.customerName"
  31. placeholder="输入姓名"
  32. style="width: 150px"
  33. size="mini"
  34. clearable
  35. />
  36. <el-input
  37. v-model="leftQuery.phone"
  38. placeholder="输入手机号"
  39. style="width: 150px; margin-left: 3px"
  40. size="mini"
  41. clearable
  42. />
  43. <el-button
  44. type="primary"
  45. size="mini"
  46. icon="el-icon-search"
  47. style="margin-left: 6px"
  48. @click="getLeftData"
  49. >查询</el-button
  50. >
  51. <el-button
  52. type="danger"
  53. size="mini"
  54. icon="el-icon-delete"
  55. style="margin-left: 6px"
  56. @click="clearLeftQuery()"
  57. >清空</el-button
  58. >
  59. </div>
  60. <el-table
  61. :data="leftData"
  62. border
  63. size="mini"
  64. :resizable="false"
  65. highlight-current-row
  66. height="500"
  67. @selection-change="handleLeftChange"
  68. disabled
  69. ref="leftTable"
  70. >
  71. >
  72. <el-table-column label="可选">
  73. <el-table-column
  74. prop="phone"
  75. label="姓名"
  76. type="selection"
  77. ></el-table-column>
  78. <el-table-column
  79. prop="customerName"
  80. label="姓名"
  81. ></el-table-column>
  82. <el-table-column
  83. prop="phone"
  84. label="手机号"
  85. ></el-table-column>
  86. <el-table-column label="添加" width="60px" align="center">
  87. <template slot-scope="scope">
  88. <el-button
  89. type="text"
  90. icon="el-icon-circle-plus-outline"
  91. class="underline btn24"
  92. size="mini"
  93. @click="handleMoveLabel('right', 1, scope.row)"
  94. >添加</el-button
  95. >
  96. </template>
  97. </el-table-column>
  98. </el-table-column>
  99. </el-table>
  100. <pagination
  101. v-show="leftTotal > 0"
  102. :total="leftTotal"
  103. :page.sync="leftQuery.pageNum"
  104. :limit.sync="leftQuery.pageSize"
  105. @pagination="getLeftData"
  106. style="margin-bottom: 30px"
  107. :pagerCount="5"
  108. layout="total, prev, pager, next"
  109. />
  110. </el-col>
  111. <el-col :span="2" style="text-align: center">
  112. <el-button
  113. type="primary"
  114. size="mini"
  115. @click="toggleLabel"
  116. style="margin-top: 200px"
  117. :disabled="toggleable"
  118. >切换</el-button
  119. >
  120. </el-col>
  121. <el-col :span="11">
  122. <div>
  123. <el-input
  124. v-model="rightQuery.customerName"
  125. placeholder="输入姓名"
  126. style="width: 150px"
  127. size="mini"
  128. clearable
  129. />
  130. <el-input
  131. v-model="rightQuery.phone"
  132. placeholder="输入手机号"
  133. style="width: 150px; margin-left: 3px"
  134. size="mini"
  135. clearable
  136. />
  137. <el-button
  138. type="primary"
  139. size="mini"
  140. icon="el-icon-search"
  141. style="margin-left: 6px"
  142. @click="getRightData"
  143. >查询</el-button
  144. >
  145. <el-button
  146. type="danger"
  147. size="mini"
  148. icon="el-icon-delete"
  149. style="margin-left: 6px"
  150. @click="clearRightQuery()"
  151. >清空</el-button
  152. >
  153. </div>
  154. <el-table
  155. :data="rightData"
  156. border
  157. size="mini"
  158. highlight-current-row
  159. :resizable="false"
  160. height="500"
  161. @selection-change="handleRightChange"
  162. :loading="true"
  163. ref="rightTable"
  164. >
  165. <el-table-column label="已选" :resizable="false">
  166. <el-table-column
  167. prop="phone"
  168. type="selection"
  169. ></el-table-column>
  170. <el-table-column
  171. prop="customerName"
  172. label="姓名"
  173. ></el-table-column>
  174. <el-table-column
  175. prop="phone"
  176. label="手机号"
  177. ></el-table-column>
  178. <el-table-column label="移除" width="60px" align="center">
  179. <template slot-scope="scope">
  180. <el-button
  181. type="text"
  182. icon="el-icon-remove-outline"
  183. class="underline btn24"
  184. size="mini"
  185. @click="handleMoveLabel('left', 1, scope.row)"
  186. >移除</el-button
  187. >
  188. </template>
  189. </el-table-column>
  190. </el-table-column>
  191. </el-table>
  192. <pagination
  193. v-show="rightTotal > 0"
  194. :total="rightTotal"
  195. :page.sync="rightQuery.pageNum"
  196. :limit.sync="rightQuery.pageSize"
  197. @pagination="getRightData"
  198. style="margin-bottom: 30px"
  199. :pagerCount="5"
  200. layout="total, prev, pager, next"
  201. />
  202. </el-col>
  203. </el-collapse-item>
  204. </el-collapse>
  205. </div>
  206. <div v-else>你未启用标签功能</div>
  207. </div>
  208. </PermissionContainer>
  209. </template>
  210. <script>
  211. import {
  212. sysDeptDemoList,
  213. selectCustomerLabelInfo,
  214. addAndDelCustomerLabel,
  215. selectPhoneList,
  216. selectNotCustomerLabelInfo,
  217. } from "@/api/label/label";
  218. export default {
  219. name: "Label_SetLabel",
  220. data() {
  221. return {
  222. activeNames: undefined,
  223. labelList: {},
  224. notCustomerLabelList: [],
  225. customerLabelList: [],
  226. loading: false,
  227. error: false,
  228. currentLabelId: undefined,
  229. pageStatus: 0,
  230. timer: null,
  231. leftData: [],
  232. rightData: [],
  233. leftTotal: 100,
  234. rightTotal: 100,
  235. leftQuery: {
  236. pageNum: 1,
  237. pageSize: 10,
  238. labelId: null,
  239. customerName: null,
  240. phone: null,
  241. },
  242. rightQuery: {
  243. pageNum: 1,
  244. pageSize: 10,
  245. labelId: null,
  246. customerName: null,
  247. phone: null,
  248. },
  249. moveRightData: [],
  250. moveLeftData: [],
  251. };
  252. },
  253. created() {
  254. this.init();
  255. },
  256. computed: {
  257. toggleable() {
  258. if (this.moveRightData.length === 0 && this.moveLeftData.length === 0) {
  259. return true;
  260. }
  261. return false;
  262. },
  263. },
  264. methods: {
  265. getLeftData() {
  266. // this.leftData = [];
  267. selectNotCustomerLabelInfo(this.leftQuery)
  268. .then((res) => {
  269. if (res.code == 200) {
  270. this.leftData = res.rows;
  271. this.leftTotal = res.total;
  272. } else {
  273. throw new Error("");
  274. }
  275. })
  276. .catch((err) => {
  277. this.leftData = [];
  278. this.leftTotal = 0;
  279. this.msgError("拉取左边标签用户失败,请刷新~");
  280. });
  281. },
  282. getRightData() {
  283. // this.rightData = [];
  284. selectPhoneList(this.rightQuery)
  285. .then((res) => {
  286. if (res.code == 200) {
  287. this.rightData = res.rows;
  288. this.rightTotal = res.total;
  289. } else {
  290. throw new Error("");
  291. }
  292. })
  293. .catch(() => {
  294. this.rightData = [];
  295. this.rightTotal = 0;
  296. this.msgError("拉取右边标签用户失败,请刷新~");
  297. });
  298. },
  299. handleMoveLabel(direction = "right", type = 1, row, labelIdArr) {
  300. // type 1 传row type 2 idArr direction right 向右转移 left 向左转移
  301. let changeArr = [];
  302. if (type == 1) {
  303. changeArr.push(row.phone);
  304. } else if (type == 2) {
  305. changeArr = labelIdArr;
  306. }
  307. const query = {
  308. labelId:
  309. direction == "right"
  310. ? this.leftQuery.labelId
  311. : this.rightQuery.labelId,
  312. flag: "1",
  313. phoneList: changeArr,
  314. };
  315. if (direction == "right") {
  316. query.flag = "0";
  317. } else if (direction == "left") {
  318. query.flag = "1";
  319. }
  320. addAndDelCustomerLabel(query)
  321. .then((res) => {
  322. if (res.code == 200) {
  323. this.getLeftData();
  324. this.getRightData();
  325. } else {
  326. throw new Error("");
  327. }
  328. })
  329. .catch((err) => {});
  330. },
  331. clearLeftQuery(labelId = this.leftQuery.labelId) {
  332. this.leftQuery = {
  333. pageNum: 1,
  334. pageSize: 10,
  335. labelId,
  336. customerName: null,
  337. phone: null,
  338. };
  339. },
  340. clearRightQuery(labelId = this.rightQuery.labelId) {
  341. console.log(this.rightQuery);
  342. this.rightQuery = {
  343. pageNum: 1,
  344. pageSize: 10,
  345. labelId,
  346. customerName: null,
  347. phone: null,
  348. };
  349. },
  350. handleLeftChange(val) {
  351. let changeArr = [];
  352. val.map((ele) => {
  353. changeArr.push(ele.phone);
  354. });
  355. this.moveLeftData = [];
  356. this.moveRightData = changeArr;
  357. this.$refs.rightTable.map((ele) => {
  358. ele.clearSelection();
  359. });
  360. },
  361. handleRightChange(val) {
  362. let changeArr = [];
  363. val.map((ele) => {
  364. changeArr.push(ele.phone);
  365. });
  366. this.moveLeftData = changeArr;
  367. this.moveRightData = [];
  368. this.$refs.leftTable.map((ele) => {
  369. ele.clearSelection();
  370. });
  371. },
  372. init() {
  373. this.setPageStatus();
  374. this.getLabelList();
  375. },
  376. setPageStatus() {
  377. this.queryPageStatus([2]).then((res) => {
  378. this.pageStatus = res;
  379. });
  380. },
  381. openLabel(id) {
  382. this.clearLeftQuery(id);
  383. this.clearRightQuery(id);
  384. this.getLeftData();
  385. this.getRightData();
  386. },
  387. // getLabelUser(id) {
  388. // this.loading = true;
  389. // selectCustomerLabelInfo({
  390. // labelId: id,
  391. // })
  392. // .then((res) => {
  393. // if (res.code == 200) {
  394. // this.notCustomerLabelList = res.data.notCustomerLabelList;
  395. // this.customerLabelList = res.data.phoneList;
  396. // } else {
  397. // throw new Error("");
  398. // }
  399. // })
  400. // .catch(() => {
  401. // this.loading = false;
  402. // this.error = true;
  403. // this.msgError("拉取标签下用户信息失败");
  404. // });
  405. // },
  406. toggleLabel() {
  407. console.log(this.moveLeftData);
  408. console.log(this.moveRightData);
  409. if (this.moveLeftData.length !== 0) {
  410. this.handleMoveLabel("left", 2, null, this.moveLeftData);
  411. return;
  412. }
  413. if (this.moveRightData.length !== 0) {
  414. this.handleMoveLabel("right", 2, null, this.moveRightData);
  415. return;
  416. }
  417. return;
  418. },
  419. getLabelList() {
  420. return sysDeptDemoList().then((res) => {
  421. if (res.code == 200) {
  422. this.labelList = res.data;
  423. } else {
  424. this.msgError("初始化数据失败");
  425. }
  426. });
  427. },
  428. // transfer(originlArr, direction, changeArr) {
  429. // const query = {
  430. // labelId: this.activeNames,
  431. // flag: "1",
  432. // phoneList: changeArr,
  433. // };
  434. // if (direction == "right") {
  435. // query.flag = "0";
  436. // } else if (direction == "left") {
  437. // query.flag = "1";
  438. // }
  439. // addAndDelCustomerLabel(query).then((res) => {
  440. // if (res.code == 200) {
  441. // this.getRightUser();
  442. // } else {
  443. // }
  444. // });
  445. // },
  446. },
  447. };
  448. </script>
  449. <style lang="scss">
  450. .Label_AddUser {
  451. .collapse {
  452. width: 1200px;
  453. margin: 0 auto;
  454. //.el-collapse-item__wrap {
  455. // border-bottom: 1px solid;
  456. //}
  457. .el-transfer-panel {
  458. width: 300px;
  459. height: 600px;
  460. }
  461. .el-transfer-panel__list.is-filterable {
  462. height: 465px;
  463. }
  464. }
  465. }
  466. </style>