

<script>
import test from "@/components/form-test/index.vue";
import query from "@/components/query/index.vue";

import byTable from "@/components/by-table/index.js";
import addAfterSales from "./addAfterSales.vue";

import * as API from "@/api/order-management/afterSales/index.js";
// import { customerList } from "@/api/product-material/customer/index.js";

export default {
  components: {
    test,
    byTable,
    query,
    addAfterSales,
  },
  data() {
    return {
      afterSalesTypeList: [],
      orderStatusList: [],
      afterSalesStatusList: [],
      customerSelectList: [],
      btnForm: {
        otherButton: {
          list: [
            {
              name: "tiann",
              methodsText: "add",
              type: "primary",
              add: () => {
                this.handleAdd();
              },
            },
          ],
        },
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyword: "",
        type: "",
        afterSalesStatus: "",
      },
      selectConfig: [
        {
          label: "售后类型",
          prop: "type",
          data: [],
        },
        {
          label: "状态",
          prop: "afterSalesStatus",
          data: [],
        },
      ],
      tableList: [],
      total: 0,
      loading: false,
      titleText: "",
      open: false,
      form: {
        id: "",
        type: "",
        remark: "",
      },
      isAdd: false,
      openOne: false,
    };
  },
  created() {
    const businessDictData = JSON.parse(
      window.localStorage.getItem("businessDict")
    );
    this.afterSalesTypeList = businessDictData.find(
      (item) => item.code === "afterSalesType"
    ).children;
    this.selectConfig[0].data = this.afterSalesTypeList.map((item) => ({
      label: item.dictValue,
      value: item.dictKey,
    }));
    this.orderStatusList = businessDictData.find(
      (item) => item.code === "orderStatus"
    ).children;
    this.afterSalesStatusList = businessDictData.find(
      (item) => item.code === "afterSalesStatus"
    ).children;
    this.selectConfig[1].data = this.afterSalesStatusList.map((item) => ({
      label: item.dictValue,
      value: item.dictKey,
    }));
    // customerList({ pageNum: 1, pageSize: 999 }).then((res) => {
    //   this.customerSelectList = res.data.data.records;
    // });
    API.customerSelectData().then((res) => {
      this.customerSelectList = res.data.data;
    });
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      API.afterSalesList(this.queryParams).then(
        (res) => {
          this.tableList = res.data.data.records;
          this.total = res.data.data.total;
          this.loading = false;
        },
        (err) => {
          console.log("afterSalesList: " + err);
          this.loading = false;
        }
      );
    },
    handleQuery() {
      this.getList();
    },
    handleAdd() {
      this.titleText = "添加售后记录";
      this.isAdd = true;
      this.form = {
        id: "",
        type: "",
        remark: "",
        productList: [],
      };
      this.open = true;
    },
    handleCancel() {
      this.open = false;
    },
    handleFollow(row) {
      this.titleText = "跟进";
      this.isAdd = false;
      this.form = {
        customerInfoId: row.customerInfoId,
        id: row.code,
        type: String(row.type),
        remarkOne: row.remark,
        orderInfoId: row.id,
        afterSalesStatus: "",
        remark: "",
      };

      this.open = true;
    },
    handleSubmit() {
      if (this.isAdd) {
        API.afterSalesAdd(this.form).then(
          () => {
            this.msgSuccess("添加成功");
            this.$refs.addAfterSales.loading = false;
            this.open = false;
            this.getList();
          },
          (err) => {
            console.log("afterSalesAdd: " + err);
            this.$refs.addAfterSales.loading = false;
          }
        );
      } else {
        delete this.form.customerInfoId;
        delete this.form.remarkOne;
        delete this.form.id;
        delete this.form.type;
        API.afterSalesFollow(this.form).then(
          () => {
            this.msgSuccess("操作成功");
            this.$refs.addAfterSales.loading = false;
            this.open = false;
            this.getList();
          },
          (err) => {
            console.log("afterSalesFollow: " + err);
            this.$refs.addAfterSales.loading = false;
          }
        );
      }
    },

    showAddress(row) {
      return (
        <div>
          {row.countryName} , {row.provinceName} , {row.cityName}
        </div>
      );
    },
    lookRecords() {
      this.openOne = true;
    },
  },
};
</script>


