product-attribute.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. const app = getApp()
  13. Page({
  14. mixins: [mixins],
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. routeObjNameGoTo: 'goodsBrand',
  20. goodsBrandService: app.globalData['goodsBrandService'],
  21. goodsCategoryService: app.globalData['goodsCategoryService'],
  22. goodsSeriesService: app.globalData['goodsSeriesService'],
  23. unitService: app.globalData['unitService'],
  24. commonService: app.globalData['commonService'],
  25. // 路由
  26. routeObjName: 'product-attribute',
  27. // 查询条件
  28. searchContent: [{
  29. code: 'flgValid', title: mixins.$t('allValidInvalid'), searchType: Constants.searchType.switch,
  30. list: [
  31. { code: 1, title: mixins.$t('valid'), value: true },
  32. { code: 2, title: mixins.$t('invalid'), value: false }]
  33. }],
  34. // 列表区(内容)商品品牌
  35. contentList: [
  36. { name: 'brandCode', title: mixins.$t('brandCode') },
  37. { name: 'brandName', title: mixins.$t('brandName') },
  38. { name: 'supplierNames', title: mixins.$t('supplier') }
  39. ],
  40. buttonSaveList:[{code:'add',title:'新建',width:'120rpx',color:'#CAA977'}],
  41. contentSaveList:[],
  42. formDataName: mixins.$t('goodsBrand'),
  43. popContent:
  44. [
  45. { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
  46. { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
  47. { code: 'supplierIds',formMode: 'index', idKey: 'roleId', chooseType:true, name: 'supplierNames', title: 'supplier', type: 'choose', required: true, dropType: 'supplier', required: true, },
  48. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  49. ],
  50. sideKey: 0,
  51. // statusItem: {
  52. // text: '全部',
  53. // value: -1
  54. // },
  55. // statusList: [
  56. // { checked: false, text: '有效', value: 1 },
  57. // { checked: false, text: '无效', value: 0 },
  58. // { checked: true, text: '全部', value: -1 },
  59. // ], //状态
  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. if (this.data.formDataName == mixins.$t('goodsBrand')) {
  89. service = this.data.goodsBrandService
  90. id = 'brandId'
  91. }
  92. if (this.data.formDataName == mixins.$t('goodsCategory')) {
  93. service = this.data.goodsCategoryService
  94. id = 'catId'
  95. }
  96. if (this.data.formDataName == mixins.$t('goodsSeries')) {
  97. service = this.data.goodsSeriesService
  98. id = 'seriesId'
  99. }
  100. if (this.data.formDataName == mixins.$t('unit')) {
  101. service = this.data.unitService
  102. id = 'unitId'
  103. }
  104. //执行接口
  105. this.handleMoreDataIsValid(service, item, id)
  106. },
  107. /**
  108. * @desc : 新建编辑事件
  109. * @author : 于继渤
  110. * @date : 2024/1/26 11:46
  111. */
  112. editItems(e) {
  113. let data = e.detail.form
  114. this.setData({
  115. formData: JSON.stringify(data)
  116. })
  117. //执行保存编辑操作
  118. this.save({})
  119. },
  120. /**
  121. * @desc : 商品种类停用启用
  122. * @author : 于继渤
  123. * @date : 2024/1/26 11:46
  124. */
  125. onSwipeBind(e) {
  126. let swipeFlag = true
  127. let item = e.detail.currentTarget.dataset.item
  128. if(item && item.children && item.children.length > 0){
  129. for (let i = 0; i < item.children.length; i++) {
  130. if(item.children[i].flgValid){
  131. return swipeFlag = false
  132. }
  133. }
  134. }
  135. if(swipeFlag){
  136. this.handleMoreDataIsValid(this.data.goodsCategoryService, item, 'catId')
  137. }else{
  138. wx.showToast({
  139. title: '无法停用',
  140. image: '/static/image/warning.png',
  141. duration: 1000
  142. })
  143. }
  144. },
  145. /**
  146. * @desc : 保存编辑
  147. * @author : 于继渤
  148. * @date : 2022/5/26 20:16
  149. */
  150. saveData(params) {
  151. let id = null
  152. let service = null
  153. if (this.data.formDataName == mixins.$t('goodsBrand')) { //商品品牌
  154. service = this.data.goodsBrandService
  155. id = params.brandId
  156. } else if (this.data.formDataName == mixins.$t('goodsCategory')) { //商品种类
  157. service = this.data.goodsCategoryService
  158. id = params.catId
  159. } else if (this.data.formDataName == mixins.$t('goodsSeries')) { //商品系列
  160. service = this.data.goodsSeriesService
  161. id = params.seriesId
  162. } else if (this.data.formDataName == mixins.$t('unit')) { //计量单位
  163. service = this.data.unitService
  164. id = params.unitId
  165. }
  166. if (id) { //编辑
  167. return this.excute(service, service.update, params);
  168. } else { //新建
  169. return this.excute(service, service.insert, params);
  170. }
  171. },
  172. /**
  173. * @desc : 处理数据
  174. * @author : 于继渤
  175. * @date : 2024/1/26 11:46
  176. */
  177. handleData(data) {
  178. this.searchData()
  179. },
  180. /**
  181. * @desc : 分类切换
  182. * @author : 于继渤
  183. * @date : 2022/5/26 20:16
  184. */
  185. changeSidebar(e) {
  186. let detail = e.detail
  187. this.setData({
  188. formDataName: this.data.sidebarList[detail].kindName
  189. })
  190. this.searchData()
  191. },
  192. /**
  193. * @desc : 列表对象点击
  194. * @author : 于继渤
  195. * @date : 2024/1/23 9:16
  196. */
  197. toDetail(e) {
  198. this.setPopContent();
  199. console.log(e)
  200. let item = e.detail.item
  201. this.setData({
  202. popContent: this.data.popContent,
  203. showPop: true,
  204. dataItem: JSON.stringify(item)
  205. })
  206. },
  207. /**
  208. * @desc : 新建
  209. * @author : 于继渤
  210. * @date : 2024/1/23 9:16
  211. */
  212. toAdd() {
  213. this.setPopContent();
  214. this.setData({
  215. dataItem: null,
  216. formData: null,
  217. showPop: true,
  218. })
  219. },
  220. /**
  221. * @desc : 处理接口返回数据
  222. * @date : 2024/2/1 15:49
  223. * @author : 于继渤
  224. */
  225. handleSearchData(tableData) {
  226. if (this.data.formDataName == mixins.$t('goodsCategory')) {
  227. this.setData({
  228. tableData: util.convertToChildren(tableData, 'parentId', 'catId', null)
  229. })
  230. const myComponent = this.selectComponent('#treeSelect');
  231. myComponent.setDataFromPage(this.data.tableData);
  232. }
  233. },
  234. /**
  235. * @desc : 设置查询参数
  236. * @author : 于继渤
  237. * @date : 2024/1/23 9:16
  238. */
  239. setSearchParams(params) {
  240. //有效标识
  241. if (params.flgValidList && params.flgValidList.indexOf("true") != -1 && params.flgValidList.indexOf("false") == -1) {
  242. params.flgValid = true
  243. } else if (params.flgValidList && params.flgValidList.indexOf("true") == -1 && params.flgValidList.indexOf("false") != -1) {
  244. params.flgValid = false
  245. }
  246. if (this.data.formDataName == mixins.$t('goodsCategory')) {
  247. params.pageSize = 100000
  248. params.currentPage = 1
  249. }
  250. return params
  251. },
  252. /**
  253. * @desc : 加载数据
  254. * @author : 于继渤
  255. * @date : 2024/1/23 9:16
  256. */
  257. getData(params) {
  258. if (this.data.formDataName == mixins.$t('goodsBrand')) { //商品品牌
  259. return this.excute(this.data.goodsBrandService, this.data.goodsBrandService.selectByCond, params);
  260. } else if (this.data.formDataName == mixins.$t('goodsCategory')) { //商品种类
  261. return this.excute(this.data.goodsCategoryService, this.data.goodsCategoryService.selectByCond, params);
  262. } else if (this.data.formDataName == mixins.$t('goodsSeries')) { //商品系列
  263. return this.excute(this.data.goodsSeriesService, this.data.goodsSeriesService.selectByCond, params);
  264. } else if (this.data.formDataName == mixins.$t('unit')) { //计量单位
  265. return this.excute(this.data.unitService, this.data.unitService.selectByCond, params);
  266. }
  267. },
  268. /**
  269. * @desc : 获取左侧数据
  270. * @date : 2024/2/1 15:49
  271. * @author : 于继渤
  272. */
  273. getDataKind() {
  274. return this.excute(this.data.commonService, this.data.commonService.getDataKind, {
  275. kindType: Constants.kindType.goodsAttr
  276. }).then(res => {
  277. this.setData({
  278. sidebarList: res.data.data
  279. })
  280. })
  281. },
  282. /**
  283. * @desc : 设置pop字段
  284. * @author : 于继渤
  285. * @date : 2024/1/23 9:16
  286. */
  287. setPopContent() {
  288. let formDataName = this.data.formDataName
  289. let popContent = this.data.popContent
  290. let routeObjNameGoTo = this.data.routeObjNameGoTo
  291. if (formDataName == mixins.$t('goodsBrand')) {//商品品牌
  292. popContent =
  293. [
  294. { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
  295. { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
  296. { code: 'supplierIds', name: 'supplierNames', title: 'supplier', type: 'choose', required: true, dropType: 'supplier', required: true, urlKey: 'selectProductAttributeSuppliers', code: 'supplierIds',formMode: 'index', idKey: 'roleId', },
  297. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  298. ]
  299. routeObjNameGoTo = 'goodsBrand'
  300. }
  301. if (formDataName == mixins.$t('goodsCategory')) { //商品种类
  302. popContent =
  303. [
  304. { code: 'catCode', type: 'str', title: mixins.$t('catCode'), required: false, readonly: true, },
  305. { code: 'parentId', name: 'parentName', title: 'parent', type: 'choose', required: true, dropType: 'supplier', required: true, urlKey: 'selectProductTypes', },
  306. { code: 'catName', type: 'str', title: mixins.$t('catName'), required: true },
  307. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  308. ]
  309. routeObjNameGoTo = 'goodsCategory'
  310. }
  311. if (formDataName == mixins.$t('goodsSeries')) { //商品系列
  312. popContent =
  313. [
  314. { code: 'seriesCode', type: 'str', title: mixins.$t('seriesCode'), required: false, readonly: true, },
  315. { code: 'seriesName', type: 'str', title: mixins.$t('seriesName'), required: true },
  316. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  317. ]
  318. }
  319. if (formDataName == mixins.$t('unit')) { //计量单位
  320. popContent =
  321. [
  322. { code: 'unitCode', type: 'str', title: mixins.$t('unitCode'), required: false, readonly: true, },
  323. { code: 'unitName', type: 'str', title: mixins.$t('unitName'), required: true },
  324. { code: 'decimalPlaces', type: 'number',sign:"",digits:0, title: mixins.$t('decimalPlaces'), required: true},
  325. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  326. ]
  327. }
  328. this.setData({
  329. popContent: popContent,
  330. routeObjNameGoTo: routeObjNameGoTo
  331. })
  332. },
  333. /**
  334. * 生命周期函数--监听页面加载
  335. */
  336. onLoad(options) {
  337. this.getDataKind()
  338. let _this = this;
  339. wx.getSystemInfo({
  340. success: function (res) {
  341. _this.setData({
  342. windowHeight: res.windowHeight,
  343. windowWidth: res.windowWidth
  344. })
  345. }
  346. })
  347. },
  348. })