<template>
  <div class="user">
    <div class="tree">
      <treeList
        title="产品分类"
        submitType="1"
        :data="treeListData"
        v-model="sourceList.pagination.productClassifyId"
        @change="treeChange"
        @changeTreeList="getTreeList"
      >
      </treeList>
    </div>
    <div class="content">
      <byTable
        :tableHeight="tableHeight"
        :source="sourceList.data"
        :pagination="sourceList.pagination"
        :config="config"
        :loading="loading"
        highlight-current-row
        :selectConfig="selectConfig"
        :table-events="{
          //element talbe事件都能传
          select: select,
        }"
        :action-list="[
          {
            text: 'Excel导入',
            action: () => openExcel(),
            disabled: false,
          },
          {
            text: '添加产品',
            action: () => openModal('add'),
            disabled: false,
          },
        ]"
        @get-list="getList"
      >
        <template #pic="{ item }">
          <div v-if="item.fileList.length > 0">
            <img
              :src="item.fileList[0].fileUrl"
              class="pic"
              @click="handleClickFile(item.fileList[0])"
            />
          </div>
          <div v-else></div>
        </template>
      </byTable>
    </div>
    <el-dialog
      :title="modalType == 'add' ? '添加' : '编辑'"
      v-model="dialogVisible"
      width="800"
      v-loading="loadingOne"
      destroy-on-close
    >
      <div class="public_height_dialog">
        <byForm
          :formConfig="formConfig"
          :formOption="formOption"
          v-model="formData.data"
          :rules="rules"
          ref="byform"
        >
          <template #productPic>
            <div>
              <el-upload
                v-model:fileList="fileList"
                action="https://winfaster.obs.cn-south-1.myhuaweicloud.com"
                :data="uploadData"
                list-type="picture-card"
                :on-remove="handleRemove"
                :on-success="handleSuccess"
                :before-upload="handleBeforeUpload"
                accept=".gif, .jpeg, .jpg, .png"
              >
                <el-icon><Plus /></el-icon>
              </el-upload>
            </div>
          </template>

          <template #combination>
            <div style="width: 100%">
              <div
                style="
                  font-size: 14px;
                  font-weight: bold;
                  margin-bottom: 10px;
                  color: #333333;
                "
                v-show="formData.data.combination == 1"
              >
                组合明细
              </div>
              <el-button
                type="primary"
                @click="openProduct = true"
                style="margin-bottom: 10px"
                v-show="formData.data.combination == 1"
              >
                添加
              </el-button>
              <el-table
                :data="formData.data.productCombinationList"
                v-show="formData.data.combination == 1"
              >
                <el-table-column prop="code" label="产品编码" />
                <el-table-column prop="name" label="产品名称" />
                <el-table-column
                  prop="linkQuantity"
                  label="组合数量"
                  min-width="150"
                >
                  <template #default="{ row, $index }">
                    <el-form-item
                      :prop="
                        'productCombinationList.' + $index + '.linkQuantity'
                      "
                      :rules="rules.linkQuantity"
                      :inline-message="true"
                    >
                      <el-input-number
                        v-model="row.linkQuantity"
                        placeholder="请输入"
                        :min="1"
                        :controls="false"
                        :precision="0"
                        onmousewheel="return false;"
                      />
                    </el-form-item>
                  </template>
                </el-table-column>
                <el-table-column prop="zip" label="操作" width="100">
                  <template #default="{ $index }">
                    <el-button
                      type="primary"
                      link
                      @click="handleRemoveProduct($index)"
                      >删除</el-button
                    >
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </template>
          <template #one>
            <div style="width: 100%">
              <el-row>
                <el-col :span="4">
                  <el-input
                    v-model="formData.data.victoriatouristJson.newProductsDay1"
                    placeholder="请输入"
                    disabled
                  />
                </el-col>
                <el-col :span="1" style="text-align: center"> ~ </el-col>
                <el-col :span="4">
                  <el-input-number
                    v-model="formData.data.victoriatouristJson.newProductsDay"
                    placeholder="请输入"
                    :min="0"
                    :controls="false"
                    :precision="0"
                    style="width: 100%"
                    @change="changeDay(10)"
                    onmousewheel="return false;"
                  >
                  </el-input-number>
                </el-col>
                <el-col :span="1" style="text-align: center"> : </el-col>
                <el-col :span="6">
                  <el-input-number
                    v-model="
                      formData.data.victoriatouristJson.newProductsExpectedSales
                    "
                    placeholder="预期销量"
                    :min="0"
                    :controls="false"
                    :precision="0"
                    style="width: 100%"
                    onmousewheel="return false;"
                  />
                </el-col>
              </el-row>
            </div>
          </template>
          <template #two>
            <div style="width: 100%">
              <el-row>
                <el-col :span="4">
                  <el-input
                    v-model="formData.data.victoriatouristJson.growUpDay1"
                    placeholder="请输入"
                    disabled
                  />
                </el-col>
                <el-col :span="1" style="text-align: center"> ~ </el-col>
                <el-col :span="4">
                  <el-input-number
                    v-model="formData.data.victoriatouristJson.growUpDay"
                    placeholder="请输入"
                    :min="0"
                    :controls="false"
                    :precision="0"
                    style="width: 100%"
                    @change="changeDay(20)"
                    onmousewheel="return false;"
                  >
                  </el-input-number>
                </el-col>
                <el-col :span="1" style="text-align: center"> : </el-col>
                <el-col :span="6">
                  <el-input-number
                    v-model="
                      formData.data.victoriatouristJson.growUpExpectedSales
                    "
                    placeholder="预期销量"
                    :min="0"
                    :controls="false"
                    :precision="0"
                    style="width: 100%"
                    onmousewheel="return false;"
                  />
                </el-col>
              </el-row>
            </div>
          </template>
          <template #three>
            <el-row style="width: 100%">
              <el-col :span="5">
                大于{{ formData.data.victoriatouristJson.attDay }}天：
              </el-col>
              <el-col :span="6">
                <el-input-number
                  v-model="
                    formData.data.victoriatouristJson.matureExpectedSales
                  "
                  placeholder="预期销量"
                  :min="0"
                  :controls="false"
                  :precision="0"
                  style="width: 100%"
                  onmousewheel="return false;"
                />
              </el-col>
            </el-row>
          </template>
        </byForm>
      </div>
      <template #footer>
        <el-button @click="dialogVisible = false" size="large">取 消</el-button>
        <el-button
          type="primary"
          @click="submitForm('byform')"
          size="large"
          :loading="submitLoading"
        >
          确 定
        </el-button>
      </template>
    </el-dialog>
    <el-dialog
      title="Excel导入"
      v-model="openExcelDialog"
      width="400"
      v-loading="loading"
    >
      <template #footer>
        <el-button @click="openExcelDialog = false" size="large"
          >取 消</el-button
        >
        <el-button
          type="primary"
          @click="submitExcel()"
          size="large"
          :loading="submitLoading"
        >
          确 定
        </el-button>
      </template>
    </el-dialog>

    <el-dialog title="移交" v-model="moveDept" width="400" v-loading="loading">
      <div style="margin-bottom: 15px">请选择部门</div>
      <el-tree-select
        v-model="moveForm.deptId"
        :data="deptList"
        :render-after-expand="false"
        check-strictly
        :node-key="'deptId'"
        :props="defaultProps"
      />
      <template #footer>
        <el-button @click="moveDept = false">取 消</el-button>
        <el-button
          type="primary"
          @click="submitMove()"
          :loading="submitLoading"
        >
          确 定
        </el-button>
      </template>
    </el-dialog>
    <el-dialog
      v-model="openProduct"
      title="选择产品"
      width="70%"
      append-to-body
    >
      <SelectProduct @handleSelect="handleSelect"></SelectProduct>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="openProduct = false">取消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
