selectContact.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template>
  2. <view class="mainBox">
  3. <uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="选择" @clickLeft="backAdd">
  4. <!--右菜单-->
  5. <template slot="right">
  6. <u-button type="success" size="small" class="u-reset-button" @click="$refs.treePicker._show()"
  7. text="选择分类"></u-button>
  8. </template>
  9. </uni-nav-bar>
  10. <view class="searchBox">
  11. <input v-model="searchVal" placeholder="请输入名称" class="searchInput" />
  12. <u-button type="icon-shixiangxinzeng" size="30" @click="doSearch" data-icon="Search" class="searchBtn">
  13. <view class="iconfont icon-sousuo"></view>
  14. <view class="text">搜索</view>
  15. </u-button>
  16. </view>
  17. <view class="wrapper">
  18. <u-list @scrolltolower="scrolltolower" class="listContent">
  19. <checkbox-group v-for="(item, index) in listData" :key="index"
  20. @change="(e) => selectVal(e, item, index)">
  21. <label>
  22. <view class="listBox">
  23. <view class="listBox-sel">
  24. <checkbox :value="item.code" color="#fff" :disabled="item.disabled"
  25. :checked="item.checked" />
  26. </view>
  27. <view class="listBox-con">
  28. <view class="listBox-top">
  29. <view class="listBox-name">
  30. {{ item.name }}
  31. </view>
  32. </view>
  33. <view class="listBox-bottom">
  34. <!-- <view v-for="(itm, index) in tableHeader" :key="index">{{ itm.label }}:{{ item[itm.prop] }}</view> -->
  35. <view>代号:{{ item.serialNo || "" }}</view>
  36. <view>详细地址:{{
  37. (item.addressName || "") + item.address || ""
  38. }}</view>
  39. <view>是否指派:{{
  40. (item.assignStatus === 1 ? "是" : "否") || ""
  41. }}</view>
  42. <view>销售员:{{ item.salesmanName || "" }}</view>
  43. <view>创建人:{{ item.createUsername || "" }}</view>
  44. </view>
  45. </view>
  46. </view>
  47. </label>
  48. </checkbox-group>
  49. <u-empty class="noDate" style="margin-top: 20vh" v-if="!listData.length"></u-empty>
  50. </u-list>
  51. </view>
  52. <view class="footer">
  53. <view class="bottom" v-if="this.isAll == 1">
  54. <checkbox v-if="!seletedAll" color="#fff" :checked="seletedAll" @tap="_seletedAll">全选</checkbox>
  55. <checkbox class="select-all" color="#fff" v-else :checked="seletedAll" @tap="_seletedAll">取消全选
  56. </checkbox>
  57. </view>
  58. <u-button type="success" size="small" class="u-reset-button" :disabled="!checkListLen" @click="jumpAdd">
  59. <view class="selBtn">选择( {{ checkListLen }} )</view>
  60. </u-button>
  61. </view>
  62. <ba-tree-picker ref="treePicker" key="verify" :multiple="false" @select-change="confirm" title="选择分类"
  63. :localdata="classificationList" valueKey="id" textKey="name" />
  64. </view>
  65. </template>
  66. <script>
  67. import {
  68. contactPage
  69. } from "@/api/saleManage/contact/index.js";
  70. import {
  71. getTreeByPid
  72. } from "@/api/classifyManage/index.js";
  73. import baTreePicker from "@/components/ba-tree-picker/ba-tree-picker.vue";
  74. export default {
  75. components: {
  76. baTreePicker,
  77. },
  78. data() {
  79. return {
  80. page: 1,
  81. size: 20,
  82. isEnd: true,
  83. searchVal: "",
  84. pickTabIndex: 1,
  85. popupShow: false, //右侧搜索窗
  86. typeIndex: 1,
  87. listData: [], //列表数据
  88. classificationList: [], //分类数据
  89. seletedAll: false, //全选状态,
  90. isAll: "",
  91. isDemand: "",
  92. contactType: "",
  93. code: ''
  94. };
  95. },
  96. //选择的列表长度
  97. computed: {
  98. checkListLen() {
  99. return this.listData.filter((el) => el.checked).length;
  100. },
  101. },
  102. onLoad({
  103. isAll,
  104. type,
  105. contactType,code
  106. }) {
  107. this.isAll = isAll; //1多选 2单选
  108. this.contactType = contactType || 17; //17客户 19供应商
  109. this.code = code
  110. // *** 新增 需求进来的话 要增加查询条件
  111. if (type == "需求") {
  112. this.isDemand = "1";
  113. }
  114. this.getClassify();
  115. },
  116. onShow() {},
  117. methods: {
  118. scrolltolower() {
  119. if (this.isEnd) {
  120. return;
  121. }
  122. // 显示加载图标
  123. uni.showLoading({
  124. title: "数据加载中",
  125. });
  126. //获取更多数据
  127. this.page++;
  128. this.getList();
  129. },
  130. //列表数据
  131. async getList() {
  132. this.isEnd = false;
  133. this._getClassifyList();
  134. },
  135. async _getClassifyList() {
  136. uni.showLoading({
  137. title: "数据加载中",
  138. });
  139. const params = {
  140. pageNum: this.page,
  141. size: this.size,
  142. name: this.searchVal,
  143. categoryId: this.categoryLevelId,
  144. status: 1,
  145. type: this.contactType == 17 ? 1 : 2,
  146. };
  147. // 需求新增参数 ***
  148. if (this.isDemand == "1") {
  149. params.type = "1";
  150. params.status = "1";
  151. }
  152. contactPage(params).then((res) => {
  153. uni.hideLoading();
  154. if (this.page == 1) {
  155. this.listData = [];
  156. }
  157. this.listData = this.listData.concat(res.list);
  158. this.isEnd = this.listData.length >= res.count;
  159. });
  160. },
  161. confirm([id]) {
  162. this.categoryLevelId = id;
  163. this.page = 1;
  164. if (this.isAll === "2") {
  165. this.listData.forEach((item) => (item.checked = false));
  166. }
  167. this.getList();
  168. },
  169. async getClassify() {
  170. getTreeByPid(this.contactType).then((res) => {
  171. this.classificationList = res.data;
  172. if (this.classificationList.length) {
  173. if (this.code) {
  174. this.classificationList = this.filterTreeByCode(this.classificationList, this
  175. .code);
  176. }
  177. this.categoryLevelId = this.classificationList[0].id
  178. this.page = 1;
  179. this.getList();
  180. }
  181. });
  182. },
  183. /* 递归过滤树节点 */
  184. filterTreeByCode(list, code) {
  185. const result = [];
  186. const walk = (nodes) => {
  187. for (const node of nodes) {
  188. if (node.code === code) {
  189. result.push(node);
  190. } else if (node.children && node.children.length) {
  191. walk(node.children);
  192. }
  193. }
  194. };
  195. walk(list);
  196. return result;
  197. },
  198. doSearch() {
  199. this.page = 1;
  200. this.getList();
  201. },
  202. //勾选
  203. selectVal(e, val, index) {
  204. this.$set(this.listData[index], "checked", !this.listData[index].checked);
  205. if (this.isAll != 1) {
  206. this.listData.forEach((item, i) => {
  207. if (item.id != val.id) {
  208. this.$set(this.listData[i], "checked", false);
  209. }
  210. });
  211. } else {
  212. this.seletedAll = !this.listData.some((item) => !item.checked);
  213. }
  214. },
  215. //全选按钮
  216. _seletedAll() {
  217. if (!this.seletedAll) {
  218. this.seletedAll = true;
  219. this.listData.map((item) => {
  220. this.$set(item, "checked", true);
  221. });
  222. } else {
  223. this.seletedAll = false;
  224. //this.checkListLen = 0;
  225. this.listData.map((item) => {
  226. this.$set(item, "checked", false);
  227. });
  228. }
  229. },
  230. //跳转回添加页面
  231. jumpAdd() {
  232. uni.$emit(
  233. "setSelectList",
  234. this.listData.filter((item) => item.checked),
  235. );
  236. console.log(
  237. this.listData.filter((item) => item.checked),
  238. "222",
  239. );
  240. uni.navigateBack();
  241. },
  242. //返回添加页
  243. backAdd() {
  244. uni.navigateBack();
  245. },
  246. },
  247. };
  248. </script>
  249. <style lang="scss" scoped>
  250. .mainBox {
  251. height: 100vh;
  252. display: flex;
  253. flex-direction: column;
  254. .wrapper {
  255. flex: 1;
  256. overflow: hidden;
  257. }
  258. .searchBox {
  259. padding: 10rpx 0;
  260. box-sizing: border-box;
  261. background-color: #dedede;
  262. height: 90rpx;
  263. width: 100%;
  264. line-height: 90rpx;
  265. display: flex;
  266. justify-content: space-around;
  267. align-items: center;
  268. input {
  269. height: 78rpx;
  270. width: 65%;
  271. background: #f9f9f9 !important;
  272. margin: 0 10rpx;
  273. padding: 0 10rpx;
  274. box-sizing: border-box;
  275. border-radius: 5rpx;
  276. }
  277. .searchBtn {
  278. height: 80rpx;
  279. background: #f9f9f9 !important;
  280. color: #676767;
  281. font-size: 28rpx;
  282. padding: 0 42rpx;
  283. box-sizing: border-box;
  284. outline: none;
  285. border: none;
  286. width: 260rpx;
  287. .icon-sousuo {
  288. font-size: 22px;
  289. }
  290. .text {
  291. font-size: 16px;
  292. margin-left: 10px;
  293. }
  294. }
  295. }
  296. .tab-title {
  297. position: fixed;
  298. top: 190rpx;
  299. z-index: 99;
  300. width: 100%;
  301. display: flex;
  302. justify-content: space-between;
  303. align-items: center;
  304. height: $tab-height;
  305. line-height: $tab-height;
  306. background-color: #ffffff;
  307. border-bottom: 2rpx solid #f2f2f2;
  308. box-sizing: border-box;
  309. .tab-item {
  310. width: 25%;
  311. text-align: center;
  312. font-size: 32rpx;
  313. color: $uni-text-color-grey;
  314. }
  315. .tab-item.active {
  316. color: $j-primary-border-green;
  317. border-bottom: 1px solid $j-primary-border-green;
  318. font-weight: bold;
  319. }
  320. .tab-item.filter {
  321. flex: 1;
  322. padding: 0px 30rpx;
  323. .uni-icons {
  324. display: flex;
  325. padding-top: 5px;
  326. }
  327. }
  328. .screenIcon {
  329. display: flex;
  330. width: 80px;
  331. justify-content: center;
  332. .screenText {
  333. font-size: 32rpx;
  334. color: $uni-text-color-grey;
  335. }
  336. }
  337. }
  338. .listContent {
  339. height: 100% !important;
  340. .listBox {
  341. display: flex;
  342. // height: 180rpx;
  343. padding: 20rpx 0;
  344. border-bottom: 2rpx solid #e5e5e5;
  345. .listBox-sel {
  346. height: 90rpx;
  347. width: 80rpx;
  348. // line-height: 90rpx;
  349. text-align: center;
  350. checkbox {
  351. transform: scale(1.2);
  352. }
  353. }
  354. .listBox-con {
  355. width: 100%;
  356. // display: flex;
  357. // flex-wrap: wrap;
  358. // justify-content: space-between;
  359. align-items: center;
  360. padding: 0 18rpx 0 0;
  361. .listBox-top {
  362. width: 100%;
  363. display: flex;
  364. justify-content: space-between;
  365. padding-bottom: 10rpx;
  366. .listBox-name,
  367. .listBox-code {
  368. display: inline-block;
  369. font-size: $uni-font-size-sm;
  370. font-weight: bold;
  371. }
  372. }
  373. .listBox-bottom {
  374. width: 100%;
  375. display: flex;
  376. justify-content: space-between;
  377. font-size: $uni-font-size-sm;
  378. flex-wrap: wrap;
  379. >view {
  380. width: 50%;
  381. overflow: hidden;
  382. white-space: nowrap;
  383. text-overflow: ellipsis;
  384. }
  385. }
  386. }
  387. }
  388. .noDate {
  389. height: 100%;
  390. }
  391. }
  392. //底部按钮
  393. .footer {
  394. height: 90rpx;
  395. position: relative;
  396. display: flex;
  397. justify-content: space-between;
  398. align-items: center;
  399. bottom: 0;
  400. width: 100%;
  401. height: 100rpx;
  402. border-top: 1rpx solid #eeecec;
  403. background-color: #ffffff;
  404. z-index: 999;
  405. .bottom {
  406. margin-left: 10rpx;
  407. }
  408. .u-reset-button {
  409. position: absolute;
  410. right: 10rpx;
  411. top: 20rpx;
  412. width: 150rpx;
  413. }
  414. }
  415. }
  416. </style>