product-attribute.js 18 KB

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