/* eslint-disable vue/no-unused-components */
import { ElMessage, ElMessageBox } from "element-plus";
import byTable from "@/components/byTable/index";
import byForm from "@/components/byForm/index";
import treeList from "@/components/product/treeList";
import SelectProduct from "@/components/WDLY/product/SelectProduct";
import useUserStore from "@/store/modules/user";
// 引入插件解决json.parse()会导致id值错误
import { parse, stringify } from "lossless-json";
import { computed, defineComponent, ref } from "vue";
const tableHeight = window.innerHeight - 360;
let openProduct = ref(false);
const loading = ref(false);
const loadingOne = ref(false);
const submitLoading = ref(false);
const sourceList = ref({
  data: [],
  pagination: {
    total: 3,
    pageNum: 1,
    pageSize: 10,
    type: "",
    productClassifyId: "",
    keyword: "",
    definition: "1",
  },
});
let dialogVisible = ref(false);
let openExcelDialog = ref(false);
let moveDept = ref(false);
const deptIdCopy = ref("");
let modalType = ref("add");
let rules = ref({
  productClassifyId: [
    { required: true, message: "请选择产品分类", trigger: "change" },
  ],
  type: [{ required: true, message: "请选择产品类型", trigger: "change" }],
  name: [{ required: true, message: "请输入产品名称", trigger: "blur" }],
  unit: [{ required: true, message: "请选择单位", trigger: "change" }],
  linkQuantity: [
    { required: true, message: "请输入组合数量", trigger: "blur" },
  ],
});
const { proxy } = getCurrentInstance();
const productUnit = ref([]);
const productType = ref([]);
const salesStatus = ref([]);
const selectConfig = computed(() => [
  {
    label: "产品类型",
    prop: "type",
    data: productType.value,
  },
  {
    label: "生命周期",
    prop: "lifeCycle",
    data: [
      {
        label: "新品",
        value: "1",
      },
      {
        label: "成长",
        value: "2",
      },
      {
        label: "成熟",
        value: "3",
      },
    ],
  },
  {
    label: "是否组合",
    prop: "combination",
    data: [
      {
        label: "是",
        value: "1",
      },
      {
        label: "否",
        value: "0",
      },
    ],
  },
  {
    label: "销售状态",
    prop: "salesStatus",
    data: salesStatus.value,
  },
]);
const config = computed(() => {
  return [
    {
      attrs: {
        label: "产品类型",
        prop: "type",
        width: 80,
      },
      render(type) {
        return proxy.dictValueLabel(type, productType.value);
      },
    },
    {
      attrs: {
        label: "产品编码",
        prop: "customCode",
      },
    },
    {
      attrs: {
        label: "产品名称",
        prop: "name",
      },
    },
    {
      attrs: {
        label: "是否组合",
        prop: "combination",
      },
      render(combination) {
        return combination == 1 ? "是" : combination == 0 ? "否" : "";
      },
    },
    {
      attrs: {
        label: "销售状态",
        prop: "salesStatus",
      },
      render(status) {
        return proxy.dictValueLabel(status, salesStatus.value);
      },
    },
    {
      attrs: {
        label: "图片",
        prop: "unit",
        slot: "pic",
        width: 60,
      },
    },
    {
      attrs: {
        label: "单位",
        prop: "unit",
      },
      render(unit) {
        return proxy.dictValueLabel(unit, productUnit.value);
      },
    },
    {
      attrs: {
        label: "规格型号",
        prop: "spec",
      },
    },
    {
      attrs: {
        label: "材质",
        prop: "materialQuality",
      },
    },
    {
      attrs: {
        label: "管理部门",
        prop: "deptName",
      },
    },
    {
      attrs: {
        label: "生命周期",
        prop: "lifeCycle",
        width: 80,
      },
      render(lifeCycle) {
        return lifeCycle == "1" ? "新品" : lifeCycle == "2" ? "成长" : "成熟";
      },
    },
    {
      attrs: {
        label: "京东供价",
        prop: "jdPurchasePrice",
        width: 80,
      },
    },
    {
      attrs: {
        label: "标准售价",
        prop: "sellingPrice",
        width: 80,
      },
    },
    // {
    //   attrs: {
    //     label: "标准采购价",
    //     prop: "purchasePrice",
    //     width: 100,
    //   },
    // },
    // {
    //   attrs: {
    //     label: "产品备注",
    //     prop: "remark",
    //   },
    // },
    {
      attrs: {
        label: "操作",
        width: "160",
        align: "center",
        fixed: "right",
      },
      // 渲染 el-button，一般用在最后一列。
      renderHTML(row) {
        return [
          {
            attrs: {
              label: "修改",
              type: "primary",
              text: true,
            },
            el: "button",
            click() {
              getDtl(row);
            },
          },
          {
            attrs: {
              label: "移交",
              type: "primary",
              text: true,
            },
            el: "button",
            click() {
              getDtlOne(row);
            },
          },
          {
            attrs: {
              label: "删除",
              type: "danger",
              text: true,
            },
            el: "button",
            click() {
              // 弹窗提示是否删除
              ElMessageBox.confirm(
                "此操作将永久删除该数据, 是否继续?",
                "提示",
                {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning",
                }
              ).then(() => {
                // 删除
                proxy
                  .post("/productInfo/delete", {
                    id: row.id,
                  })
                  .then((res) => {
                    ElMessage({
                      message: "删除成功",
                      type: "success",
                    });
                    getList();
                  });
              });
            },
          },
        ];
      },
    },
  ];
});

