product-attribute.js 11 KB

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