product-attribute.js 11 KB

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