basic-data.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  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. this.setData({
  261. formDataName: this.data.sidebarList[detail].kindName,
  262. dictCode: this.data.sidebarList[detail].kindCode
  263. })
  264. this.setPopContent();
  265. this.searchData()
  266. },
  267. /**
  268. * @desc : 列表对象点击
  269. * @author : 于继渤
  270. * @date : 2024/1/23 9:16
  271. */
  272. toDetail(e) {
  273. let item = e.detail.item
  274. this.setPopContent(item);
  275. this.setData({
  276. popContent: this.data.popContent,
  277. showPop: true,
  278. dataItem: JSON.stringify(item),
  279. historyDataItem: item
  280. })
  281. },
  282. /**
  283. * @desc : 新建
  284. * @author : 于继渤
  285. * @date : 2024/1/23 9:16
  286. */
  287. toAdd() {
  288. this.setPopContent();
  289. this.setData({
  290. dataItem: null,
  291. formData: null,
  292. showPop: true,
  293. })
  294. //清除组件数据
  295. this.selectComponent('#popup').setFormNull()
  296. },
  297. /**
  298. * @desc : 跳转排序
  299. * @author : 于继渤
  300. * @date : 2024/1/23 9:16
  301. */
  302. toSort() {
  303. let this_ = this
  304. wx.navigateTo({
  305. url: this.data.route.sort.url,
  306. success: function (res) {
  307. // 通过eventChannel向被打开页面传送数据 TODO 测试例子url是写死的,实际中,需要从route中读取
  308. res.eventChannel.emit('params', {
  309. formType: this_.data.dictCode,
  310. formMode: 'index'
  311. })
  312. }
  313. })
  314. },
  315. /**
  316. * @desc : 设置查询参数
  317. * @author : 于继渤
  318. * @date : 2024/1/23 9:16
  319. */
  320. setSearchParams(params) {
  321. params.flgValidList = params.flgValidList ? params.flgValidList : [true]
  322. params.dictCode = this.data.dictCode
  323. return params
  324. },
  325. /**
  326. * @desc : 加载数据
  327. * @author : 于继渤
  328. * @date : 2024/1/23 9:16
  329. */
  330. getData(params) {
  331. if (this.data.dictCode == mixins.$t('warehouseSys')) { //仓库档案
  332. return this.excute(this.data.warehouseService, this.data.warehouseService.selectByCond, params);
  333. } else if (this.data.dictCode == mixins.$t('saleChannelSys')) { //销售渠道
  334. return this.excute(this.data.saleChannelService, this.data.saleChannelService.selectByCond, params);
  335. } else {
  336. //基础数据接口
  337. return this.excute(this.data.service, this.data.service.selectByCond, params);
  338. }
  339. },
  340. /**
  341. * @desc : 获取左侧数据
  342. * @date : 2024/2/1 15:49
  343. * @author : 于继渤
  344. */
  345. getDataKind() {
  346. // 读取系统字典
  347. let dataKindList = app.globalData.dataKindList
  348. let sidebarList = dataKindList.filter(it => it.kindType == Constants.kindType.basicData)
  349. this.setData({
  350. sidebarList: sidebarList
  351. })
  352. },
  353. /**
  354. * @desc : 处理接口返回数据
  355. * @date : 2024/2/1 15:49
  356. * @author : 于继渤
  357. */
  358. handleSearchData(tableData) {
  359. tableData.forEach(res => {
  360. res.listItemTitle = this.data.formDataName
  361. if (this.data.dictCode == mixins.$t('warehouseSys')) { //仓库档案
  362. res.title = res.whName
  363. res['flgDefaultDisabled'] = res.flgDefault
  364. } else if (this.data.dictCode == mixins.$t('saleChannelSys')) { //销售渠道
  365. res.title = res.channelName
  366. res['flgDefaultDisabled'] = res.flgDefault
  367. } else {
  368. res.title = res.dataValue
  369. }
  370. })
  371. this.setData({
  372. tableData: tableData
  373. })
  374. },
  375. /**
  376. * @desc : 新建编辑事件
  377. * @author : 于继渤
  378. * @date : 2024/1/26 11:46
  379. */
  380. editItems(e) {
  381. let data = e.detail.form
  382. this.setData({
  383. formData: JSON.stringify(data)
  384. })
  385. //执行保存编辑操作
  386. this.save({})
  387. },
  388. /**
  389. * @desc : 保存编辑
  390. * @author : 于继渤
  391. * @date : 2022/5/26 20:16
  392. */
  393. saveData(params) {
  394. let id = null
  395. let service = null
  396. let historyDataItem = this.data.historyDataItem
  397. if (this.data.dictCode == mixins.$t('warehouseSys')) { //仓库档案
  398. service = this.data.warehouseService
  399. id = params.whId
  400. if (id && !historyDataItem.flgDefault && params.flgDefault) {
  401. //判断默认给提示
  402. this.isFlgDefault(id, historyDataItem, params, service)
  403. return
  404. }
  405. } else
  406. if (this.data.dictCode == mixins.$t('saleChannelSys')) { //销售渠道
  407. service = this.data.saleChannelService
  408. id = params.channelId
  409. if (id && !historyDataItem.flgDefault && params.flgDefault) {
  410. //判断默认给提示
  411. this.isFlgDefault(id, historyDataItem, params, service)
  412. return
  413. }
  414. } else { //基础数据
  415. service = this.data.service
  416. id = params.dataId
  417. params.dictCode = this.data.dictCode
  418. if (id && !historyDataItem.flgDefault && params.flgDefault && this.data.dictCode == '基础资料-账户') {
  419. //判断默认给提示
  420. this.isFlgDefault(id, historyDataItem, params, service)
  421. return
  422. }
  423. }
  424. if (id) { //编辑
  425. return this.excute(service, service.update, params);
  426. } else { //新建
  427. this.isFlgDefaultSave(service).then(it => {
  428. console.log(it, params)
  429. if (!it && params.flgDefault) {
  430. //存在默认
  431. Dialog.confirm({
  432. message: '已存在默认,是否要新作默认',
  433. }).then(() => {
  434. return this.excute(service, service.insert, params).then(res => {
  435. if (res.data.code === Constants.SUCESS_CODE) {
  436. wx.showToast({
  437. title: '保存成功',
  438. image: '/static/image/success.png',
  439. duration: 2000
  440. })
  441. // 重新查询
  442. this.searchData()
  443. }
  444. })
  445. }).catch(() => {
  446. this.setData({
  447. dataItem:null
  448. })
  449. //清除组件数据
  450. this.selectComponent('#popup').setFormNull()
  451. return
  452. });
  453. } else {
  454. return this.excute(service, service.insert, params);
  455. }
  456. })
  457. }
  458. },
  459. /**
  460. * @desc : 编辑默认设置提示
  461. * @author : 于继渤
  462. * @date : 2022/5/26 20:16
  463. */
  464. isFlgDefault(id, historyDataItem, params, service) {
  465. Dialog.confirm({
  466. message: '已存在默认,是否要新作默认',
  467. }).then(() => {
  468. this.excute(service, service.update, params).then(res => {
  469. console.log(res)
  470. if (res.data.code === Constants.SUCESS_CODE) {
  471. wx.showToast({
  472. title: '保存成功',
  473. image: '/static/image/success.png',
  474. duration: 2000
  475. })
  476. // 重新查询
  477. this.searchData()
  478. }
  479. })
  480. }).catch(() => {
  481. console.log('setFormNull')
  482. //清除组件数据
  483. this.setData({
  484. dataItem:null
  485. })
  486. this.selectComponent('#popup').setFormNull()
  487. });
  488. },
  489. /**
  490. * @desc : 新建默认设置提示
  491. * @author : 于继渤
  492. * @date : 2022/5/26 20:16
  493. */
  494. isFlgDefaultSave(service) {
  495. return new Promise((resolve, reject) => {
  496. this.excute(service, service.selectByCond, {
  497. flgDefault: true
  498. }).then(res => {
  499. if (res.data.data.list && res.data.data.list.length > 0) {
  500. resolve(false)
  501. } else {
  502. resolve(true)
  503. }
  504. })
  505. })
  506. },
  507. /**
  508. * 生命周期函数--监听页面加载
  509. */
  510. onLoad(options) {
  511. this.getDataKind()
  512. let _this = this;
  513. wx.getSystemInfo({
  514. success: function (res) {
  515. _this.setData({
  516. windowHeight: res.windowHeight,
  517. windowWidth: res.windowWidth
  518. })
  519. }
  520. })
  521. },
  522. })