basic-data.js 12 KB

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