<template>
  <div class="newApply pagePadding">
    出库方发货{{ myType }}

    <div
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
    >
      <el-form
        :disabled="myType !== 3"
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="150px"
      >
        <el-form-item label="发货物流公司" prop="expressage_company">
          <el-select
            v-model="value"
            placeholder="请选择发货公司"
            :size="searchSize"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="发货物流编号" prop="expressage_sn">
          <el-input
            type="number"
            :rows="2"
            style="width: 30%"
            placeholder="请输入物流单号"
            :size="searchSize"
            v-model="expressage"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item label="发货物流费用" prop="expressage_cost">
          <el-input
            type="number"
            style="width: 20%"
            placeholder="请输入物流费用"
            :size="searchSize"
            v-model="expressage_cost"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-col :span="24" style="text-align: right; margin-top: 10px">
            <el-button type="primary" @click="save" v-show="myType === 3"
              >保 存
            </el-button>
            <!-- <el-button type="warning" @click="submitForm"
              >保 存 并 发 起 流 程
            </el-button> -->
          </el-col>
        </el-form-item>
      </el-form>

      <add-edit
        :id="modelId"
        :sitem="sitem"
        :show-model="showModel"
        :is-detail="isDetail"
        @refresh="searchList"
        @cancel="showModel = false"
      />
    </div>
    <div v-else>
      <no-auth></no-auth>
    </div>
  </div>
</template>
   <script>
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import ExTable from "@/components/ExTableNew.vue";
import statusList from "@/assets/js/statusList";
// import asyncRequest from "@/apis/service/stock/newApply";
import asyncRequest from "@/mock/service/stock/newApply";
import addEdit from "./addEdit-newApply";
import { mapGetters } from "vuex";

