product-attribute.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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: '',
  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: 'supplierId', name: 'supplierName', 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. console.log('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. if (this.data.formDataName == mixins.$t('goodsBrand')) {
  86. service = this.data.goodsBrandService
  87. id = 'brandId'
  88. }
  89. if (this.data.formDataName == mixins.$t('goodsCategory')) {
  90. service = this.data.goodsCategoryService
  91. id = 'catId'
  92. }
  93. if (this.data.formDataName == mixins.$t('goodsSeries')) {
  94. service = this.data.goodsSeriesService
  95. id = 'seriesId'
  96. }
  97. if (this.data.formDataName == mixins.$t('unit')) {
  98. service = this.data.unitService
  99. id = 'unitId'
  100. }
  101. //执行接口
  102. this.handleMoreDataIsValid(service, item, id)
  103. },
  104. /**
  105. * @desc : 新建编辑事件
  106. * @author : 于继渤
  107. * @date : 2024/1/26 11:46
  108. */
  109. editItems(e) {
  110. let data = e.detail.form
  111. this.setData({
  112. formData: JSON.stringify(data)
  113. })
  114. //执行保存编辑操作
  115. this.save({})
  116. },
  117. /**
  118. * @desc : 商品种类停用启用
  119. * @author : 于继渤
  120. * @date : 2024/1/26 11:46
  121. */
  122. onSwipe(e) {
  123. console.log('商品种类停用启用',e)
  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. console.log(e.detail)
  159. let detail = e.detail
  160. this.setData({
  161. formDataName: this.data.sidebarList[detail].name
  162. })
  163. this.searchData()
  164. },
  165. /**
  166. * @desc : 列表对象点击
  167. * @author : 于继渤
  168. * @date : 2024/1/23 9:16
  169. */
  170. toDetail(e) {
  171. this.setPopContent();
  172. let item = e.detail.item
  173. this.setData({
  174. popContent: this.data.popContent,
  175. showPop: true,
  176. dataItem: JSON.stringify(item)
  177. })
  178. },
  179. /**
  180. * @desc : 关闭弹窗
  181. * @author : 于继渤
  182. * @date : 2024/1/23 9:16
  183. */
  184. onClosePopup() {
  185. this.setData({
  186. showPopup: false
  187. })
  188. },
  189. /**
  190. * @desc : 新建
  191. * @author : 于继渤
  192. * @date : 2024/1/23 9:16
  193. */
  194. toAdd() {
  195. this.setPopContent();
  196. this.setData({
  197. dataItem: null,
  198. formData: null,
  199. showPop: true,
  200. })
  201. },
  202. /**
  203. * @desc : 处理接口返回数据
  204. * @date : 2024/2/1 15:49
  205. * @author : 于继渤
  206. */
  207. handleSearchData(tableData) {
  208. console.log('this.data.formDataName', this.data.formDataName, tableData)
  209. if (this.data.formDataName == mixins.$t('goodsCategory')) {
  210. this.setData({
  211. tableData: util.convertToChildren(tableData, 'parentId', 'catId', null)
  212. })
  213. const myComponent = this.selectComponent('#treeSelect');
  214. myComponent.setDataFromPage(this.data.tableData);
  215. }
  216. },
  217. /**
  218. * @desc : 设置查询参数
  219. * @author : 于继渤
  220. * @date : 2024/1/23 9:16
  221. */
  222. setSearchParams(params) {
  223. if (this.data.formDataName == mixins.$t('goodsCategory')) {
  224. params.pageSize = 100000
  225. params.currentPage = 1
  226. }
  227. return params
  228. },
  229. /**
  230. * @desc : 加载数据
  231. * @author : 于继渤
  232. * @date : 2024/1/23 9:16
  233. */
  234. getData(params) {
  235. if (this.data.formDataName == mixins.$t('goodsBrand')) { //商品品牌
  236. return this.excute(this.data.goodsBrandService, this.data.goodsBrandService.selectByCond, params);
  237. } else if (this.data.formDataName == mixins.$t('goodsCategory')) { //商品种类
  238. return this.excute(this.data.goodsCategoryService, this.data.goodsCategoryService.selectByCond, params);
  239. } else if (this.data.formDataName == mixins.$t('goodsSeries')) { //商品系列
  240. return this.excute(this.data.goodsSeriesService, this.data.goodsSeriesService.selectByCond, params);
  241. } else if (this.data.formDataName == mixins.$t('unit')) { //计量单位
  242. return this.excute(this.data.unitService, this.data.unitService.selectByCond, params);
  243. }
  244. },
  245. /**
  246. * @desc : 设置pop字段
  247. * @author : 于继渤
  248. * @date : 2024/1/23 9:16
  249. */
  250. setPopContent() {
  251. let formDataName = this.data.formDataName
  252. let popContent = this.data.popContent
  253. let routeObjNameGoTo = this.data.routeObjNameGoTo
  254. console.log('formDataName', formDataName)
  255. if (formDataName == mixins.$t('goodsBrand')) {//商品品牌
  256. popContent =
  257. [
  258. { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
  259. { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
  260. { code: 'supplierId', name: 'supplierName', title: 'supplier', type: 'choose', required: true, dropType: 'supplier', required: true },
  261. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  262. ]
  263. }
  264. if (formDataName == mixins.$t('goodsCategory')) { //商品种类
  265. popContent =
  266. [
  267. { code: 'catCode', type: 'str', title: mixins.$t('catCode'), required: false, readonly: true, },
  268. { code: 'parentId', name: 'parentName', title: 'parent', type: 'choose', required: true, dropType: 'supplier', required: true, urlKey: 'selectProductTypes', },
  269. { code: 'catName', type: 'str', title: mixins.$t('catName'), required: true },
  270. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  271. ]
  272. routeObjNameGoTo = 'goodsCategory'
  273. }
  274. if (formDataName == mixins.$t('goodsSeries')) { //商品系列
  275. popContent =
  276. [
  277. { code: 'seriesCode', type: 'str', title: mixins.$t('seriesCode'), required: false, readonly: true, },
  278. { code: 'seriesName', type: 'str', title: mixins.$t('seriesName'), required: true },
  279. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  280. ]
  281. }
  282. if (formDataName == mixins.$t('unit')) { //计量单位
  283. popContent =
  284. [
  285. { code: 'unitCode', type: 'str', title: mixins.$t('unitCode'), required: false, readonly: true, },
  286. { code: 'unitName', type: 'str', title: mixins.$t('unitName'), required: true },
  287. { code: 'decimalPlaces', type: 'number', title: mixins.$t('decimalPlaces'), required: true },
  288. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  289. ]
  290. }
  291. this.setData({
  292. popContent: popContent,
  293. routeObjNameGoTo: routeObjNameGoTo
  294. })
  295. },
  296. /**
  297. * 生命周期函数--监听页面加载
  298. */
  299. onLoad(options) {
  300. let _this = this;
  301. wx.getSystemInfo({
  302. success: function (res) {
  303. _this.setData({
  304. windowHeight: res.windowHeight,
  305. windowWidth: res.windowWidth
  306. })
  307. }
  308. })
  309. },
  310. })