add.vue 4.7 KB

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