product-attribute.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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).then(result=>{
  187. if (result && result.data && result.data.code === Constants.SUCESS_CODE) {
  188. wx.showToast({
  189. title: '保存成功',
  190. image: '/static/image/success.png',
  191. duration: 2000
  192. })
  193. // 执行查询方法
  194. this.searchData()
  195. }
  196. });;
  197. } else { //新建
  198. return this.excute(service, service.insert, params).then(result=>{
  199. if (result && result.data && result.data.code === Constants.SUCESS_CODE) {
  200. wx.showToast({
  201. title: '保存成功',
  202. image: '/static/image/success.png',
  203. duration: 2000
  204. })
  205. // 执行查询方法
  206. this.searchData()
  207. }
  208. });;
  209. }
  210. },
  211. // /**
  212. // * @desc : 处理数据
  213. // * @author : 于继渤
  214. // * @date : 2024/1/26 11:46
  215. // */
  216. // handleData(data) {
  217. // this.searchData()
  218. // },
  219. /**
  220. * @desc : 分类切换
  221. * @author : 于继渤
  222. * @date : 2022/5/26 20:16
  223. */
  224. changeSidebar(e) {
  225. let detail = e.detail
  226. if (!detail) {
  227. this.setData({
  228. sideKey: null
  229. })
  230. } else {
  231. this.setData({
  232. sideKey: e.detail
  233. })
  234. }
  235. this.setData({
  236. formDataName: this.data.sidebarList[detail].kindName
  237. })
  238. this.searchData()
  239. },
  240. /**
  241. * @desc : 列表对象点击
  242. * @author : 于继渤
  243. * @date : 2024/1/23 9:16
  244. */
  245. toDetail(e) {
  246. this.setPopContent();
  247. console.log(e)
  248. let item = e.detail.item
  249. this.setData({
  250. popContent: this.data.popContent,
  251. showPop: true,
  252. dataItem: JSON.stringify(item)
  253. })
  254. },
  255. /**
  256. * @desc : 新建
  257. * @author : 于继渤
  258. * @date : 2024/1/23 9:16
  259. */
  260. toAdd() {
  261. this.setPopContent();
  262. this.setData({
  263. dataItem: null,
  264. formData: null,
  265. showPop: true,
  266. })
  267. //清除组件数据
  268. this.selectComponent('#popup').setFormNull()
  269. },
  270. /**
  271. * @desc : 处理接口返回数据
  272. * @date : 2024/2/1 15:49
  273. * @author : 于继渤
  274. */
  275. handleSearchData(tableData) {
  276. if (this.data.formDataName == mixins.$t('goodsCategorySys')) {
  277. tableData.forEach(element => {
  278. element.open = true
  279. });
  280. this.setData({
  281. tableData: util.convertToChildren(tableData, 'parentId', 'catId', null)
  282. })
  283. const myComponent = this.selectComponent('#treeSelect');
  284. myComponent.setDataFromPage([]);
  285. myComponent.setDataFromPage(this.data.tableData);
  286. }
  287. },
  288. /**
  289. * @desc : 设置查询参数
  290. * @author : 于继渤
  291. * @date : 2024/1/23 9:16
  292. */
  293. setSearchParams(params) {
  294. //有效标识
  295. params.flgValidList = params.flgValidList ? params.flgValidList : [true]
  296. if (this.data.formDataName == mixins.$t('goodsCategorySys')) {
  297. params.pageSize = 100000
  298. params.currentPage = 1
  299. }
  300. return params
  301. },
  302. /**
  303. * @desc : 加载数据
  304. * @author : 于继渤
  305. * @date : 2024/1/23 9:16
  306. */
  307. getData(params) {
  308. if (this.data.formDataName == mixins.$t('goodsBrandSys')) { //商品品牌
  309. return this.excute(this.data.goodsBrandService, this.data.goodsBrandService.selectByCond, params);
  310. } else if (this.data.formDataName == mixins.$t('goodsCategorySys')) { //商品种类
  311. return this.excute(this.data.goodsCategoryService, this.data.goodsCategoryService.selectByCond, params);
  312. } else if (this.data.formDataName == mixins.$t('goodsSeriesSys')) { //商品系列
  313. return this.excute(this.data.goodsSeriesService, this.data.goodsSeriesService.selectByCond, params);
  314. } else if (this.data.formDataName == mixins.$t('unitSys')) { //计量单位
  315. return this.excute(this.data.unitService, this.data.unitService.selectByCond, params);
  316. }
  317. },
  318. /**
  319. * @desc : 获取左侧数据
  320. * @date : 2024/2/1 15:49
  321. * @author : 于继渤
  322. */
  323. getDataKind() {
  324. // 读取系统字典
  325. let dataKindList = app.globalData.dataKindList
  326. console.log('dataKindList',dataKindList)
  327. let sidebarList = dataKindList.filter(it=>it.kindType == Constants.kindType.goodsAttr)
  328. this.setData({
  329. sidebarList: sidebarList
  330. })
  331. },
  332. /**
  333. * @desc : 设置pop字段
  334. * @author : 于继渤
  335. * @date : 2024/1/23 9:16
  336. */
  337. setPopContent() {
  338. let formDataName = this.data.formDataName
  339. let popContent = this.data.popContent
  340. let routeObjNameGoTo = this.data.routeObjNameGoTo
  341. if (formDataName == mixins.$t('goodsBrandSys')) {//商品品牌
  342. popContent =
  343. [
  344. { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
  345. { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
  346. { code: 'shortName', type: 'str', title: mixins.$t('abbreviation'), required: false },
  347. { 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') },
  348. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  349. ]
  350. routeObjNameGoTo = 'goodsBrand'
  351. }
  352. if (formDataName == mixins.$t('goodsCategorySys')) { //商品种类
  353. popContent =
  354. [
  355. { code: 'catCode', type: 'str', title: mixins.$t('catCode'), required: false, readonly: true, },
  356. { code: 'parentId', name: 'parentName', title: mixins.$t('parent'), type: 'choose', required: false, urlKey: 'selectProductTypes', },
  357. { code: 'catName', type: 'str', title: mixins.$t('catName'), required: true },
  358. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  359. ]
  360. routeObjNameGoTo = 'goodsCategory'
  361. }
  362. if (formDataName == mixins.$t('goodsSeriesSys')) { //商品系列
  363. popContent =
  364. [
  365. { code: 'seriesCode', type: 'str', title: mixins.$t('seriesCode'), required: false, readonly: true, },
  366. { code: 'seriesName', type: 'str', title: mixins.$t('seriesName'), required: true },
  367. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  368. ]
  369. }
  370. if (formDataName == mixins.$t('unitSys')) { //计量单位
  371. popContent =
  372. [
  373. { code: 'unitCode', type: 'str', title: mixins.$t('unitCode'), required: false, readonly: true, },
  374. { code: 'unitName', type: 'str', title: mixins.$t('unitName'), required: true },
  375. { code: 'decimalPlaces', max:6, type: 'number', sign: "", digits: 0, title: mixins.$t('decimalPlaces'), required: true ,formatThousandth:false},
  376. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  377. ]
  378. }
  379. this.setData({
  380. popContent: popContent,
  381. routeObjNameGoTo: routeObjNameGoTo
  382. })
  383. },
  384. /**
  385. * 生命周期函数--监听页面加载
  386. */
  387. onLoad(options) {
  388. this.getDataKind()
  389. let _this = this;
  390. wx.getSystemInfo({
  391. success: function (res) {
  392. _this.setData({
  393. windowHeight: res.windowHeight,
  394. windowWidth: res.windowWidth
  395. })
  396. }
  397. })
  398. },
  399. })