const uploadData = ref({});
const fileList = ref([]);
const fileListCopy = ref([]);

let formData = reactive({
  data: {},
});
const formOption = reactive({
  inline: true,
  labelWidth: 100,
  itemWidth: 100,
  rules: [],
});
const byform = ref(null);
const treeListData = ref([]);
const formConfig = computed(() => {
  return [
    {
      type: "treeSelect",
      prop: "productClassifyId",
      label: "产品分类",
      data: treeListData.value,
    },
    {
      type: "select",
      prop: "type",
      label: "产品类型",
      required: true,
      data: productType.value,
    },
    {
      type: "input",
      prop: "name",
      label: "产品名称",
    },
    {
      type: "input",
      prop: "spec",
      label: "规格型号",
    },
    {
      type: "input",
      prop: "customCode",
      label: "产品编码",
    },
    {
      type: "select",
      prop: "unit",
      label: "单位",
      required: true,
      data: productUnit.value,
    },
    {
      type: "slot",
      slotName: "productPic",
      prop: "fileList",
      label: "产品图片",
    },
    {
      type: "input",
      prop: "remark",
      label: "备注",
      itemType: "textarea",
    },

    {
      type: "json",
      prop: "victoriatouristJson",
      json: [
        {
          type: "number",
          prop: "jdPurchasePrice",
          label: "京东供价",
          itemWidth: 33,
          precision: 2,
          min: 0,
          controls: false,
          style: {
            width: "100%",
            "margin-right": "10px",
          },
        },
        {
          type: "number",
          prop: "sellingPrice",
          label: "标准售价",
          itemWidth: 33,
          precision: 2,
          min: 0,
          controls: false,
        },
        // {
        //   type: "number",
        //   prop: "purchasePrice",
        //   label: "标准采购价",
        //   itemWidth: 33,
        //   precision: 2,
        //   min: 0,
        //   controls: false,
        // },
        {
          type: "input",
          prop: "weight",
          label: "重量",
          itemWidth: 50,
          precision: 2,
          min: 0,
          controls: false,
        },
        {
          type: "input",
          prop: "materialQuality",
          label: "材质 / 面料",
          itemWidth: 50,
          precision: 2,
          min: 0,
          controls: false,
        },
        {
          type: "input",
          prop: "applicableTemp",
          label: "适用温度",
          itemWidth: 50,
          precision: 2,
          min: 0,
          controls: false,
        },
        {
          type: "select",
          prop: "salesStatus",
          label: "销售状态",
          required: true,
          data: salesStatus.value,
        },
        {
          type: "date",
          prop: "clearancePeriod",
          label: "库存清空期限",
          itemWidth: 50,
          format: "MM-DD",
        },
      ],
    },
    {
      type: "radio",
      prop: "combination",
      label: "是否组合",
      required: true,
      border: true,
      data: [
        { label: "是", value: "1" },
        { label: "否", value: "0" },
      ],
    },
    {
      type: "slot",
      slotName: "combination",
      label: "",
    },
    {
      type: "title",
      title: "生命周期规则",
      label: "",
    },
    {
      type: "slot",
      slotName: "one",
      label: "新品期",
    },
    {
      type: "slot",
      slotName: "two",
      label: "成长期",
    },
    {
      type: "slot",
      slotName: "three",
      label: "成熟期",
    },
  ];
});
const newPassword = () => {
  formData.data.password = generatePassword();
};

