product-attribute.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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. import Dialog from '@/dist/dialog/dialog.js';
  13. const app = getApp()
  14. Page({
  15. mixins: [mixins],
  16. /**
  17. * 页面的初始数据
  18. */
  19. data: {
  20. routeObjNameGoTo: 'goodsBrand',
  21. gradeCode: app.globalData.company.gradeCode,
  22. goodsBrandService: app.globalData['goodsBrandService'],
  23. goodsCategoryService: app.globalData['goodsCategoryService'],
  24. goodsSeriesService: app.globalData['goodsSeriesService'],
  25. unitService: app.globalData['unitService'],
  26. commonService: app.globalData['commonService'],
  27. // 路由
  28. routeObjName: 'productAttribute',
  29. dataItem: null,
  30. // 查询条件
  31. searchContent: [{
  32. code: 'flgValid', key: 'valueList', title: mixins.$t('allValidInvalid'), searchType: Constants.searchType.switch,
  33. list: [
  34. { code: 1, title: mixins.$t('valid'), value: true, checked: true },
  35. { code: 2, title: mixins.$t('invalid'), value: false }]
  36. }],
  37. // 列表区(内容)商品品牌
  38. contentList: [
  39. // { name: 'brandCode', title: mixins.$t('brandCode') },
  40. // { name: 'brandName', title: mixins.$t('brandName') },
  41. { name: 'supplierNames', title: mixins.$t('supplier') }
  42. ],
  43. buttonSaveList: [{ code: 'add', title: '新建', width: '120rpx', }],
  44. contentSaveList: [],
  45. formDataName: mixins.$t('goodsBrandSys'),
  46. formDataTitle: mixins.$t('goodsBrand'),
  47. popContent:
  48. [
  49. // { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
  50. { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
  51. // { code: 'shortName', type: 'str', title: mixins.$t('abbreviation'), required: false },
  52. {
  53. code: 'supplierIds', formMode: 'index', idKey: 'roleId', chooseType: true, name: 'supplierNames',
  54. title: mixins.$t('supplier'), type: 'choose', required: true, dropType: 'supplier', required: true,
  55. },
  56. { code: 'remarks', type: 'textarea', title: mixins.$t('remarks'), required: false }
  57. ],
  58. sideKey: 0,
  59. pageFlag: false,
  60. navigateBackFlag: true,
  61. },
  62. /**
  63. * @desc : 侧滑事件
  64. * @author : 于继渤
  65. * @date : 2024/1/26 11:46
  66. */
  67. changeSwipe(e) {
  68. let item = e.detail.item
  69. //停用启用
  70. let param = {
  71. brandId: item.brandId,
  72. flgValid: !item.flgValid,
  73. }
  74. this.setData({
  75. formData: JSON.stringify(param)
  76. })
  77. //执行编辑操作
  78. this.save({})
  79. },
  80. /**
  81. * @desc : 启用停用
  82. * @date : 2024/2/1 15:49
  83. * @author : 于继渤
  84. */
  85. deactivateEnable(e) {
  86. let item = e.detail.item
  87. let service = null
  88. let id = null
  89. if (this.data.formDataName == mixins.$t('goodsBrandSys')) {
  90. service = this.data.goodsBrandService
  91. id = 'brandId'
  92. let goodService = app.globalData['commonService']
  93. // 启用直接调用
  94. if (!item.flgValid) {
  95. //执行接口
  96. this.handleMoreDataIsValid(service, item, id)
  97. } else {
  98. this.excute(goodService, goodService.getGoods, { brandId: item.brandId }).then(res => {
  99. if (res.data.code == Constants.SUCESS_CODE) {
  100. if (res.data && res.data.data && res.data.data.length > 0) {
  101. //提示信息
  102. Dialog.confirm({
  103. message: '已有商品档案引用了品牌,不允许停用,是否跳转到商品档案页面?',
  104. }).then(() => {
  105. //跳转
  106. wx.navigateTo({
  107. url: '/package-basic-data/pages/product-file/product-file',
  108. success: function (res) {
  109. res.eventChannel.emit('params', { formMode: Constants.formMode.index, item: { brandId: item.brandId } })
  110. }
  111. })
  112. }).catch(() => {
  113. })
  114. return;
  115. }
  116. //执行接口
  117. this.handleMoreDataIsValid(service, item, id)
  118. }
  119. })
  120. }
  121. }
  122. if (this.data.formDataName == mixins.$t('goodsCategorySys')) {
  123. service = this.data.goodsCategoryService
  124. id = 'catId'
  125. //执行接口
  126. this.handleMoreDataIsValid(service, item, id)
  127. }
  128. if (this.data.formDataName == mixins.$t('goodsSeriesSys')) {
  129. service = this.data.goodsSeriesService
  130. id = 'seriesId'
  131. //执行接口
  132. this.handleMoreDataIsValid(service, item, id)
  133. }
  134. if (this.data.formDataName == mixins.$t('unitSys')) {
  135. service = this.data.unitService
  136. id = 'unitId'
  137. //执行接口
  138. this.handleMoreDataIsValid(service, item, id)
  139. }
  140. },
  141. /**
  142. * @desc : 新建编辑事件
  143. * @author : 于继渤
  144. * @date : 2024/1/26 11:46
  145. */
  146. editItems(e) {
  147. let data = e.detail.form
  148. this.setData({
  149. formData: JSON.stringify(data)
  150. })
  151. //执行保存编辑操作
  152. this.save({})
  153. },
  154. /**
  155. * @desc : 保存数据服务--校验
  156. * @date : 2024/2/1 15:49
  157. * @author : 王英杰
  158. */
  159. validData() {
  160. let formData = JSON.parse(this.data.formData)
  161. // //商品种类
  162. if (this.data.formDataName == mixins.$t('goodsCategorySys')
  163. && formData.catId != null && formData.catId == formData.parentId) {
  164. util.showToast('父级不能和该种类相同');
  165. this.selectComponent('#popup').setLoading(false);
  166. return false
  167. }
  168. return true
  169. },
  170. /**
  171. * @desc : 商品种类停用启用
  172. * @author : 于继渤
  173. * @date : 2024/1/26 11:46
  174. */
  175. onSwipeBind(e) {
  176. let swipeFlag = true
  177. let item = e.detail.currentTarget.dataset.item
  178. // return
  179. let flgValidList = []
  180. if (item && item.children && item.children.length > 0) {
  181. flgValidList = item.children.filter(res => {
  182. return res.flgValid == true
  183. })
  184. }
  185. if (!item.children || (flgValidList.length == (item.children && item.children.length)) || flgValidList.length == 0) {
  186. this.handleMoreDataIsValid(this.data.goodsCategoryService, item, 'catId')
  187. } else {
  188. Dialog.confirm({
  189. message: '有启用下级种类,不能停用',
  190. }).then(() => {
  191. }).catch(() => {
  192. })
  193. return
  194. }
  195. },
  196. /**
  197. * @desc : 保存编辑
  198. * @author : 于继渤
  199. * @date : 2022/5/26 20:16
  200. */
  201. saveData(params) {
  202. let id = null
  203. let service = null
  204. if (this.data.formDataName == mixins.$t('goodsBrandSys')) { //商品品牌
  205. params.supplierIds = params.supplierIds ? params.supplierIds : null
  206. service = this.data.goodsBrandService
  207. id = params.brandId
  208. } else if (this.data.formDataName == mixins.$t('goodsCategorySys')) { //商品种类
  209. service = this.data.goodsCategoryService
  210. id = params.catId
  211. } else if (this.data.formDataName == mixins.$t('goodsSeriesSys')) { //商品系列
  212. service = this.data.goodsSeriesService
  213. id = params.seriesId
  214. } else if (this.data.formDataName == mixins.$t('unitSys')) { //计量单位
  215. service = this.data.unitService
  216. id = params.unitId
  217. }
  218. if (id) { //编辑
  219. return this.excute(service, service.update, params);
  220. } else { //新建 TODO
  221. return this.excute(service, service.insert, params).then(result => {
  222. if (result && result.data && result.data.code === Constants.SUCESS_CODE) {
  223. wx.showToast({
  224. title: '保存成功',
  225. image: '/static/image/success.png',
  226. duration: 2000
  227. })
  228. this.setData({
  229. dataItem: null
  230. })
  231. // 商品种类
  232. if (this.data.formDataName == mixins.$t('goodsCategorySys')) {
  233. }
  234. //清除组件数据
  235. this.selectComponent('#popup').setFormNull()
  236. // 执行查询方法
  237. this.searchData()
  238. } else {
  239. this.selectComponent('#popup').setLoading(false);
  240. }
  241. });;
  242. }
  243. },
  244. /**
  245. * @desc : 关闭表单弹窗
  246. * @author : 刘尧
  247. * @date : 2022/5/28 17:28
  248. */
  249. handleData() {
  250. this.setData({
  251. showPop: false
  252. })
  253. },
  254. /**
  255. * @desc : 分类切换
  256. * @author : 于继渤
  257. * @date : 2022/5/26 20:16
  258. */
  259. changeSidebar(e) {
  260. let detail = e.detail
  261. if (!detail) {
  262. this.setData({
  263. sideKey: null
  264. })
  265. } else {
  266. this.setData({
  267. sideKey: e.detail
  268. })
  269. }
  270. this.setData({
  271. formDataName: this.data.sidebarList[detail].kindCode,
  272. formDataTitle: this.data.sidebarList[detail].kindName
  273. })
  274. this.searchData()
  275. },
  276. /**
  277. * @desc : 列表对象点击
  278. * @author : 于继渤
  279. * @date : 2024/1/23 9:16
  280. */
  281. toDetail(e) {
  282. let item = e.detail.item
  283. this.setPopContent(item);
  284. this.setData({
  285. popContent: this.data.popContent,
  286. showPop: true,
  287. dataItem: JSON.stringify(item)
  288. })
  289. },
  290. /**
  291. * @desc : 新建
  292. * @author : 于继渤
  293. * @date : 2024/1/23 9:16
  294. */
  295. toAdd() {
  296. this.setPopContent();
  297. this.setData({
  298. dataItem: JSON.stringify({ decimalPlaces: 0 }),
  299. formData: null,
  300. showPop: true,
  301. })
  302. //清除组件数据
  303. this.selectComponent('#popup').setFormNull()
  304. },
  305. /**
  306. * @desc : 处理接口返回数据
  307. * @date : 2024/2/1 15:49
  308. * @author : 于继渤
  309. */
  310. handleSearchData(tableData) {
  311. if (this.data.formDataName == mixins.$t('goodsCategorySys')) {
  312. tableData.forEach(element => {
  313. element.open = true
  314. });
  315. this.setData({
  316. tableData: util.convertToChildren(tableData, 'parentId', 'catId', null)
  317. })
  318. const myComponent = this.selectComponent('#treeSelect');
  319. myComponent.setDataFromPage([]);
  320. myComponent.setDataFromPage(this.data.tableData);
  321. }
  322. },
  323. /**
  324. * @desc : 设置查询参数
  325. * @author : 于继渤
  326. * @date : 2024/1/23 9:16
  327. */
  328. setSearchParams(params) {
  329. //有效标识
  330. params.flgValidList = params.flgValidList ? params.flgValidList : [true]
  331. if (this.data.formDataName == mixins.$t('goodsCategorySys')) {
  332. params.pageSize = 100000
  333. params.currentPage = 1
  334. }
  335. return params
  336. },
  337. /**
  338. * @desc : 加载数据
  339. * @author : 于继渤
  340. * @date : 2024/1/23 9:16
  341. */
  342. getData(params) {
  343. if (this.data.formDataName == mixins.$t('goodsBrandSys')) { //商品品牌
  344. return this.excute(this.data.goodsBrandService, this.data.goodsBrandService.selectByCond, params);
  345. } else if (this.data.formDataName == mixins.$t('goodsCategorySys')) { //商品种类
  346. return this.excute(this.data.goodsCategoryService, this.data.goodsCategoryService.selectByCond, params);
  347. } else if (this.data.formDataName == mixins.$t('goodsSeriesSys')) { //商品系列
  348. return this.excute(this.data.goodsSeriesService, this.data.goodsSeriesService.selectByCond, params);
  349. } else if (this.data.formDataName == mixins.$t('unitSys')) { //计量单位
  350. return this.excute(this.data.unitService, this.data.unitService.selectByCond, params);
  351. }
  352. },
  353. /**
  354. * @desc : 获取左侧数据
  355. * @date : 2024/2/1 15:49
  356. * @author : 于继渤
  357. */
  358. getDataKind() {
  359. // 读取系统字典
  360. let dataKindList = app.globalData.dataKindList
  361. let sidebarList = dataKindList.filter(it => it.kindType == Constants.kindType.goodsAttr)
  362. this.setData({
  363. sidebarList: sidebarList
  364. })
  365. },
  366. /**
  367. * @desc : 设置pop字段
  368. * @author : 于继渤
  369. * @date : 2024/1/23 9:16
  370. */
  371. setPopContent(dataItem) {
  372. let formDataName = this.data.formDataName
  373. let popContent = this.data.popContent
  374. let routeObjNameGoTo = this.data.routeObjNameGoTo
  375. if (formDataName == mixins.$t('goodsBrandSys')) {//商品品牌
  376. if (dataItem) {
  377. if (this.data.gradeCode == Constants.gradeCode.STD) {
  378. popContent =
  379. [
  380. { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
  381. { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
  382. // { code: 'shortName', type: 'str', title: mixins.$t('abbreviation'), required: false },
  383. { code: 'remarks', type: 'textarea', title: mixins.$t('remarks'), required: false }
  384. ]
  385. } else {
  386. popContent =
  387. [
  388. { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
  389. { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
  390. // { code: 'shortName', type: 'str', title: mixins.$t('abbreviation'), required: false },
  391. { code: 'supplierIds', name: 'supplierNames', title: 'supplier', type: 'choose', required: true, dropType: 'supplier', required: true, urlKey: 'selectProductAttributeSuppliers', code: 'supplierIds', formMode: 'index', idKey: 'roleId', title: mixins.$t('supplier') },
  392. { code: 'remarks', type: 'textarea', title: mixins.$t('remarks'), required: false }
  393. ]
  394. }
  395. } else {
  396. if (this.data.gradeCode == Constants.gradeCode.STD) {
  397. popContent =
  398. [
  399. // { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
  400. { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
  401. // { code: 'shortName', type: 'str', title: mixins.$t('abbreviation'), required: false },
  402. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  403. ]
  404. } else {
  405. popContent =
  406. [
  407. // { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
  408. { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
  409. // { code: 'shortName', type: 'str', title: mixins.$t('abbreviation'), required: false },
  410. { code: 'supplierIds', name: 'supplierNames', title: 'supplier', type: 'choose', required: true, dropType: 'supplier', required: true, urlKey: 'selectProductAttributeSuppliers', code: 'supplierIds', formMode: 'index', idKey: 'roleId', title: mixins.$t('supplier') },
  411. { code: 'remarks', type: 'textarea', title: mixins.$t('remarks'), required: false }
  412. ]
  413. }
  414. }
  415. routeObjNameGoTo = 'goodsBrand'
  416. }
  417. if (formDataName == mixins.$t('goodsCategorySys')) { //商品种类
  418. if (dataItem) {
  419. popContent =
  420. [
  421. { code: 'catCode', type: 'str', title: mixins.$t('catCode'), required: false, readonly: true },
  422. { code: 'parentId', name: 'parentName', title: mixins.$t('parent'), type: 'choose', required: false, urlKey: 'selectProductTypes', notClear: true, clear: true },
  423. { code: 'catName', type: 'str', title: mixins.$t('catName'), required: true },
  424. { code: 'remarks', type: 'textarea', title: mixins.$t('remarks'), required: false }
  425. ]
  426. } else {
  427. popContent =
  428. [
  429. // { code: 'catCode', type: 'str', title: mixins.$t('catCode'), required: false, readonly: true, },
  430. { code: 'parentId', name: 'parentName', title: mixins.$t('parent'), type: 'choose', required: false, urlKey: 'selectProductTypes', notClear: true, clear: true },
  431. { code: 'catName', type: 'str', title: mixins.$t('catName'), required: true },
  432. { code: 'remarks', type: 'textarea', title: mixins.$t('remarks'), required: false }
  433. ]
  434. }
  435. routeObjNameGoTo = 'goodsCategory'
  436. }
  437. if (formDataName == mixins.$t('goodsSeriesSys')) { //商品系列
  438. if (dataItem) {
  439. popContent =
  440. [
  441. { code: 'seriesCode', type: 'str', title: mixins.$t('seriesCode'), required: false, readonly: true, },
  442. { code: 'seriesName', type: 'str', title: mixins.$t('seriesName'), required: true },
  443. { code: 'remarks', type: 'textarea', title: mixins.$t('remarks'), required: false }
  444. ]
  445. } else {
  446. popContent =
  447. [
  448. // { code: 'seriesCode', type: 'str', title: mixins.$t('seriesCode'), required: false, readonly: true, },
  449. { code: 'seriesName', type: 'str', title: mixins.$t('seriesName'), required: true },
  450. { code: 'remarks', type: 'textarea', title: mixins.$t('remarks'), required: false }
  451. ]
  452. }
  453. }
  454. // todo
  455. if (formDataName == mixins.$t('unitSys')) { //计量单位
  456. if (dataItem) {
  457. popContent =
  458. [
  459. { code: 'unitCode', type: 'str', title: mixins.$t('unitCode'), required: false, readonly: true, },
  460. { code: 'unitName', type: 'str', title: mixins.$t('unitName'), required: true },
  461. { code: 'decimalPlaces', max: 6, min: 0, type: 'number', sign: "", digits: 0, title: mixins.$t('decimalPlaces'), required: true, formatThousandth: false },
  462. { code: 'remarks', type: 'textarea', title: mixins.$t('remarks'), required: false }
  463. ]
  464. } else {
  465. popContent =
  466. [
  467. // { code: 'unitCode', type: 'str', title: mixins.$t('unitCode'), required: false, readonly: true, },
  468. { code: 'unitName', type: 'str', title: mixins.$t('unitName'), required: true },
  469. { code: 'decimalPlaces', max: 6, min: 0, type: 'number', sign: "", digits: 0, title: mixins.$t('decimalPlaces'), required: true, formatThousandth: false },
  470. { code: 'remarks', type: 'textarea', title: mixins.$t('remarks'), required: false }
  471. ]
  472. }
  473. }
  474. this.setData({
  475. popContent: popContent,
  476. routeObjNameGoTo: routeObjNameGoTo
  477. })
  478. },
  479. /**
  480. * 生命周期函数--监听页面加载
  481. */
  482. onLoad(options) {
  483. this.getDataKind()
  484. let _this = this;
  485. this.getStickyHeight()
  486. wx.getSystemInfo({
  487. success: function (res) {
  488. _this.setData({
  489. windowHeight: res.windowHeight,
  490. windowWidth: res.windowWidth
  491. })
  492. }
  493. })
  494. },
  495. })