product-attribute.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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 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: 1000
  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].name
  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. /**
  224. * @desc : 处理接口返回数据
  225. * @date : 2024/2/1 15:49
  226. * @author : 于继渤
  227. */
  228. handleSearchData(tableData) {
  229. if (this.data.formDataName == mixins.$t('goodsCategory')) {
  230. this.setData({
  231. tableData: util.convertToChildren(tableData, 'parentId', 'catId', null)
  232. })
  233. const myComponent = this.selectComponent('#treeSelect');
  234. myComponent.setDataFromPage(this.data.tableData);
  235. }
  236. },
  237. /**
  238. * @desc : 设置查询参数
  239. * @author : 于继渤
  240. * @date : 2024/1/23 9:16
  241. */
  242. setSearchParams(params) {
  243. //有效标识
  244. if (params.flgValidList && params.flgValidList.indexOf("true") != -1 && params.flgValidList.indexOf("false") == -1) {
  245. params.flgValid = true
  246. } else if (params.flgValidList && params.flgValidList.indexOf("true") == -1 && params.flgValidList.indexOf("false") != -1) {
  247. params.flgValid = false
  248. }
  249. if (this.data.formDataName == mixins.$t('goodsCategory')) {
  250. params.pageSize = 100000
  251. params.currentPage = 1
  252. }
  253. return params
  254. },
  255. /**
  256. * @desc : 加载数据
  257. * @author : 于继渤
  258. * @date : 2024/1/23 9:16
  259. */
  260. getData(params) {
  261. if (this.data.formDataName == mixins.$t('goodsBrand')) { //商品品牌
  262. return this.excute(this.data.goodsBrandService, this.data.goodsBrandService.selectByCond, params);
  263. } else if (this.data.formDataName == mixins.$t('goodsCategory')) { //商品种类
  264. return this.excute(this.data.goodsCategoryService, this.data.goodsCategoryService.selectByCond, params);
  265. } else if (this.data.formDataName == mixins.$t('goodsSeries')) { //商品系列
  266. return this.excute(this.data.goodsSeriesService, this.data.goodsSeriesService.selectByCond, params);
  267. } else if (this.data.formDataName == mixins.$t('unit')) { //计量单位
  268. return this.excute(this.data.unitService, this.data.unitService.selectByCond, params);
  269. }
  270. },
  271. /**
  272. * @desc : 设置pop字段
  273. * @author : 于继渤
  274. * @date : 2024/1/23 9:16
  275. */
  276. setPopContent() {
  277. let formDataName = this.data.formDataName
  278. let popContent = this.data.popContent
  279. let routeObjNameGoTo = this.data.routeObjNameGoTo
  280. if (formDataName == mixins.$t('goodsBrand')) {//商品品牌
  281. popContent =
  282. [
  283. { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
  284. { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
  285. { code: 'supplierIds', name: 'supplierNames', title: 'supplier', type: 'choose', required: true, dropType: 'supplier', required: true, urlKey: 'selectProductAttributeSuppliers', code: 'supplierIds',formMode: 'index', idKey: 'roleId', },
  286. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  287. ]
  288. routeObjNameGoTo = 'goodsBrand'
  289. }
  290. if (formDataName == mixins.$t('goodsCategory')) { //商品种类
  291. popContent =
  292. [
  293. { code: 'catCode', type: 'str', title: mixins.$t('catCode'), required: false, readonly: true, },
  294. { code: 'parentId', name: 'parentName', title: 'parent', type: 'choose', required: true, dropType: 'supplier', required: true, urlKey: 'selectProductTypes', },
  295. { code: 'catName', type: 'str', title: mixins.$t('catName'), required: true },
  296. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  297. ]
  298. routeObjNameGoTo = 'goodsCategory'
  299. }
  300. if (formDataName == mixins.$t('goodsSeries')) { //商品系列
  301. popContent =
  302. [
  303. { code: 'seriesCode', type: 'str', title: mixins.$t('seriesCode'), required: false, readonly: true, },
  304. { code: 'seriesName', type: 'str', title: mixins.$t('seriesName'), required: true },
  305. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  306. ]
  307. }
  308. if (formDataName == mixins.$t('unit')) { //计量单位
  309. popContent =
  310. [
  311. { code: 'unitCode', type: 'str', title: mixins.$t('unitCode'), required: false, readonly: true, },
  312. { code: 'unitName', type: 'str', title: mixins.$t('unitName'), required: true },
  313. { code: 'decimalPlaces', type: 'number', title: mixins.$t('decimalPlaces'), required: true },
  314. { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
  315. ]
  316. }
  317. this.setData({
  318. popContent: popContent,
  319. routeObjNameGoTo: routeObjNameGoTo
  320. })
  321. },
  322. /**
  323. * 生命周期函数--监听页面加载
  324. */
  325. onLoad(options) {
  326. let _this = this;
  327. wx.getSystemInfo({
  328. success: function (res) {
  329. _this.setData({
  330. windowHeight: res.windowHeight,
  331. windowWidth: res.windowWidth
  332. })
  333. }
  334. })
  335. },
  336. })