add.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*******************************************************************************
  2. * Copyright(c) 2022 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:
  5. * 编辑履历:
  6. * 作者 日期 版本 修改内容
  7. * 王英杰 2024-1-24 1.00 新建商品档案
  8. *******************************************************************************/
  9. const mixins = require('@/mixins/index.js')
  10. const app = getApp()
  11. const util = require('@/utils/util.js')
  12. const Constants = require('@/utils/Constants')
  13. Page({
  14. mixins: [mixins],
  15. /**
  16. * 页面的初始数据
  17. */
  18. data: {
  19. table: Constants.tables.goodsSku,
  20. cardList: ['main', 'goods', "warehouse", 'price', 'other'],
  21. contentObj: {
  22. main: [{ //唯一编码
  23. code: 'onlyCode',
  24. type: 'textarea',
  25. title: mixins.$t("onlyCode"),
  26. readonly: true
  27. }, { //商品型号
  28. code: 'skuModel',
  29. type: 'textarea',
  30. title: mixins.$t("skuModel"),
  31. required: true,
  32. }, { //商品名称
  33. code: 'skuName',
  34. type: 'textarea',
  35. title: mixins.$t("skuName"),
  36. required: true,
  37. }, {
  38. code: 'skuImages',
  39. name:mixins.$t("commodityPicture"), //商品图片
  40. type: 'uploader',
  41. },
  42. ],
  43. goods: [{ //商品品牌
  44. code: 'brandId',
  45. name: 'brandName',
  46. title: mixins.$t("goodsBrand"),
  47. type: 'choose',
  48. urlKey:'goodsBrand' ,
  49. required: true,
  50. },
  51. { //商品种类
  52. code: 'categoryId',
  53. name: 'catName',
  54. title: mixins.$t("goodsCategory"),
  55. type: 'choose',
  56. urlKey:'goodsCategory' ,
  57. required: true,
  58. }, { //计量单位
  59. code: 'unitId',
  60. name: 'unitName',
  61. title: mixins.$t("unit"),
  62. type: 'choose',
  63. urlKey: 'unit',
  64. required: true,
  65. }, { //辅助计量单位
  66. code: 'subUnitId',
  67. name: 'subUnitName',
  68. title: mixins.$t("subUnitId"),
  69. type: 'choose',
  70. urlKey: 'unit',
  71. }, { //商品系列
  72. code: 'seriesId',
  73. name: 'seriesName',
  74. title: mixins.$t("goodsSeries"),
  75. type: 'choose',
  76. urlKey: 'goodsSeries',
  77. }, { //商品规格
  78. code: 'skuSpec',
  79. name: 'skuSpec',
  80. type: 'textarea',
  81. title: mixins.$t("sukSpec"),
  82. }
  83. ],
  84. warehouse: [{ //仓库名称
  85. code: 'whId',
  86. name: 'whName',
  87. title: mixins.$t("whName"),
  88. type: 'choose',
  89. urlKey: 'openingInventory',
  90. },
  91. { //库存批号
  92. code: 'nonStdCode',
  93. type: 'textarea',
  94. title: mixins.$t("iinventoryBatchNumber"),
  95. },
  96. { //期初数量
  97. code: 'intoQty',
  98. type: 'number',
  99. sign:"",
  100. digits:0,
  101. title: mixins.$t("openingInventoryQty"),
  102. },
  103. { //期初成本价
  104. code: 'intoAmt',
  105. type: 'textarea',
  106. title: mixins.$t("iinitialCostPrice"),
  107. },
  108. ],
  109. price: [{ //采购价
  110. tip:mixins.$t("purchasePricetip"),
  111. code: 'pricePurchase',
  112. type: 'number',
  113. title: mixins.$t("purchasePrice"),
  114. }, { //零售价
  115. tip:mixins.$t("retailPricetip"),
  116. code: 'priceStandard',
  117. type: 'number',
  118. title: mixins.$t("retailPrice"),
  119. }, { //批发价
  120. tip:mixins.$t("wholesalePricetip"),
  121. code: 'priceWholesale',
  122. type: 'number',
  123. title: mixins.$t("wholesalePrice"),
  124. }, { //销售限价
  125. tip:mixins.$t("SaleSPriceLimittip"),
  126. code: 'priceLimited',
  127. type: 'number',
  128. title: mixins.$t("SaleSPriceLimit"),
  129. }, { //其他价
  130. tip: mixins.$t("otherPriceLimittip"),
  131. code: 'priceOther',
  132. type: 'number',
  133. title: mixins.$t("otherPriceLimit"),
  134. },],
  135. other: [{
  136. code: 'remarks',
  137. type: 'textarea',
  138. title: mixins.$t("remarks"),
  139. }]
  140. },
  141. // 路由
  142. routeObjName: 'goodsSku',
  143. },
  144. chooseData(e){
  145. console.log("t",e,this.data.formData);
  146. let formData = JSON.parse(this.data.formData)
  147. let code = e.detail.code
  148. let data = e.detail.data.data
  149. if(code == "brandId"){ //商品品牌
  150. formData.brandId = data.id
  151. formData.brandName = data.name
  152. }
  153. if(code == "categoryId"){ //商品种类
  154. formData.categoryId = data.id
  155. formData.catName = data.name
  156. }
  157. if(code == "unitId"){ //计量单位
  158. formData.unitId = data.id
  159. formData.unitName = data.name
  160. }
  161. if(code == "subUnitId"){ //补助计量单位
  162. formData.subUnitId = data.id
  163. formData.subUnitName = data.name
  164. }
  165. if(code == "seriesId"){ //补助计量单位
  166. formData.seriesId = data.id
  167. formData.seriesName = data.name
  168. }
  169. if(code == "whId"){ //补助计量单位
  170. formData.whId = data.id
  171. formData.whName = data.name
  172. }
  173. this.setData({
  174. formData: JSON.stringify(formData)
  175. })
  176. },
  177. /**
  178. * @desc : 保存数据服务--校验
  179. * @date : 2024/2/1 15:49
  180. * @author : 王英杰
  181. */
  182. validData() {
  183. let formData = JSON.parse(this.data.formData)
  184. if(formData.whId||formData.nonStdCode||formData.intoQty||formData.intoAmt){
  185. //只要上面有一个有值 剩下三个也要必输
  186. if(!formData.whId){
  187. util.showToast('请选择仓库');
  188. return false
  189. }
  190. if(!formData.nonStdCode){
  191. util.showToast('请输入非标号');
  192. return false
  193. }
  194. if(!formData.intoQty){
  195. util.showToast('请输入期初数量');
  196. return false
  197. }
  198. if(!formData.intoAmt){
  199. util.showToast('请输入期初成本价');
  200. return false
  201. }
  202. }
  203. return true
  204. },
  205. // 设置保存参数
  206. setParams(params) {
  207. let saveData = JSON.parse(this.data.formData)
  208. // 修改之后的 值
  209. params = Object.assign({}, params, saveData);
  210. params.serviceCategories = (params.serviceCategories && params.serviceCategories.length > 0) ? params.serviceCategories.split(',') : []
  211. params.skuImages = params.annexPaths
  212. return params
  213. },
  214. /**
  215. * @desc : 保存数据服务
  216. * @date : 2024/2/1 15:49
  217. * @author : 王英杰
  218. */
  219. saveData() {
  220. console.log("参数",this.data.params);
  221. if (this.data.formMode == Constants.formMode.edit) { //编辑接口
  222. return this.excute(this.data.service, this.data.service.update, this.data.params)
  223. } else { //新建接口
  224. return this.excute(this.data.service, this.data.service.insert, this.data.params);
  225. }
  226. },
  227. /**
  228. * @desc : 页面加载数据方法
  229. * @date : 2024/2/1 15:49
  230. * @author : 王英杰
  231. */
  232. loadInit() {
  233. if (this.data.formMode == Constants.formMode.edit) {
  234. wx.setNavigationBarTitle({
  235. title: mixins.$t('编辑商品档案'),
  236. })
  237. } else {
  238. wx.setNavigationBarTitle({
  239. title: mixins.$t('新建商品档案'),
  240. })
  241. }
  242. },
  243. /**
  244. * @desc : 给表单赋值
  245. * @date : 2024/2/1 15:49
  246. * @author : 王英杰
  247. */
  248. setValuesByEdit(data) {
  249. // data.serviceCategories = (data.serviceCategories && data.serviceCategories.length > 0) ? data.serviceCategories.join(',') : undefined
  250. data.annexPaths = data.skuImages
  251. data.onlyCode = data.skuCode
  252. this.setData({
  253. formData: JSON.stringify(data)
  254. })
  255. },
  256. })