const generatePassword = () => {
  var length = 12,
    charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
    password = "";
  for (var i = 0, n = charset.length; i < length; ++i) {
    password += charset.charAt(Math.floor(Math.random() * n));
  }
  return password;
};

const getList = async (req) => {
  sourceList.value.pagination = { ...sourceList.value.pagination, ...req };
  loading.value = true;
  proxy
    .post("/productInfo/pageByWdly", sourceList.value.pagination)
    .then((message) => {
      console.log(message);
      sourceList.value.data = message.rows.map((x) => ({
        ...x,
        fileList: [],
        ...JSON.parse(x.victoriatouristJson),
      }));
      sourceList.value.pagination.total = message.total;
      setTimeout(() => {
        loading.value = false;
      }, 200);

      const productIdList = message.rows.map((x) => x.id);
      // 请求文件数据并回显
      if (productIdList.length > 0) {
        proxy
          .post("/fileInfo/getList", { businessIdList: productIdList })
          .then((fileObj) => {
            for (let i = 0; i < sourceList.value.data.length; i++) {
              const e = sourceList.value.data[i];
              for (const key in fileObj) {
                if (e.id === key) {
                  e.fileList = fileObj[key];
                }
              }
            }
          });
      }
    });
};

const treeChange = (e) => {
  sourceList.value.pagination.productClassifyId = e.id;
  getList({ productClassifyId: e.id });
};

