product-attribute.js 11 KB

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