addEdit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <template>
  2. <div class="stockApply-com">
  3. <el-form
  4. :model="ruleForm"
  5. :rules="rulesThis"
  6. status-icon
  7. :size="'mini'"
  8. ref="ruleForm"
  9. label-width="90px"
  10. class="demo-ruleForm"
  11. >
  12. <el-row>
  13. <el-col :span="12">
  14. <el-form-item label="商品名称" prop="good_name">
  15. <el-input
  16. :disabled="
  17. !(
  18. id === 'add' ||
  19. (status === '0' && powers.some((item) => item == '005'))
  20. )
  21. "
  22. v-model="ruleForm.good_name"
  23. readonly="true"
  24. :placeholder="'商品名称'"
  25. @focus="showGoodsModel = true"
  26. ></el-input>
  27. </el-form-item>
  28. </el-col>
  29. <!-- 采购数量 -->
  30. <el-col :span="5">
  31. <el-form-item label="采购数量" prop="goods_num">
  32. <digital-input
  33. :values="ruleForm.goods_num"
  34. :name="'ruleForm.goods_num'"
  35. :placeholder="'采购数量'"
  36. :min="0"
  37. :disabled="
  38. !(
  39. id === 'add' ||
  40. (status === '0' && powers.some((item) => item == '005'))
  41. )
  42. "
  43. :max="100000000000"
  44. :position="'right'"
  45. :precision="0"
  46. :size="'mini'"
  47. :controls="false"
  48. :append="''"
  49. @reschange="number_change($event, 'goods_num')"
  50. />
  51. </el-form-item>
  52. </el-col>
  53. <!-- 最晚入库时间 -->
  54. <el-col :span="7">
  55. <el-form-item
  56. label="最晚入库时间"
  57. prop="lasttime"
  58. label-width="120px"
  59. >
  60. <el-date-picker
  61. v-model="ruleForm.lasttime"
  62. type="date"
  63. style="width: 100%"
  64. value-format="yyyy-MM-dd"
  65. placeholder="最晚入库时间"
  66. :picker-options="pickerOptions"
  67. :disabled="
  68. !(
  69. id === 'add' ||
  70. (status === '0' && powers.some((item) => item == '005'))
  71. )
  72. "
  73. >
  74. </el-date-picker>
  75. </el-form-item>
  76. </el-col>
  77. <el-col :span="12">
  78. <el-form-item label="附件" prop="file_url">
  79. <div
  80. class="file_url"
  81. :class="{
  82. disabled: !(
  83. id === 'add' ||
  84. (status === '0' && powers.some((item) => item == '005'))
  85. ),
  86. }"
  87. >
  88. <p v-if="ruleForm.file_url">
  89. <el-link :underline="false" :href="ruleForm.file_url" target="_blank">{{
  90. ruleForm.file_url_name
  91. }}</el-link>
  92. <el-link class="fr" type="info" :underline="false"
  93. ><i
  94. class="el-icon-circle-close"
  95. @click="close_url"
  96. :size="'mini'"
  97. ></i
  98. ></el-link>
  99. </p>
  100. <p v-else class="no">附件</p>
  101. <div v-if="ruleForm.file_url === ''">
  102. <file-upload-pdf
  103. v-if="
  104. id === 'add' ||
  105. (status === '0' && powers.some((item) => item == '005'))
  106. "
  107. class="Upload"
  108. :accept="'.pdf'"
  109. :multiple="false"
  110. :size="'mini'"
  111. :uploadcondition="beforeAvatarUpload"
  112. @UploadErrorEvent="UploadErrorEvent"
  113. @UploadSuccessEvent="UploadSuccessEvent"
  114. />
  115. </div>
  116. </div>
  117. </el-form-item>
  118. </el-col>
  119. <el-col :span="12">
  120. <el-form-item label="备注" prop="remark">
  121. <el-input
  122. type="textarea"
  123. :rows="2"
  124. placeholder="备注"
  125. v-model="ruleForm.remark"
  126. >
  127. </el-input>
  128. </el-form-item>
  129. </el-col>
  130. <el-col :span="12" style="padding: 0 0 15px 0; text-align: right">
  131. <el-button
  132. type="primary"
  133. @click="submitForm"
  134. :size="'mini'"
  135. v-if="
  136. id === 'add' ||
  137. (status == '0' && powers.some((item) => item == '005'))
  138. "
  139. >保 存
  140. </el-button>
  141. </el-col>
  142. </el-row>
  143. </el-form>
  144. <search-good-modal
  145. :once="true"
  146. :cat_id="cat_id"
  147. :show-model="showGoodsModel"
  148. @cancel="showGoodsModel = false"
  149. @resultList="addGoodsRes"
  150. />
  151. </div>
  152. </template>
  153. <script>
  154. import resToken from "@/mixins/resToken";
  155. import asyncRequest from "@/apis/service/sellOut/stockApply";
  156. import searchGoodModal from "@/components/search-good-modal";
  157. export default {
  158. name: "stockApply",
  159. props: ["id", "sitem", "newTime", "type"],
  160. mixins: [resToken],
  161. components: {
  162. searchGoodModal,
  163. },
  164. computed: {
  165. powers() {
  166. let tran =
  167. this.$store.getters.btnList.find(
  168. (item) => item.menu_route == "stockApplyDetail"
  169. ) || {};
  170. if (tran && tran.action && tran.action.length > 0) {
  171. return tran.action;
  172. } else {
  173. return [];
  174. }
  175. },
  176. },
  177. watch: {
  178. newTime: function (val) {
  179. if (val) {
  180. this.initForm();
  181. }
  182. },
  183. },
  184. data() {
  185. const validate_num_0 = (rule, value, callback) => {
  186. const { required } = rule;
  187. if (required && value === "") {
  188. callback(new Error("不能为空!"));
  189. } else if (
  190. required &&
  191. (value === "0" ||
  192. value === "0." ||
  193. value === "0.0" ||
  194. value === "0.00" ||
  195. value === "0.000")
  196. ) {
  197. callback(new Error("不能为零!"));
  198. } else {
  199. callback();
  200. }
  201. };
  202. return {
  203. pickerOptions: {
  204. disabledDate(time) {
  205. return time.getTime() < Date.now();
  206. },
  207. },
  208. status: "",
  209. cat_id: "",
  210. routerId: "",
  211. stockCode: "",
  212. showGoodsModel: "",
  213. loading: false,
  214. ruleForm: {
  215. id: "",
  216. good_code: "",
  217. good_name: "",
  218. goods_num: "",
  219. file_url: "",
  220. file_url_name: "",
  221. lasttime: "",
  222. remark: "",
  223. // supplier_code: [],
  224. // supplier_name: "",
  225. // stock_code: [],
  226. },
  227. rulesThis: this.rules,
  228. rules: {
  229. good_name: [
  230. {
  231. required: true,
  232. message: "商品名称不能为空!",
  233. trigger: "blur",
  234. },
  235. ],
  236. goods_num: [
  237. {
  238. required: true,
  239. validator: validate_num_0,
  240. trigger: "blur",
  241. },
  242. ],
  243. lasttime: [
  244. {
  245. required: true,
  246. message: "请输入最晚入库时间!",
  247. trigger: "change",
  248. },
  249. ],
  250. file_url: [
  251. {
  252. required: true,
  253. message: "请选择附件!",
  254. trigger: "change",
  255. },
  256. ],
  257. remark: [
  258. {
  259. required: true,
  260. message: "备注不能为空!",
  261. trigger: "blur",
  262. },
  263. ],
  264. },
  265. };
  266. },
  267. mounted() {
  268. this.initForm();
  269. },
  270. methods: {
  271. async initForm() {
  272. this.loading = true;
  273. this.status = this.sitem !== undefined ? this.sitem.status : "";
  274. this.status = "";
  275. this.rulesThis = this.rules;
  276. await this.resetForm();
  277. this.loading = false;
  278. },
  279. // 执行点击商品名称的抛出事件
  280. addGoodsRes(e) {
  281. console.log(e);
  282. let { spuCode, good_name } = e[0];
  283. this.ruleForm.good_name = good_name;
  284. this.ruleForm.good_code = spuCode;
  285. this.$refs.ruleForm.validateField("good_name");
  286. },
  287. number_change(e, key) {
  288. this.ruleForm[key] = e + "" || "0";
  289. this.$refs.ruleForm.validateField(key);
  290. },
  291. closeModel() {
  292. this.$emit("closeModel");
  293. },
  294. close_url() {
  295. this.ruleForm.file_url_name = "";
  296. this.ruleForm.file_url = "";
  297. this.$refs.ruleForm.validateField("file_url");
  298. },
  299. // 重置
  300. async resetForm() {
  301. // 重置
  302. await this.$nextTick(() => {
  303. if (this.$refs.ruleForm) {
  304. this.$refs.ruleForm.resetFields();
  305. this.$refs.ruleForm.clearValidate();
  306. if (this.sitem) {
  307. const {
  308. id,
  309. good_code,
  310. good_name, //商品名
  311. good_num, //采购数量
  312. lasttime, //最晚入库时间
  313. file_url,
  314. file_name,
  315. status,
  316. } = this.sitem;
  317. this.ruleForm = {
  318. id: id || "",
  319. good_code: good_code || "",
  320. good_name: good_name || "",
  321. goods_num: good_num || "0",
  322. lasttime: lasttime || "",
  323. file_url: file_url || "",
  324. file_url_name: file_name || "",
  325. status: status || "",
  326. };
  327. }
  328. }
  329. });
  330. },
  331. // 保存更改
  332. async submitForm() {
  333. await this.$refs.ruleForm.validate(async (valid) => {
  334. if (valid) {
  335. this.loading = true;
  336. let {
  337. id,
  338. good_code,
  339. good_type_code,
  340. goods_num,
  341. file_url,
  342. // file_name,
  343. // stock_code,
  344. lasttime,
  345. } = this.ruleForm;
  346. let model = {
  347. id: id,
  348. good_code,
  349. good_type_code,
  350. good_num: goods_num || "",
  351. file_url: file_url || "",
  352. // file_url_name: file_name || "",
  353. lastime: lasttime || "",
  354. };
  355. let res = {};
  356. if (this.id === "add") {
  357. delete model["id"];
  358. res = await asyncRequest.add(model);
  359. } else {
  360. res = await asyncRequest.update(model);
  361. }
  362. if (res && res.code === 0) {
  363. const title = this.id === "add" ? "添加成功" : "修改成功";
  364. this.$notify.success({
  365. title,
  366. message: "",
  367. });
  368. this.$emit("refresh");
  369. this.$emit("closeModel");
  370. } else if (res && res.code >= 100 && res.code <= 104) {
  371. await this.logout();
  372. } else {
  373. this.$message.warning(res.message);
  374. }
  375. this.loading = false;
  376. } else {
  377. console.log("error submit!!");
  378. return false;
  379. }
  380. });
  381. },
  382. //附件上传失败
  383. async UploadErrorEvent(e) {
  384. if (e !== "break") {
  385. this.$message.error("附件上传失败!");
  386. this.$refs.ruleForm.validateField("file_url");
  387. }
  388. },
  389. //附件上传成功
  390. async UploadSuccessEvent(data) {
  391. const { url, name } = data;
  392. if (url === "noToken") {
  393. await this.logout();
  394. } else {
  395. this.ruleForm.file_url_name = name;
  396. this.ruleForm.file_url = url;
  397. this.$message.success("附件上传成功!");
  398. this.$refs.ruleForm.validateField("file_url");
  399. }
  400. },
  401. //判断附件规格
  402. beforeAvatarUpload(file) {
  403. let isJPG = false,
  404. isLt2M = false;
  405. if (file) {
  406. if (file.type === "application/pdf") {
  407. isJPG = true;
  408. }
  409. isLt2M = file.size / 1024 / 1024 < 1;
  410. if (!isJPG) {
  411. this.$message.error("附件格式不正确!");
  412. }
  413. if (!isLt2M) {
  414. this.$message.error("附件大小不能超过 1MB!");
  415. }
  416. }
  417. return isJPG && isLt2M;
  418. },
  419. },
  420. };
  421. </script>
  422. <style lang="scss" scoped>
  423. .stockApply-com {
  424. .demo-ruleForm {
  425. .file_url {
  426. position: relative;
  427. width: 100%;
  428. -webkit-appearance: none;
  429. background-color: #ffffff;
  430. background-image: none;
  431. border-radius: 4px;
  432. border: 1px solid #dcdfe6;
  433. -webkit-box-sizing: border-box;
  434. box-sizing: border-box;
  435. color: #606266;
  436. display: inline-block;
  437. font-size: inherit;
  438. height: 40px;
  439. line-height: 40px;
  440. outline: none;
  441. //
  442. -webkit-transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  443. transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  444. width: 100%;
  445. p {
  446. // width: calc(100% - 100px);
  447. width: 100%;
  448. padding: 0 15px;
  449. overflow: hidden;
  450. color: #606266;
  451. &.no {
  452. color: #c0c4cc;
  453. }
  454. }
  455. &.disabled {
  456. p {
  457. background-color: #f5f7fa;
  458. border-color: #dfe4ed;
  459. cursor: not-allowed;
  460. color: #c0c4cc;
  461. }
  462. }
  463. .Upload {
  464. z-index: 5;
  465. // width: ;
  466. }
  467. .yulan {
  468. position: absolute;
  469. width: 50px;
  470. text-align: center;
  471. right: 0;
  472. top: 0;
  473. cursor: pointer;
  474. // background: chocolate;
  475. }
  476. }
  477. }
  478. }
  479. </style>