product-attribute.js 16 KB

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