const openModal = () => {
  dialogVisible.value = true;
  modalType.value = "add";
  formData.data = {
    definition: "1",
    // type: "1",
    fileList: [],
    combination: "1",
    victoriatouristJson: {
      combination: 1,
      newProductsDay1: 0,
      newProductsDay: 60,
      growUpDay1: 61,
      growUpDay: 120,
      attDay: 120,
    },
    productCombinationList: [],
  };
  fileList.value = [];
  fileListCopy.value = [];
};

const openExcel = () => {
  openExcelDialog.value = true;
};
const submitExcel = () => {
  openExcelDialog.value = false;
};
const TreetenantId = ref("");
const selection = ref({
  data: [],
});
const select = (_selection, row) => {
  selection.value.data = _selection;
  console.log(_selection.length);
};

const tree = ref(null);
let submitProductData = ref({});
const submitForm = () => {
  byform.value.handleSubmit((valid) => {
    submitProductData.value = { ...formData.data };
    const list = formData.data.productCombinationList;
    let jsonObj = JSON.parse(formData.data.victoriatouristJson);
    if (formData.data.combination == 1) {
      if (!(list.length > 0)) {
        formData.data.victoriatouristJson = jsonObj;
        return ElMessage({
          message: "请添加组合明细",
          type: "info",
        });
      }
    }
    if (jsonObj.growUpDay <= Number(jsonObj.growUpDay1)) {
      formData.data.victoriatouristJson = jsonObj;
      return ElMessage({
        message: "生命周期规则输入有误!",
        type: "info",
      });
    }
    loadingOne.value = true;
    if (deptIdCopy.value) {
      jsonObj.deptId = deptIdCopy.value;
    }
    formData.data.victoriatouristJson = jsonObj;
    jsonObj.productCombinationList = list;
    jsonObj.combination = formData.data.combination;
    delete formData.data.productCombinationList;
    delete formData.data.combination;
    formData.data.victoriatouristJson = JSON.stringify(jsonObj);
    formData.data.fileList = fileListCopy.value.map((x) => ({
      id: x.id,
      fileName: x.fileName,
    }));
    submitLoading.value = true;
    let url =
      modalType.value == "add" ? "/productInfo/addByWdly" : "/productInfo/edit";
    proxy.post(url, formData.data).then(
      (res) => {
        ElMessage({
          message: modalType.value == "add" ? "添加成功" : "编辑成功",
          type: "success",
        });
        dialogVisible.value = false;
        loadingOne.value = false;

        submitLoading.value = false;
        getList();
      },
      (err) => {
        formData.data = { ...submitProductData.value };
        formData.data.victoriatouristJson = JSON.parse(
          submitProductData.value.victoriatouristJson
        );
        loadingOne.value = false;
        submitLoading.value = false;
      }
    );
  });
};

