<template>
  <div class="consultOrder pagePadding">
    <div
      v-if="powers && powers.length > 0 && powers.some((item) => item == '001')"
    >
      <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 #table-header="{}">
          <div style="width: 100%">
            <el-row style="padding: 0 0 0 80px">
              <el-col :span="24">
                <el-col :span="4" style="width: 120px">
                  <el-select
                    :size="searchSize"
                    v-model="parmValue.zxtype"
                    filterable
                    clearable
                    placeholder="咨询类型"
                    style="width: 100%"
                    @change="
                      pageInfo.curr = 1;
                      parmValue.page = 1;
                      searchList();
                    "
                  >
                    <el-option
                      v-for="item in statusList"
                      :key="'zxtype' + item"
                      :label="iteme"
                      :value="item"
                    />
                  </el-select>
                </el-col>
                <el-col :span="4" style="width: 150px; padding: 0 0 0 10px">
                  <el-input
                    :size="searchSize"
                    v-model="parmValue.name"
                    :maxlength="40"
                    placeholder="业务员姓名"
                  />
                </el-col>
                <el-col :span="4" style="width: 160px; padding: 0 0 0 10px">
                  <el-input
                    :size="searchSize"
                    v-model="parmValue.username"
                    :maxlength="40"
                    placeholder="手机号"
                  />
                </el-col>
                <el-col :span="4" style="width: 54px">
                  <el-button
                    :size="searchSize"
                    type="primary"
                    class="fr"
                    icon="el-icon-search"
                    @click="searchList"
                /></el-col>
                <el-col :span="4" style="width: 66px">
                  <el-button
                    type="warning"
                    class="fr"
                    :size="searchSize"
                    @click="restSearch"
                  >
                    重置
                  </el-button>
                </el-col>
                <el-col :span="3" style="width: 66px; float: right">
                  <el-button
                    :size="searchSize"
                    type="primary"
                    style="float: right; margin-left: 5px"
                    @click="searchList"
                  >
                    刷新
                  </el-button>
                </el-col>
              </el-col>
            </el-row>
          </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 #operation="{ scope }">
          <el-tooltip
            v-if="powers.some((item) => item == '007')"
            effect="dark"
            content="详情"
            placement="top"
          >
            <i
              class="el-icon-view tb-icon"
              @click="openModal(scope.row.id, true)"
            ></i>
          </el-tooltip>

          <el-tooltip
            v-if="powers.some((item) => item == '006')"
            effect="dark"
            content="删除"
            placement="top"
          >
            <i
              class="el-icon-delete tb-icon"
              @click="deleteById(scope.row.id, scope.row.status)"
            ></i>
          </el-tooltip>
        </template>
      </ex-table>
      <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 addEdit from "./addEdit";
import statusList from "@/assets/js/statusList";
import asyncRequest from "@/apis/service/sellOut/consultOrder";
import { mapGetters } from "vuex";

export default {
  name: "consultOrder",
  mixins: [mixinPage, resToken],
  components: {
    addEdit,
  },
  computed: {
    ...mapGetters(["tablebtnSize", "searchSize", "size"]),
    powers() {
      let tran =
        this.$store.getters.btnList.find(
          (item) => item.menu_route == "consultOrder"
        ) || {};
      if (tran && tran.action && tran.action.length > 0) {
        return tran.action;
      } else {
        return [];
      }
    },
  },
  data() {
    return {
      sitem: null,
      // 状态
      statusOptions: [
        { id: "0", label: "禁用" },
        { id: "1", label: "启用" },
      ],
      statusList: statusList,
      loading: true,
      showModel: false,
      isDetail: false,
      modelId: 0,
      parmValue: {
        name: "", // 业务员名字
        username: "", // 账号
        status: "", //
        page: 1, // 页码
        size: 15, // 每页显示条数
      },
      tableData: [],
      passwordModel: false,
      passwordModelId: 0,
      isPasswordDetail: false,
      // 表格 - 数据
      tableData: [],
      // 表格 - 参数
      table: {
        stripe: true,
        border: true,
        _defaultHeader_: ["setcol"],
      },
      // 表格 - 分页
      pageInfo: {
        size: 15,
        curr: 1,
        total: 0,
      },
      // 表格 - 列参数
      columns: [
        {
          prop: "zxNo",
          label: "咨询单号",
          fixed: "left",
          width: "152px",
        },
        {
          prop: "salesman",
          label: "申请人",
          width: "60px",
        },
        {
          prop: "khNo",
          label: "客户公司编码",
          width: "125px",
        },
        {
          prop: "khname",
          label: "客户公司名称",
          "min-width": "160px",
        },
        {
          prop: "zxtype",
          label: "咨询类型",
          width: "85px",
        },

        {
          prop: "cpname",
          label: "产品名称",
          "min-width": "160px",
        },
        {
          prop: "unit",
          label: "单位",
          width: "45px",
        },
        {
          prop: "num",
          label: "需求数量",
          width: "80px",
        },
        {
          prop: "sale_price",
          label: "财务定价",
          width: "110px",
        },
        {
          prop: "sale_fee",
          label: "最终销售单价",
          width: "110px",
        },

        {
          prop: "color",
          label: "颜色",
        },
        {
          prop: "model",
          label: "型号",
        },
        {
          prop: "material",
          label: "材质",
        },
        // {
        //   prop: "status",
        //   label: "状态",
        //   _slot_: "status",
        //   width: "80px",
        // },
        {
          prop: "scheme_name",
          label: "方案名称",
        },
        {
          prop: "zxtime",
          label: "创建时间",
          width: "140px",
        },
        {
          prop: "",
          label: "操作",
          fixed: "right",
          _noset_: true,
          width: "80px",
          _slot_: "operation",
        },
      ],
    };
  },
  mounted() {
    this.searchList();
  },

  methods: {
    restSearch() {
      this.parmValue = {
        name: "", // 业务员名字
        username: "", // 账号
        status: "", //
        page: 1, // 页码
        size: 10, // 每页显示条数
      };
      this.searchList();
    },
    openModal(id, isDetail) {
      this.showModel = true;
      this.modelId = id;
      this.isDetail = isDetail;
    },
    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.delete(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.tableData.map((v) => {
          v.sale_price = this.setNum(v.sale_price);
          v.sale_fee = this.setNum(v.sale_fee);
          // v.num =
          //pa (v.sale_price);
          return v;
        });
        //
        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;
    },
  },
};
</script>
   <style lang="scss" scoped>
.consultOrder {
}
</style>
   