out-store-add-new.vue 11 KB

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