const getTreeList = () => {
  proxy
    .post("/productClassify/tree", { parentId: "", name: "", definition: "1" })
    .then((message) => {
      treeListData.value = message;
    });
};

const deptList = ref([]);
const defaultProps = {
  children: "children",
  label: "deptName",
};
const getDept = () => {
  proxy
    .get("/tenantDept/list", {
      pageNum: 1,
      pageSize: 999,
      tenantId: useUserStore().user.tenantId,
    })
    .then((res) => {
      deptList.value = proxy.handleTree(res.data, "deptId");
    });
};

const getDtl = (row) => {
  modalType.value = "edit";
  proxy.post("/productInfo/detailByWdly", { id: row.id }).then((res) => {
    if (res.victoriatouristJson) {
      res.victoriatouristJson = res.victoriatouristJson.replace(
        /\"deptId":(\d+)/g,
        '"deptId": "$1"'
      );
      res.victoriatouristJson = res.victoriatouristJson.replace(
        /\"linkProductId":(\d+)/g,
        '"linkProductId": "$1"'
      );
    }
    fileList.value = row.fileList.map((x) => ({ ...x, url: x.fileUrl }));
    fileListCopy.value = [...fileList.value];
    res.type = res.type + ""; //type回显
    res.definition = "1"; //产品
    res.victoriatouristJson = res.victoriatouristJson
      ? JSON.parse(res.victoriatouristJson)
      : {};
    res.combination = res.victoriatouristJson.combination
      ? res.victoriatouristJson.combination + ""
      : "0";
    if (
      res.victoriatouristJson.productCombinationList &&
      res.victoriatouristJson.productCombinationList.length > 0
    ) {
      res.productCombinationList =
        res.victoriatouristJson.productCombinationList.map((item) => {
          return {
            ...item,
            code: item.customCode,
          };
        });
    } else {
      res.productCombinationList = [];
    }
    formData.data = res;
    dialogVisible.value = true;
  });
};
getTreeList();
getDept();
// getDict()
getList();
const handleBeforeUpload = async (file) => {
  const res = await proxy.post("/fileInfo/getSing", { fileName: file.name });
  uploadData.value = res.uploadBody;
  fileListCopy.value.push({
    id: res.id,
    fileName: res.fileName,
    path: res.fileUrl,
    url: res.fileUrl,
    uid: file.uid,
  });
};

const handleSuccess = (res, file, files) => {
  // 查当前file的index值去赋值对应的copy变量的值
  // let uid = file.uid;
  // const index = fileList.value.findIndex((x) => x.uid === uid);
  // fileListCopy.value[index].uid = uid;
};

