basic-data.js 12 KB

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