basic-data.js 13 KB

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