product-attribute.js 12 KB

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