index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <view class="">
  3. <uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="新增入库单" @clickLeft="onBack">
  4. </uni-nav-bar>
  5. <view class="p10">
  6. <u--form :model="form" labelPosition="left" :rules="rules" label-width="140rpx">
  7. <u-form-item label="入库单号" prop="code" borderBottom>
  8. <u--input v-model="form.code" disabled placeholder="自动生成"></u--input>
  9. </u-form-item>
  10. <u-form-item label="入库类型" prop="entryTypeValue" borderBottom>
  11. <u--input v-model="entryTypeValue" placeholder="请选择入库类型" @click.native="show=true" readonly>
  12. </u--input>
  13. <u-icon slot="right" name="arrow-right"></u-icon>
  14. </u-form-item>
  15. <u-form-item label="入库时间" prop="entryTime" borderBottom>
  16. <u--input v-model="entryTime" placeholder="请选择入库时间" @click.native="showCalendar=true" readonly>
  17. </u--input>
  18. <u-icon slot="right" name="arrow-right"></u-icon>
  19. </u-form-item>
  20. <u-form-item label="登记时间" prop="registrationTime" borderBottom>
  21. <u--input v-model="form.registrationTime" disabled placeholder="登记时间"></u--input>
  22. </u-form-item>
  23. <u-form-item label="登记人" prop="registrant.name" borderBottom>
  24. <u--input v-model="form.registrant.name" disabled placeholder="登记人"></u--input>
  25. </u-form-item>
  26. <u-form-item label="部门" prop="registrationDept" borderBottom>
  27. <u--input v-model="form.registrationDept" disabled placeholder="部门"></u--input>
  28. </u-form-item>
  29. <u-form-item label="备注" prop="remark" borderBottom>
  30. <u--textarea v-model="form.remark" confirm-type="send" count placeholder="请输入备注"></u--textarea>
  31. </u-form-item>
  32. </u--form>
  33. </view>
  34. <view class="mt10">
  35. <CellTip title="选择归还区域" class="area_tips">
  36. <view class="right">
  37. <u-button size="small" type="primary" @click="select_type">选择备件类型</u-button>
  38. </view>
  39. </CellTip>
  40. <uni-swipe-action v-if="orderList.length !== 0">
  41. <uni-swipe-action-item class="customeSwipe" @click="swipeAction(index)" :right-options="options"
  42. v-for="(item,index) in orderList" :key="index">
  43. <view>
  44. <!-- sparepartTypeCode.name -->
  45. <OrderList lable1="编码:" :value1="item.code" lable2="名称:" :value2="item.name" lable3="规格:"
  46. :value3="item.spec" lable4="型号:" :value4="item.model" lable5="库存:" :value5="item.stock"
  47. lable6="单位:" :value6="item.unit">
  48. <u--input placeholder="请输入批次号" v-model="item.batchNo"></u--input>
  49. <u--input placeholder="请输入入库数量" v-model="item.receipt"></u--input>
  50. <u--input placeholder="请输入最小包装单位" v-model="item.leastPack"></u--input>
  51. <u--input readonly placeholder="请选择仓库地址" @click.native="selectAddress(index)"
  52. v-model="item.warehouse">
  53. <template slot="suffix">
  54. <!-- <u-icon name="arrow-right"></u-icon> -->
  55. <uni-icons type="right" size="30"></uni-icons>
  56. </template>
  57. </u--input>
  58. </OrderList>
  59. </view>
  60. </uni-swipe-action-item>
  61. </uni-swipe-action>
  62. <view class="no_data" v-else>
  63. <u-empty mode="data"></u-empty>
  64. </view>
  65. </view>
  66. <view class="btnList">
  67. <!-- <u-button type="success">暂存</u-button> -->
  68. <u-button type="primary" @click="submit">提交</u-button>
  69. <u-button @click="cancelPage">取消</u-button>
  70. </view>
  71. <u-picker :show="show" :columns="columns" key-name="name" @cancel="show=false" @confirm="onConfirm"></u-picker>
  72. <u-calendar :show="showCalendar" @close="showCalendar=false" class="customCalendar" @confirm="handleConfirm">
  73. </u-calendar>
  74. <u-picker :show="showPicker" ref="uPicker" :loading="loading " :columns="columnsPicker" keyName="name"
  75. @cancel="showPicker=false" @change="changeHandler" @confirm="handleConfirmPicker">
  76. </u-picker>
  77. </view>
  78. </template>
  79. <script>
  80. import CellTip from '@/components/CellTip.vue'
  81. import OrderList from '../components/OrderList.vue'
  82. import {
  83. get,
  84. post,
  85. postJ
  86. } from "@/utils/api.js"
  87. export default {
  88. components: {
  89. CellTip,
  90. OrderList
  91. },
  92. data() {
  93. return {
  94. orderList: [],
  95. showPicker: false,
  96. columns: [],
  97. loading: false,
  98. entryTypeValue: "",
  99. showCalendar: false,
  100. entryTime: "",
  101. columnsPicker: [],
  102. show: false,
  103. options: [{
  104. text: '删除',
  105. style: {
  106. backgroundColor: '#f56c6c'
  107. }
  108. }],
  109. rules: {},
  110. columnData: [],
  111. warehouseIndex: 0,
  112. form: {
  113. code: "",
  114. entryType: "",
  115. entryTime: "",
  116. registrationTime: "",
  117. registrant: {
  118. name: ""
  119. },
  120. registrationDept: "",
  121. remark: ""
  122. }
  123. }
  124. },
  125. onShow() {
  126. this.orderList = this.$store.state.tour_tally.selectSparepart ? this.$store.state.tour_tally.selectSparepart :
  127. []
  128. this.init()
  129. },
  130. methods: {
  131. onBack() {
  132. this.$store.dispatch("tour_tally/setSelectSparepart", [])
  133. uni.redirectTo({
  134. url: "/pages/put_storage/order/index"
  135. })
  136. },
  137. swipeAction(idx) {
  138. this.orderList.splice(idx, 1)
  139. this.$store.dispatch("tour_tally/setSelectSparepart", this.orderList)
  140. },
  141. submit() {
  142. this.form.spareparts = this.orderList
  143. this.form.entryTypeValue = this.form.entryType.id
  144. postJ(this.apiUrl + "/feature/book/sparepartsEntry/putWarehouse", this.form).then(res => {
  145. // console.log(res)
  146. if (res.success) {
  147. uni.showToast({
  148. title: "操作成功"
  149. })
  150. setTimeout(() => {
  151. this.cancelPage()
  152. }, 2000)
  153. }
  154. })
  155. },
  156. cancelPage() {
  157. this.$store.dispatch("tour_tally/setSelectSparepart", [])
  158. uni.redirectTo({
  159. url: "/pages/put_storage/order/index"
  160. })
  161. },
  162. selectAddress(idx) {
  163. this.showPicker = true
  164. this.warehouseIndex = idx
  165. },
  166. handleConfirmPicker(e) {
  167. this.orderList[this.warehouseIndex].warehouse = ""
  168. e.value.forEach((item, index) => {
  169. let name = index == 0 ? "deviceWarehouse" : index == 2 ? "deviceStoreArea" : "deviceStoreSpace"
  170. if (index === e.value.length - 1) {
  171. this.orderList[this.warehouseIndex][name] = item ? item.name : ""
  172. } else {
  173. this.orderList[this.warehouseIndex][name] = {
  174. id: item ? item.code : "",
  175. name: ""
  176. }
  177. }
  178. this.orderList[this.warehouseIndex].warehouse +=
  179. `${index==0?'':item?"/":""}${item?item.name:""}`
  180. })
  181. // console.log(this.orderList[this.warehouseIndex])
  182. this.$forceUpdate()
  183. this.showPicker = false
  184. },
  185. changeHandler(e) {
  186. const {
  187. columnIndex,
  188. index,
  189. // 微信小程序无法将picker实例传出来,只能通过ref操作
  190. picker = this.$refs.uPicker
  191. } = e
  192. if (columnIndex === 0) {
  193. this.loading = true
  194. this.getColumnsPicker(e.value[0].code)
  195. }
  196. },
  197. onConfirm(e) {
  198. // console.log(e)
  199. this.form.entryType = {
  200. id: e.value[0].value,
  201. name: e.value[0].name
  202. }
  203. this.entryTypeValue = e.value[0].name
  204. this.show = false
  205. },
  206. handleConfirm(e) {
  207. // console.log(e)
  208. this.form.entryTime = e[0] + " 00:00:00"
  209. this.entryTime = e[0]
  210. this.showCalendar = false
  211. },
  212. pickerList() {
  213. return new Promise((reslove, reject) => {
  214. post(this.apiUrl + "/wms/warehouse/list").then(res => {
  215. reslove(res.data)
  216. })
  217. })
  218. },
  219. init() {
  220. uni.showLoading({
  221. title: "加载中"
  222. })
  223. Promise.all([this.loadCreate(), this.putType(), this.pickerList()]).then(res => {
  224. uni.hideLoading()
  225. this.form = res[0]
  226. this.columns = [res[1]]
  227. this.columnsPicker = [res[2].items]
  228. this.getColumnsPicker()
  229. })
  230. },
  231. getColumnsPicker(code) {
  232. // console.log(code)
  233. let pickerCode = code ? code : this.columnsPicker[0][0].code
  234. get(this.apiUrl + "/wms/warehouse/infoByCode?code=" + pickerCode).then(res => {
  235. // console.log(res)
  236. if (res.success) {
  237. let uPicker = this.$refs.uPicker
  238. res.data.storeAreas.forEach(item => {
  239. item.spaceList.forEach(el => {
  240. el.name = el.code
  241. })
  242. })
  243. if (res.data.storeAreas && res.data.storeAreas.length !== 0) {
  244. uPicker.setColumnValues(1, res.data.storeAreas)
  245. uPicker.setColumnValues(2, res.data.storeAreas[0].spaceList)
  246. } else {
  247. uPicker.setColumnValues(1, [])
  248. uPicker.setColumnValues(2, [])
  249. }
  250. }
  251. this.loading = false
  252. })
  253. },
  254. loadCreate() {
  255. return new Promise((reslove, reject) => {
  256. get(this.apiUrl + "/feature/book/sparepartsEntry/create").then(res => {
  257. // console.log(res)
  258. if (res.success) {
  259. reslove(res.data)
  260. }
  261. })
  262. })
  263. },
  264. putType() {
  265. return new Promise((reslove, reject) => {
  266. get(this.apiUrl + "/feature/book/sparepartsEntry/putType").then(res => {
  267. // console.log(res)
  268. if (res.success) {
  269. reslove(res.data)
  270. }
  271. })
  272. })
  273. },
  274. select_type() {
  275. uni.redirectTo({
  276. url: "/pages/put_storage/linkage/index"
  277. })
  278. }
  279. }
  280. }
  281. </script>
  282. <style lang="scss" scoped>
  283. .p10 {
  284. padding: 20rpx;
  285. }
  286. .customeSwipe {
  287. /deep/ .u-input {
  288. border-bottom: 1px solid #ccc;
  289. }
  290. /deep/ .u-input:last-child {
  291. border-bottom: none;
  292. }
  293. }
  294. .btnList {
  295. position: fixed;
  296. bottom: 0;
  297. left: 0;
  298. width: 100%;
  299. display: flex;
  300. z-index: 999;
  301. /deep/ .u-button {
  302. width: 50% !important;
  303. }
  304. }
  305. .mt10 {
  306. margin-top: 20rpx;
  307. padding-bottom: 160rpx;
  308. position: relative;
  309. }
  310. .right {
  311. position: absolute;
  312. right: 20rpx;
  313. }
  314. .no_data {
  315. margin-top: 80rpx;
  316. }
  317. /deep/ .u-picker__view__column__item {
  318. height: 88rpx !important;
  319. line-height: 88rpx !important;
  320. }
  321. /deep/ .uni-picker-view-indicator {
  322. height: 88rpx !important;
  323. line-height: 88rpx !important;
  324. }
  325. .customCalendar {
  326. /deep/.u-button {
  327. width: 100% !important;
  328. }
  329. }
  330. </style>