<template>
    <div class="testdiv">
        <!-- 查询条件 -->
        <div class="divborder newSearchDiv" style="margin: 0px">
            <div class="filter">
                <label>{{ $t("600539") }}：</label>
                <Input class="searchInput" type="text" v-model="title" />
            </div>
            <div class="filter">
                <label>{{ $t("900253") }}：</label>
                <Select class="searchSelect" v-model="mid" clearable>
                    <Option
                        v-for="item in creatorlist"
                        :value="item.id"
                        :key="item.id"
                        >{{ item.nickname }}</Option
                    >
                </Select>
            </div>
            <div class="filter">
                <label>{{ $t("900525") }}：</label>
                <Select class="searchSelect" v-model="companyid" clearable>
                    <Option
                        v-for="item in companylist"
                        :value="item.id"
                        :key="item.id"
                        >{{ item.chinesename }}</Option
                    >
                </Select>
            </div>
            <div class="filter">
                <label>{{ $t("900254") }}：</label>
                <Select class="searchSelect" v-model="dutymid" clearable>
                    <Option
                        v-for="item in dutylist"
                        :value="item.id"
                        :key="item.index"
                        >{{ item.realname }}</Option
                    >
                </Select>
            </div>
            <!-- 二级隐藏 -->
            <div v-show="morecondition">
                <div class="filter">
                    <label>{{ $t("800184") }}：</label>
                    <Select class="searchSelect" v-model="salesmid" clearable>
                        <Option
                            v-for="item in salelist"
                            :value="item.id"
                            :key="item.index"
                            >{{ item.nickname }}</Option
                        >
                    </Select>
                </div>
                <div class="filter">
                    <label>{{ $t("900672") }}：</label>
                    <Select class="searchSelect" v-model="typeid" clearable>
                        <Option
                            v-for="item in projecttypelist"
                            :value="item.id"
                            :key="item.id"
                            >{{ item.name }}</Option
                        >
                    </Select>
                </div>
            </div>
            <!-- 按钮 -->
            <div class="searchBtn">
                <Button
                    type="primary"
                    class="twoWord"
                    icon="ios-search"
                    @click="handdlesearch"
                    >{{ $t("1001") }}</Button
                >
                <!-- <Button
                    type="success"
                    class="twoWord"
                    icon="md-add-circle"
                    @click="add"
                    >新项目注册</Button
                > -->
                <Button
                    type="success"
                    class="twoWord"
                    icon="md-add-circle"
                    @click="add"
                    >{{$t(1002)}}</Button
                >
                <Button
                    type="warning"
                    class="twoWord"
                    icon="ios-create-outline"
                    @click="edit"
                    >{{ $t("1003") }}</Button
                >
                <Button
                    type="error"
                    class="twoWord"
                    icon="md-close-circle"
                    @click="del"
                    >{{ $t("1004") }}</Button
                >
            </div>
            <!-- 更多条件 按钮 -->
            <MoreConbtn
                @getCon="morecondition = !morecondition"
                :morecondition="morecondition"
            ></MoreConbtn>
        </div>
        <!-- 数据展示 -->
        <div class="divborder newTableDiv">
            <Table
                @on-current-change="handleRowChange"
                highlight-row
                :data="tableData"
                :columns="tableColumns"
                class="tableClass"
            ></Table>
            <div class="pageDiv">
                <div class="pageDirection">
                    <Page
                        :total="total"
                        :current="page"
                        @on-change="changePage"
                        show-elevator
                        show-sizer
                        show-total
                        @on-page-size-change="handlePageSize"
                        :page-size-opts="[10, 20, 30, 40, 100]"
                    ></Page>
                </div>
            </div>
        </div>
        <!-- 添加 -->
        <Modal
            class="newModalClass newModalClass1"
            v-model="addmodal"
            :styles="{ width: '640px' }"
        >
            <p slot="header">
                <span v-if="type === 1">{{ $t("1002") }}</span>
                <!-- <span v-if="type === 2">{{ $t("1003") }}</span> -->
            </p>
            <div class="modal_body">
                <div>
                    <div v-show="step == 1">
                        <div>
                            <Button
                                size="large"
                                style="
                                    background-color: #2d8cf0;
                                    color: #fff;
                                    margin-right: 20px;
                                "
                                @click="newClient"
                                >新客户</Button
                            >
                            <Button
                                size="large"
                                style="background-color: #797979; color: #fff"
                                @click="oldClient"
                                >旧客户</Button
                            >
                        </div>
                        <div
                            v-show="businesstype == 1"
                            style="margin-top: 20px"
                        >
                            <div class="filter">
                                <label> <i>*</i> 客户名称： </label>
                                <Select
                                    class="searchSelect"
                                    v-model="cilentDetail.cid"
                                    label-in-value
                                    @on-change="getOldCilent"
                                    clearable
                                >
                                    <Option
                                        v-for="item in companylist"
                                        :value="item.id"
                                        :key="item.id"
                                        >{{ item.chinesename }}</Option
                                    >
                                </Select>
                            </div>
                        </div>
                        <div v-show="businesstype == 0">
                            <div class="stepTitle">客户资料</div>
                            <div class="filter">
                                <label> <i>*</i> 客户名称： </label>
                                <Input
                                    class="searchInput"
                                    type="text"
                                    v-model="cilentDetail.name"
                                    required="required"
                                />
                            </div>
                            <div class="filter">
                                <label>英文名称：</label>
                                <Input
                                    class="searchInput"
                                    type="text"
                                    v-model="cilentDetail.nameEn"
                                />
                            </div>
                            <div class="filter">
                                <label>
                                    <i>*</i>
                                    客户地址：
                                </label>

                                <Select
                                    v-model="cilentDetail.province"
                                    label-in-value
                                    @on-change="provincechange"
                                    clearable
                                    class="searchSelect"
                                >
                                    <Option
                                        v-for="item in provincelist"
                                        :value="item.code"
                                        :key="item.id"
                                        >{{ item.name }}</Option
                                    >
                                </Select>
                                <Select
                                    v-model="cilentDetail.city"
                                    label-in-value
                                    @on-change="citychange"
                                    clearable
                                    class="searchSelect"
                                    style="margin-left: 10px"
                                >
                                    <Option
                                        v-for="item in addcitylist"
                                        :value="item.code"
                                        :key="item.id"
                                        >{{ item.name }}</Option
                                    >
                                </Select>
                                <Select
                                    class="searchSelect"
                                    v-model="cilentDetail.area"
                                    label-in-value
                                    clearable
                                    style="margin-left: 10px"
                                >
                                    <Option
                                        v-for="item in addcountylist"
                                        :value="item.code"
                                        :key="item.id"
                                        >{{ item.name }}</Option
                                    >
                                </Select>
                            </div>
                            <div class="filter">
                                <label>
                                    <i>*</i>
                                    {{ $t(600572) }}：
                                </label>
                                <Input
                                    class="searchInput"
                                    type="text"
                                    v-model="cilentDetail.address"
                                />
                            </div>
                            <div class="filter">
                                <label>
                                    <i>*</i>
                                    {{ $t(600573) }}：
                                </label>
                                <Input
                                    class="searchInput"
                                    type="text"
                                    v-model="cilentDetail.contacts"
                                />
                            </div>
                            <div class="filter">
                                <label>
                                    <i>*</i>
                                    联系电话：
                                </label>
                                <Input
                                    class="searchInput"
                                    type="tel"
                                    v-model="cilentDetail.phone"
                                />
                            </div>
                            <div class="filter">
                                <label> <i>*</i>电子邮箱： </label>
                                <Input
                                    class="searchInput"
                                    type="email"
                                    v-model="cilentDetail.email"
                                />
                            </div>
                            <div class="filter">
                                <label>{{ $t(600577) }}：</label>
                                <Input
                                    class="searchInput"
                                    type="text"
                                    v-model="cilentDetail.companycode"
                                />
                            </div>
                            <div class="filter">
                                <label>{{ $t(600575) }}：</label>
                                <Select
                                    v-model="cilentDetail.industrycategory"
                                    label-in-value
                                    @on-change="addIndustrychange"
                                    clearable
                                    class="searchSelect"
                                >
                                    <Option
                                        v-for="item in Industrylist"
                                        :value="item.id"
                                        :key="item.id"
                                        >{{ item.name }}</Option
                                    >
                                </Select>
                            </div>
                            <div class="filter">
                                <label>{{ $t(1218) }}：</label>
                                <Select
                                    v-model="cilentDetail.industrysecond"
                                    label-in-value
                                    clearable
                                    class="searchSelect"
                                >
                                    <Option
                                        v-for="item in Industrysonlist"
                                        :value="item.id"
                                        :key="item.id"
                                        >{{ item.name }}</Option
                                    >
                                </Select>
                            </div>

                            <div style="display: flex">
                                <label>{{ $t(600528) }}：</label>
                                <div class="uploadMax">
                                    <img :src="loadimg" alt />
                                    <input
                                        type="file"
                                        name
                                        ref="fileIntimg"
                                        id
                                        @change="unloadimg"
                                        accept="image/png, image/gif, image/jpeg"
                                    />
                                </div>
                            </div>
                        </div>
                    </div>
                    <div v-show="step == 2">
                        <p class="stepTitle">项目资料</p>
                        <div class="filter">
                            <label><i>*</i>{{ $t("600539") }}：</label>
                            <Input
                                v-model="projectDetail.title"
                                class="searchInput"
                                type="text"
                            />
                        </div>
                        <div class="filter">
                            <label><i>*</i>{{ $t("900672") }}：</label>
                            <Select
                                v-model="projectDetail.typeid"
                                label-in-value
                                clearable
                                class="searchSelect"
                            >
                                <Option
                                    v-for="item in projecttypelist"
                                    :value="item.id"
                                    :key="item.id"
                                    >{{ item.name }}</Option
                                >
                            </Select>
                        </div>

                        <div class="filter">
                            <label><i>*</i>销售人员：</label>
                            <Select
                                v-model="projectDetail.salesmid"
                                label-in-value
                                clearable
                                class="searchSelect"
                            >
                                <Option
                                    v-for="item in creatorlist"
                                    :value="item.id"
                                    :key="item.id"
                                    >{{ item.nickname }}</Option
                                >
                            </Select>
                        </div>
                        <div class="filter">
                            <label><i>*</i>{{ $t("600543") }}：</label>
                            <Input
                                v-model="projectDetail.realname"
                                class="searchInput"
                                type="text"
                            />
                        </div>
                        <div class="filter">
                            <label><i>*</i>登陆{{ $t("600544") }}：</label>
                            <Input
                                v-model="projectDetail.account"
                                class="searchInput"
                                type="text"
                            />
                        </div>
                        <div class="filter">
                            <label> <i>*</i>登陆{{ $t("1016") }}： </label>
                            <Input
                                v-model="projectDetail.password"
                                class="searchInput"
                                type="password"
                            />
                        </div>
                        <div class="filter">
                            <label>{{ $t("600545") }}：</label>
                            <InputNumber
                                v-model="projectDetail.initialoffer"
                                class="searchInput"
                                :min="0"
                            ></InputNumber>
                        </div>
                        <div class="filter">
                            <label>{{ $t("600546") }}：</label>
                            <InputNumber
                                v-model="projectDetail.finaloffer"
                                :min="0"
                                class="searchInput"
                            >
                            </InputNumber>
                        </div>
                        <div class="filter" style="margin-bottom: 10px">
                            <label>{{ $t("600540") }}：</label>
                            <Input
                                type="textarea"
                                v-model="projectDetail.description"
                                class="MaxWidth"
                                style="vertical-align: text-top"
                                :autosize="{ minRows: 2, maxRows: 2 }"
                            />
                        </div>
                        <!-- <div class="filter">
                            <label><i>*</i>{{ $t("950041") }}：</label>
                            <Select
                                :max-tag-count="8"
                                v-model="addobj.modular"
                                label-in-value
                                clearable
                                class="searchSelect MaxWidth nowropStyle"
                                style="overflow-y: scorll; margin-top: 10px"
                                multiple
                            >
                                <Option
                                    v-for="item in modularlist"
                                    :value="item.value"g
                                    :key="item.id"
                                    >{{ $t(item.name) }}</Option
                                >
                            </Select>
                        </div> -->
                    </div>
                    <div v-show="step == 3">
                        <p class="stepTitle">产线层级</p>
                        <div>
                            <Table
                                highlight-row
                                :data="tableData1"
                                :columns="tableColumns1"
                                :max-height="396"
                                @on-selection-change="getProjectList"
                            ></Table>
                        </div>
                    </div>
                    <div v-show="step == 4">
                        <p class="stepTitle">用户授权管理</p>

                        <div style="margin: 10px; padding-left: 30px">
                            <RadioGroup v-model="licenceobj.type">
                                <Radio
                                    :label="1"
                                    style="
                                        font-size: 16px;
                                        width: 150px !important;
                                    "
                                >
                                    <span>永久授权</span>
                                </Radio>
                                <Radio
                                    :label="2"
                                    style="
                                        font-size: 16px;
                                        width: 150px !important;
                                    "
                                    ><span>按时间授权</span></Radio
                                >
                            </RadioGroup>
                        </div>
                        <div>
                            <div class="filter" style="height: 165px">
                                <label>{{ $t("920020") }}：</label>
                                <Input
                                    v-model="licenceobj.values"
                                    type="textarea"
                                    :autosize="{ minRows: 5, maxRows: 5 }"
                                    placeholder="请输入系统授权码"
                                    class="searchInput MaxWidth"
                                />
                            </div>
                        </div>
                        <div>
                            <div class="filter" style="height: 165px">
                                <label>MySql配置：</label>
                                <Input
                                    v-model="licenceobj.mysql"
                                    type="textarea"
                                    :autosize="{ minRows: 5, maxRows: 5 }"
                                    placeholder="请输入MySQL授权码"
                                    class="searchInput MaxWidth"
                                />
                            </div>
                            <!-- <div class="searchBtn" style="margin-left: 105px">
                                <Button
                                    type="primary"
                                    class="twoWord"
                                    icon="ios-build"
                                    @click="save(1)"
                                    >{{ $t("900306") }}</Button
                                >
                            </div> -->
                        </div>
                    </div>
                    <div v-show="step == 5">
                        <p class="stepTitle">账户创建完成</p>
                        <div>
                            <div>账号已创建成功,去登陆验证功能吧！</div>
                            <div>登录账号：</div>
                            <div>登陆密码：</div>
                        </div>
                    </div>
                </div>
            </div>
            <div slot="footer">
                <Button
                    type="primary"
                    size="large"
                    @click="lastStep"
                    v-show="step != 5 && step > 1"
                    >上一步</Button
                >
                <Button
                    type="primary"
                    size="large"
                    @click="nextStep"
                    v-show="step != 5"
                    >下一步</Button
                >
                <Button
                    type="primary"
                    size="large"
                    @click="addmodal = false"
                    v-show="step == 5"
                    >完成</Button
                >
                <!-- <Button type="text" size="large" @click="cancle">取消</Button> -->
                <!-- <Button
                    type="primary"
                    v-if="type === 1"
                    size="large"
                    @click="adddata(1)"
                    >{{ $t("1002") }}</Button
                >
                <Button
                    type="primary"
                    v-if="type === 2"
                    size="large"
                    @click="adddata(2)"
                    >{{ $t("1003") }}</Button
                > -->
            </div>
        </Modal>
        <!-- 编辑 -->
        <Modal
            class="newModalClass"
            v-model="editshow"
            :styles="{ width: '600px' }"
        >
            <p slot="header">
                <span v-if="type === 1">{{ $t("1002") }}</span>
                <span v-if="type === 2">{{ $t("1003") }}</span>
            </p>
            <div class="modal_body">
                <div class="filter">
                    <label><i>*</i>PID：</label>
                    <Input
                        v-if="type === 1"
                        v-model="addobj.projectid"
                        class="searchInput"
                        type="number"
                    />
                    <Input
                        v-if="type === 2"
                        disabled
                        v-model="addobj.projectid"
                        class="searchInput"
                        type="number"
                    />
                </div>
                <div class="filter">
                    <label><i>*</i>{{ $t("600539") }}：</label>
                    <Input
                        v-model="addobj.title"
                        class="searchInput"
                        type="text"
                    />
                </div>
                <div class="filter">
                    <label><i>*</i>{{ $t("900672") }}：</label>
                    <Select
                        v-model="addobj.typeid"
                        label-in-value
                        clearable
                        class="searchSelect"
                    >
                        <Option
                            v-for="item in projecttypelist"
                            :value="item.id"
                            :key="item.id"
                            >{{ item.name }}</Option
                        >
                    </Select>
                </div>
                <div class="filter">
                    <label><i>*</i>{{ $t("600541") }}：</label>
                    <Select
                        v-model="addobj.companyid"
                        label-in-value
                        clearable
                        class="searchSelect"
                    >
                        <Option
                            v-for="item in companylist"
                            :value="item.id"
                            :key="item.id"
                            >{{ item.chinesename }}</Option
                        >
                    </Select>
                </div>
                <div class="filter">
                    <label><i>*</i>{{ $t("600542") }}：</label>
                    <Select
                        v-model="addobj.salesmid"
                        label-in-value
                        clearable
                        class="searchSelect"
                    >
                        <Option
                            v-for="item in creatorlist"
                            :value="item.id"
                            :key="item.id"
                            >{{ item.nickname }}</Option
                        >
                    </Select>
                </div>
                <div class="filter">
                    <label><i>*</i>{{ $t("600543") }}：</label>
                    <Input
                        v-model="addobj.realname"
                        class="searchInput"
                        type="text"
                    />
                </div>
                <div class="filter">
                    <label><i>*</i>{{ $t("600544") }}：</label>
                    <Input
                        v-model="addobj.mobile"
                        class="searchInput"
                        type="text"
                    />
                </div>
                <div class="filter">
                    <label> <i>*</i>{{ $t("1016") }}： </label>
                    <Input
                        v-model="addobj.password"
                        class="searchInput"
                        type="password"
                    />
                </div>
                <div class="filter">
                    <label>{{ $t("600545") }}：</label>
                    <Input
                        v-model="addobj.initialquotation"
                        class="searchInput"
                        type="number"
                    />
                </div>
                <div class="filter">
                    <label>{{ $t("600546") }}：</label>
                    <Input
                        v-model="addobj.finaloffer"
                        class="searchInput"
                        type="number"
                    />
                </div>
                <div class="filter" style="margin-bottom: 10px">
                    <label>{{ $t("600540") }}：</label>
                    <Input
                        type="textarea"
                        v-model="addobj.description"
                        class="MaxWidth"
                        style="vertical-align: text-top"
                        :autosize="{ minRows: 2, maxRows: 2 }"
                    />
                </div>
                <div class="filter">
                    <label><i>*</i>{{ $t("950041") }}：</label>
                    <Select
                        :max-tag-count="8"
                        v-model="addobj.modular"
                        label-in-value
                        clearable
                        class="searchSelect MaxWidth nowropStyle"
                        style="overflow-y: scorll; margin-top: 10px"
                        multiple
                    >
                        <Option
                            v-for="item in modularlist"
                            :value="item.value"
                            :key="item.id"
                            >{{ $t(item.name) }}</Option
                        >
                    </Select>
                </div>
            </div>
            <div slot="footer">
                <Button type="text" size="large" @click="cancle">取消</Button>
                <Button
                    type="primary"
                    v-if="type === 1"
                    size="large"
                    @click="adddata(1)"
                    >{{ $t("1002") }}</Button
                >
                <Button
                    type="primary"
                    v-if="type === 2"
                    size="large"
                    @click="adddata(2)"
                    >{{ $t("1003") }}</Button
                >
            </div>
        </Modal>
    </div>
