product-attribute.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. // 路由
  25. routeObjName: 'product-attribute',
  26. // 列表区(内容)商品品牌
  27. contentList: [
  28. { name: 'brandCode', title: mixins.$t('brandCode') },
  29. { name: 'brandName', title: mixins.$t('brandName') },
  30. { name: 'supplierName', title: mixins.$t('supplier') }
  31. ],
  32. sidebarList: [
  33. { id: 0, name: mixins.$t('goodsBrand') },
  34. { id: 1, name: mixins.$t('goodsCategory') },
  35. { id: 2, name: mixins.$t('goodsSeries') },
  36. { id: 3, name: mixins.$t('unit') }
  37. ],
  38. formDataName: mixins.$t('goodsBrand'),
  39. popContent:
  40. [
  41. { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
  42. { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
  43. { code: 'supplierIds', name: 'supplierNames', title: 'supplier', type: 'choose', required: true, dropType: 'supplier', required: true, },
  44. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  45. ],
  46. sideKey: 0,
  47. // statusItem: {
  48. // text: '全部',
  49. // value: -1
  50. // },
  51. // statusList: [
  52. // { checked: false, text: '有效', value: 1 },
  53. // { checked: false, text: '无效', value: 0 },
  54. // { checked: true, text: '全部', value: -1 },
  55. // ], //状态
  56. },
  57. /**
  58. * @desc : 侧滑事件
  59. * @author : 于继渤
  60. * @date : 2024/1/26 11:46
  61. */
  62. changeSwipe(e) {
  63. let item = e.detail.item
  64. //停用启用
  65. let param = {
  66. brandId: item.brandId,
  67. flgValid: !item.flgValid,
  68. }
  69. this.setData({
  70. formData: JSON.stringify(param)
  71. })
  72. //执行编辑操作
  73. this.save({})
  74. },
  75. /**
  76. * @desc : 启用停用
  77. * @date : 2024/2/1 15:49
  78. * @author : 于继渤
  79. */
  80. deactivateEnable(e) {
  81. let item = e.detail.item
  82. let service = null
  83. let id = null
  84. if (this.data.formDataName == mixins.$t('goodsBrand')) {
  85. service = this.data.goodsBrandService
  86. id = 'brandId'
  87. }
  88. if (this.data.formDataName == mixins.$t('goodsCategory')) {
  89. service = this.data.goodsCategoryService
  90. id = 'catId'
  91. }
  92. if (this.data.formDataName == mixins.$t('goodsSeries')) {
  93. service = this.data.goodsSeriesService
  94. id = 'seriesId'
  95. }
  96. if (this.data.formDataName == mixins.$t('unit')) {
  97. service = this.data.unitService
  98. id = 'unitId'
  99. }
  100. //执行接口
  101. this.handleMoreDataIsValid(service, item, id)
  102. },
  103. /**
  104. * @desc : 新建编辑事件
  105. * @author : 于继渤
  106. * @date : 2024/1/26 11:46
  107. */
  108. editItems(e) {
  109. let data = e.detail.form
  110. this.setData({
  111. formData: JSON.stringify(data)
  112. })
  113. //执行保存编辑操作
  114. this.save({})
  115. },
  116. /**
  117. * @desc : 商品种类停用启用
  118. * @author : 于继渤
  119. * @date : 2024/1/26 11:46
  120. */
  121. onSwipeBind(e) {
  122. let item = e.detail.currentTarget.dataset.item
  123. this.handleMoreDataIsValid(this.data.goodsCategoryService, item, 'catId')
  124. },
  125. /**
  126. * @desc : 保存编辑
  127. * @author : 于继渤
  128. * @date : 2022/5/26 20:16
  129. */
  130. saveData(params) {
  131. let id = null
  132. let service = null
  133. if (this.data.formDataName == mixins.$t('goodsBrand')) { //商品品牌
  134. service = this.data.goodsBrandService
  135. id = params.brandId
  136. } else if (this.data.formDataName == mixins.$t('goodsCategory')) { //商品种类
  137. service = this.data.goodsCategoryService
  138. id = params.catId
  139. } else if (this.data.formDataName == mixins.$t('goodsSeries')) { //商品系列
  140. service = this.data.goodsSeriesService
  141. id = params.seriesId
  142. } else if (this.data.formDataName == mixins.$t('unit')) { //计量单位
  143. service = this.data.unitService
  144. id = params.unitId
  145. }
  146. if (id) { //编辑
  147. return this.excute(service, service.update, params);
  148. } else { //新建
  149. return this.excute(service, service.insert, params);
  150. }
  151. },
  152. /**
  153. * @desc : 分类切换
  154. * @author : 于继渤
  155. * @date : 2022/5/26 20:16
  156. */
  157. changeSidebar(e) {
  158. let detail = e.detail
  159. this.setData({
  160. formDataName: this.data.sidebarList[detail].name
  161. })
  162. this.searchData()
  163. },
  164. /**
  165. * @desc : 列表对象点击
  166. * @author : 于继渤
  167. * @date : 2024/1/23 9:16
  168. */
  169. toDetail(e) {
  170. this.setPopContent();
  171. let item = e.detail.item
  172. this.setData({
  173. popContent: this.data.popContent,
  174. showPop: true,
  175. dataItem: JSON.stringify(item)
  176. })
  177. },
  178. /**
  179. * @desc : 新建
  180. * @author : 于继渤
  181. * @date : 2024/1/23 9:16
  182. */
  183. toAdd() {
  184. this.setPopContent();
  185. this.setData({
  186. dataItem: null,
  187. formData: null,
  188. showPop: true,
  189. })
  190. },
  191. /**
  192. * @desc : 处理接口返回数据
  193. * @date : 2024/2/1 15:49
  194. * @author : 于继渤
  195. */
  196. handleSearchData(tableData) {
  197. if (this.data.formDataName == mixins.$t('goodsCategory')) {
  198. this.setData({
  199. tableData: util.convertToChildren(tableData, 'parentId', 'catId', null)
  200. })
  201. const myComponent = this.selectComponent('#treeSelect');
  202. myComponent.setDataFromPage(this.data.tableData);
  203. }
  204. },
  205. /**
  206. * @desc : 设置查询参数
  207. * @author : 于继渤
  208. * @date : 2024/1/23 9:16
  209. */
  210. setSearchParams(params) {
  211. if (this.data.formDataName == mixins.$t('goodsCategory')) {
  212. params.pageSize = 100000
  213. params.currentPage = 1
  214. }
  215. return params
  216. },
  217. /**
  218. * @desc : 加载数据
  219. * @author : 于继渤
  220. * @date : 2024/1/23 9:16
  221. */
  222. getData(params) {
  223. if (this.data.formDataName == mixins.$t('goodsBrand')) { //商品品牌
  224. return this.excute(this.data.goodsBrandService, this.data.goodsBrandService.selectByCond, params);
  225. } else if (this.data.formDataName == mixins.$t('goodsCategory')) { //商品种类
  226. return this.excute(this.data.goodsCategoryService, this.data.goodsCategoryService.selectByCond, params);
  227. } else if (this.data.formDataName == mixins.$t('goodsSeries')) { //商品系列
  228. return this.excute(this.data.goodsSeriesService, this.data.goodsSeriesService.selectByCond, params);
  229. } else if (this.data.formDataName == mixins.$t('unit')) { //计量单位
  230. return this.excute(this.data.unitService, this.data.unitService.selectByCond, params);
  231. }
  232. },
  233. /**
  234. * @desc : 设置pop字段
  235. * @author : 于继渤
  236. * @date : 2024/1/23 9:16
  237. */
  238. setPopContent() {
  239. let formDataName = this.data.formDataName
  240. let popContent = this.data.popContent
  241. let routeObjNameGoTo = this.data.routeObjNameGoTo
  242. if (formDataName == mixins.$t('goodsBrand')) {//商品品牌
  243. popContent =
  244. [
  245. { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
  246. { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
  247. { code: 'supplierIds', name: 'supplierNames', title: 'supplier', type: 'choose', required: true, dropType: 'supplier', required: true, urlKey: 'selectProductAttributeSuppliers', },
  248. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  249. ]
  250. routeObjNameGoTo = 'goodsBrand'
  251. }
  252. if (formDataName == mixins.$t('goodsCategory')) { //商品种类
  253. popContent =
  254. [
  255. { code: 'catCode', type: 'str', title: mixins.$t('catCode'), required: false, readonly: true, },
  256. { code: 'parentId', name: 'parentName', title: 'parent', type: 'choose', required: true, dropType: 'supplier', required: true, urlKey: 'selectProductTypes', },
  257. { code: 'catName', type: 'str', title: mixins.$t('catName'), required: true },
  258. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  259. ]
  260. routeObjNameGoTo = 'goodsCategory'
  261. }
  262. if (formDataName == mixins.$t('goodsSeries')) { //商品系列
  263. popContent =
  264. [
  265. { code: 'seriesCode', type: 'str', title: mixins.$t('seriesCode'), required: false, readonly: true, },
  266. { code: 'seriesName', type: 'str', title: mixins.$t('seriesName'), required: true },
  267. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  268. ]
  269. }
  270. if (formDataName == mixins.$t('unit')) { //计量单位
  271. popContent =
  272. [
  273. { code: 'unitCode', type: 'str', title: mixins.$t('unitCode'), required: false, readonly: true, },
  274. { code: 'unitName', type: 'str', title: mixins.$t('unitName'), required: true },
  275. { code: 'decimalPlaces', type: 'number', title: mixins.$t('decimalPlaces'), required: true },
  276. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  277. ]
  278. }
  279. this.setData({
  280. popContent: popContent,
  281. routeObjNameGoTo: routeObjNameGoTo
  282. })
  283. },
  284. /**
  285. * 生命周期函数--监听页面加载
  286. */
  287. onLoad(options) {
  288. let _this = this;
  289. wx.getSystemInfo({
  290. success: function (res) {
  291. _this.setData({
  292. windowHeight: res.windowHeight,
  293. windowWidth: res.windowWidth
  294. })
  295. }
  296. })
  297. },
  298. })