product-attribute.js 12 KB

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