<template>
  <div class="box-card">
    <el-card class="header">
      <el-button type="primary" size="mini" @click="handleAdd">
        添加售后记录
      </el-button>
    </el-card>
    <el-card class="body-main">
      <query
        :selectConfig="selectConfig"
        :req="queryParams"
        :isShowMore="true"
        @handleQuery="handleQuery"
        @handleMore="
          () => {
            queryDialog = true;
          }
        "
      ></query>
      <el-table :data="tableList" v-loading="loading">
        <el-table-column
          label="售后类型"
          align="left"
          :formatter="(row) => dictDataEcho(row.type, afterSalesTypeList)"
        />
        <!-- <el-table-column label="订单编号" align="left" prop="code">
          <template slot-scope="scope">
            <div class="show_underline">
              {{ scope.row.code }}
            </div>
          </template>
        </el-table-column> -->
        <el-table-column label="客户名称" align="left" prop="customerName" />
        <el-table-column label="售货原因" align="left" prop="" />
        <!-- <el-table-column
          label="订单金额"
          align="left"
          prop="amountMoney"
          width="140"
        />
        <el-table-column
          label="收件城市"
          align="left"
          width="150"
          :formatter="showAddress"
        />
        <el-table-column label="详细地址" align="left" prop="detailedAddress" />
        <el-table-column
          label="下单时间"
          align="left"
          prop="orderTime"
          width="150"
        />
        <el-table-column
          label="登记时间"
          align="left"
          prop="createTime"
          width="150"
        /> -->
        <el-table-column
          label="状态"
          align="left"
          :formatter="
            (row) => dictDataEcho(row.afterSalesStatus, afterSalesStatusList)
          "
        />
        <!-- <el-table-column
          label="订单状态"
          align="left"
          width="120"
          :formatter="(row) => dictDataEcho(row.status, orderStatusList)"
        /> -->
        <el-table-column label="操作" align="center" width="160">
          <template slot-scope="scope">
            <el-button type="text" @click="lookRecords(scope.row)"
              >跟进记录
            </el-button>
            <el-button type="text" @click="handleFollow(scope.row)"
              >跟进
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>

    <el-dialog
      :title="titleText"
      :visible.sync="open"
      v-if="open"
      width="30%"
      top="60px"
    >
      <add-after-sales
        :form="form"
        :isAdd="isAdd"
        :customerSelectList="customerSelectList"
        :afterSalesTypeList="afterSalesTypeList"
        :afterSalesStatusList="afterSalesStatusList"
        @submit="handleSubmit"
        @cancel="handleCancel"
        ref="addAfterSales"
      ></add-after-sales>
    </el-dialog>

    <el-dialog
      title="跟进记录"
      :visible.sync="openOne"
      v-if="openOne"
      width="30%"
      top="100px"
    >
      <div v-for="item in 3" :key="item" class="record-item">
        <div class="head">
          <span class="time"> 跟进时间：{{}} </span>
          <span class="name"> 张三 </span>
        </div>
        <div class="body">跟进记录</div>
      </div>
    </el-dialog>
  </div>
</template>


<style lang="scss" scoped>
.box-card {
  height: calc(100vh - 110px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  .header {
    // height: 100px;
    margin-bottom: 10px;
    box-sizing: border-box;
  }
  .body-main {
    flex: 1;
    overflow-y: auto;
  }
}
.record-item {
  margin-bottom: 20px;
  .head {
    margin-bottom: 10px;
    display: flex;
    span {
      font-size: 12px;
      color: #c3bdbd;
    }
    .time {
      flex: 1;
    }
    .name {
      width: 50px;
    }
  }
  .body {
    color: #000;
    font-size: 14px;
  }
}
</style>