addEdit.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template>
  2. <div>
  3. <el-form
  4. :model="ruleForm"
  5. :rules="rulesThis"
  6. status-icon
  7. ref="ruleForm"
  8. label-width="120px"
  9. class="demo-ruleForm"
  10. >
  11. <el-row>
  12. <el-col :span="type === '1' ? 12 : 24">
  13. <el-form-item label="商品分类" prop="goods_name">
  14. <good-class
  15. :value="ruleForm.goods_class"
  16. @handleChange="goods_class_change"
  17. :disabled="
  18. !(
  19. id === 'add' ||
  20. (status === '0' && powers.some((item) => item == '005'))
  21. )
  22. "
  23. :placeholder="'商品分类'"
  24. />
  25. </el-form-item>
  26. </el-col>
  27. <el-col :span="type === '1' ? 12 : 24">
  28. <el-form-item label="商品名称" prop="goods_name">
  29. <el-input
  30. :disabled="
  31. !(
  32. id === 'add' ||
  33. (status === '0' && powers.some((item) => item == '005'))
  34. )
  35. "
  36. v-model="ruleForm.goods_name"
  37. readonly="true"
  38. :placeholder="'商品名称'"
  39. @focus="hand"
  40. ></el-input>
  41. </el-form-item>
  42. </el-col>
  43. <!-- 采购数量 -->
  44. <el-col :span="type === '1' ? 12 : 24">
  45. <el-form-item label="采购数量" prop="goods_num">
  46. <el-input
  47. :disabled="
  48. !(
  49. id === 'add' ||
  50. (status === '0' && powers.some((item) => item == '005'))
  51. )
  52. "
  53. v-model="ruleForm.goods_num"
  54. placeholder="采购数量"
  55. ></el-input>
  56. </el-form-item>
  57. </el-col>
  58. <!-- 最晚入库时间 -->
  59. <el-col :span="type === '1' ? 12 : 24">
  60. <el-form-item label="最晚入库时间" prop="last_go_stock">
  61. <el-date-picker
  62. v-model="ruleForm.last_go_stock"
  63. type="date"
  64. style="width: 100%"
  65. value-format="yyyy-MM-dd HH:mm:ss"
  66. placeholder="选择日期"
  67. :picker-options="pickerOptions"
  68. @change="selectTime"
  69. :disabled="
  70. !(
  71. id === 'add' ||
  72. (status === '0' && powers.some((item) => item == '005'))
  73. )
  74. "
  75. >
  76. </el-date-picker>
  77. </el-form-item>
  78. </el-col>
  79. <!-- 供应商选择 -->
  80. <el-col :span="type === '1' ? 12 : 24">
  81. <el-form-item label="入库公司" prop="supplier_code">
  82. <search-supplier
  83. :disabled="
  84. !(
  85. id === 'add' ||
  86. (status === '0' && powers.some((item) => item == '005'))
  87. )
  88. "
  89. :value="ruleForm.supplier_code"
  90. :placeholder="'入库公司'"
  91. :names="''"
  92. @searchChange="selectSupplier"
  93. />
  94. </el-form-item>
  95. </el-col>
  96. <!-- 仓库名称 -->
  97. <el-col :span="type === '1' ? 12 : 24">
  98. <el-form-item label="入库仓库" prop="stock_code">
  99. <search-stock
  100. :disabled="!(id == 'add' || status === '0')"
  101. :value="ruleForm.stock_code"
  102. :placeholder="'入库仓库'"
  103. :isRelation="true"
  104. :names="''"
  105. :companyCode="companyCode"
  106. @searchChange="selectStock"
  107. />
  108. </el-form-item>
  109. </el-col>
  110. <el-col :span="24" style="text-align: right">
  111. <el-button
  112. type="primary"
  113. @click="submitForm"
  114. :size="'mini'"
  115. v-if="
  116. id === 'add' ||
  117. (status == '0' && powers.some((item) => item == '005'))
  118. "
  119. >保 存
  120. </el-button>
  121. </el-col>
  122. </el-row>
  123. </el-form>
  124. <search-stock-good-modal
  125. :once="true"
  126. :cat_id="cat_id"
  127. :show-model="showGoodsModel"
  128. @cancel="showGoodsModel = false"
  129. @searchChange="addGoodsRes"
  130. />
  131. </div>
  132. </template>
  133. <script>
  134. import resToken from "@/mixins/resToken";
  135. import asyncRequest from "@/apis/service/purchaseIn/storeManage";
  136. import { isnumber } from "@/utils/validate";
  137. import searchStockGoodModal from "@/components/search-stock-good-modal";
  138. export default {
  139. name: "storeManage",
  140. props: ["id", "sitem", "newTime", "type"],
  141. mixins: [resToken],
  142. components: { searchStockGoodModal },
  143. computed: {
  144. powers() {
  145. let tran =
  146. this.$store.getters.btnList.find(
  147. (item) => item.menu_route == "storeManageFlow"
  148. ) || {};
  149. if (tran && tran.action && tran.action.length > 0) {
  150. return tran.action;
  151. } else {
  152. return [];
  153. }
  154. },
  155. },
  156. watch: {
  157. newTime: function (val) {
  158. if (val) {
  159. this.initForm();
  160. }
  161. },
  162. },
  163. data() {
  164. const validateWeight = (rule, value, callback) => {
  165. if (value === "") {
  166. callback(new Error("不能为空!"));
  167. } else {
  168. if (!isnumber(value)) {
  169. callback(new Error("仅支持整数!"));
  170. } else {
  171. callback();
  172. }
  173. }
  174. };
  175. return {
  176. pickerOptions: {
  177. disabledDate(time) {
  178. return time.getTime() < Date.now();
  179. },
  180. },
  181. status: "",
  182. cat_id: "",
  183. routerId: "",
  184. stockCode: "",
  185. companyCode: "",
  186. showGoodsModel: "",
  187. loading: false,
  188. ruleForm: {
  189. id: "",
  190. goods_class: [],
  191. good_code: "",
  192. good_type_code: "",
  193. goods_name: "",
  194. goods_num: "",
  195. last_go_stock: "",
  196. supplier_code: [],
  197. supplier_name: "",
  198. stock_code: [],
  199. },
  200. rulesThis: this.rules,
  201. rules: {
  202. goods_class: [
  203. {
  204. type: "array",
  205. required: true,
  206. message: "请选择商品分类",
  207. trigger: "change",
  208. },
  209. ],
  210. //出入库规则
  211. goods_name: [
  212. {
  213. required: true,
  214. message: "商品名称不能为空",
  215. trigger: "blur",
  216. },
  217. ],
  218. goods_num: [
  219. {
  220. required: true,
  221. validator: validateWeight,
  222. trigger: "blur",
  223. },
  224. ],
  225. last_go_stock: [
  226. {
  227. required: true,
  228. message: "请输入入库最晚时间",
  229. trigger: "change",
  230. },
  231. ],
  232. supplier_code: [
  233. {
  234. type: "array",
  235. required: true,
  236. message: "请选择供入库公司",
  237. trigger: "change",
  238. },
  239. ],
  240. stock_code: [
  241. {
  242. type: "array",
  243. required: true,
  244. message: "请选择入库仓库",
  245. trigger: "change",
  246. },
  247. ],
  248. },
  249. };
  250. },
  251. created() {
  252. this.initForm();
  253. },
  254. methods: {
  255. async initForm() {
  256. this.loading = true;
  257. this.status = this.sitem !== undefined ? this.sitem.status : "";
  258. if (this.id === "add") {
  259. this.status = "";
  260. }
  261. this.rulesThis = this.rules;
  262. await this.resetForm();
  263. this.loading = false;
  264. },
  265. goods_class_change(e) {
  266. this.ruleForm.goods_class = e;
  267. this.cat_id = e.length > 0 ? e[e.length - 1] : "";
  268. this.$refs.ruleForm.validateField("goods_class");
  269. this.ruleForm.good_type_code = "";
  270. this.ruleForm.goods_name = "";
  271. this.ruleForm.goods_num = "";
  272. this.$refs.ruleForm.validateField("good_type_code");
  273. },
  274. // 最晚入库时间选择
  275. selectTime(e) {
  276. this.ruleForm.expecttime = e;
  277. },
  278. // 选择仓库
  279. selectStock(e) {
  280. if (e && e.id) {
  281. this.ruleForm.stock_code = [e.code];
  282. this.stockCode = e.code;
  283. } else {
  284. this.ruleForm.stock_code = [];
  285. this.stockCode = "";
  286. }
  287. this.$refs.ruleForm.validateField("stock_code");
  288. },
  289. // 选择供应商
  290. selectSupplier(e) {
  291. if (e && e.id) {
  292. this.ruleForm.supplier_code = [e.code];
  293. this.companyCode = e.code;
  294. } else {
  295. this.ruleForm.supplier_code = [];
  296. this.companyCode = "";
  297. this.ruleForm.stock_code = [];
  298. this.stockCode = "";
  299. }
  300. this.$refs.ruleForm.validateField("supplier_code");
  301. },
  302. // 执行点击商品名称的抛出事件
  303. addGoodsRes(e) {
  304. let { good_code, type_code, good_name } = e[0];
  305. this.ruleForm.goods_name = good_name;
  306. this.ruleForm.good_type_code = type_code;
  307. this.ruleForm.good_code = good_code;
  308. this.$refs.ruleForm.validateField("goods_name");
  309. },
  310. hand() {
  311. if (this.ruleForm.goods_class.length === 0) {
  312. this.$message.warning("请选择商品分类!");
  313. return;
  314. }
  315. this.showGoodsModel = true;
  316. },
  317. // 最晚入库时间选择
  318. selectTime(e) {
  319. this.ruleForm.last_go_stock = e;
  320. },
  321. closeModel() {
  322. this.$emit("closeModel");
  323. },
  324. // 重置
  325. async resetForm() {
  326. // 重置
  327. await this.$nextTick(() => {
  328. if (this.$refs.ruleForm) {
  329. this.$refs.ruleForm.resetFields();
  330. this.$refs.ruleForm.clearValidate();
  331. if (this.sitem) {
  332. const {
  333. id,
  334. good_code,
  335. good_type_code,
  336. good_name, //商品名
  337. good_num, //采购数量
  338. lasttime, //最晚入库时间
  339. wsm_code, //仓库名
  340. status,
  341. wsm_supplier,
  342. wsm_supplierNo,
  343. can,
  344. // 缺供应商
  345. } = this.sitem;
  346. this.companyCode = wsm_supplierNo;
  347. this.cat_id = can.length > can ? e[e.length - 1] : "";
  348. let goods_class = [];
  349. can.forEach((v) => {
  350. goods_class.push(v.id);
  351. });
  352. this.ruleForm = {
  353. id,
  354. goods_class: goods_class,
  355. good_code,
  356. good_type_code,
  357. goods_name: good_name,
  358. goods_num: good_num,
  359. last_go_stock: lasttime,
  360. supplier_code: [],
  361. stock_code: wsm_code.split(","),
  362. companyCode: wsm_supplierNo,
  363. supplier_name: wsm_supplierNo.split(","),
  364. supplier_code: wsm_supplier.split(","),
  365. status,
  366. };
  367. }
  368. }
  369. });
  370. },
  371. // 保存更改
  372. async submitForm() {
  373. await this.$refs.ruleForm.validate(async (valid) => {
  374. if (valid) {
  375. this.loading = true;
  376. let {
  377. id,
  378. good_code,
  379. good_type_code,
  380. goods_num,
  381. stock_code,
  382. last_go_stock,
  383. } = this.ruleForm;
  384. let model = {
  385. id: id,
  386. good_code,
  387. good_type_code,
  388. good_num: goods_num || "",
  389. wsm_code:
  390. this.id == "add" ? stock_code.toString() : stock_code.toString(),
  391. lastime: last_go_stock || "",
  392. };
  393. let res = {};
  394. if (this.id === "add") {
  395. delete model["id"];
  396. res = await asyncRequest.add(model);
  397. } else {
  398. res = await asyncRequest.update(model);
  399. }
  400. if (res && res.code === 0) {
  401. const title = this.id === "add" ? "添加成功" : "修改成功";
  402. this.$notify.success({
  403. title,
  404. message: "",
  405. });
  406. this.$emit("refresh");
  407. this.$emit("closeModel");
  408. } else if (res && res.code >= 100 && res.code <= 104) {
  409. await this.logout();
  410. } else {
  411. this.$message.warning(res.message);
  412. }
  413. this.loading = false;
  414. } else {
  415. console.log("error submit!!");
  416. return false;
  417. }
  418. });
  419. },
  420. // 发起申请
  421. async statusConfirm(status, message) {
  422. await this.$confirm(`确定要${message}?`, {
  423. confirmButtonText: "确定",
  424. cancelButtonText: "取消",
  425. type: "warning",
  426. })
  427. .then(async () => {
  428. if (status === "-1") {
  429. await this.deleteById(message);
  430. } else {
  431. await this.setStatus(status, message);
  432. }
  433. })
  434. .catch(() => {
  435. console.log("取消");
  436. });
  437. },
  438. // 作废该条信息
  439. async deleteById(message) {
  440. const res = await asyncRequest.delete({ id: this.routerId });
  441. if (res && res.code === 0) {
  442. this.$notify.success({
  443. title: message + "成功!",
  444. message: "",
  445. });
  446. this.routeGoto("storeManage", {});
  447. } else if (res && res.code >= 100 && res.code <= 104) {
  448. await this.logout();
  449. } else {
  450. this.$message.warning(res.message);
  451. }
  452. },
  453. // 状态修改
  454. async setStatus(status, message) {
  455. let model = {
  456. id: this.routerId,
  457. remark: "",
  458. status: status,
  459. };
  460. const res = await asyncRequest.status(model);
  461. this.loading = false;
  462. if (res && res.code === 0) {
  463. this.$notify.success({
  464. title: message + "成功!",
  465. message: "",
  466. });
  467. } else if (res && res.code >= 100 && res.code <= 104) {
  468. await this.logout();
  469. } else {
  470. this.$message.warning(res.message);
  471. }
  472. },
  473. },
  474. };
  475. </script>