basic-data.js 17 KB

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