basic-data.js 15 KB

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