dk-single-dropdown-item.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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 === 'businessDocument') {
  139. let nmb = 0
  140. let nmb_tenter = 0
  141. list.forEach(item2 => {
  142. let item = {
  143. id: item2.docName,
  144. code: item2.docName,
  145. name: item2.docName,
  146. checked: item2.docName == this.properties.contentID ? true : false,
  147. }
  148. nmb_tenter++
  149. if (item2.docName == 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 === 'org') {
  162. let nmb = 0
  163. let nmb_tenter = 0
  164. list.forEach(item2 => {
  165. let item = {
  166. id: item2.id,
  167. code: item2.orgCode,
  168. name: item2.orgName,
  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 === 'staff') {
  185. let nmb = 0
  186. let nmb_tenter = 0
  187. list.forEach(item2 => {
  188. let item = {
  189. id: item2.id,
  190. code: item2.staffCode,
  191. name: item2.staffName,
  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 == 'settlement') {
  208. let nmb = 0
  209. let nmb_tenter = 0
  210. list.forEach(item2 => {
  211. let item = {
  212. id: item2.id,
  213. code: item2.macCode,
  214. name: item2.macName,
  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 == 'customerFrom') {
  231. let nmb = 0
  232. let nmb_tenter = 0
  233. list.forEach(item2 => {
  234. let item = {
  235. id: item2.id,
  236. code: item2.dataCode,
  237. name: item2.dataValue,
  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 == 'saleChannel') {
  254. let nmb = 0
  255. let nmb_tenter = 0
  256. list.forEach(item2 => {
  257. let item = {
  258. id: item2.id,
  259. code: item2.channelCode,
  260. name: item2.channelName,
  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 == 'warehouse') {
  277. let nmb = 0
  278. let nmb_tenter = 0
  279. list.forEach(item2 => {
  280. let item = {
  281. id: item2.id,
  282. code: item2.whCode,
  283. name: item2.whName,
  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 == 'customerIntention' || typeName == 'storeRetentionTime' || typeName === 'inviteResult' || typeName === 'scaleStatus' || typeName == 'followType') {
  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. // 供应商类别
  322. if (typeName === 'supType') {
  323. let nmb = 0
  324. let nmb_tenter = 0
  325. list.forEach(item2 => {
  326. let item = {
  327. id: item2.id,
  328. code: item2.kindCode,
  329. name: item2.kindName,
  330. checked: item2.id == this.properties.contentID ? true : false,
  331. }
  332. nmb_tenter++
  333. if (item2.id == this.properties.contentID) {
  334. nmb = nmb_tenter
  335. }
  336. datalist.push(item)
  337. })
  338. this.setData({
  339. radio: this.properties.contentID ? (nmb - 1) : '',
  340. valueKey: 'id',
  341. labelKey: 'name'
  342. })
  343. }
  344. let finallist = [...datalist]
  345. datalists[this.data.typeName] = [...datalist]
  346. this.setData({
  347. datalists: datalists,
  348. finallist: finallist
  349. })
  350. })
  351. } else {
  352. if (this.properties.contentID) {
  353. // 重刷选中项
  354. datalists[this.data.typeName].forEach(item => {
  355. item.checked = item.id == this.properties.contentID ? true : false;
  356. })
  357. this.setData({
  358. datalists: datalists,
  359. })
  360. }
  361. }
  362. }
  363. }
  364. },
  365. /**
  366. * 组件的初始数据
  367. */
  368. data: {
  369. DataSourceCode: '',
  370. // 是否点击清除按钮
  371. isClickClear: false,
  372. // datalist: [],
  373. finallist: [],
  374. condition: '',
  375. dataValue: '',
  376. name: '',
  377. valueKey: 'id',
  378. labelKey: 'name',
  379. radio: null,
  380. label_title: '可选',
  381. count: 0,
  382. datalists: {},
  383. pageInfo: {
  384. pageSize: 5,
  385. currentPage: 1
  386. }
  387. },
  388. lifetimes: {
  389. attached: function () {
  390. },
  391. detached: function () {
  392. // 在组件实例被从页面节点树移除时执行
  393. },
  394. },
  395. /**
  396. * 组件的方法列表
  397. */
  398. methods: {
  399. /**
  400. * @desc : 给类型赋值
  401. * @author : 周兴
  402. * @date : 2024/1/26 11:46
  403. */
  404. setDataSource() {
  405. let DataSourceCode = ''
  406. let typeName = this.data.typeName
  407. let name = ''
  408. if (typeName === 'customerFrom') {
  409. DataSourceCode = 'customerFrom'
  410. name = '客户来源'
  411. }
  412. if (typeName === 'settlement') {
  413. DataSourceCode = 'settlement'
  414. name = '结算方式'
  415. }
  416. if (typeName === 'saleChannel') {
  417. DataSourceCode = 'saleChannel'
  418. name = '销售渠道'
  419. }
  420. if (typeName === 'org') {
  421. DataSourceCode = 'org'
  422. name = '业务部门'
  423. }
  424. //业务员
  425. if (typeName === 'staff') {
  426. DataSourceCode = 'staff'
  427. name = '员工'
  428. }
  429. if (typeName === 'customerIntention') {
  430. DataSourceCode = 'customerIntention'
  431. name = '客户意向'
  432. }
  433. if (typeName === 'storeRetentionTime') {
  434. DataSourceCode = 'storeRetentionTime'
  435. name = '留店时长'
  436. }
  437. if (typeName === 'inviteResult') {
  438. DataSourceCode = 'inviteResult'
  439. name = '邀约结果'
  440. }
  441. if (typeName === 'scaleStatus') {
  442. DataSourceCode = 'scaleStatus'
  443. name = '量尺状态'
  444. }
  445. if (typeName === 'followType') {
  446. DataSourceCode = 'followType'
  447. name = '跟进方式'
  448. }
  449. if (typeName === 'warehouse') {
  450. DataSourceCode = 'warehouse'
  451. name = '仓库'
  452. }
  453. if (typeName === 'supType') {
  454. DataSourceCode = 'supType'
  455. name = '供应商类别'
  456. }
  457. // 初始款项
  458. if (typeName === 'initialPayment') {
  459. DataSourceCode = 'initialPayment'
  460. name = '初始款项'
  461. }
  462. // 发票类型
  463. if (typeName === 'receiptType') {
  464. DataSourceCode = 'receiptType'
  465. name = '发票类型'
  466. }
  467. // 业务单据
  468. if (typeName === 'businessDocument') {
  469. DataSourceCode = 'businessDocument'
  470. name = '业务单据'
  471. }
  472. this.setData({
  473. DataSourceCode: DataSourceCode
  474. })
  475. },
  476. /**
  477. * 查询数据
  478. * @param {*} e
  479. */
  480. getdata: function (DataSourceCode, e) {
  481. let param = {
  482. dataSourceCode: DataSourceCode
  483. }
  484. let SELECT_API = 'get_init_data'
  485. return new Promise((resolve, reject) => {
  486. api.request(Constants.BASIC_COMMON_API + SELECT_API, 'POST', param).then(res => {
  487. if (res.data.code === 200) {
  488. resolve(res)
  489. } else {
  490. reject(res)
  491. }
  492. })
  493. })
  494. },
  495. /**
  496. * 关闭弹窗
  497. */
  498. onClose: function () {
  499. // this.reset()
  500. this.setData({
  501. show: false
  502. })
  503. // 为了关闭外面的下拉
  504. this.triggerEvent('muticlose')
  505. },
  506. /**
  507. * 焦点离开事件
  508. */
  509. blur_input() {
  510. if (this.data.datalists[this.data.typeName].length <= 0) {
  511. this.reset()
  512. }
  513. },
  514. /**
  515. * @desc : 值改变
  516. * @author : 周兴
  517. * @date : 2024/1/26 11:46
  518. */
  519. onChange(e) {
  520. let datalist = this.data.datalists[this.data.typeName] || []
  521. if (datalist && datalist.length > e.detail) {
  522. datalist.forEach(it => {
  523. it.checked = false;
  524. })
  525. datalist[e.detail].checked = true;
  526. let item = datalist[e.detail];
  527. this.setData({
  528. radio: e.detail,
  529. // datalist: datalist,
  530. show: false
  531. })
  532. this.triggerEvent('commit', {
  533. value: item[this.data.valueKey],
  534. text: item[this.data.labelKey],
  535. item: item
  536. })
  537. }
  538. },
  539. /**
  540. * 过滤数据
  541. * @param {*} e
  542. */
  543. onChange_input: function (e) {
  544. let finallist = this.data.finallist
  545. if (finallist === null || finallist.length === 0) return
  546. // 复制
  547. finallist = [...finallist]
  548. let condition = this.data.condition
  549. this.setData({
  550. radio: '',
  551. })
  552. let datalist = []
  553. finallist.forEach(item => {
  554. if (item.name.indexOf(condition) >= 0) {
  555. datalist.push(item)
  556. }
  557. })
  558. // 单选框的true false显示 是radio控制
  559. let nmb = 0
  560. let nmb_tenter = 0
  561. datalist.forEach(item2 => {
  562. nmb_tenter++
  563. if (item2.name == this.data.clickRodioButton) {
  564. nmb = nmb_tenter
  565. this.setData({
  566. radio: nmb - 1
  567. })
  568. }
  569. })
  570. let datalists = this.data.datalists
  571. datalists[this.data.typeName] = datalist
  572. this.setData({
  573. datalists: datalists
  574. })
  575. },
  576. /**
  577. * 重置
  578. */
  579. reset: function () {
  580. // let datalist = this.data.datalist
  581. let datalist = this.data.datalists[this.data.typeName]
  582. let finallist = this.data.finallist
  583. if (finallist == null || finallist.length === 0) return
  584. finallist.forEach(item => {
  585. item.checked = false
  586. })
  587. datalist = [...finallist]
  588. this.setData({
  589. finallist: finallist,
  590. // datalist: datalist,
  591. datalists: datalists,
  592. condition: '',
  593. radio: '',
  594. })
  595. },
  596. /**
  597. * 清除数据
  598. */
  599. clear() {
  600. let finallist = this.data.finallist
  601. // 清空勾选框
  602. finallist.forEach(item => {
  603. item.checked = false
  604. })
  605. let datalist = [...finallist]
  606. this.triggerEvent('commit', {
  607. ids: '',
  608. names: ''
  609. })
  610. let datalists = this.data.datalists
  611. datalists[thsi.data.typeName] = datalist
  612. // 清空控件
  613. this.setData({
  614. // datalist: datalist,
  615. datalists: datalists,
  616. finallist: finallist,
  617. condition: '',
  618. isClickClear: true,
  619. dataValue: '',
  620. count: 0,
  621. radio: null,
  622. label_title: '可选',
  623. defaultCheackFlag: true
  624. })
  625. },
  626. /**
  627. * 提交
  628. */
  629. commit: function () {
  630. // let datalist = this.data.datalist
  631. let datalist = this.data.datalists[this.data.typeName]
  632. if (datalist == null || datalist.length === 0) return
  633. // 获取选中的那条数据
  634. let filters = datalist.filter(it => it.checked);
  635. if (filters && filters.length > 0) {
  636. let item = filters[0];
  637. this.triggerEvent('commit', {
  638. value: item[this.data.valueKey],
  639. text: item[this.data.labelKey],
  640. item: item
  641. })
  642. this.setData({
  643. show: false
  644. })
  645. }
  646. },
  647. },
  648. })