Label_AddUser copy.vue 13 KB

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