add.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view class="bg-f9 warehouse-add">
  3. <header-bar :title="submitType === 'add' ? '添加申购' : '修改申购'"></header-bar>
  4. <view class="example" v-for="(i,index) in formList" :key="i.id">
  5. <view class="example-title">
  6. 申购明细{{index + 1}}
  7. </view>
  8. <uni-forms label-position="top" :modelValue="i" ref="form" :rules="rules">
  9. <uni-forms-item label="物品名称" required name="classifyId">
  10. <uni-data-picker v-model="form.classifyId" :map="{text:'label',value:'id'}" :localdata="treeData"
  11. popup-title="请选择物料" @change="treeChange">
  12. </uni-data-picker>
  13. </uni-forms-item>
  14. <uni-forms-item label="单位" required name="type">
  15. <uni-easyinput v-model="form.unit" :disabled="true" placeholder="选择物料后自动输入" />
  16. </uni-forms-item>
  17. <uni-forms-item label="申购数量">
  18. <uni-easyinput v-model="form.code" placeholder="请输入" />
  19. </uni-forms-item>
  20. <!-- <uni-forms-item label="到货时间" required name="unit">
  21. <uni-data-select v-model="form.type" :disabled="true" :localdata="types"></uni-data-select>
  22. </uni-forms-item>
  23. <uni-forms-item label="申购原因" name="introduce">
  24. <uni-easyinput type="textarea" v-model="form.introduce" placeholder="请输入自我介绍" />
  25. </uni-forms-item> -->
  26. </uni-forms>
  27. </view>
  28. <button class="add-list" style="margin-bottom: 140rpx" @click="addList">+ 添加明细</button>
  29. <view style="height:200rpx">
  30. </view>
  31. <button class="submit" @click="submitForm">提交</button>
  32. </view>
  33. </template>
  34. <script>
  35. import headerBar from '../../../components/header-bar/index.vue'
  36. import Vue from 'vue'
  37. export default {
  38. components: {
  39. headerBar
  40. },
  41. data() {
  42. return {
  43. formList:[
  44. {
  45. name: '',
  46. type: null,
  47. classifyId: null,
  48. code: null,
  49. unit: null,
  50. introduce: null,
  51. id:Date.now()
  52. }
  53. ],
  54. form: {
  55. name: '',
  56. type: null,
  57. classifyId: null,
  58. code: null,
  59. unit: null,
  60. introduce: null,
  61. },
  62. types: [{
  63. text: '半成品',
  64. value: '0'
  65. }, {
  66. text: '成品',
  67. value: '1'
  68. }],
  69. rules: {
  70. // 对name字段进行必填验证
  71. name: {
  72. rules: [{
  73. required: true,
  74. errorMessage: '请输入产品名称',
  75. }, ]
  76. },
  77. // 对email字段进行必填验证
  78. type: {
  79. rules: [{
  80. required: true,
  81. errorMessage: '请选择产品类型',
  82. }, ]
  83. },
  84. unit: {
  85. rules: [{
  86. required: true,
  87. errorMessage: '请输入产品单位',
  88. }, ]
  89. },
  90. classifyId: {
  91. rules: [{
  92. required: true,
  93. errorMessage: '请选择产品分类',
  94. }, ]
  95. },
  96. },
  97. submitType: 'add',
  98. treeData: [],
  99. }
  100. },
  101. onLoad(e) {
  102. if (e.id) {
  103. this.form.id = e.id
  104. this.form.remarks = e.remarks
  105. this.form.type = e.type
  106. this.form.name = e.name
  107. this.submitType = 'edit'
  108. }
  109. this.getTree()
  110. },
  111. methods: {
  112. addList(){
  113. const v = this
  114. this.formList.push({
  115. name: '',
  116. type: null,
  117. classifyId: null,
  118. code: null,
  119. unit: null,
  120. introduce: null,
  121. id:Date.now()
  122. })
  123. },
  124. treeChange() {},
  125. getTree() {
  126. const v = this
  127. v.$post('/api/basics//classify/tree', {
  128. type: 1
  129. }).then(res => {
  130. if (res.code === 200) {
  131. v.treeData = res.data
  132. }
  133. })
  134. },
  135. submitForm() {
  136. const v = this
  137. this.$refs.form.validate().then(res => {
  138. uni.showLoading({
  139. title: '加载中'
  140. });
  141. v.$post('/api/basics/product/' + this.submitType, v.form).then(res => {
  142. if (res.code === 200) {
  143. uni.showToast({
  144. title: this.submitType == 'add' ? '添加成功' : '修改成功',
  145. duration: 1000,
  146. icon: 'success'
  147. })
  148. }
  149. uni.hideLoading()
  150. let pages = getCurrentPages(); // 获取页面栈
  151. let prePage = pages[pages.length - 2]; //获取上一页
  152. prePage.$vm.needRefresh = true; // 需要刷新
  153. setTimeout(() => {
  154. uni.navigateBack(1)
  155. }, 1000)
  156. })
  157. }).catch(err => {
  158. console.log('表单错误信息:', err);
  159. })
  160. },
  161. },
  162. }
  163. </script>
  164. <style lang="less">
  165. .add-list{
  166. background-color: #fff;
  167. color: #999;
  168. }
  169. .example{
  170. margin-bottom: 20rpx;
  171. }
  172. .example-title{
  173. background-color: #fff;
  174. position: relative;
  175. height: 50rpx;
  176. line-height: 50rpx;
  177. font-size: 28rpx;
  178. padding: 0 40rpx;
  179. }
  180. .example-title::before{
  181. content: ' ';
  182. position: absolute;
  183. left: 10rpx;
  184. height: 30rpx;
  185. background-color: rgba(0, 132, 255, 1);
  186. top: 10rpx;
  187. width: 4rpx;
  188. }
  189. .bg-f9{
  190. background-color: #f9f9f9;
  191. min-height: 100vh;
  192. }
  193. .uni-forms-item{
  194. background-color: #fff;
  195. margin-bottom: 6rpx!important;
  196. padding: 6rpx 24rpx 26rpx!important;
  197. }
  198. .is-input-border{
  199. border:none!important;
  200. }
  201. </style>