const handleRemove = (file) => {
  const index = fileListCopy.value.findIndex(
    (x) => x.uid === file.uid || x.id === file.id
  );
  fileListCopy.value.splice(index, 1);
};

const handleClickFile = (file) => {
  window.open(file.fileUrl, "_blank");
};

const handleRemoveProduct = (index) => {
  formData.data.productCombinationList.splice(index, 1);
  return ElMessage({
    message: "删除成功！",
    type: "success",
  });
};

const pushGoods = (goods) => {
  const arr = goods.map((x) => ({
    linkProductId: x.id,
    linkQuantity: "",
    name: x.name,
    code: x.code,
  }));
  formData.data.productCombinationList =
    formData.data.productCombinationList.concat(arr);
  return ElMessage({
    message: "添加成功！",
    type: "success",
  });
};

const changeDay = (type) => {
  if (type == 10) {
    formData.data.victoriatouristJson.growUpDay1 =
      Number(formData.data.victoriatouristJson.newProductsDay) + 1;
  } else if (type == 20) {
    formData.data.victoriatouristJson.attDay = Number(
      formData.data.victoriatouristJson.growUpDay
    );
  }
};

const handleSelect = (row) => {
  if (
    formData.data.productCombinationList &&
    formData.data.productCombinationList.length > 0
  ) {
    const flag = formData.data.productCombinationList.some(
      (x) => x.linkProductId === row.id
    );
    if (flag)
      return ElMessage({
        message: "该产品已选择",
        type: "info",
      });
  }
  const product = {
    linkProductId: row.id,
    linkQuantity: "",
    name: row.name,
    code: row.code,
  };
  formData.data.productCombinationList.push(product);
  return ElMessage({
    message: "选择成功",
    type: "success",
  });
};
let moveForm = ref({});
let rowData = {};
const getDtlOne = (row) => {
  moveForm.value.deptId = row.deptId ? row.deptId.toString() : "";
  moveDept.value = true;
  rowData = row;
};

const submitMove = () => {
  if (!moveForm.value.deptId) {
    return ElMessage({
      message: "请选择部门！",
      type: "info",
    });
  }
  proxy
    .post("/productInfo/transfer", {
      id: rowData.id,
      deptId: moveForm.value.deptId,
    })
    .then((res) => {
      ElMessage({
        message: "移交成功",
        type: "success",
      });
      getList();
      moveDept.value = false;
    });
};

const getDict = () => {
  proxy.getDictOne(["unit", "product_type", "sales_status"]).then((res) => {
    productUnit.value = res["unit"].map((x) => ({
      label: x.dictValue,
      value: x.dictKey,
    }));
    productType.value = res["product_type"].map((x) => ({
      label: x.dictValue,
      value: x.dictKey,
    }));
    salesStatus.value = res["sales_status"].map((x) => ({
      label: x.dictValue,
      value: x.dictKey,
    }));
  });
};
getDict();
</script>

<style lang="scss" scoped>
.user {
  padding: 20px;
  display: flex;
  justify-content: space-between;
  .tree {
    width: 300px;
  }
  .content {
    width: calc(100% - 320px);
    height: calc(100vh - 140px);
  }
}
.pic {
  object-fit: contain;
  width: 50px;
  height: 50px;
  cursor: pointer;
  vertical-align: middle;
}
:deep(.el-date-picker-header) {
  span:nth-child(3) {
    display: none !important;
  }
  button:nth-child(1) {
    display: none !important;
  }
  button:nth-child(5) {
    display: none !important;
  }
}
:deep(.el-date-picker__prev-btn .el-picker-panel__icon-btn) {
  display: none;
}
:deep(.el-date-picker__next-btn .el-picker-panel__icon-btn) {
  display: none;
}
:deep(.el-date-picker__header .el-date-picker__header-label) {
  display: none;
}
</style>
