basic-data.js 15 KB

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