product-attribute.js 17 KB

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