dk-single-dropdown-item.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /*******************************************************************************
  2. * Copyright(c) 2021 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:
  5. * 2.功能描述:单选下拉组件
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * jyh 2022-5-5 1.00 新建
  9. *******************************************************************************/
  10. const api = require('../../../utils/api');
  11. const app = getApp()
  12. const Constants = require('../../../utils/Constants');
  13. Component({
  14. /**
  15. * 组件的属性列表
  16. */
  17. properties: {
  18. /**
  19. * 客户来源:customerFrom,卫生间数:toiletCount,装修类型:fitupType,房屋类型:houseType,
  20. * 装修风格:fitupStyle,年龄构成:ageComposition,决策者:decisionMaker,结算类型:settlement,
  21. * 费用项目:feeItem,业务部门:org,性别:gender orther:其他分类 supType:供应商类别
  22. */
  23. typeName: {
  24. type: String,
  25. default: 'org'
  26. },
  27. content: {
  28. type: String,
  29. default: 'org'
  30. },
  31. warehouseId: {
  32. type: String,
  33. default: 'org'
  34. },
  35. dataItem: {
  36. type: Object,
  37. default: {}
  38. },
  39. dynamicList: { //开单商品编辑临时数组
  40. type: Array,
  41. default: []
  42. },
  43. choooseFlg: {
  44. type: Boolean,
  45. default: false
  46. },
  47. docName: {
  48. type: String,
  49. value: ''
  50. },
  51. contentID: {
  52. type: Number,
  53. default: 0
  54. },
  55. channelId: {
  56. type: Number,
  57. default: null
  58. },
  59. jobIds: {
  60. type: Array,
  61. value: []
  62. },
  63. orgId: {
  64. type: Number,
  65. value: null
  66. },
  67. show: {
  68. type: Boolean,
  69. default: false,
  70. observer: function (newVal) {
  71. let show = this.properties.show
  72. if (!show) {
  73. return
  74. }
  75. // 给类型赋值
  76. this.setDataSource();
  77. let datalists = this.data.datalists;
  78. let datalist = datalists[this.data.typeName] || []
  79. if (!datalists[this.data.typeName] || datalists[this.data.typeName].length == 0) {
  80. let DataSourceCode = this.data.DataSourceCode
  81. let typeName = this.data.typeName
  82. this.getdata(DataSourceCode).then(res => {
  83. let list = res.data.data
  84. if (list == null || list.length <= 0) {
  85. this.setData({
  86. datalist: []
  87. })
  88. return;
  89. }
  90. let datalist = []
  91. // 初始款项
  92. if (typeName === 'initialPayment') {
  93. let nmb = 0
  94. let nmb_tenter = 0
  95. list.forEach(item2 => {
  96. let item = {
  97. id: item2.id,
  98. code: item2.kindCode,
  99. name: item2.kindName,
  100. checked: item2.id == this.properties.contentID ? true : false,
  101. }
  102. nmb_tenter++
  103. if (item2.id == this.properties.contentID) {
  104. nmb = nmb_tenter
  105. }
  106. datalist.push(item)
  107. })
  108. this.setData({
  109. radio: this.properties.contentID ? (nmb - 1) : '',
  110. valueKey: 'id',
  111. labelKey: 'name'
  112. })
  113. }
  114. // 发票类型
  115. if (typeName === 'receiptType') {
  116. let nmb = 0
  117. let nmb_tenter = 0
  118. list.forEach(item2 => {
  119. let item = {
  120. id: item2.id,
  121. code: item2.kindCode,
  122. name: item2.kindName,
  123. checked: item2.id == this.properties.contentID ? true : false,
  124. }
  125. nmb_tenter++
  126. if (item2.id == this.properties.contentID) {
  127. nmb = nmb_tenter
  128. }
  129. datalist.push(item)
  130. })
  131. this.setData({
  132. radio: this.properties.contentID ? (nmb - 1) : '',
  133. valueKey: 'id',
  134. labelKey: 'name'
  135. })
  136. }
  137. // 部门
  138. if (typeName === 'org') {
  139. let nmb = 0
  140. let nmb_tenter = 0
  141. list.forEach(item2 => {
  142. let item = {
  143. id: item2.id,
  144. code: item2.orgCode,
  145. name: item2.orgName,
  146. checked: item2.id == this.properties.contentID ? true : false,
  147. }
  148. nmb_tenter++
  149. if (item2.id == this.properties.contentID) {
  150. nmb = nmb_tenter
  151. }
  152. datalist.push(item)
  153. })
  154. this.setData({
  155. radio: this.properties.contentID ? (nmb - 1) : '',
  156. valueKey: 'id',
  157. labelKey: 'name'
  158. })
  159. }
  160. // 员工
  161. if (typeName === 'staff') {
  162. let nmb = 0
  163. let nmb_tenter = 0
  164. list.forEach(item2 => {
  165. let item = {
  166. id: item2.id,
  167. code: item2.staffCode,
  168. name: item2.staffName,
  169. checked: item2.id == this.properties.contentID ? true : false
  170. }
  171. nmb_tenter++
  172. if (item2.id == this.properties.contentID) {
  173. nmb = nmb_tenter
  174. }
  175. datalist.push(item)
  176. })
  177. this.setData({
  178. radio: this.properties.contentID ? (nmb - 1) : '',
  179. valueKey: 'id',
  180. labelKey: 'name'
  181. })
  182. }
  183. //结算方式
  184. if (typeName == 'settlement') {
  185. let nmb = 0
  186. let nmb_tenter = 0
  187. list.forEach(item2 => {
  188. let item = {
  189. id: item2.id,
  190. code: item2.macCode,
  191. name: item2.macName,
  192. checked: item2.id == this.properties.contentID ? true : false
  193. }
  194. nmb_tenter++
  195. if (item2.id == this.properties.contentID) {
  196. nmb = nmb_tenter
  197. }
  198. datalist.push(item)
  199. })
  200. this.setData({
  201. radio: this.properties.contentID ? (nmb - 1) : '',
  202. valueKey: 'id',
  203. labelKey: 'name'
  204. })
  205. }
  206. //客户来源
  207. if (typeName == 'customerFrom') {
  208. let nmb = 0
  209. let nmb_tenter = 0
  210. list.forEach(item2 => {
  211. let item = {
  212. id: item2.id,
  213. code: item2.dataCode,
  214. name: item2.dataValue,
  215. checked: item2.id == this.properties.contentID ? true : false
  216. }
  217. nmb_tenter++
  218. if (item2.id == this.properties.contentID) {
  219. nmb = nmb_tenter
  220. }
  221. datalist.push(item)
  222. })
  223. this.setData({
  224. radio: this.properties.contentID ? (nmb - 1) : '',
  225. valueKey: 'id',
  226. labelKey: 'name'
  227. })
  228. }
  229. //销售渠道
  230. if (typeName == 'saleChannel') {
  231. let nmb = 0
  232. let nmb_tenter = 0
  233. list.forEach(item2 => {
  234. let item = {
  235. id: item2.id,
  236. code: item2.channelCode,
  237. name: item2.channelName,
  238. checked: item2.id == this.properties.contentID ? true : false
  239. }
  240. nmb_tenter++
  241. if (item2.id == this.properties.contentID) {
  242. nmb = nmb_tenter
  243. }
  244. datalist.push(item)
  245. })
  246. this.setData({
  247. radio: this.properties.contentID ? (nmb - 1) : '',
  248. valueKey: 'id',
  249. labelKey: 'name'
  250. })
  251. }
  252. //仓库
  253. if (typeName == 'warehouse') {
  254. let nmb = 0
  255. let nmb_tenter = 0
  256. list.forEach(item2 => {
  257. let item = {
  258. id: item2.id,
  259. code: item2.whCode,
  260. name: item2.whName,
  261. checked: item2.id == this.properties.contentID ? true : false
  262. }
  263. nmb_tenter++
  264. if (item2.id == this.properties.contentID) {
  265. nmb = nmb_tenter
  266. }
  267. datalist.push(item)
  268. })
  269. this.setData({
  270. radio: this.properties.contentID ? (nmb - 1) : '',
  271. valueKey: 'id',
  272. labelKey: 'name'
  273. })
  274. }
  275. //客户意向 留店时长 邀约结果 量尺状态
  276. if (typeName == 'customerIntention' || typeName == 'storeRetentionTime' || typeName === 'inviteResult' || typeName === 'scaleStatus' || typeName == 'followType') {
  277. let nmb = 0
  278. let nmb_tenter = 0
  279. list.forEach(item2 => {
  280. let item = {
  281. id: item2.id,
  282. code: item2.kindCode,
  283. name: item2.kindName,
  284. checked: item2.id == this.properties.contentID ? true : false
  285. }
  286. nmb_tenter++
  287. if (item2.id == this.properties.contentID) {
  288. nmb = nmb_tenter
  289. }
  290. datalist.push(item)
  291. })
  292. this.setData({
  293. radio: this.properties.contentID ? (nmb - 1) : '',
  294. valueKey: 'id',
  295. labelKey: 'name'
  296. })
  297. }
  298. // 供应商类别
  299. if (typeName === 'supType') {
  300. let nmb = 0
  301. let nmb_tenter = 0
  302. list.forEach(item2 => {
  303. let item = {
  304. id: item2.id,
  305. code: item2.kindCode,
  306. name: item2.kindName,
  307. checked: item2.id == this.properties.contentID ? true : false,
  308. }
  309. nmb_tenter++
  310. if (item2.id == this.properties.contentID) {
  311. nmb = nmb_tenter
  312. }
  313. datalist.push(item)
  314. })
  315. this.setData({
  316. radio: this.properties.contentID ? (nmb - 1) : '',
  317. valueKey: 'id',
  318. labelKey: 'name'
  319. })
  320. }
  321. let finallist = [...datalist]
  322. datalists[this.data.typeName] = [...datalist]
  323. this.setData({
  324. datalists: datalists,
  325. finallist: finallist
  326. })
  327. })
  328. } else {
  329. if (this.properties.contentID) {
  330. // 重刷选中项
  331. datalists[this.data.typeName].forEach(item => {
  332. item.checked = item.id == this.properties.contentID ? true : false;
  333. })
  334. this.setData({
  335. datalists: datalists,
  336. })
  337. }
  338. }
  339. }
  340. }
  341. },
  342. /**
  343. * 组件的初始数据
  344. */
  345. data: {
  346. DataSourceCode: '',
  347. // 是否点击清除按钮
  348. isClickClear: false,
  349. // datalist: [],
  350. finallist: [],
  351. condition: '',
  352. dataValue: '',
  353. name: '',
  354. valueKey: 'id',
  355. labelKey: 'name',
  356. radio: null,
  357. label_title: '可选',
  358. count: 0,
  359. datalists: {},
  360. pageInfo: {
  361. pageSize: 5,
  362. currentPage: 1
  363. }
  364. },
  365. lifetimes: {
  366. attached: function () {
  367. },
  368. detached: function () {
  369. // 在组件实例被从页面节点树移除时执行
  370. },
  371. },
  372. /**
  373. * 组件的方法列表
  374. */
  375. methods: {
  376. /**
  377. * @desc : 给类型赋值
  378. * @author : 周兴
  379. * @date : 2024/1/26 11:46
  380. */
  381. setDataSource() {
  382. let DataSourceCode = ''
  383. let typeName = this.data.typeName
  384. let name = ''
  385. if (typeName === 'customerFrom') {
  386. DataSourceCode = 'customerFrom'
  387. name = '客户来源'
  388. }
  389. if (typeName === 'settlement') {
  390. DataSourceCode = 'settlement'
  391. name = '结算方式'
  392. }
  393. if (typeName === 'saleChannel') {
  394. DataSourceCode = 'saleChannel'
  395. name = '销售渠道'
  396. }
  397. if (typeName === 'org') {
  398. DataSourceCode = 'org'
  399. name = '业务部门'
  400. }
  401. //业务员
  402. if (typeName === 'staff') {
  403. DataSourceCode = 'staff'
  404. name = '员工'
  405. }
  406. if (typeName === 'customerIntention') {
  407. DataSourceCode = 'customerIntention'
  408. name = '客户意向'
  409. }
  410. if (typeName === 'storeRetentionTime') {
  411. DataSourceCode = 'storeRetentionTime'
  412. name = '留店时长'
  413. }
  414. if (typeName === 'inviteResult') {
  415. DataSourceCode = 'inviteResult'
  416. name = '邀约结果'
  417. }
  418. if (typeName === 'scaleStatus') {
  419. DataSourceCode = 'scaleStatus'
  420. name = '量尺状态'
  421. }
  422. if (typeName === 'followType') {
  423. DataSourceCode = 'followType'
  424. name = '跟进方式'
  425. }
  426. if (typeName === 'warehouse') {
  427. DataSourceCode = 'warehouse'
  428. name = '仓库'
  429. }
  430. if (typeName === 'supType') {
  431. DataSourceCode = 'supType'
  432. name = '供应商类别'
  433. }
  434. // 初始款项
  435. if (typeName === 'initialPayment') {
  436. DataSourceCode = 'initialPayment'
  437. name = '初始款项'
  438. }
  439. // 发票类型
  440. if (typeName === 'receiptType') {
  441. DataSourceCode = 'receiptType'
  442. name = '发票类型'
  443. }
  444. this.setData({
  445. DataSourceCode: DataSourceCode
  446. })
  447. },
  448. /**
  449. * 查询数据
  450. * @param {*} e
  451. */
  452. getdata: function (DataSourceCode, e) {
  453. let param = {
  454. dataSourceCode: DataSourceCode
  455. }
  456. let SELECT_API = 'get_init_data'
  457. return new Promise((resolve, reject) => {
  458. api.request(Constants.BASIC_COMMON_API + SELECT_API, 'POST', param).then(res => {
  459. if (res.data.code === 200) {
  460. resolve(res)
  461. } else {
  462. reject(res)
  463. }
  464. })
  465. })
  466. },
  467. /**
  468. * 关闭弹窗
  469. */
  470. onClose: function () {
  471. // this.reset()
  472. this.setData({
  473. show: false
  474. })
  475. // 为了关闭外面的下拉
  476. this.triggerEvent('muticlose')
  477. },
  478. /**
  479. * 焦点离开事件
  480. */
  481. blur_input() {
  482. if (this.data.datalists[this.data.typeName].length <= 0) {
  483. this.reset()
  484. }
  485. },
  486. /**
  487. * @desc : 值改变
  488. * @author : 周兴
  489. * @date : 2024/1/26 11:46
  490. */
  491. onChange(e) {
  492. let datalist = this.data.datalists[this.data.typeName] || []
  493. if (datalist && datalist.length > e.detail) {
  494. datalist.forEach(it => {
  495. it.checked = false;
  496. })
  497. datalist[e.detail].checked = true;
  498. let item = datalist[e.detail];
  499. this.setData({
  500. radio: e.detail,
  501. // datalist: datalist,
  502. show: false
  503. })
  504. this.triggerEvent('commit', {
  505. value: item[this.data.valueKey],
  506. text: item[this.data.labelKey],
  507. item: item
  508. })
  509. }
  510. },
  511. /**
  512. * 过滤数据
  513. * @param {*} e
  514. */
  515. onChange_input: function (e) {
  516. let finallist = this.data.finallist
  517. if (finallist === null || finallist.length === 0) return
  518. // 复制
  519. finallist = [...finallist]
  520. let condition = this.data.condition
  521. this.setData({
  522. radio: '',
  523. })
  524. let datalist = []
  525. finallist.forEach(item => {
  526. if (item.name.indexOf(condition) >= 0) {
  527. datalist.push(item)
  528. }
  529. })
  530. // 单选框的true false显示 是radio控制
  531. let nmb = 0
  532. let nmb_tenter = 0
  533. datalist.forEach(item2 => {
  534. nmb_tenter++
  535. if (item2.name == this.data.clickRodioButton) {
  536. nmb = nmb_tenter
  537. this.setData({
  538. radio: nmb - 1
  539. })
  540. }
  541. })
  542. let datalists = this.data.datalists
  543. datalists[this.data.typeName] = datalist
  544. this.setData({
  545. datalists: datalists
  546. })
  547. },
  548. /**
  549. * 重置
  550. */
  551. reset: function () {
  552. // let datalist = this.data.datalist
  553. let datalist = this.data.datalists[this.data.typeName]
  554. let finallist = this.data.finallist
  555. if (finallist == null || finallist.length === 0) return
  556. finallist.forEach(item => {
  557. item.checked = false
  558. })
  559. datalist = [...finallist]
  560. this.setData({
  561. finallist: finallist,
  562. // datalist: datalist,
  563. datalists: datalists,
  564. condition: '',
  565. radio: '',
  566. })
  567. },
  568. /**
  569. * 清除数据
  570. */
  571. clear() {
  572. let finallist = this.data.finallist
  573. // 清空勾选框
  574. finallist.forEach(item => {
  575. item.checked = false
  576. })
  577. let datalist = [...finallist]
  578. this.triggerEvent('commit', {
  579. ids: '',
  580. names: ''
  581. })
  582. let datalists = this.data.datalists
  583. datalists[thsi.data.typeName] = datalist
  584. // 清空控件
  585. this.setData({
  586. // datalist: datalist,
  587. datalists: datalists,
  588. finallist: finallist,
  589. condition: '',
  590. isClickClear: true,
  591. dataValue: '',
  592. count: 0,
  593. radio: null,
  594. label_title: '可选',
  595. defaultCheackFlag: true
  596. })
  597. },
  598. /**
  599. * 提交
  600. */
  601. commit: function () {
  602. // let datalist = this.data.datalist
  603. let datalist = this.data.datalists[this.data.typeName]
  604. if (datalist == null || datalist.length === 0) return
  605. // 获取选中的那条数据
  606. let filters = datalist.filter(it => it.checked);
  607. if (filters && filters.length > 0) {
  608. let item = filters[0];
  609. this.triggerEvent('commit', {
  610. value: item[this.data.valueKey],
  611. text: item[this.data.labelKey],
  612. item: item
  613. })
  614. this.setData({
  615. show: false
  616. })
  617. }
  618. },
  619. },
  620. })