basic-data.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. /*******************************************************************************
  2. * Copyright(c) 2022 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:
  5. * 编辑履历:
  6. * 作者 日期 版本 修改内容
  7. * 于继渤 2024-1-23 1.00 基础资料
  8. *******************************************************************************/
  9. const Constants = require('@/utils/Constants.js');
  10. const util = require('@/utils/util.js')
  11. import Dialog from '@/dist/dialog/dialog.js';
  12. const mixins = require('@/mixins/index.js')
  13. const app = getApp()
  14. Page({
  15. mixins: [mixins],
  16. /**
  17. * 页面的初始数据
  18. */
  19. data: {
  20. gradeCode: app.globalData.company.gradeCode,
  21. flgValidList: null,
  22. flgDefault: 'flgDefault',
  23. navigateBackFlag: true,
  24. routeObjNameGoTo: '',
  25. formDataName: '仓库',
  26. dictCode: mixins.$t('warehouseSys'),
  27. //接口
  28. warehouseService: app.globalData['warehouseService'],
  29. saleChannelService: app.globalData['saleChannelService'],
  30. commonService: app.globalData['commonService'],
  31. routeObjName: 'basicData',
  32. tableData: [],
  33. buttonSaveList: [{ code: 'sort', title: '排序', width: '120rpx', plain: true }, { code: 'add', title: '新建', width: '120rpx', }],
  34. contentSaveList: [],
  35. // 查询条件
  36. searchContent: [{
  37. code: 'flgValid', key: 'valueList', title: mixins.$t('allValidInvalid'), searchType: Constants.searchType.switch,
  38. list: [
  39. { code: 1, title: mixins.$t('valid'), value: true, checked: true },
  40. { code: 2, title: mixins.$t('invalid'), value: false }]
  41. }],
  42. sidebarList: [],
  43. contentList: [
  44. { name: 'whCode', title: mixins.$t('whCode') },
  45. { name: 'whName', title: mixins.$t('whName') },
  46. { name: 'supervisor', title: mixins.$t('supervisor') }
  47. ],
  48. contentObj: {
  49. //TODO 怎么国际化 ?
  50. '基础资料-仓库': [{ name: 'whCode', title: mixins.$t('whCode') },
  51. { name: 'supervisor', title: mixins.$t('supervisor') }],
  52. '基础资料-渠道': [{ name: 'channelCode', title: mixins.$t('channelCode') },
  53. ],
  54. '基础资料-收入': [{ name: 'dataCode', title: mixins.$t('incomeCode') },
  55. ],
  56. '基础资料-支出': [{ name: 'dataCode', title: mixins.$t('expenditureCode') },
  57. ],
  58. '基础资料-入库': [{ name: 'dataCode', title: mixins.$t('reasonCode') },
  59. ],
  60. '基础资料-出库': [{ name: 'dataCode', title: mixins.$t('reasonCode') },
  61. ],
  62. '基础资料-账户': [{ name: 'dataCode', title: mixins.$t('accountCode') },
  63. ],
  64. '基础资料-来源': [{ name: 'dataCode', title: mixins.$t('sourceCode') },
  65. ],
  66. '基础资料-盈亏原因': [{ name: 'dataCode', title: mixins.$t('profitLossCode') },
  67. ],
  68. },
  69. popContent:
  70. [
  71. { code: 'whCode', type: 'str', title: mixins.$t('whCode'), required: false, readonly: true, },
  72. { code: 'whName', type: 'str', title: mixins.$t('whName'), required: true },
  73. {
  74. name: 'supervisor',
  75. code: 'supervisor',
  76. title: mixins.$t("supervisor"),
  77. type: 'choose',
  78. required: true,
  79. urlKey: 'chooseStaff'
  80. },
  81. { code: 'contactPhone', type: 'str', title: mixins.$t('contactPhone'), required: true },
  82. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  83. ],
  84. sideKey: 0,
  85. },
  86. /**
  87. * @desc : 设置pop字段
  88. * @author : 于继渤
  89. * @date : 2024/1/23 9:16
  90. */
  91. setPopContent(item) {
  92. let formDataName = this.data.formDataName
  93. let dictCode = this.data.dictCode
  94. let popContent = this.data.popContent
  95. let contentList = this.data.contentList
  96. let dataItem = item
  97. let routeObjNameGoTo = this.data.routeObjNameGoTo
  98. this.setData({
  99. flgDefault: 'flgDefault'
  100. })
  101. if (dictCode == mixins.$t('warehouseSys')) {//仓库档案
  102. //设置新建编辑字段
  103. console.log('dictCode',dictCode)
  104. popContent =
  105. [
  106. { code: 'whCode', type: 'str', title: mixins.$t('whCode'), required: false, readonly: true, },
  107. { code: 'whName', type: 'str', title: mixins.$t('whName'), required: true },
  108. {
  109. name: 'supervisor',
  110. code: 'supervisor',
  111. title: mixins.$t("supervisor"),
  112. type: 'choose',
  113. required: true,
  114. urlKey: 'chooseStaff'
  115. },
  116. { code: 'contactPhone', type: 'str', title: mixins.$t('contactPhone'), required: true },
  117. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  118. ]
  119. routeObjNameGoTo = 'warehouse'
  120. console.log('popContent',popContent)
  121. } else if (dictCode == mixins.$t('saleChannelSys')) {
  122. //设置新建编辑字段
  123. popContent =
  124. [
  125. { code: 'channelCode', type: 'str', title: mixins.$t('channelCode'), required: false, readonly: true, },
  126. { code: 'channelName', type: 'str', title: mixins.$t('channelName'), required: true },
  127. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  128. ]
  129. } else {
  130. if (dictCode == mixins.$t('incomeCategorySys')) {
  131. //设置新建编辑字段 收入类别
  132. popContent =
  133. [
  134. { code: 'dataCode', type: 'str', title: mixins.$t('incomeCode'), required: false, readonly: true, },
  135. { code: 'dataValue', type: 'str', title: mixins.$t('incomeName'), required: true }
  136. ]
  137. this.setData({
  138. flgDefault: null
  139. })
  140. }
  141. if (dictCode == mixins.$t('expenditureCategorySys')) {
  142. //设置新建编辑字段 支出类别
  143. popContent =
  144. [
  145. { code: 'dataCode', type: 'str', title: mixins.$t('expenditureCode'), required: false, readonly: true, },
  146. { code: 'dataValue', type: 'str', title: mixins.$t('expenditureName'), required: true }
  147. ]
  148. this.setData({
  149. flgDefault: null
  150. })
  151. }
  152. if (dictCode == mixins.$t('reasonStorageSys')) {
  153. //设置新建编辑字段 入库原因
  154. popContent =
  155. [
  156. { code: 'dataCode', type: 'str', title: mixins.$t('reasonCode'), required: false, readonly: true, },
  157. { code: 'dataValue', type: 'str', title: mixins.$t('reasonName'), required: true }
  158. ]
  159. this.setData({
  160. flgDefault: null
  161. })
  162. }
  163. if (dictCode == mixins.$t('reasonOutboundSys')) {
  164. //设置新建编辑字段 出库原因
  165. popContent =
  166. [
  167. { code: 'dataCode', type: 'str', title: mixins.$t('reasonCode'), required: false, readonly: true, },
  168. { code: 'dataValue', type: 'str', title: mixins.$t('reasonName'), required: true }
  169. ]
  170. this.setData({
  171. flgDefault: null
  172. })
  173. }
  174. if (dictCode == mixins.$t('accountCategorySys')) {
  175. //设置新建编辑字段 账户类别
  176. popContent =
  177. [
  178. { code: 'dataCode', type: 'str', title: mixins.$t('accountCode'), required: false, readonly: true, },
  179. { code: 'dataValue', type: 'str', title: mixins.$t('accountName'), required: true }
  180. ]
  181. this.setData({
  182. flgDefault: null
  183. })
  184. }
  185. if (dictCode == mixins.$t('customerSourceSys')) {
  186. //设置新建编辑字段 客户来源
  187. popContent =
  188. [
  189. { code: 'dataCode', type: 'str', title: mixins.$t('sourceCode'), required: false, readonly: true, },
  190. { code: 'dataValue', type: 'str', title: mixins.$t('sourceName'), required: true },
  191. ]
  192. }
  193. if (dictCode == mixins.$t('profitLossSys')) {
  194. //设置新建编辑字段 客户来源
  195. popContent =
  196. [
  197. { code: 'dataCode', type: 'str', title: mixins.$t('profitLossCode'), required: false, readonly: true, },
  198. { code: 'dataValue', type: 'str', title: mixins.$t('profitLossName'), required: true },
  199. ]
  200. this.setData({
  201. flgDefault: null
  202. })
  203. }
  204. popContent.push({ code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false })
  205. }
  206. this.setData({
  207. contentList: contentList,
  208. popContent: popContent,
  209. routeObjNameGoTo: routeObjNameGoTo
  210. })
  211. },
  212. /**
  213. * @desc : 底部按钮
  214. * @date : 2024/2/1 15:49
  215. * @author : 于继渤
  216. */
  217. open(e) {
  218. let name = e.detail.name
  219. if (name == 'sort') {
  220. this.toSort()
  221. } else if (name == 'add') {
  222. this.toAdd()
  223. }
  224. },
  225. /**
  226. * @desc : 启用停用
  227. * @date : 2024/2/1 15:49
  228. * @author : 于继渤
  229. */
  230. deactivateEnable(e) {
  231. let item = e.detail.item
  232. let service = null
  233. let id = null
  234. if (this.data.dictCode == mixins.$t('warehouseSys')) {
  235. service = this.data.warehouseService
  236. id = 'whId'
  237. } else if (this.data.dictCode == mixins.$t('saleChannelSys')) {
  238. service = this.data.saleChannelService
  239. id = 'channelId'
  240. } else { //基础数据
  241. service = this.data.service
  242. id = 'dataId'
  243. }
  244. if (this.data.dictCode == mixins.$t('accountCategorySys')) { //账户类别
  245. this.countByCondMoneyAccount(item.dataId, service, item, id)
  246. } else {
  247. //执行接口
  248. this.handleMoreDataIsValid(service, item, id)
  249. }
  250. },
  251. countByCondMoneyAccount(dataId, service, item, id) {
  252. this.excute(this.data.service, this.data.service.countByCondMoneyAccount + '/' + dataId, {}).then(res => {
  253. console.log(res, service)
  254. if (res.data.code == 200) {
  255. if (res.data.data > 0 && item.flgValid) {
  256. //提示信息
  257. Dialog.confirm({
  258. message: '账户类别有资金账户不能停用',
  259. }).then(() => { }).catch(() => {
  260. });
  261. return
  262. } else {
  263. //执行接口
  264. this.handleMoreDataIsValid(service, item, id)
  265. }
  266. }
  267. })
  268. },
  269. /**
  270. * @desc : 分类切换
  271. * @author : 于继渤
  272. * @date : 2022/5/26 20:16
  273. */
  274. changeSidebar(e) {
  275. let detail = e.detail
  276. if (!detail) {
  277. this.setData({
  278. sideKey: null
  279. })
  280. } else {
  281. this.setData({
  282. sideKey: e.detail
  283. })
  284. }
  285. this.setData({
  286. formDataName: this.data.sidebarList[detail].kindName,
  287. dictCode: this.data.sidebarList[detail].kindCode
  288. })
  289. this.setPopContent();
  290. this.searchData()
  291. },
  292. handleData(){
  293. this.searchData()
  294. },
  295. /**
  296. * @desc : 列表对象点击
  297. * @author : 于继渤
  298. * @date : 2024/1/23 9:16
  299. */
  300. toDetail(e) {
  301. let item = e.detail.item
  302. this.setPopContent(item);
  303. this.setData({
  304. popContent: this.data.popContent,
  305. showPop: true,
  306. dataItem: JSON.stringify(item),
  307. historyDataItem: item
  308. })
  309. },
  310. /**
  311. * @desc : 新建
  312. * @author : 于继渤
  313. * @date : 2024/1/23 9:16
  314. */
  315. toAdd() {
  316. this.setPopContent();
  317. this.setData({
  318. dataItem: null,
  319. formData: null,
  320. showPop: true,
  321. })
  322. //清除组件数据
  323. this.selectComponent('#popup').setFormNull()
  324. },
  325. /**
  326. * @desc : 跳转排序
  327. * @author : 于继渤
  328. * @date : 2024/1/23 9:16
  329. */
  330. toSort() {
  331. let this_ = this
  332. wx.navigateTo({
  333. url: this.data.route.sort.url,
  334. success: function (res) {
  335. // 通过eventChannel向被打开页面传送数据 TODO 测试例子url是写死的,实际中,需要从route中读取
  336. res.eventChannel.emit('params', {
  337. formType: this_.data.dictCode,
  338. formMode: 'index'
  339. })
  340. }
  341. })
  342. },
  343. /**
  344. * @desc : 设置查询参数
  345. * @author : 于继渤
  346. * @date : 2024/1/23 9:16
  347. */
  348. setSearchParams(params) {
  349. params.flgValidList = params.flgValidList ? params.flgValidList : [true]
  350. params.dictCode = this.data.dictCode
  351. return params
  352. },
  353. /**
  354. * @desc : 加载数据
  355. * @author : 于继渤
  356. * @date : 2024/1/23 9:16
  357. */
  358. getData(params) {
  359. if (this.data.dictCode == mixins.$t('warehouseSys')) { //仓库档案
  360. return this.excute(this.data.warehouseService, this.data.warehouseService.selectByCond, params);
  361. } else if (this.data.dictCode == mixins.$t('saleChannelSys')) { //销售渠道
  362. return this.excute(this.data.saleChannelService, this.data.saleChannelService.selectByCond, params);
  363. } else {
  364. //基础数据接口
  365. return this.excute(this.data.service, this.data.service.selectByCond, params);
  366. }
  367. },
  368. /**
  369. * @desc : 获取左侧数据
  370. * @date : 2024/2/1 15:49
  371. * @author : 于继渤
  372. */
  373. getDataKind() {
  374. // 读取系统字典
  375. let dataKindList = app.globalData.dataKindList
  376. let sidebarList = dataKindList.filter(it => it.kindType == Constants.kindType.basicData)
  377. this.setData({
  378. sidebarList: sidebarList
  379. })
  380. },
  381. /**
  382. * @desc : 处理接口返回数据
  383. * @date : 2024/2/1 15:49
  384. * @author : 于继渤
  385. */
  386. handleSearchData(tableData) {
  387. tableData.forEach(res => {
  388. res.listItemTitle = this.data.dictCode
  389. if (this.data.dictCode == mixins.$t('warehouseSys')) { //仓库档案
  390. res.title = res.whName
  391. res['flgDefaultDisabled'] = res.flgDefault
  392. } else if (this.data.dictCode == mixins.$t('saleChannelSys')) { //销售渠道
  393. res.title = res.channelName
  394. res['flgDefaultDisabled'] = res.flgDefault
  395. } else {
  396. res.title = res.dataValue
  397. }
  398. })
  399. this.setData({
  400. tableData: tableData
  401. })
  402. },
  403. /**
  404. * @desc : 新建编辑事件
  405. * @author : 于继渤
  406. * @date : 2024/1/26 11:46
  407. */
  408. editItems(e) {
  409. let data = e.detail.form
  410. this.setData({
  411. formData: JSON.stringify(data)
  412. })
  413. //执行保存编辑操作
  414. this.save({})
  415. },
  416. /**
  417. * @desc : 保存编辑
  418. * @author : 于继渤
  419. * @date : 2022/5/26 20:16
  420. */
  421. saveData(params) {
  422. let id = null
  423. let service = null
  424. let historyDataItem = this.data.historyDataItem
  425. if (this.data.dictCode == mixins.$t('warehouseSys')) { //仓库档案
  426. service = this.data.warehouseService
  427. id = params.whId
  428. if (id && !historyDataItem.flgDefault && params.flgDefault) {
  429. //判断默认给提示
  430. this.isFlgDefault(id, historyDataItem, params, service)
  431. return
  432. }
  433. } else
  434. if (this.data.dictCode == mixins.$t('saleChannelSys')) { //销售渠道
  435. service = this.data.saleChannelService
  436. id = params.channelId
  437. if (id && !historyDataItem.flgDefault && params.flgDefault) {
  438. //判断默认给提示
  439. this.isFlgDefault(id, historyDataItem, params, service)
  440. return
  441. }
  442. } else { //基础数据
  443. service = this.data.service
  444. id = params.dataId
  445. params.dictCode = this.data.dictCode
  446. if (id && !historyDataItem.flgDefault && params.flgDefault && this.data.dictCode == '基础资料-账户') {
  447. //判断默认给提示
  448. this.isFlgDefault(id, historyDataItem, params, service)
  449. return
  450. }
  451. }
  452. if (id) { //编辑
  453. if (this.data.dictCode == '基础资料-账户') {
  454. if (this.data.gradeCode == Constants.gradeCode.STD) { //标准
  455. params.gradeCode = this.data.gradeCode
  456. // params.orgId = app.globalData.user.orgId
  457. }
  458. }
  459. return this.excute(service, service.update, params).then(result=>{
  460. if (result && result.data && result.data.code === Constants.SUCESS_CODE) {
  461. wx.showToast({
  462. title: '保存成功',
  463. image: '/static/image/success.png',
  464. duration: 2000
  465. })
  466. // 执行查询方法
  467. this.searchData()
  468. }
  469. });
  470. } else { //新建
  471. this.isFlgDefaultSave(service).then(it => {
  472. console.log(it, params)
  473. if (!it && params.flgDefault) {
  474. //存在默认
  475. Dialog.confirm({
  476. message: '已存在默认,是否要新作默认',
  477. }).then(() => {
  478. return this.excute(service, service.insert, params).then(res => {
  479. if (res.data.code === Constants.SUCESS_CODE) {
  480. wx.showToast({
  481. title: '保存成功',
  482. image: '/static/image/success.png',
  483. duration: 2000
  484. })
  485. // 重新查询
  486. this.searchData()
  487. }
  488. })
  489. }).catch(() => {
  490. this.setData({
  491. dataItem: null
  492. })
  493. //清除组件数据
  494. this.selectComponent('#popup').setFormNull()
  495. return
  496. });
  497. } else {
  498. if (this.data.dictCode == '基础资料-账户') {
  499. if (this.data.gradeCode == Constants.gradeCode.STD) { //标准
  500. params.gradeCode = this.data.gradeCode
  501. params.orgId = app.globalData.user.orgId
  502. }
  503. }
  504. return this.excute(service, service.insert, params).then(result=>{
  505. if (result && result.data && result.data.code === Constants.SUCESS_CODE) {
  506. wx.showToast({
  507. title: '保存成功',
  508. image: '/static/image/success.png',
  509. duration: 2000
  510. })
  511. // 执行查询方法
  512. this.searchData()
  513. }
  514. });
  515. }
  516. })
  517. }
  518. },
  519. /**
  520. * @desc : 编辑默认设置提示
  521. * @author : 于继渤
  522. * @date : 2022/5/26 20:16
  523. */
  524. isFlgDefault(id, historyDataItem, params, service) {
  525. Dialog.confirm({
  526. message: '已存在默认,是否要新作默认',
  527. }).then(() => {
  528. this.excute(service, service.update, params).then(res => {
  529. console.log(res)
  530. if (res.data.code === Constants.SUCESS_CODE) {
  531. wx.showToast({
  532. title: '保存成功',
  533. image: '/static/image/success.png',
  534. duration: 2000
  535. })
  536. // 重新查询
  537. this.searchData()
  538. }
  539. })
  540. }).catch(() => {
  541. console.log('setFormNull')
  542. //清除组件数据
  543. this.setData({
  544. dataItem: null
  545. })
  546. this.selectComponent('#popup').setFormNull()
  547. });
  548. },
  549. /**
  550. * @desc : 新建默认设置提示
  551. * @author : 于继渤
  552. * @date : 2022/5/26 20:16
  553. */
  554. isFlgDefaultSave(service) {
  555. return new Promise((resolve, reject) => {
  556. this.excute(service, service.selectByCond, {
  557. flgDefault: true
  558. }).then(res => {
  559. if (res.data.data.list && res.data.data.list.length > 0) {
  560. resolve(false)
  561. } else {
  562. resolve(true)
  563. }
  564. })
  565. })
  566. },
  567. /**
  568. * 生命周期函数--监听页面加载
  569. */
  570. onLoad(options) {
  571. this.getDataKind()
  572. let _this = this;
  573. wx.getSystemInfo({
  574. success: function (res) {
  575. _this.setData({
  576. windowHeight: res.windowHeight,
  577. windowWidth: res.windowWidth
  578. })
  579. }
  580. })
  581. },
  582. })