RecordEdit.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <uni-drawer ref="drawer" mode="left" :mask-click="false" width="85%" :maskClick='true'>
  3. <scroll-view class="scroll-view" scroll-y="true">
  4. <uni-section :title="'编辑:' + (type==='in'?'入库记录':'出库记录')" type="line"></uni-section>
  5. <view class="form-wrap" >
  6. <uni-forms ref="form" label-position="top" :rules="rules" :model="form">
  7. <view class="inbound" v-if="type==='in'">
  8. <uni-forms-item label="入库人员" name="accountId" required>
  9. <uni-data-select v-model="form.accountId" :localdata="userList" placeholder="请选择入库人员" :clear="false"></uni-data-select>
  10. </uni-forms-item>
  11. <uni-forms-item label="入库类型" name="inboundType" required>
  12. <uni-data-select v-model="form.inboundType" :localdata="inboundTypeList" placeholder="请选择入库类型" :clear="false"></uni-data-select>
  13. </uni-forms-item>
  14. <uni-forms-item label="物资种类" name="goodsCatId" required>
  15. <uni-data-select v-model="form.goodsCatId" :localdata="goodsCats" placeholder="请选择物资种类" :clear="false"></uni-data-select>
  16. </uni-forms-item>
  17. <uni-forms-item label="物资数量" label-position="left" required>
  18. <uni-easyinput v-model="form.qty" placeholder="请输入物资数量" :clearable="false" />
  19. </uni-forms-item>
  20. <uni-forms-item label="物资编号" >
  21. <uni-easyinput v-model="form.goodsNo" placeholder="请输入物资编号" :clearable="false" />
  22. </uni-forms-item>
  23. <uni-forms-item label="存放位置" name="inboundLocation" required>
  24. <uni-easyinput v-model="form.inboundLocation" placeholder="请输入存放位置" :clearable="false" />
  25. </uni-forms-item>
  26. <uni-forms-item label="物资名称" >
  27. <uni-easyinput v-model="form.goodsTitle" ></uni-easyinput>
  28. </uni-forms-item>
  29. <uni-forms-item label="生产日期">
  30. <uni-datetime-picker type="date" v-model="form.goodsPdDate" />
  31. </uni-forms-item>
  32. <uni-forms-item label="过期时间">
  33. <uni-datetime-picker type="date" v-model="form.goodsExpDate"/>
  34. </uni-forms-item>
  35. <uni-forms-item label="物资说明">
  36. <uni-easyinput type="textarea" :maxlength="1000" v-model="form.goodsDesc" placeholder="请输入物资说明" autoHeight ></uni-easyinput>
  37. <view class="word-limit">{{form.goodsDesc.length||0}}/1000</view>
  38. </uni-forms-item>
  39. </view>
  40. <view class="outbound" v-if="type==='out'">
  41. <uni-card margin="10px 0">
  42. <uni-list>
  43. <uni-list-item title="物资种类" >
  44. <template v-slot:footer><uni-tag :text="form.goodsCatTitle" type="success"></uni-tag></template>
  45. </uni-list-item>
  46. <uni-list-item title="库存数量" >
  47. <template v-slot:footer><uni-tag :text="`${form.qty}`" type="primary"></uni-tag></template>
  48. </uni-list-item>
  49. </uni-list>
  50. </uni-card>
  51. <uni-forms-item label="出库人员" name="accountId" required>
  52. <uni-data-select v-model="form.accountId" :localdata="userList" placeholder="请选择出库人员" :clear="false"></uni-data-select>
  53. </uni-forms-item>
  54. <uni-forms-item label="出库类型" name="outboundType" v-if="type==='out'" required>
  55. <uni-data-select v-model="form.outboundType" :localdata="outboundTypeList" placeholder="请选择出库类型" :clear="false"></uni-data-select>
  56. </uni-forms-item>
  57. <uni-forms-item label="出库地点" name="outboundLocation" required>
  58. <uni-easyinput v-model="form.outboundLocation" placeholder="请输入存放位置" :clearable="false" />
  59. </uni-forms-item>
  60. </view>
  61. <uni-forms-item label="备注">
  62. <uni-easyinput type="textarea" :maxlength="500"
  63. v-model="form.remark" autoHeight
  64. placeholder="请输入备注"></uni-easyinput>
  65. <view class="word-limit">{{form.remark.length||0}}/500</view>
  66. </uni-forms-item>
  67. </uni-forms>
  68. <view class="handle-container">
  69. <button class="save" type="primary" @click="onSubmit">保存</button>
  70. <button class="cancel" type="default" @click="close">取消</button>
  71. </view>
  72. </view>
  73. </scroll-view>
  74. </uni-drawer>
  75. </template>
  76. <script>
  77. import goodsApi from '@/api/goods.js'
  78. import { parseTime } from '@/libs'
  79. export default{
  80. name:"RecordEdit",
  81. computed:{
  82. ocId(){
  83. let accountInfo=uni.getStorageSync('accountInfo')
  84. if(!accountInfo)return undefined
  85. return accountInfo.ocId
  86. },
  87. goodsCats(){
  88. let goodsCats=uni.getStorageSync('goodsCats')
  89. if(!goodsCats)return []
  90. return goodsCats.map(item=>{
  91. return{
  92. value:item.goodsCatId,
  93. text:item.goodsCatTitle
  94. }
  95. })
  96. },
  97. userList(){
  98. let groupUser=uni.getStorageSync('groupUser')
  99. let userList=[]
  100. groupUser.map((item,index)=>{
  101. userList.push({...item,value:`root-${index+1}`,text:item.name,disable:true})
  102. if(Array.isArray(item.children)&&item.children.length>0){
  103. userList=userList.concat(item.children.map(item=>{return{...item,value:item.accountId,text:item.accountName}}))
  104. }
  105. })
  106. return userList
  107. }
  108. },
  109. data(){
  110. return{
  111. type:undefined,
  112. rules:{
  113. accountId:{
  114. rules:[
  115. {
  116. required: true,
  117. errorMessage:this.type==='in'?'入库人员':'出库人员'
  118. }
  119. ],
  120. validateTrigger:'submit'
  121. },
  122. intboundType:{
  123. rules:[
  124. {
  125. required: true,
  126. errorMessage:"请选择入库类型"
  127. }
  128. ],
  129. validateTrigger:'submit'
  130. },
  131. outboundType:{
  132. rules:[
  133. {
  134. required: true,
  135. errorMessage:"请选择出库类型"
  136. }
  137. ],
  138. validateTrigger:'submit'
  139. },
  140. goodsCatId:{
  141. rules:[
  142. {
  143. required: true,
  144. errorMessage: '请选择物资种类',
  145. }
  146. ],
  147. validateTrigger:'submit'
  148. },
  149. },
  150. inboundTypeList:[
  151. { value: 1, text: '正常入库' },
  152. { value: 2, text: '报溢' },
  153. ],
  154. outboundTypeList:[
  155. { value: 1, text: '正常出库' },
  156. { value: 2, text: '报损' },
  157. { value: 3, text: '过期' },
  158. ],
  159. form:{
  160. groupId: undefined,
  161. groupName: undefined,
  162. inboundId: 0,
  163. inboundType: 1,
  164. inboundTime: '',
  165. inboundLocation: '',
  166. accountId: "",
  167. accountName:"",
  168. goodsType: "",
  169. goodsCatId: 1,
  170. goodsCatTitle: '',
  171. qty: 1,
  172. goodsNo: '',
  173. goodsTitle: '',
  174. goodsPdDate: '',
  175. goodsExpDate: '',
  176. goodsDesc: '',
  177. remark: '',
  178. //out
  179. outboundId: 0,
  180. outboundType: 1,
  181. outboundTime: '',
  182. outboundLocation: ''
  183. }
  184. }
  185. },
  186. methods:{
  187. resetForm(){
  188. this.form={
  189. groupId: undefined,
  190. groupName: undefined,
  191. inboundId: 0,
  192. inboundType: 1,
  193. inboundTime: '',
  194. inboundLocation: '',
  195. accountId: "",
  196. accountName:"",
  197. goodsType: "",
  198. goodsCatId: 1,
  199. goodsCatTitle: '',
  200. qty: 1,
  201. goodsNo: '',
  202. goodsTitle: '',
  203. goodsPdDate: '',
  204. goodsExpDate: '',
  205. goodsDesc: '',
  206. remark: '',
  207. //out
  208. outboundId: 0,
  209. outboundType: 1,
  210. outboundTime: '',
  211. outboundLocation: ''
  212. }
  213. },
  214. onSubmit(){
  215. this.$refs.form.validate().then(res=>{
  216. let submitFx=this.type==='in'?goodsApi.updateInbound:goodsApi.updateOutbound
  217. let user=this.userList.find(item=>this.form.accountId===item.accountId)
  218. let goodsCat=this.goodsCats.find(item=>this.form.goodsCatId===item.value)
  219. let params={
  220. accountId: user.accountId,
  221. accountName: user.accountName,
  222. positionId: user.positionId,
  223. positionName: user.positionName,
  224. ocId:this.ocId,
  225. goodsType: this.form.goodsType,
  226. goodsCatId: goodsCat.value,
  227. goodsCatTitle:goodsCat.text,
  228. qty: this.form.qty,
  229. remark: this.form.remark
  230. }
  231. if(this.type==='in'){
  232. params={...params,
  233. goodsNo:this.form.goodsNo,
  234. goodsTitle: this.form.goodsTitle,
  235. goodsPdDate:this.form.goodsPdDate,
  236. goodsExpDate: this.form.goodsExpDate,
  237. goodsDesc: this.form.goodsDesc,
  238. inboundId: this.form.inboundId,
  239. inboundType: this.form.inboundType,
  240. inboundTime: this.form.inboundTime,
  241. inboundLocation: this.form.inboundLocation,
  242. }
  243. }else{
  244. params={...params,
  245. outboundId: this.form.outboundId,
  246. outboundType: this.form.outboundType,
  247. outboundTime: this.form.outboundTime,
  248. outboundLocation: this.form.outboundLocation,
  249. }
  250. }
  251. submitFx(params).then(()=>{
  252. uni.showToast({
  253. icon:"none",
  254. title:"成功!!"
  255. })
  256. this.$emit('success')
  257. this.close();
  258. })
  259. }).catch(err =>{
  260. console.log(err)
  261. uni.showToast({
  262. icon:"none",
  263. title:"请检查填写信息!"
  264. })
  265. })
  266. },
  267. show({type,item}){
  268. this.resetForm()
  269. this.form={...this.form,...item}
  270. this.type=type
  271. this.$refs.drawer.open()
  272. },
  273. close(){
  274. this.$refs.drawer.close()
  275. }
  276. }
  277. }
  278. </script>
  279. <style lang="scss" scoped>
  280. .scroll-view {
  281. height: 100%;
  282. padding: 20rpx;
  283. box-sizing: border-box;
  284. .form-wrap{
  285. padding:40rpx 20rpx;
  286. .handle-container{
  287. display: flex;
  288. justify-content: center;
  289. align-items: center;
  290. button{
  291. width: 160rpx;
  292. padding: 20rpx 16rpx;
  293. line-height: 1;
  294. font-size: 28rpx;
  295. &.save{
  296. background-color: #007aff;
  297. }
  298. }
  299. }
  300. .word-limit{
  301. text-align: right;
  302. padding: 10rpx 0;
  303. color: #999;
  304. font-size: 26rpx;
  305. }
  306. }
  307. }
  308. </style>