123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- <template>
- <div>
- <el-form
- :model="ruleForm"
- :rules="rulesThis"
- status-icon
- ref="ruleForm"
- label-width="80px"
- class="demo-ruleForm"
- >
- <el-row>
- <el-col :span="24">
- <el-form-item label="盘点公司" prop="wsm_supplier">
- <search-supplier
- :value="ruleForm.wsm_supplier"
- :placeholder="'请选择盘点公司'"
- @searchChange="supplierChange"
- />
- </el-form-item>
- </el-col>
- <el-col :span="24">
- <el-form-item label="盘点仓库" prop="wsm_code">
- <search-stock
- :value="ruleForm.wsm_code"
- :isDetail="true"
- :placeholder="'请选择盘点仓库'"
- :isRelation="true"
- :companyCode="companyCode"
- :names="''"
- @searchChange="stockChange"
- />
- </el-form-item>
- </el-col>
- <el-col :span="24">
- <el-form-item label="盘点类型" prop="type">
- <el-select
- v-model="ruleForm.type"
- placeholder="请选择盘点类型"
- style="width: 100%"
- >
- <el-option
- v-for="item in typeList"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- >
- </el-option>
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="24" style="text-align: right">
- <el-button type="primary" @click="submitForm" v-if="!isDetail"
- >保 存
- </el-button>
- </el-col>
- </el-row>
- </el-form>
- <search-good-modal
- :show-model="showGoodsModel"
- @cancel="showGoodsModel = false"
- @resultList="addGoodsRes"
- />
- </div>
- </template>
- <script>
- import asyncRequest from "@/apis/service/stock/check";
- import resToken from "@/mixins/resToken";
- import columns from "./columns";
- export default {
- name: "addEdit",
- props: ["id"],
- mixins: [resToken],
- data() {
- return {
- companyCode: "",
- loading: false,
- showGoodsModel: false,
- typeList: [
- {
- value: "1",
- label: "全盘",
- },
- {
- value: "2",
- label: "抽盘",
- },
- ],
- columns: columns,
- ruleForm: {
- wsm_supplier: [], //供应商
- wsm_code: [], // 盘点仓库
- type: "2", // 盘点类型
- // good_type_code: [], //商品列表
- },
- rulesThis: this.rules,
- rules: {
- wsm_supplier: [
- {
- type: "array",
- required: true,
- message: "请选择盘点公司",
- trigger: "change",
- },
- ],
- wsm_code: [
- {
- type: "array",
- required: true,
- message: "请选择盘点仓库",
- trigger: "change",
- },
- ],
- type: [
- {
- required: true,
- message: "请选择盘点类型",
- trigger: "change",
- },
- ],
- },
- };
- },
- created() {
- this.initForm();
- },
- watch: {
- id: function (val) {
- console.log(val);
- if (val) {
- this.initForm();
- }
- },
- },
- methods: {
- closeModel() {
- console.log("closeModel!!");
- },
- //供应商选择
- supplierChange(e) {
- if (e && e.id) {
- this.ruleForm.wsm_supplier = [e.code];
- this.companyCode = e.code;
- } else {
- this.ruleForm.wsm_supplier = [];
- this.companyCode = "";
- }
- this.ruleForm.wsm_code = [];
- this.$refs.ruleForm.validateField("wsm_supplier");
- this.$refs.ruleForm.validateField("wsm_code");
- },
- //仓库选择
- stockChange(e) {
- if (e && e.id) {
- this.ruleForm.wsm_code = [e.code];
- } else {
- this.ruleForm.wsm_code = [];
- }
- this.$refs.ruleForm.validateField("wsm_code");
- },
- deleteById(index) {
- this.ruleForm.good_type_code.splice(index, 1);
- this.$refs.ruleForm.validateField("good_type_code");
- },
- async initForm() {
- this.loading = true;
- if (this.id === "add") {
- this.rulesThis = this.rules;
- await this.resetForm();
- } else {
- this.rulesThis = this.rules;
- await this.resetForm();
- await this.initData();
- }
- this.loading = false;
- },
- async initData() {
- const res = await asyncRequest.detail({ id: this.id });
- if (res && res.code === 0 && res.data) {
- this.ruleForm = res.data;
- this.ruleForm.role_id = this.ruleForm.role;
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(res.message);
- }
- },
- async resetForm() {
- // 重置
- await this.$nextTick(() => {
- if (this.$refs.ruleForm) {
- this.$refs.ruleForm.resetFields();
- this.$refs.ruleForm.clearValidate();
- this.ruleForm = {
- wsm_supplier: [], // 盘点公司
- wsm_code: [], // 盘点仓库
- type: "2", // 真实姓名
- };
- }
- });
- },
- getId(list) {
- let arr = JSON.parse(JSON.stringify(list));
- return arr.join(",");
- },
- async submitForm() {
- await this.$refs.ruleForm.validate(async (valid) => {
- if (valid) {
- this.loading = true;
- const { wsm_code, type, good_type_code } = JSON.parse(
- JSON.stringify(this.ruleForm)
- );
- const model = {
- id: this.id,
- wsm_code: this.getId(wsm_code) || "", // 盘点仓库
- type: type || "", // 盘点类型
- };
- let res = {};
- if (this.id === "add") {
- delete model["id"];
- res = await asyncRequest.add(model);
- } else {
- res = await asyncRequest.update(model);
- }
- this.loading = false;
- if (res && res.code === 0) {
- const title = this.id === "add" ? "添加成功" : "修改成功";
- this.$notify.success({
- title,
- message: "",
- });
- // 刷新
- this.$emit("refresh");
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(res.message);
- }
- } else {
- console.log("error submit!!");
- return false;
- }
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .check {
- }
- </style>
-
|