in-store-add-new.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <view class="mx3">
  3. <my-add-button @handleClick="openSpare" />
  4. <view class="main-color-bg main-bg-future"></view>
  5. <view class="p3 bg-color-white form-view">
  6. <u-form :model="form" :error-type="['message']" ref="uForm">
  7. <view class="main-color-text f-size-32 f-weight-6">入库信息</view>
  8. <!--<u-form-item label="仓库名称" prop="storeId" required label-width="150">
  9. <my-select
  10. :list="storeList"
  11. :value-name="'id'"
  12. :label-name="'name'"
  13. v-model="form.storeId"
  14. placeholder="请选择仓库"
  15. @selected="storeSelect"
  16. />
  17. </u-form-item>-->
  18. <!-- <u-form-item required prop="storeName" label="选择仓库" :label-width="150">
  19. <uni-data-picker style="width:100%" placeholder="请选择" v-model="form.industryType" :localdata="industryTypeList" />
  20. <my-select v-model="form.storeName" label-name="title" child-name="children" :list="storeTree" mode="mutil-column-auto" placeholder="请选择仓库" @selected="industryTypeConfirm"></my-select>
  21. </u-form-item> -->
  22. <u-form-item label="备品用途" prop="type" label-width="150">
  23. <my-select :list="reasonList" v-model="form.type" @selected="typeSelect" placeholder="请选择备品用途" />
  24. </u-form-item>
  25. <u-form-item label="入库说明" label-width="150">
  26. <u-input type="textarea" v-model="form.remark" />
  27. </u-form-item>
  28. </u-form>
  29. </view>
  30. <view class="m3">
  31. <u-button @click="handleQrCode" shape="circle">备件扫码</u-button>
  32. </view>
  33. <view class="shop-car">
  34. <commonCar :list="goodsProducts" @delect="delect" ref="refCar" @accounts="accounts">
  35. </commonCar>
  36. <image src="" mode=""></image>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. import commonCar from '@/components/shopCar/shopCar.vue'
  42. export default {
  43. components: { commonCar },
  44. data() {
  45. return {
  46. goodsProducts: [],
  47. storeTree: [],
  48. industryTypeShow: false,
  49. typeMap: {},
  50. form: {
  51. storeId: '',
  52. type: '',
  53. reason: '',
  54. storeName: null
  55. },
  56. receiveDetailFormList: [],
  57. backSpareId: '',
  58. backSpareName: '',
  59. backFormName: '',
  60. backPrice: 0,
  61. isRefreshDetail: true,
  62. sbSpareList: [],
  63. storeList: [],
  64. reasonList: [
  65. {
  66. label: '采购入库',
  67. value: '1'
  68. },
  69. {
  70. label: '闲置入库',
  71. value: '2'
  72. },
  73. {
  74. label: '调拨入库',
  75. value: '3'
  76. },
  77. {
  78. label: '发运入库',
  79. value: '4'
  80. },
  81. {
  82. label: '盘点校准',
  83. value: '5'
  84. }
  85. ],
  86. rules: {
  87. type: [
  88. {
  89. required: true,
  90. message: '请选择入库类型',
  91. trigger: ['change']
  92. }
  93. ],
  94. storeName: [
  95. {
  96. required: true,
  97. message: '请选择仓库',
  98. trigger: ['change']
  99. }
  100. ]
  101. },
  102. detailFormRules: {
  103. spareId: [
  104. {
  105. required: true,
  106. message: '请选择备品',
  107. trigger: ['change']
  108. }
  109. ],
  110. num: [
  111. {
  112. required: true,
  113. message: '请填写数量',
  114. trigger: ['change', 'blur']
  115. }
  116. ]
  117. },
  118. id: '', // 列表 id
  119. aId: 0
  120. }
  121. },
  122. created() {
  123. this.typeMap = this.$DictCache.getLabelByValueMapByType(this.$DictCache.TYPE.IN_STORE_FORM_TYPE)
  124. this.$Http.fetchStoreTree().then(res => {
  125. this.storeTree = res.data
  126. })
  127. },
  128. onShow() {
  129. // 获取设备与仓库
  130. this.initData()
  131. const pages = getCurrentPages()
  132. const currPage = pages[pages.length - 1]
  133. if (currPage.goods != null && currPage.goods.length > 0) {
  134. currPage.goods.forEach(item => {
  135. console.log('item.spareId:', item.id)
  136. let find = false
  137. this.goodsProducts.forEach(spare => {
  138. if (spare.id === item.id) {
  139. find = true
  140. return
  141. }
  142. })
  143. if (!find) {
  144. const length = this.goodsProducts.length
  145. //this.goodsProducts.push(item)
  146. const target = { ...item }
  147. this.$set(this.goodsProducts, length, target)
  148. }
  149. })
  150. console.log(this.goodsProducts)
  151. currPage.goods = null
  152. // #ifdef MP-WEIXIN
  153. this.$refs.refCar.setDatas(this.goodsProducts)
  154. //this.$refs.refCar.statistics()
  155. // #endif
  156. }
  157. },
  158. onLoad(options) {},
  159. onReady() {
  160. this.$refs.uForm.setRules(this.rules)
  161. },
  162. methods: {
  163. // 刪除
  164. delect(e) {
  165. this.goodsProducts.forEach((item, index) => {
  166. if (item.checked === 2) {
  167. this.goodsProducts.splice(index, 1)
  168. return
  169. }
  170. })
  171. },
  172. // 提交
  173. accounts(e) {
  174. const params = { ...this.form }
  175. params.detailList = this.goodsProducts
  176. this.$Http.addInStoreForm(params).then(res => {
  177. uni.redirectTo({
  178. url: '/pages/in-store/in-store-detail?id=' + res.data.id
  179. })
  180. })
  181. },
  182. del(index) {
  183. console.log(this.receiveDetailFormList)
  184. this.receiveDetailFormList.splice(index, 1)
  185. console.log(this.receiveDetailFormList)
  186. },
  187. handleSelect() {
  188. uni.navigateTo({
  189. url: '/pages/search/spare-search?storeId=' + encodeURIComponent(JSON.stringify(this.form.storeId)) + '&formName=' + encodeURIComponent(JSON.stringify(formName))
  190. })
  191. },
  192. initData() {
  193. if (this.storeList.length == 0) {
  194. this.$Http.getStorePage({ pageNum: 1, pageSize: 1000 }).then(res => {
  195. this.storeList = res.data.rows
  196. })
  197. }
  198. },
  199. openSpare() {
  200. uni.navigateTo({
  201. url: '/pages/search/spare-search-goods'
  202. })
  203. },
  204. storeSelect(value, item) {
  205. this.form.storeName = item.name
  206. this.isRefreshDetail = true
  207. this.receiveDetailFormList = []
  208. },
  209. industryTypeConfirm(e) {
  210. console.log(e)
  211. this.form.storeName = e[e.length - 1].label
  212. this.form.storeId = e[e.length - 1].value
  213. console.log('this.form.storeName:' + this.form.storeName)
  214. this.isRefreshDetail = true
  215. this.receiveDetailFormList = []
  216. },
  217. typeSelect(value, item) {
  218. this.isRefreshDetail = true
  219. //this.receiveDetailFormList = []
  220. },
  221. spareSelect(value, item) {
  222. this.receiveDetailFormList.forEach(spare => {
  223. if (spare.spareId === item.spareId) {
  224. spare.item = item
  225. } else {
  226. console.log(2222, spare.spareId, item.id)
  227. }
  228. })
  229. },
  230. // 扫码
  231. handleQrCode() {
  232. const that = this
  233. // #ifdef H5
  234. uni.showToast({
  235. title: '暂不支持该功能',
  236. icon: 'none'
  237. })
  238. // #endif
  239. // #ifndef H5
  240. uni.scanCode({
  241. success(e) {
  242. console.log(e.result)
  243. if (e.result) {
  244. const id = e.result
  245. if (id != null) {
  246. that.$Http.fetchSparePartInfo({ id: id }).then(res => {
  247. var item = res.data
  248. let find = false
  249. that.goodsProducts.forEach(spare => {
  250. if (spare.spareId === id) {
  251. find = true
  252. return
  253. }
  254. })
  255. if (!find) {
  256. const selectGoods = {
  257. spareId: item.id,
  258. image: item.image,
  259. name: item.name,
  260. remark: item.ggxh,
  261. price: item.initialValue,
  262. number: 1.0,
  263. checked: 2
  264. }
  265. that.goodsProducts.push(selectGoods)
  266. // #ifdef MP-WEIXIN
  267. that.$refs.refCar.setDatas(that.goodsProducts)
  268. //that.$refs.refCar.statistics()
  269. // #endif
  270. }
  271. })
  272. } else {
  273. uni.showToast('非本系统二维码,无法识别')
  274. }
  275. }
  276. }
  277. })
  278. // #endif
  279. },
  280. // 提交
  281. submit() {
  282. if (this.form.storeName == null) {
  283. uni.showToast({
  284. title: '请选择入库仓',
  285. icon: 'none'
  286. })
  287. return
  288. }
  289. if (this.receiveDetailFormList == null || this.receiveDetailFormList.length === 0) {
  290. uni.showToast({
  291. title: '请添加入库明细',
  292. icon: 'none'
  293. })
  294. return
  295. }
  296. const promiseList = []
  297. promiseList.push(
  298. new Promise((resolve, reject) => {
  299. this.$refs.uForm.validate().then(valid => {
  300. if (valid) {
  301. resolve(valid)
  302. } else {
  303. reject(valid)
  304. }
  305. })
  306. })
  307. )
  308. this.receiveDetailFormList.forEach(item => {
  309. promiseList.push(
  310. new Promise((resolve, reject) => {
  311. this.$refs[item.formName][0].validate(valid => {
  312. if (valid) {
  313. resolve(valid)
  314. } else {
  315. reject(valid)
  316. }
  317. })
  318. })
  319. )
  320. })
  321. Promise.all(promiseList).then(
  322. res => {
  323. // 执行
  324. const params = { ...this.form }
  325. const detailList = []
  326. this.receiveDetailFormList.forEach(item => {
  327. const space = item.item
  328. const detail = {
  329. spareId: item.spareId,
  330. num: item.num,
  331. price: item.price,
  332. spareName: item.spareName,
  333. storeNum: item.num,
  334. totalPrice: this.$BaseTool.Number.mul(item.num, item.price)
  335. }
  336. detailList.push(detail)
  337. })
  338. params.detailList = detailList
  339. console.log(33, params)
  340. this.$Http.addInStoreForm(params).then(res => {
  341. uni.redirectTo({
  342. url: '/pages/out-store/out-store-detail?id=' + res.data.id
  343. })
  344. })
  345. },
  346. err => {
  347. console.log(err)
  348. }
  349. )
  350. }
  351. },
  352. onReady() {
  353. //this.$refs.uForm.setRules(this.rules);
  354. }
  355. }
  356. </script>
  357. <style lang="less">
  358. page {
  359. background-color: #f4f4f4;
  360. }
  361. .mt-3-imt {
  362. margin-top: 30rpx;
  363. }
  364. .shop-car {
  365. min-height: 100vh;
  366. display: flex;
  367. flex-direction: column;
  368. align-items: center;
  369. background: #f5f5f5;
  370. }
  371. </style>