addGood.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <view class="goods-page">
  3. <u-navbar
  4. height="40px"
  5. title="新增录入"
  6. bgColor="rgba(2, 86, 255, 1)"
  7. autoBack
  8. placeholder
  9. titleStyle="color:#fff"
  10. leftIconColor="#fff"
  11. >
  12. <view class="u-nav-slot depot-label" slot="right">
  13. <view class="name" style="color: #fff">{{ curDepotName }}</view>
  14. </view>
  15. </u-navbar>
  16. <view class="container_main">
  17. <u--form
  18. labelPosition="left"
  19. :model="form"
  20. :rules="rules"
  21. ref="uForm"
  22. labelWidth="90"
  23. >
  24. <u-form-item
  25. label="货物条码"
  26. prop="barCode"
  27. borderBottom
  28. required
  29. customStyle="padding: 30rpx 0"
  30. >
  31. <u-input v-model="form.barCode" border="none" placeholder="请输入">
  32. <u-image
  33. slot="suffix"
  34. src="@/static/image/scan-icon-2.png"
  35. width="40rpx"
  36. height="40rpx"
  37. @click="scanCode"
  38. ></u-image>
  39. </u-input>
  40. </u-form-item>
  41. <u-form-item
  42. label="货物名称"
  43. prop="name"
  44. borderBottom
  45. required
  46. customStyle="padding: 30rpx 0"
  47. >
  48. <u-input
  49. v-model="form.name"
  50. border="none"
  51. placeholder="请输入"
  52. ></u-input>
  53. </u-form-item>
  54. <u-form-item
  55. label="规格"
  56. prop="standard"
  57. borderBottom
  58. required
  59. customStyle="padding: 30rpx 0"
  60. >
  61. <u-input
  62. v-model="form.standard"
  63. border="none"
  64. placeholder="请输入"
  65. ></u-input>
  66. </u-form-item>
  67. <u-form-item
  68. label="生产日期"
  69. prop="productionDate"
  70. borderBottom
  71. required
  72. customStyle="padding: 30rpx 0"
  73. >
  74. <view
  75. :class="['date-val', { grey: !form.productionDate }]"
  76. @click="showDatePicker = true"
  77. >{{ form.productionDate ? form.productionDate : "请输入" }}</view
  78. >
  79. </u-form-item>
  80. <u-form-item
  81. label="上传图片"
  82. prop="imgName"
  83. borderBottom
  84. required
  85. customStyle="padding: 30rpx 0"
  86. >
  87. <upload-image
  88. v-model="form.imgName"
  89. width="196rpx"
  90. height="196rpx"
  91. ></upload-image>
  92. </u-form-item>
  93. <u-form-item
  94. label="库位"
  95. prop="position"
  96. borderBottom
  97. required
  98. customStyle="padding: 30rpx 0"
  99. >
  100. <u-input
  101. v-model="form.position"
  102. border="none"
  103. placeholder="请输入"
  104. ></u-input>
  105. </u-form-item>
  106. </u--form>
  107. </view>
  108. <u-datetime-picker
  109. :show="showDatePicker"
  110. @cancel="showDatePicker = false"
  111. @confirm="confirmDate"
  112. v-model="dateVal"
  113. mode="date"
  114. ></u-datetime-picker>
  115. <!-- 新增录入-->
  116. <view class="footer">
  117. <u-button class="add-btn" type="primary" plain @click="save">
  118. 保存
  119. </u-button>
  120. </view>
  121. </view>
  122. </template>
  123. <script>
  124. import { mapGetters } from "vuex";
  125. import { goodsSave } from "@/common/request/apis/goodsEnter.js";
  126. export default {
  127. data() {
  128. return {
  129. form: {
  130. barCode: "",
  131. name: "",
  132. standard: "",
  133. imgName: "",
  134. position: "",
  135. productionDate: "",
  136. },
  137. rules: {
  138. barCode: [
  139. {
  140. required: true,
  141. message: "请输入货物条码",
  142. trigger: ["blur", "change"],
  143. },
  144. ],
  145. name: [
  146. {
  147. required: true,
  148. message: "请输入货物名称",
  149. trigger: ["blur", "change"],
  150. },
  151. ],
  152. standard: [
  153. {
  154. required: true,
  155. message: "请输入规格",
  156. trigger: ["blur", "change"],
  157. },
  158. ],
  159. productionDate: [
  160. {
  161. required: true,
  162. message: "请输入生产日期",
  163. trigger: ["blur", "change"],
  164. },
  165. ],
  166. imgName: [
  167. {
  168. required: true,
  169. message: "请上传图片",
  170. trigger: ["blur", "change"],
  171. },
  172. ],
  173. position: [
  174. {
  175. required: true,
  176. message: "请输入库位",
  177. trigger: ["blur", "change"],
  178. },
  179. ],
  180. },
  181. showDatePicker: false,
  182. dateVal: "",
  183. };
  184. },
  185. computed: {
  186. ...mapGetters(["depotInfo"]),
  187. curDepotId() {
  188. return this.depotInfo ? this.depotInfo.id : "";
  189. },
  190. curDepotName() {
  191. return this.depotInfo ? this.depotInfo.depotName : "";
  192. },
  193. },
  194. onHide() {
  195. uni.$off("scanFinish");
  196. },
  197. onShow() {
  198. uni.$on("scanFinish", (data) => {
  199. this.form.barCode = data;
  200. this.$refs.uForm.validateField("barCode");
  201. });
  202. },
  203. methods: {
  204. scanCode() {
  205. this.$scan.scanCode();
  206. },
  207. confirmDate(e) {
  208. console.log("confirmDate====", e);
  209. const { value } = e;
  210. this.form.productionDate = this.$u.date(value, "yyyy-mm-dd");
  211. console.log("form====", this.form);
  212. this.showDatePicker = false;
  213. },
  214. save() {
  215. this.$refs.uForm
  216. .validate()
  217. .then(async (res) => {
  218. try {
  219. const params = { ...this.form, depotId: this.curDepotId };
  220. const result = await goodsSave(params);
  221. console.log("result====", result);
  222. if (result.code === 200) {
  223. uni.$u.toast(result.msg);
  224. setTimeout(() => {
  225. uni.navigateBack();
  226. }, 1000);
  227. uni.setStorageSync("goodsEnterRefresh", true);
  228. } else {
  229. uni.$u.toast(result.msg);
  230. }
  231. } catch (error) {}
  232. })
  233. .catch((errors) => {});
  234. },
  235. },
  236. };
  237. </script>
  238. <style lang="scss" scoped>
  239. .goods-page {
  240. min-height: 100vh;
  241. background-color: #f0f6fb;
  242. .container_main {
  243. margin: 24rpx;
  244. background-color: #fff;
  245. border-radius: 16rpx;
  246. padding: 24rpx;
  247. }
  248. }
  249. .footer {
  250. position: fixed;
  251. bottom: 0;
  252. left: 0;
  253. right: 0;
  254. height: 144rpx;
  255. background-color: #fff;
  256. display: flex;
  257. align-items: center;
  258. justify-content: center;
  259. .add-btn {
  260. width: 700rpx;
  261. height: 88rpx;
  262. border-radius: 16rpx;
  263. font-size: 36rpx;
  264. font-weight: bold;
  265. color: #fff;
  266. background-color: #0256ff;
  267. line-height: 88rpx;
  268. text-align: center;
  269. }
  270. }
  271. .date-val {
  272. width: 100%;
  273. font-size: 28rpx;
  274. }
  275. .grey {
  276. color: #999;
  277. }
  278. </style>