detail.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate';
  3. const { stock_type } = require('../../utils/dict');
  4. const app = getApp()
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. frameStyle: { useTop: true, name: '信息管理', leftArrow: true, useBar: false },
  11. // 主体高度
  12. infoHeight: '',
  13. userInfo: {},
  14. form: {
  15. // operate_id: "61d50d6bea746006960a7f8e",
  16. // operate_name: "入库-1",
  17. // order: [
  18. // {
  19. // name: "商品-1",
  20. // num: "10",
  21. // stock_market_id: "61d6b4cc07c0500a5957423f",
  22. // }, {
  23. // stock_type: "2",
  24. // code: '1',
  25. // type_id: "61d506bc68b28e3a22e74a46",
  26. // name: "商品-2",
  27. // num: "21",
  28. // money: "1",
  29. // brief: "1",
  30. // img_url: [],
  31. // }
  32. // ],
  33. // reason: "入库原因",
  34. // register_date: "2022-01-07",
  35. // register_name: "登记人",
  36. // register_phone: "登记人电话",
  37. },
  38. // 弹框
  39. dialog: { title: '添加商品', show: false, type: '1' },
  40. // 入库商品
  41. order: [],
  42. // 库存已存
  43. oneorderForm: {},
  44. // 查询库存
  45. shoppinginput: '',
  46. stockList: [],
  47. // 库存未存
  48. twoorderForm: {},
  49. img_url: [],
  50. typeList: [],
  51. stock_type: '',
  52. stock_typeList: stock_type
  53. },
  54. initValidate() {
  55. const rules = { register_name: { required: true, }, register_phone: { required: true, }, register_date: { required: true, }, reason: { required: true, } }
  56. // 验证字段的提示信息,若不传则调用默认的信息
  57. const messages = { register_name: { required: '请输入登记人', }, register_phone: { required: '请输入电话', }, register_date: { required: '请选择登记时间', }, reason: { required: '请输入入库原因', } };
  58. this.WxValidate = new WxValidate(rules, messages)
  59. },
  60. back: function () {
  61. wx.navigateBack({ url: '/pages/indepot/index' })
  62. },
  63. // 选择登记时间
  64. registerdateChange: function (e) {
  65. let { value } = e.detail;
  66. this.setData({ 'form.register_date': value })
  67. },
  68. // 添加商品
  69. addOrder: function (e) {
  70. const { type } = e.currentTarget.dataset;
  71. this.setData({ dialog: { title: '添加商品', show: true, type: type } })
  72. },
  73. // 已有库存
  74. // 取消保存
  75. oneorderReset: function () {
  76. this.setData({ dialog: { title: '添加商品', show: false, type: '1' } })
  77. },
  78. // 查询
  79. shoppinginput: function (e) {
  80. this.setData({ shoopingtext: e.detail.value })
  81. },
  82. // 查询库存
  83. searchStock: function () {
  84. let shoopingtext = this.data.shoopingtext;
  85. if (shoopingtext) {
  86. wx.request({
  87. url: app.globalData.publicUrl + `/api/hc/stock`,
  88. method: "get",
  89. data: { name: shoopingtext },
  90. header: {},
  91. success: (res) => {
  92. if (res.data.errcode == '0') {
  93. if (res.data.total > 0) {
  94. this.setData({ stockList: res.data.data })
  95. } else {
  96. wx.showToast({ title: `暂无产品`, icon: 'sucess', duration: 2000 })
  97. }
  98. } else {
  99. wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 })
  100. }
  101. },
  102. })
  103. } else {
  104. wx.showToast({ title: `请输入商品名称`, icon: 'error', duration: 2000 })
  105. }
  106. },
  107. // 确认选择商品
  108. stockChange: function (e) {
  109. const { item } = e.currentTarget.dataset;
  110. this.setData({ 'oneorderForm.stock_market_id': item.id })
  111. this.setData({ 'oneorderForm.name': item.name })
  112. },
  113. // 提交保存
  114. oneorderSubmit: function (e) {
  115. const params = e.detail.value;
  116. if (!params.name) wx.showToast({ title: `商品名称`, icon: 'error', duration: 2000 });
  117. else if (!params.num) wx.showToast({ title: `商品数量`, icon: 'error', duration: 2000 });
  118. if (params.name && params.num) {
  119. this.setData({ order: [...this.data.order, params] });
  120. this.setData({ oneorderForm: {} });
  121. this.setData({ dialog: { title: '添加商品', show: false, type: '1' } });
  122. }
  123. },
  124. // 库存无商品
  125. twoorderReset: function () {
  126. this.setData({ dialog: { title: '添加商品', show: false, type: '2' } })
  127. },
  128. // 类别选择
  129. stocktypeChange: function (e) {
  130. let { value } = e.detail;
  131. let data = this.data.stock_typeList[value];
  132. this.setData({ 'stock_type': data.value })
  133. this.setData({ 'twoorderForm.stock_type': data.value })
  134. this.setData({ 'twoorderForm.stock_type_name': data.label })
  135. },
  136. // 选择商品类型
  137. typeChange: function (e) {
  138. let { value } = e.detail;
  139. let data = this.data.typeList[value];
  140. this.setData({ 'twoorderForm.type_id': data.id })
  141. this.setData({ 'twoorderForm.type_name': data.name })
  142. },
  143. // 上传图片
  144. afterRead: function (event) {
  145. const { file } = event.detail;
  146. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  147. wx.uploadFile({
  148. url: app.globalData.fileUrl + '/files/consumables/market/upload',
  149. filePath: file.url,
  150. name: 'file',
  151. formData: {},
  152. success: (res) => {
  153. if (res.statusCode == '200') {
  154. let data = [{ name: JSON.parse(res.data).name, url: `${app.globalData.fileUrl}` + JSON.parse(res.data).uri }]
  155. this.setData({ img_url: this.data.img_url.concat(data) })
  156. } else {
  157. wx.showToast({ title: `${res.data.errmsg}`, icon: 'fail', duration: 2000 })
  158. }
  159. },
  160. });
  161. },
  162. // 删除图片
  163. uploadDelete: function (e) {
  164. const index = e.detail.index;
  165. const imgList = this.data.img_url;
  166. if (imgList.length === 1) this.setData({ img_url: [] })
  167. else { let data = imgList.splice(0, 1); this.setData({ img_url: data }) }
  168. },
  169. twoorderSubmit: function (e) {
  170. const params = e.detail.value;
  171. params.img_url = this.data.img_url;
  172. if (!params.stock_type_name) wx.showToast({ title: `请选择商品类别`, icon: 'error', duration: 2000 });
  173. else if (!params.type_name) wx.showToast({ title: `请选择商品类型`, icon: 'error', duration: 2000 });
  174. else if (!params.name) wx.showToast({ title: `请输入商品名称`, icon: 'error', duration: 2000 });
  175. else if (!params.num) wx.showToast({ title: `请输入商品数量`, icon: 'error', duration: 2000 });
  176. if (params.stock_type_name && params.type_name && params.name && params.num) {
  177. this.setData({ order: [...this.data.order, params] });
  178. this.setData({ twoorderForm: {} });
  179. this.setData({ dialog: { title: '添加商品', show: false, type: '2' } });
  180. }
  181. },
  182. // 取消保存
  183. onReset: function (e) {
  184. this.back()
  185. },
  186. // 提交保存
  187. onSubmit: function (e) {
  188. const params = e.detail.value;
  189. if (!this.WxValidate.checkForm(params)) {
  190. const error = this.WxValidate.errorList[0];
  191. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  192. return false
  193. } else {
  194. params.order = this.data.order;
  195. wx.request({
  196. url: app.globalData.publicUrl + `/api/hc/marketEnter`,
  197. method: "post",
  198. data: { ...params },
  199. header: {},
  200. success: (res) => {
  201. if (res.data.errcode == '0') {
  202. wx.showToast({ title: `入库添加完成`, icon: 'success', duration: 2000 })
  203. this.back()
  204. } else {
  205. wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 })
  206. }
  207. },
  208. })
  209. }
  210. },
  211. /**
  212. * 生命周期函数--监听页面加载
  213. */
  214. onLoad: function (options) {
  215. // 查询用户是否登录
  216. wx.getStorage({
  217. key: 'user',
  218. success: res => {
  219. if (res.data) {
  220. if (res.data) this.setData({ userInfo: res.data });
  221. this.setData({ form: { operate_id: res.data.id, operate_name: res.data.name } })
  222. } else {
  223. wx.redirectTo({ url: '/pages/login/index', })
  224. }
  225. }
  226. })
  227. // 查询其他信息
  228. this.searchOther();
  229. //验证规则函数
  230. this.initValidate()
  231. // 计算高度
  232. this.searchHeight()
  233. },
  234. // 查询其他信息
  235. searchOther: function () {
  236. // 查询商品类型
  237. wx.request({
  238. url: app.globalData.publicUrl + `/api/hc/type`,
  239. method: "get",
  240. data: {},
  241. header: {},
  242. success: (res) => {
  243. if (res.data.errcode == '0') {
  244. this.setData({ typeList: res.data.data })
  245. } else {
  246. wx.showToast({ title: `${res.data.errmsg}`, icon: 'error', duration: 2000 })
  247. }
  248. },
  249. })
  250. },
  251. // 计算高度
  252. searchHeight: function () {
  253. let frameStyle = this.data.frameStyle;
  254. let client = app.globalData.client;
  255. // 减去状态栏
  256. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  257. // 是否减去底部菜单
  258. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  259. if (infoHeight) this.setData({ infoHeight: infoHeight })
  260. },
  261. /**
  262. * 生命周期函数--监听页面初次渲染完成
  263. */
  264. onReady: function () {
  265. },
  266. /**
  267. * 生命周期函数--监听页面显示
  268. */
  269. onShow: function () {
  270. },
  271. /**
  272. * 生命周期函数--监听页面隐藏
  273. */
  274. onHide: function () {
  275. },
  276. /**
  277. * 生命周期函数--监听页面卸载
  278. */
  279. onUnload: function () {
  280. },
  281. /**
  282. * 页面相关事件处理函数--监听用户下拉动作
  283. */
  284. onPullDownRefresh: function () {
  285. },
  286. /**
  287. * 页面上拉触底事件的处理函数
  288. */
  289. onReachBottom: function () {
  290. },
  291. /**
  292. * 用户点击右上角分享
  293. */
  294. onShareAppMessage: function () {
  295. }
  296. })