<template>
  <div class="zixunOrder pagePadding">
    <ex-table
      v-loading="loading"
      :table="table"
      :data="tableData"
      :columns="columns"
      :page="pageInfo"
      :size="size"
      @page-curr-change="handlePageChange"
      @page-size-change="handleSizeChange"
      @screen-reset="
        pageInfo.curr = 1;
        parmValue.page = 1;
        searchList();
      "
      @screen-submit="
        pageInfo.curr = 1;
        parmValue.page = 1;
        searchList();
      "
    >
      <template #good_img="{ scope }">
        <div
          v-if="scope.row.good_img"
          style="width: 20px; height: 20px"
          class="hover"
          v-viewer
        >
          <img
            :src="scope.row.good_img"
            style="display: inline-block; width: 100%; height: 100%"
            alt=""
          />
        </div>
      </template>
      <template #status="{ scope }">
        <el-tag
          :size="tablebtnSize"
          :type="scope.row.status == '0' ? 'warning' : ''"
          v-text="
            (statusOptions.find((item) => item.id == scope.row.status) || {})
              .label || '--'
          "
        ></el-tag>
      </template>
      <template #specinfo="{ scope }">
        <span v-for="(si, sii) in scope.row.specinfo" :key="si.specid + sii">
          <span v-if="sii !== 0"></span>{{ si.spec_name }}[{{
            si.spec_value_name
          }}]</span
        >
      </template>

      <template #operation="{ scope }">
        <!-- <el-tooltip
            v-if="powers.some((item) => item == '007')"
            effect="dark"
            content="详情"
            placement="top"
          >
            <i
              class="el-icon-view tb-icon"
              @click="
                routeGoto('zixunOrderDetail', {
                  id: scope.row.infoNo,
                  type: 'view',
                })
              "
            ></i>
          </el-tooltip> -->
        <el-tooltip
          v-if="
            powers &&
            powers.length > 0 &&
            powers.some((item) => item == '068') &&
            !is_project
          "
          effect="dark"
          content="发起议价流程"
          placement="top"
        >
          <i
            class="el-icon-s-flag tb-icon"
            @click="wantBargaining(scope.row)"
          ></i>
        </el-tooltip>
      </template>
    </ex-table>
    <add-edit-bargain
      :showModel="wantBmodel"
      :sitem="wantBsitem"
      @cancel="wantBmodel = false"
      @refresh="(wantBmodel = false), searchList()"
    />
  </div>
</template>
   <script>
import mixinPage from "@/mixins/elPaginationHandle";
import resToken from "@/mixins/resToken";
import asyncRequest from "@/apis/service/sellOut/zixunOrder";
import { feedbackListCol } from "../columns";
import { mapGetters } from "vuex";
import addEditBargain from "./addEditBargain";

export default {
  name: "zixunOrder",
  mixins: [mixinPage, resToken],
  props: ["id", "newTime", "sitem"],
  components: {
    addEditBargain,
  },
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "zixunOrderDetail"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      wantBmodel: false,
      wantBsitem: "",
      select: "1",
      s_input: "",
      is_project: false,
      customerCode: [], //客户公司code
      options: [
        { id: "0", label: "待发布竞标" },
        { id: "1", label: "招标进行中" },
        { id: "2", label: "招标已结束" },
        { id: "3", label: "等待议价结果" },
        { id: "4", label: "待选择商品" },
        { id: "5", label: "已成功转单" },
        { id: "6", label: "已取消转单" },
        { id: "7", label: "招标已暂停" },
      ],
      post_ownOptions: [
        { id: "1", label: "客户承担" },
        { id: "2", label: "公司承担" },
        { id: "3", label: "供应商承担" },
      ],
      sitem: null,
      // 状态
      statusOptions: [
        { id: "0", label: "待审核" },
        { id: "1", label: "待物流反馈" },
        { id: "3", label: "待退货" },
        { id: "4", label: "已退货" },
        { id: "5", label: "待客户验收" },
      ],
      loading: true,
      showModel: false,
      isDetail: false,
      modelId: 0,
      parmValue: {
        zxNo: "",
        infoNo: "",
        bidNo: "",
        projectNo: "",
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        // _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: feedbackListCol,
      serviceOptions: [
        {
          value: "0",
          label: "待审核",
        },
        {
          value: "1",
          label: "待物流反馈",
        },
        {
          value: "2",
          label: "待退货",
        },
        {
          value: "3",
          label: "已退货",
        },
      ],
      serviceValue: "", //售后申请处理状态
      expectOptions: [
        {
          value: "1",
          label: "退货",
        },
        {
          value: "2",
          label: "换货",
        },
        {
          value: "3",
          label: "改变售价",
        },
      ],
      expectValue: "", //期望意愿
      resultOptions: [
        {
          value: "ad",
          label: "处理中",
        },
        {
          value: "选项2",
          label: "已同意",
        },
        {
          value: "选项2",
          label: "已驳回",
        },
      ],
      resultValue: "", //处理结果
    };
  },
  mounted() {
    console.log(this.sitem);
    const { is_project } = this.sitem;
    this.is_project = is_project;
    this.searchList();
  },

  methods: {
    restSearch() {
      this.parmValue = {
        zxNo: "",
        infoNo: "",
        bidNo: "",
        projectNo: "",
        page: 1, // 页码
        size: 15, // 每页显示条数
      };
      // 表格 - 分页
      this.pageInfo = {
        size: 15,
        curr: 1,
        total: 0,
      };
      this.searchList();
    },

    wantBargaining(row) {
      this.wantBsitem = row;
      this.wantBmodel = true;
    },
    openModal(id, isDetail, sitem) {
      this.showModel = true;
      this.modelId = id;
      this.isDetail = isDetail;
      this.sitem = sitem;
    },

    // 列表搜索
    async searchList() {
      this.loading = true;
      this.parmValue.infoNo = this.id;

      const res = await asyncRequest.feedList(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 handleTime(e) {
      if (e.startTime !== "") {
        this.parmValue.start = e.startTime;
      } else {
        this.parmValue.start = "";
      }
      if (e.endTime !== "") {
        this.parmValue.end = e.endTime;
      } else {
        this.parmValue.end = "";
      }
      if (this.parmValue.start !== "" && this.parmValue.end !== "") {
        this.pageInfo.curr = 1;
        this.parmValue.page = 1;
        await this.searchList();
      }
    },
    async customerChange(e) {
      if (e && e.id) {
        this.customerCode = [e.code];
        this.parmValue.customer_code = e.code;
      } else {
        this.customerCode = [];
        this.parmValue.customer_code = "";
      }
      this.pageInfo.curr = 1;
      this.parmValue.page = 1;
      await this.searchList();
    },
  },
};
</script>
   <style lang="scss" scoped>
.zixunOrder {
}
</style>
   