</template>
<script>
import axios from "@/libs/api.request";
import { constants } from "crypto";
export default {
    data() {
        return {
            morecondition: false,
            creatorlist: [],
            dutylist: [],
            salelist: [],
            mid: "",
            companylist: [],
            companyid: "",
            projectadmin: "",
            dutymid: "",
            salesmid: "",
            projecttypelist: [],
            typeid: "",
            title: "",
            total: 0,
            page: 1,
            pagesize: 10,
            tableData: [],
            addmodal: false,
            editshow: false,
            obj: {},
            addobj: {},
            modularlist: [],
            type: 0,
            tableColumns: [
                {
                    type: "index2",
                    title: this.$t("1008"),
                    key: "xuhao",
                    render: (h, params) => {
                        return h(
                            "span",
                            params.index + (this.page - 1) * this.pagesize + 1
                        );
                    },
                    width: "60px",
                },
                {
                    title: "PID",
                    key: "projectid",
                    width: "80px",
                },
                {
                    title: this.$t("600539"),
                    key: "title",
                    width: "200px",
                },
                {
                    title: this.$t("1115"),
                    key: "typename",
                    width: "120px",
                },
                {
                    title: this.$t("900525"),
                    key: "companyname",
                    width: "150px",
                },
                {
                    title: this.$t("600540"),
                    key: "description",
                    width: "200px",
                },
                {
                    title: this.$t("900253"),
                    key: "creatname",
                },
                {
                    title: this.$t("900254"),
                    key: "responsiblename",
                },
                {
                    title: this.$t("920176"),
                    key: "mobile",
                },
                {
                    title: this.$t("900256"),
                    key: "salename",
                },
            ],
            step: 0,
            loadimg: require("../../../static/images/xiangjitwo.png"),
            Industrycategoryson: "",
            Industrysonlist: [],
            province: "",
            provincelist: [],
            Industrylist: [],
            addcitylist: [],
            editcitylist: [],
            county: "",
            countylist: [],
            addcountylist: [],
            cilentDetail: {
                cid: 0,
            },
            projectDetail: {},
            licenceobj: {},
            tableColumns1: [
                {
                    type: "index",
                    title: this.$t("1008"),
                    key: "xuhao",
                    render: (h, params) => {
                        return h("span", params.index + 1);
                    },
                    width: 80,
                },
                {
                    type: "selection",
                    width: 80,
                },
                {
                    title: this.$t("800225"),
                    key: "title",
                },
            ],
            tableData1: [],
            selection: [],
            businesstype: 0,
        };
    },
    created() {
        this.initCreator();
        this.initDuty();
        this.initSale();
        this.initCompany();
        this.initProjectType();
        this.search();
        this.initModuleData();
        this.getMainLevelLists();
        this.initprovince();
        this.initIndustry();
        // 格式化表格样式
        this.tableColumns = this.$time.initTableTitle(this.tableColumns);
    },
    methods: {
        initIndustry() {
            axios
                .request({
                    url: "config/Industry/GetIndustryFirst",
                    method: "get",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        this.Industrylist = res.data.data;
                    } else {
                        this.$Message.error(this.$t(res.data.msg));
                    }
                });
        },
        initprovince() {
            var params = {
                type: 1,
                status: 1,
            };
            axios
                .request({
                    url: "config/Location/GetLocation",
                    params,
                    method: "get",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        this.provincelist = res.data.data;
                    }
                });
        },
        provincechange(val) {
            var params = {
                type: 2,
                status: 1,
                province_code: val.value ? val.value : "",
            };
            axios
                .request({
                    url: "config/Location/GetLocation",
                    params,
                    method: "get",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        if (this.addmodal) {
                            this.addcitylist = res.data.data;
                        } else if (this.editmodal) {
                            this.editcitylist = res.data.data;
                        } else {
                            this.citylist = res.data.data;
                        }
                    } else {
                        this.$Message.error(this.$t(res.data.msg));
                    }
                });
        },
        citychange(val) {
            var params = {
                type: 3,
                status: 1,
                city_code: val.value ? val.value : "",
            };
            axios
                .request({
                    url: "config/Location/GetLocation",
                    params,
                    method: "get",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        if (this.addmodal) {
                            this.addcountylist = res.data.data;
                        } else if (this.editmodal) {
                            this.editcountylist = res.data.data;
                        } else {
                            this.countylist = res.data.data;
                        }
                    } else {
                        this.$Message.error(this.$t(res.data.msg));
                    }
                });
        },
        addIndustrychange(val) {
            let id = val.value ? val.value : "";
            var params = { firstid: id };
            axios
                .request({
                    url: "config/Industry/GetIndustrySecond",
                    params,
                    method: "get",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        this.Industrysonlist = res.data.data;
                    } else {
                        this.$Message.error(this.$t(res.data.msg));
                    }
                });
        },
        getMainLevelLists() {
            axios
                .request({
                    url: "/config/ProjectLevel/getMainLevelLists",
                    methods: "get",
                })
                .then((res) => {
                    // this.mainLevel = res.data.data
                    let data = res.data.data;
                    this.tableData1 = [];
                    if (
                        res.data.ret === 1 &&
                        Array.isArray(data) &&
                        data.length > 0
                    ) {
                        this.tableData1 = res.data.data;
                    }
                });
        },
        getProjectList(e) {
            console.log(e);
            this.selection = e;
        },
        initCreator() {
            axios
                .request({
                    url: "/config/user/ListUserInfo3",
                    methods: "get",
                })
                .then((res) => {
                    res.data.data.forEach((item, index, arry) => {
                        if (item.nickname !== "") {
                            this.creatorlist.push(item);
                        }
                    });
                });
        },
        initDuty() {
            axios
                .request({
                    url: "/config/Project/GetUser?type=0",
                    methods: "get",
                })
                .then((res) => {
                    res.data.data.forEach((item, index, arry) => {
                        this.dutylist.push(item);
                    });
                });
        },
        initSale() {
            axios
                .request({
                    url: "/config/Project/GetUser?type=1",
                    methods: "get",
                })
                .then((res) => {
                    res.data.data.forEach((item, index, arry) => {
                        if (item.nickname !== "") {
                            this.salelist.push(item);
                        }
                    });
                });
        },
        initCompany() {
            axios
                .request({
                    url: "/config/Company/GetCompany",
                    methods: "get",
                })
                .then((res) => {
                    this.companylist = res.data.data;
                });
        },
        initProjectType() {
            axios
                .request({
                    url: "/config/ProjectType/GetProjectType",
                    methods: "get",
                })
                .then((res) => {
                    this.projecttypelist = res.data.data;
                });
        },
        initTableData(tablelist) {
            let data = [];
            tablelist.forEach((item) => {
                if (item) {
                    data.push({
                        title: item.title,
                        description: item.description,
                        initialquotation: item.initialquotation,
                        finaloffer: item.finaloffer,
                        companyname: item.companyname,
                        creatname: item.creatname,
                        mobile: item.mobile,
                        responsiblename: item.responsiblename,
                        salename: item.salename,
                        typename: item.typename,
                        projectid: item.projectid,
                    });
                }
            });
            this.tableData = data;
        },
        initModuleData() {
            axios
                .request({
                    url: "/config/userpower/getmodular",
                    methods: "get",
                })
                .then((ret) => {
                    this.modularlist = ret.data.data;
                });
        },
        handdlesearch() {
            this.page = 1;
            this.search();
        },
        search() {
            var params = {
                page: this.page,
                pagesize: this.pagesize,
                title: this.title,
                mid: this.mid,
                companyid: this.companyid,
                dutymid: this.dutymid,
                salesmid: this.salesmid,
                typeid: this.typeid,
            };
            axios
                .request({
                    url: "/config/Project/getLists",
                    params,
                    methods: "get",
                })
                .then((res) => {
                    this.total = res.data.total;
                    this.initTableData(res.data.data);
                });
        },
        getOldCilent(val) {
            let chinaname = val.label ? val.label : "";
            var params = {
                page: 1,
                pagesize: 10,
                chinesename: chinaname,
            };
            axios
                .request({
                    url: "/config/company/Getcompanylist",
                    params,
                    method: "get",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        console.log(res.data.data);
                        let obj = res.data.data[0];

                        let val1 = {},
                            val2 = {};
                        val1.value = obj.province;
                        val2.value = obj.city;
                        this.provincechange(val1);
                        this.citychange(val2);
                        if (obj.industry_first != 0) {
                            let val3 = {};
                            val3.value = obj.industry_first;
                            this.addIndustrychange(val3);
                        }
                        setTimeout(() => {
                            this.loadimg = obj.litpic;
                            this.cilentDetail = {
                                cid: obj.id,
                                name: obj.chinesename,
                                nameEn: obj.chinesepinyin,
                                province: obj.province,
                                city: obj.city,
                                area: obj.county,
                                address: obj.detailaddress,
                                contacts: obj.contact,
                                phone: obj.telephone,
                                email: obj.email,
                                companycode: obj.companycode,
                                industrycategory: obj.industry_first,
                                industrysecond: obj.industry_second,
                                logoimg: obj.litpic,
                            };
                            this.businesstype = 0;
                        }, 500);

                        // this.total = res.data.total;
                        // this.mockTableData1(res.data.data);
                        // // this.detailobj = {}
                        // this.page = res.data.page;
                    }
                });
        },
        add() {
            this.type = 1;
            // this.cilentDetail = {};
            // this.cilentDetail.cid = 0;
            // this.projectDetail = {};
            // this.selection = [];
            // this.licenceobj = {};
            // this.step = 1;
            // this.addmodal = true;
            this.addobj = {};
            this.editshow=true;
        },
        newClient() {
            this.businesstype = 0;
        },
        oldClient() {
            this.businesstype = 1;
        },
        lastStep() {
            this.step -= 1;
        },
        nextStep() {
            if (this.step == 1) {
                if (
                    this.cilentDetail.name == undefined ||
                    this.cilentDetail.province == undefined ||
                    this.cilentDetail.city == undefined ||
                    this.cilentDetail.area == undefined ||
                    this.cilentDetail.address == undefined ||
                    this.cilentDetail.contacts == undefined ||
                    this.cilentDetail.phone == undefined ||
                    this.cilentDetail.email == undefined ||
                    this.cilentDetail.name == "" ||
                    this.cilentDetail.province == "" ||
                    this.cilentDetail.city == "" ||
                    this.cilentDetail.area == "" ||
                    this.cilentDetail.address == "" ||
                    this.cilentDetail.contacts == "" ||
                    this.cilentDetail.phone == "" ||
                    this.cilentDetail.email == ""
                ) {
                    this.$Message.error(this.$t(9000136));
                    return false;
                }
            }
            if (this.step == 2) {
                if (
                    this.projectDetail.title == undefined ||
                    this.projectDetail.typeid == undefined ||
                    this.projectDetail.salesmid == undefined ||
                    this.projectDetail.realname == undefined ||
                    this.projectDetail.account == undefined ||
                    this.projectDetail.password == undefined ||
                    this.projectDetail.title == "" ||
                    this.projectDetail.typeid == "" ||
                    this.projectDetail.salesmid == "" ||
                    this.projectDetail.realname == "" ||
                    this.projectDetail.account == "" ||
                    this.projectDetail.password == ""
                ) {
                    this.$Message.error(this.$t(9000136));
                    return false;
                }
            }
            if (this.step == 3) {
                if (this.selection.length == 0) {
                    this.$Message.error(this.$t(1037));
                    return false;
                }
            }
            if (this.step == 4) {
                if (
                    this.licenceobj.type == undefined ||
                    this.licenceobj.type == 0 ||
                    this.licenceobj.type == ""
                ) {
                    this.$Message.error(this.$t(666606));
                    return false;
                }
                if (
                    this.licenceobj.type == 2 &&
                    (this.licenceobj.values == "" ||
                        this.licenceobj.values == undefined)
                ) {
                    this.$Message.error(this.$t(90000088));
                    return false;
                }
                this.registerPost();
            } else {
                this.step += 1;
            }
        },
        registerPost() {
            // this.cilentDetail.cid = 0;
            let data = {
                company: this.cilentDetail,
                project: this.projectDetail,
                levels: this.selection,
                licence: this.licenceobj,
            };
            console.log(data);
            axios
                .request({
                    url: "/config/Company/Register",
                    data,
                    method: "post",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        console.log(res.data);
                        // this.$Message.success(this.$t(1055));
                        // this.page = 1;
                        this.search();
                        this.step += 1;
                    } else {
                        this.$Message.error(this.$t(res.data.msg));
                        // this.search();
                    }
                });
        },
        adddata(type) {
            let data = this.addobj;
            console.log(data);
            if (
                data.projectid === "" ||
                data.projectid === undefined ||
                data.title === "" ||
                data.title === undefined ||
                data.typeid === "" ||
                data.typeid === undefined ||
                data.companyid === "" ||
                data.companyid === undefined ||
                data.salesmid === "" ||
                data.salesmid === undefined ||
                data.realname === "" ||
                data.realname === undefined ||
                data.mobile === "" ||
                data.mobile === undefined ||
                data.password === "" ||
                data.password === undefined ||
                data.modular === "" ||
                data.modular === undefined
            ) {
                this.$Message.error(this.$t("1063"));
                return false;
            }
            var arry = [];
            for (var item in data.modular) {
                arry.push(data.modular[item]);
            }
            delete data.modular;
            data.modular = arry.join(",");
            data.dashboard_ids = "";
            // 添加
            if (type === 1) {
                axios
                    .request({
                        url: "/config/project/AddProjectAndUser",
                        data,
                        method: "post",
                    })
                    .then((res) => {
                        if (res.data.ret === 1) {
                            this.$Message.success(this.$t(1055));
                            this.page = 1;
                            this.search();
                            this.editshow = false;
                        } else {
                            this.$Message.error(this.$t(res.data.msg));
                            this.search();
                        }
                    });
                // 修改
            } else if (type === 2) {
                if (data.password === "**1") {
                    data.is_password = 1;
                    delete data.password;
                } else {
                    data.password = this.addobj.password;
                }
                axios
                    .request({
                        url: "/config/project/EditProject",
                        data,
                        method: "post",
                    })
                    .then((res) => {
                        if (res.data.ret === 1) {
                            this.$Message.success(this.$t(1060));
                            this.page = 1;
                            this.search();
                            this.editshow = false;
                        } else {
                            this.$Message.error(this.$t(res.data.msg));
                            this.search();
                        }
                    });
            }
        },
        edit() {
            if (JSON.stringify(this.obj) === "{}") {
                this.$Message.error(this.$t(1043));
                return false;
            }
            var params = { id: this.obj.projectid };
            axios
                .request({
                    url: "/config/Project/GetProjectItem",
                    params,
                    method: "get",
                })
                .then((res) => {
                    this.addobj = res.data.data;
                    this.addobj.salesmid = res.data.data.saleid;
                    this.addobj.realname = res.data.data.managename;
                    this.addobj.mobile = res.data.data.managemobile;
                    this.addobj.modular = res.data.data.modular.split(",");
                    this.addobj.id = res.data.data.projectid;
                    this.addobj.password = "**1";
                });
            this.initModuleData();
            this.editshow = true;
            this.type = 2;
        },
        del() {
            if (JSON.stringify(this.obj) === "{}") {
                this.$Message.error(this.$t("1017"));
                return false;
            } else {
                this.$Modal.confirm({
                    title: this.$t("1018"),
                    content: "",
                    width: "290px",
                    closable: true,
                    okText: this.$t("1004"),
                    onOk: () => {
                        var params = { id: this.obj.projectid };
                        axios
                            .request({
                                url: "/config/Project/DeleteProject",
                                params,
                                method: "post",
                            })
                            .then((res) => {
                                if (res.data.ret === 1) {
                                    this.$Message.success(this.$t("1058"));
                                    this.page = 1;
                                    this.search();
                                } else {
                                    this.$Message.error(this.$t(res.data.msg));
                                    this.search();
                                }
                            });
                    },
                });
            }
        },
        cancle() {
            this.addobj = {};
            this.addmodal = false;
        },
        unloadimg() {
            // 上传照片
            const file = this.$refs.fileIntimg.files[0];
            const data = new FormData();
            data.append("file", file);
            axios
                .request({
                    url: "/config/upload/UploadImage",
                    data,
                    method: "post",
                })
                .then((res) => {
                    if (res.data.ret === 1) {
                        this.$Message.success(this.$t(100378));
                        this.loadimg = axios.publicPath + res.data.data;
                        this.cilentDetail.logoimg = res.data.data;
                    } else {
                        this.$Message.error(this.$t(res.data.msg));
                    }
                })
                .catch((err) => {
                    alert(err.msg);
                });
        },
        changecondition() {
            this.morecondition = !this.morecondition;
        },
        handleRowChange(currentRow, oldCurrentRow) {
            this.obj = currentRow;
        },
        handlePageSize(value) {
            this.pagesize = value;
            this.tableData = this.search();
        },
        changePage(value) {
            this.page = value;
            this.tableData = this.search();
        },
    },
};
</script>
<style lang="less" scoped>
.stepTitle {
    height: 40px;
    line-height: 40px;
    padding-left: 20px;
    font-size: 20px;
    font-weight: bold;
    background-color: #d7d7d7;
    margin: 15px auto;
}
</style>
