basic-data.js 17 KB

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