product-attribute.js 12 KB

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