export default {
  name: "allotFlow",
  mixins: [mixinPage, resToken],
  props: ["myType"],
  components: {
    addEdit,
    ExTable,
  },
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "allotFlow"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      options: [
        {
          value: "选项1",
          label: "顺丰",
        },
        {
          value: "选项2",
          label: "韵达",
        },
        {
          value: "选项3",
          label: "中通",
        },
      ],
      value: "",
      // selectStock_in: "", //选择的入库仓库名称
      // selectStock_go: "", //选择的出库仓库名称
      // stock_go: "", //出库仓库name
      // stock_in: "", //入库仓库name
      //   options: [], //用于渲染二级仓库名
      ruleForm: {},
      rules: {
        //出入库规则
        expressage_company: [
          {
            required: true,
            message: "请选择发货公司",
            trigger: "blur",
          },
        ],
        expressage_sn: [
          {
            required: true,
            message: "请输入物流单号",
            trigger: "blur",
          },
        ],
        expressage_cost: [
          {
            required: true,
            message: "请输入物流费用",
            trigger: "blur",
          },
        ],
      },
      expressage: "",
      expressage_cost: 0,
      loading: true,
      showModel: false,
      isDetail: false,
      modelId: 0,
      tableData: [], //渲染表格
      //
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        // _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: [
        {
          prop: "nickname",
          label: "商品编号",
        },
        {
          prop: "role_name",
          label: "商品名称",
        },
        {
          prop: "mobile",
          label: "数量",
        },
        {
          prop: "",
          label: "操作",
          fixed: "right",
          _noset_: true,
          _slot_: "operation",
        },
      ],
      // sitem: null,
      // // 状态
      // statusOptions: [
      //   { id: "0", label: "禁用" },
      //   { id: "1", label: "启用" },
      // ],
      parmValue: {
        //入参
        // name: "", // 业务员名字
        // username: "", // 账号
        // status: "", //
        // page: 1, // 页码
        // size: 15, // 每页显示条数
      },
      // passwordModel: false,
      // passwordModelId: 0,
      // isPasswordDetail: false,
      // statusList: statusList,
    };
  },
  mounted() {
    this.searchList();
    // this.stockName(); //假数据,获取二级仓库名
  },

  methods: {
    restSearch() {
      //重置入参
      this.parmValue = {
        // name: "", // 业务员名字
        // username: "", // 账号
        // status: "", //
        // page: 1, // 页码
        // size: 10, // 每页显示条数
      };
      this.searchList();
    },

    openModal(id, isDetail, sitem) {
      this.showModel = true;
      this.modelId = id;
      this.isDetail = isDetail;
      this.sitem = sitem;
    },
    async deleteById(id, status) {
      // await this.$confirm("确定要删除？", {
      //   confirmButtonText: "确定",
      //   cancelButtonText: "取消",
      //   type: "warning",
      // })
      //   .then(async () => {
      //     const model = {
      //       id: id,
      //       status: status === "1" ? "0" : "1",
      //     };
      //     const res = await asyncRequest.status(model);
      //     if (res && res.code === 0) {
      //       this.$notify.success({
      //         title: "删除成功",
      //         message: "",
      //       });
      //       this.searchList();
      //     } else if (res && res.code >= 100 && res.code <= 104) {
      //       await this.logout();
      //     } else {
      //       this.$message.warning(res.message);
      //     }
      //   })
      //   .catch(() => {
      //     console.log("取消");
      //   });
    },
    async searchList() {
      // this.loading = true;
      // const res = await asyncRequest.list(this.parmValue);
      // if (res && res.code === 0 && res.data) {
      //   this.tableData = res.data.list;
      //   this.pageInfo.total = Number(res.data.count);
      // } else if (res && res.code >= 100 && res.code <= 104) {
      //   await this.logout();
      // } else {
      //   this.tableData = [];
      //   this.pageInfo.total = 0;
      // }
      // this.loading = false;
    },

    async statusConfirm(id, status) {
      // let str = status === "1" ? "禁用" : "启用";
      // await this.$confirm("确定要改为" + str + "?", {
      //   confirmButtonText: "确定",
      //   cancelButtonText: "取消",
      //   type: "warning",
      // })
      //   .then(async () => {
      //     this.loading = true;
      //     const model = {
      //       id: id,
      //       status: status === "1" ? "0" : "1",
      //     };
      //     const res = await asyncRequest.status(model);
      //     if (res && res.code === 0) {
      //       this.loading = false;
      //       this.$notify.success({
      //         title: "状态修改成功！",
      //         message: "",
      //       });
      //       await this.searchList();
      //     } else if (res && res.code >= 100 && res.code <= 104) {
      //       await this.logout();
      //     } else {
      //       this.$message.warning(res.message);
      //     }
      //   })
      //   .catch(() => {
      //     console.log("取消");
      //   });
    },
    // async stockName() {
    //   //获取多级仓库名称的方法
    //   const res = await asyncRequest.listAll(this.parmValue);
    //   // console.log(res.data);
    //   // this.openModal("005", true);
    //   // console.log(this.selectStock_go);
    //   // console.log(this.selectStock_in);
    //   // this.options = res.data;
    //   // console.log(this.options);
    //   let arr = res.data;
    //   // console.log(arr);
    //   arr.forEach((ele) => {
    //     //重新封装后台传递来的数据,转换格式
    //     let item = {
    //       value: ele.id,
    //       label: ele.name,
    //       children: [],
    //     };
    //     ele.child.forEach((elem) => {
    //       let model = {
    //         value: elem.id,
    //         label: elem.name,
    //       };
    //       item.children.push(model);
    //     });
    //     this.options.push(item);
    //   });
    //   this.options.forEach((ele) => {
    //     //从数据表中筛选出我们要用的数据
    //     if (ele.value === this.selectStock_go[0]) {
    //       ele.children.forEach((elem) => {
    //         if (elem.value === this.selectStock_go[1]) {
    //           this.stock_go = ele.label + "/" + elem.label;
    //         }
    //       });
    //     }
    //     if (ele.value === this.selectStock_in[0]) {
    //       ele.children.forEach((elem) => {
    //         if (elem.value === this.selectStock_in[1]) {
    //           this.stock_in = ele.label + "/" + elem.label;
    //         }
    //       });
    //     }
    //   });
    //   if (this.selectStock_in != "" || this.selectStock_go != "") {
    //     console.log("选择了一个项目");
    //     this.openModal("005", true);
    //   }
    //   // console.log(this.stock_go);
    //   // console.log(this.stock_in);
    //   // console.log(this.pageInfo.total);
    //   this.compareStock(); //比较出库仓库和入库仓库是否相同
    // },

    compareStock() {
      //比较出库仓库和入库仓库是否相同
      if (
        this.stock_go === this.stock_in &&
        this.stock_go !== "" &&
        this.stock_go != ""
      ) {
        console.log("出库仓库和入库仓库相同");
        this.$message({
          message: "出库仓库不能和入库仓库相同",
          type: "error",
        });
      }
    },
  },
};
</script>
   <style lang="scss" >
.newApply {
}
.el-form-item__content {
  margin: 0 !important;
}
.setcol-table-lie {
  // margin: 0 !important;
}
</style>
   