RecordEdit.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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=this.cats;
  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. props:{
  110. cats:{
  111. type:Array,
  112. default:()=>[]
  113. }
  114. },
  115. data(){
  116. return{
  117. type:undefined,
  118. rules:{
  119. accountId:{
  120. rules:[
  121. {
  122. required: true,
  123. errorMessage:this.type==='in'?'入库人员':'出库人员'
  124. }
  125. ],
  126. validateTrigger:'submit'
  127. },
  128. intboundType:{
  129. rules:[
  130. {
  131. required: true,
  132. errorMessage:"请选择入库类型"
  133. }
  134. ],
  135. validateTrigger:'submit'
  136. },
  137. outboundType:{
  138. rules:[
  139. {
  140. required: true,
  141. errorMessage:"请选择出库类型"
  142. }
  143. ],
  144. validateTrigger:'submit'
  145. },
  146. goodsCatId:{
  147. rules:[
  148. {
  149. required: true,
  150. errorMessage: '请选择物资种类',
  151. }
  152. ],
  153. validateTrigger:'submit'
  154. },
  155. },
  156. inboundTypeList:[
  157. { value: 1, text: '正常入库' },
  158. { value: 2, text: '报溢' },
  159. ],
  160. outboundTypeList:[
  161. { value: 1, text: '正常出库' },
  162. { value: 2, text: '报损' },
  163. { value: 3, text: '过期' },
  164. ],
  165. form:{
  166. groupId: undefined,
  167. groupName: undefined,
  168. inboundId: 0,
  169. inboundType: 1,
  170. inboundTime: '',
  171. inboundLocation: '',
  172. accountId: "",
  173. accountName:"",
  174. goodsType: "",
  175. goodsCatId: 1,
  176. goodsCatTitle: '',
  177. qty: 1,
  178. goodsNo: '',
  179. goodsTitle: '',
  180. goodsPdDate: '',
  181. goodsExpDate: '',
  182. goodsDesc: '',
  183. remark: '',
  184. //out
  185. outboundId: 0,
  186. outboundType: 1,
  187. outboundTime: '',
  188. outboundLocation: ''
  189. }
  190. }
  191. },
  192. methods:{
  193. resetForm(){
  194. this.form={
  195. groupId: undefined,
  196. groupName: undefined,
  197. inboundId: 0,
  198. inboundType: 1,
  199. inboundTime: '',
  200. inboundLocation: '',
  201. accountId: "",
  202. accountName:"",
  203. goodsType: "",
  204. goodsCatId: 1,
  205. goodsCatTitle: '',
  206. qty: 1,
  207. goodsNo: '',
  208. goodsTitle: '',
  209. goodsPdDate: '',
  210. goodsExpDate: '',
  211. goodsDesc: '',
  212. remark: '',
  213. //out
  214. outboundId: 0,
  215. outboundType: 1,
  216. outboundTime: '',
  217. outboundLocation: ''
  218. }
  219. },
  220. onSubmit(){
  221. this.$refs.form.validate().then(res=>{
  222. let submitFx=this.type==='in'?goodsApi.updateInbound:goodsApi.updateOutbound
  223. let user=this.userList.find(item=>this.form.accountId===item.accountId)
  224. let goodsCat=this.goodsCats.find(item=>this.form.goodsCatId===item.value)
  225. let params={
  226. accountId: user.accountId,
  227. accountName: user.accountName,
  228. positionId: user.positionId,
  229. positionName: user.positionName,
  230. ocId:this.ocId,
  231. goodsType: this.form.goodsType,
  232. goodsCatId: goodsCat.value,
  233. goodsCatTitle:goodsCat.text,
  234. qty: this.form.qty,
  235. remark: this.form.remark
  236. }
  237. if(this.type==='in'){
  238. params={...params,
  239. goodsNo:this.form.goodsNo,
  240. goodsTitle: this.form.goodsTitle,
  241. goodsPdDate:this.form.goodsPdDate,
  242. goodsExpDate: this.form.goodsExpDate,
  243. goodsDesc: this.form.goodsDesc,
  244. inboundId: this.form.inboundId,
  245. inboundType: this.form.inboundType,
  246. inboundTime: this.form.inboundTime,
  247. inboundLocation: this.form.inboundLocation,
  248. }
  249. }else{
  250. params={...params,
  251. outboundId: this.form.outboundId,
  252. outboundType: this.form.outboundType,
  253. outboundTime: this.form.outboundTime,
  254. outboundLocation: this.form.outboundLocation,
  255. }
  256. }
  257. submitFx(params).then(()=>{
  258. uni.showToast({
  259. icon:"none",
  260. title:"成功!!"
  261. })
  262. this.$emit('success')
  263. this.close();
  264. })
  265. }).catch(err =>{
  266. console.log(err)
  267. uni.showToast({
  268. icon:"none",
  269. title:"请检查填写信息!"
  270. })
  271. })
  272. },
  273. show({type,item}){
  274. this.resetForm()
  275. this.form={...this.form,...item}
  276. this.type=type
  277. this.$refs.drawer.open()
  278. },
  279. close(){
  280. this.$refs.drawer.close()
  281. }
  282. }
  283. }
  284. </script>
  285. <style lang="scss" scoped>
  286. .scroll-view {
  287. height: 100%;
  288. padding: 20rpx;
  289. box-sizing: border-box;
  290. .form-wrap{
  291. padding:40rpx 20rpx;
  292. .handle-container{
  293. display: flex;
  294. justify-content: center;
  295. align-items: center;
  296. button{
  297. width: 160rpx;
  298. padding: 20rpx 16rpx;
  299. line-height: 1;
  300. font-size: 28rpx;
  301. &.save{
  302. background-color: #007aff;
  303. }
  304. }
  305. }
  306. .word-limit{
  307. text-align: right;
  308. padding: 10rpx 0;
  309. color: #999;
  310. font-size: 26rpx;
  311. }
  312. }
  313. }
  314. </style>