basic-data.js 12 KB

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