"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _navbar = _interopRequireDefault(require("@/common/navbar/navbar.vue"));

var _tableColumDialog = _interopRequireDefault(require("./components/tableColumDialog.vue"));

var _integralDialog = _interopRequireDefault(require("./components/integralDialog.vue"));

var _batchgradeDialog = _interopRequireDefault(require("./components/batchgradeDialog.vue"));

var _mainstoreDialog = _interopRequireDefault(require("./components/mainstoreDialog.vue"));

var _substoreDialog = _interopRequireDefault(require("./components/substoreDialog.vue"));

var _batchList = _interopRequireDefault(require("./components/batchList.vue"));

var _importDialog = _interopRequireDefault(require("./components/importDialog.vue"));

var _api = require("../../components/axios/api");

var _url = _interopRequireDefault(require("../../components/axios/url"));

var _vuex = require("vuex");

var _utils = require("@/utils/utils");

var _default2 = _interopRequireDefault(require("../../../static/img/default.png"));

var _auth = _interopRequireDefault(require("@/mixins/auth"));

var _checkStatus = require("../../../static/js/checkStatus");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var _default = {
  name: "allCustomersList",
  data: function data() {
    return {
      sceneValue: "member",
      // 人群筛选器场景值
      navpath: [{
        name: "首页",
        path: ""
      }, {
        name: "客户列表",
        path: ""
      }, {
        name: "全部客户",
        path: ""
      }],
      pageParam: {
        currentPage: 1,
        pageSize: 20,
        phoneNameCard: "",
        // 搜索字段
        memberSearchStr: -1,
        // 人群筛选
        sortColName: "",
        // 排序字段
        sortType: "" // 排序方式

      },
      totalCount: 0,
      loading: false,
      tableData: [],
      customerTypeLabel: "",
      //  "非会员,微信会员,POS会员",
      customerType: [// { id: 1, label: "非会员" },
        // { id: 3, label: "微信会员" },
        // { id: 4, label: "POS会员" }
      ],
      oldCustomerType: "",
      showSearch: false,
      // 高级搜索开关
      toggleTag: false,
      // 人群筛选器按钮开关
      dialogFieldVisible: false,
      // 列表字段设置弹窗开关
      memberFields: [],
      // 列表字段
      checkedFields: [],
      // 已选列表字段
      memberFieldsName: {},
      // 已选列表字段名称
      isExist: {},
      // 该商户表中是否存在列表字段 判断是否支持排序
      multipleList: [],
      dialogIntegralVisible: false,
      dialogGradeVisible: false,
      dialogMainstoreVisible: false,
      dialogSubStoreVisible: false,
      dialogImportVisible: false,
      selectAll: false,
      // 列表全选开关
      batchValue: '',
      batchOpt: [// 批处理选项
      {
        value: "integral",
        label: "调整积分",
        code: "memberBatchSetIntegral"
      }, {
        value: "grade",
        label: "修改等级",
        code: "memberBatchSetGrade"
      }, {
        value: "mainstore",
        label: "修改服务门店",
        code: "memberBatchSetService"
      }, {
        value: "store",
        label: "修改协管门店",
        code: "memberBatchSetCustomer"
      }],
      defaultImg: _default2["default"],
      integralFlag: "",
      // 积分调整权限
      memberGrade: [],
      // 商户等级列表
      cliqueMemberGrade: [],
      // 集团等级列表
      treeData: [{
        id: 1,
        label: "非会员",
        disabled: false
      }, {
        id: 2,
        label: "会员",
        disabled: false,
        children: [{
          id: 3,
          label: "微信会员",
          disabled: false
        }, {
          id: 4,
          label: "POS会员",
          disabled: false
        }]
      }],
      defaultProps: {
        children: "children",
        label: "label"
      }
    };
  },
  mixins: [_auth["default"]],
  components: {
    NavPath: _navbar["default"],
    tableColumDailog: _tableColumDialog["default"],
    integralDailog: _integralDialog["default"],
    gradeDailog: _batchgradeDialog["default"],
    mainstoreDailog: _mainstoreDialog["default"],
    substoreDailog: _substoreDialog["default"],
    importDialog: _importDialog["default"],
    batchList: _batchList["default"]
  },
  computed: _objectSpread({
    pageName: function pageName() {
      // 1-非会员 notMember 3-微信会员 wxOpenCarMember 4-pos会员 posMember
      var filterObj = {
        1: "notMember",
        3: "wxOpenCarMember",
        4: "posMember"
      };
      var list = [];
      this.customerType.forEach(function (el) {
        list.push(filterObj[el.id]);
      });
      return list.length ? list.join(",") : "notMember,wxOpenCarMember,posMember";
    },
    selectObj: function selectObj() {
      return {
        selectAll: this.selectAll,
        multipleList: this.multipleList,
        totalCount: this.totalCount
      };
    },
    ajaxObj: function ajaxObj() {
      return _objectSpread({}, this.pageParam, {
        pageName: this.pageName
      });
    }
  }, (0, _vuex.mapState)(["storeImageUrl", "showEditClique"])),
  filters: {
    sexFilter: function sexFilter(v) {
      switch (v) {
        case 1:
          return "男";

        case 2:
          return "女";

        default:
          return "--";
      }
    }
  },
  watch: {
    customerType: {
      handler: function handler(newV, oldV) {
        this.onSearch();
      },
      deep: true
    },
    $route: function $route(n, o) {
      if (n.path === "/allCustomers") {
        this.$store.commit("mutations-slide", true);
      }
    }
  },
  created: function created() {
    this.$store.commit("mutations-slide", true);
    this.initialize();
    this.getGradeList();
    this.getCliqueGradeList();
  },
  mounted: function mounted() {
    this.getFindMemberFields();
    this.getAjaxMembers();
    this.getEnterpriseInfo(); // 默认勾选全部客户类型 1-非会员 notMember 3-微信会员 wxOpenCarMember 4-pos会员 posMember
    // this.$refs.tree.setCheckedNodes(this.treeData);
    // this.$nextTick(_ => {
    //   this.handleCheckChange();
    // });
  },
  beforUpdate: function beforUpdate() {},
  methods: {
    selectChange: function selectChange(e) {
      var _this = this;

      var arrNew = [];
      var dataLength = this.customerType.length;
      var eleng = e.length;

      for (var i = 0; i < dataLength; i++) {
        for (var j = 0; j < eleng; j++) {
          if (e[j] === this.customerType[i].label) {
            arrNew.push(this.customerType[i]);
          }
        }
      }

      this.$refs.tree.setCheckedNodes(arrNew);
      this.$nextTick(function (_) {
        _this.handleCheckChange();
      });
    },
    handleCheckChange: function handleCheckChange(data, nodes) {
      var res = this.$refs.tree.getCheckedNodes(true, true); // 这里两个true，1. 是否只是叶子节点 2. 是否包含半选节点（就是使得选择的时候不包含父节点）

      var getAllCheck = this.$refs.tree.getCheckedNodes(false, true);
      var arrLabel = [];
      var arr = [];
      res.forEach(function (item) {
        item.disabled = false;
        arrLabel.push(item.label);
        arr.push(item);
      });
      this.customerType = [].concat(arr);
      this.customerTypeLabel = [].concat(arrLabel);
      var sum = this.searchTreeNodeNum(this.treeData);
      if (getAllCheck.length == sum) this.customerTypeLabel = ['全部客户'];
    },
    searchTreeNodeNum: function searchTreeNodeNum(tree) {
      var _this2 = this;

      var num = 0;
      tree.forEach(function (el) {
        num++;
        if (Array.isArray(el.children) && el.children.length > 0) num += _this2.searchTreeNodeNum(el.children, num);
      });
      return num;
    },
    handleClickNode: function handleClickNode(data, node) {
      this.$refs.tree.setChecked(data, !node.checked, true);
      this.handleCheckChange();
    },
    initialize: function initialize() {
      this.pageParam.phoneNameCard = sessionStorage.getItem("phoneNameCard") ? sessionStorage.getItem("phoneNameCard") : "";
      this.pageParam.currentPage = sessionStorage.getItem("currentPage") ? sessionStorage.getItem("currentPage") : 1;
    },
    handleCurrentChange: function handleCurrentChange(val) {
      this.pageParam.currentPage = val;
      sessionStorage.setItem("currentPage", val);
      this.getAjaxMembers();
    },
    handleSizeChange: function handleSizeChange(val) {
      this.pageParam.pageSize = val;
      this.getAjaxMembers();
    },
    onSearch: function onSearch() {
      this.pageParam.currentPage = 1;
      this.getAjaxMembers();
    },
    // 获取列表数据
    getAjaxMembers: function getAjaxMembers() {
      var _this3 = this;

      this.loading = true;
      this.selectAll = false;
      (0, _api.doFetch)(_url["default"].ajaxMembers, Object.assign({}, this.pageParam, {
        pageName: this.pageName,
        showFields: "-1"
      })).then(function (res) {
        _this3.loading = false;

        if (res.data.errorCode === 0 && res.data.result) {
          _this3.checkedFields = res.data.result.fieldsStr ? res.data.result.fieldsStr.split(",") : ["name", "grade", "status", "channel", "costAll", "costTimes", "lastCostTime", "attentionDate"];
          _this3.isExist = Object.assign({}, res.data.result.fields || {}); // 首先先保存数据 某些品牌的数据返回的很慢

          var resultData = res.data.result.page ? res.data.result.page.result : [];
          var tableData = [];

          if (resultData.length) {
            tableData = resultData.map(function (ele) {
              return _objectSpread({}, ele, {
                avgNumber: ele.avgNumber.toFixed(2),
                lastCostTime: ele.lastCostTime != -1 ? (0, _utils.formatLongTime)(ele.lastCostTime, 2) : "--",
                // 最近消费时间
                createTime: ele.createTime != -1 ? (0, _utils.formatLongTime)(ele.createTime, 1) : "--",
                // 新增时间
                attentionDate: ele.attentionDate != -1 ? (0, _utils.formatLongTime)(ele.attentionDate, 1) : "--",
                // 关注时间
                cancelAttentionTime: ele.cancelAttentionTime != -1 ? (0, _utils.formatLongTime)(ele.cancelAttentionTime, 1) : "--",
                // 取关时间
                attentionTime: ele.attentionTime != -1 ? (0, _utils.formatLongTime)(ele.attentionTime, 1) : "--",
                // 关注时间
                crateCardDateString: ele.crateCardDateString != -1 ? (0, _utils.formatLongTime)(ele.crateCardDateString, 1) : "--",
                // 开卡
                birthdayMD: ele.birthdayMD != 0 ? (0, _utils.paddingBorth)(ele.birthdayMD) : "--",
                // 生日补全
                sex: ele.sex == 0 ? "--" : ele.sex == 1 ? "男" : "女",
                age: ele.age ? ele.age : "--",
                cardNo: ele.cardNo ? ele.cardNo : "--",
                mainStoreName: ele.mainStoreName ? ele.mainStoreName : "--",
                thirdImgUrl: ele.thirdImgUrl ? ele.thirdImgUrl : _this3.storeImageUrl
              });
            });
          }

          _this3.pageParam.currentPage = res.data.result.page.currentPage;
          _this3.totalCount = res.data.result.page.totalCount;
          _this3.tableData = [].concat(tableData);
        } else {
          (0, _checkStatus.checkFalse)(res.data.message);
        }
      })["catch"](function (err) {
        (0, _checkStatus.checkStatus)(err);
      })["finally"](function (_) {
        return _this3.loading = false;
      });
    },
    getFindMemberFields: function getFindMemberFields() {
      var _this4 = this;

      (0, _api.doFetch)(_url["default"].findMemberFields, {
        pageName: this.pageName
      }).then(function (res) {
        if (res.data.errorCode === 0 && Array.isArray(res.data.result)) {
          var tempArr = [].concat(res.data.result);
          var memberFields = [];
          var memberFieldsName = [];
          tempArr.forEach(function (item) {
            memberFieldsName[item.code] = item.name;
            memberFields.push(item);
          });
          _this4.memberFields = [].concat(memberFields);
          _this4.memberFieldsName = Object.assign({}, memberFieldsName); // this.$nextTick(_ => {
          // });
        } else {
          (0, _checkStatus.checkFalse)(res.data.message);
        }
      })["catch"](function (err) {
        (0, _checkStatus.checkStatus)(err);
      });
    },
    submitMemberFields: function submitMemberFields(v) {
      var _this5 = this;

      (0, _api.doFetch)(_url["default"].updateFields, {
        pageName: this.pageName,
        fields: v
      }).then(function (res) {
        if (res.data.errorCode === 0) {
          (0, _checkStatus.checkSuccess)();
          _this5.checkedFields = v.split(",");

          _this5.getAjaxMembers();
        } else {
          (0, _checkStatus.checkFalse)(res.data.message);
        }
      })["catch"](function (err) {
        (0, _checkStatus.checkStatus)(err);
      });
    },
    // 处理table 全选事件
    handleSelectAlll: function handleSelectAlll(val) {
      if (!val.length) this.selectAll = false;
    },
    // 处理table select事件
    handleSelectionChange: function handleSelectionChange(val) {
      if (val.length !== this.pageParam.pageSize) this.selectAll = false;
      this.multipleList = val;
    },
    // 处理table 排序事件
    sortChange: function sortChange(column, prop, order) {
      this.pageParam.sortColName = column.prop;

      if (column.order === "descending") {
        this.pageParam.sortType = "desc";
      }

      if (column.order === "ascending") {
        this.pageParam.sortType = "asc";
      }

      this.getAjaxMembers();
    },
    // 人群筛选器 - 校验与提交筛选结果
    getData: function getData() {
      this.$refs.peopleFilter.confirmSet();
    },
    // 人群筛选器 - 子组件触发父组件事件,返回过滤条件数据
    findFilter: function findFilter(value) {
      this.pageParam.memberSearchStr = !value ? -1 : value;
      this.onSearch();
    },
    // 人群筛选器 - 显示按钮
    editShow: function editShow() {
      this.toggleTag = true;
    },
    // 人群筛选器 - 确认好选择条件之后 隐藏按钮
    editHide: function editHide() {
      this.toggleTag = false;
    },
    // 人群筛选器 - 隐藏保存按钮和确认按钮  (子组件会调用)
    hideBtn: function hideBtn(refresh) {
      if (refresh == 0) {
        this.pageParam.memberSearchStr = -1;
        this.getAjaxMembers();
        this.toggleTag = false;
      }
    },
    // 人群筛选器 - 取消人群筛选
    cancelFilter: function cancelFilter() {
      this.$refs.peopleFilter.cancelSet();
      this.toggleTag = false;
    },
    // 客户列表选择
    selectAllmultipleList: function selectAllmultipleList() {
      var _this6 = this;

      this.selectAll = !this.selectAll;

      if (this.selectAll) {
        this.tableData.forEach(function (row) {
          _this6.$refs.multipleTable.toggleRowSelection(row, true);
        });
      } else {
        this.$refs.multipleTable.clearSelection();
      }
    },
    // 批量导入
    openDialogImport: function openDialogImport() {
      this.dialogImportVisible = true;
    },
    successImport: function successImport(taskId) {
      var _this7 = this;

      // this.dialogImportVisible = false;
      this.$confirm("任务发起成功，请去【企业管理】-【任务中心】查看处理结果和执行进度", "任务发起成功", {
        confirmButtonText: "去任务中心",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        customClass: "import-link-confirm-content",
        type: "warning"
      }).then(function () {
        window.open("/gic-web/#/taskDetail/".concat(taskId));

        _this7.batchRefresh();
      })["catch"](function () {
        _this7.batchRefresh();
      });
    },
    // 批量处理
    handleFocusBatch: function handleFocusBatch(val) {
      if (this.multipleList.length < 1) {
        this.batchValue = "";
        (0, _checkStatus.checkFalse)("请勾选会员");
        return false;
      }

      if (this.batchValue == "integral") {
        this.dialogIntegralVisible = true;
      } else if (this.batchValue == "grade") {
        this.dialogGradeVisible = true;
      } else if (this.batchValue == "mainstore") {
        this.dialogMainstoreVisible = true;
      } else if (this.batchValue == "store") {
        this.dialogSubStoreVisible = true;
      }

      this.batchValue = "";
    },
    // 批量导入修改
    batchImport: function batchImport() {
      this.openDialogImport();
    },
    batchRefresh: function batchRefresh() {
      this.getAjaxMembers();
    },
    getGradeList: function getGradeList() {
      var _this8 = this;

      (0, _api.doFetch)(_url["default"].gradeList).then(function (res) {
        if (res.data.errorCode === 0) {
          _this8.memberGrade = res.data.result || [];
        } else {
          (0, _checkStatus.checkFalse)(res.data.message);
          return false;
        }
      })["catch"](function (err) {
        (0, _checkStatus.checkStatus)(err);
      });
    },
    getCliqueGradeList: function getCliqueGradeList() {
      var _this9 = this;

      (0, _api.doFetch)(_url["default"].cliqueGradeList).then(function (res) {
        if (res.data.errorCode === 0) {
          _this9.cliqueMemberGrade = res.data.result || [];
        } else {
          (0, _checkStatus.checkFalse)(res.data.message);
          return false;
        }
      })["catch"](function (err) {
        (0, _checkStatus.checkStatus)(err);
      });
    },
    linkDetail: function linkDetail(memberId) {
      if (!this.getCodeAuth('memberIntoCustomDetail')) return;
      this.$router.push({
        path: "/customerDetail",
        query: {
          memberId: memberId
        }
      });
    },
    getEnterpriseInfo: function getEnterpriseInfo() {
      var _this10 = this;

      (0, _api.doFetch)(_url["default"].enterpriseInfo).then(function (res) {
        if (res.data.errorCode == 0) {
          _this10.integralFlag = res.data.result.enterpriseInfo.integralFlag;
        } else {
          (0, _checkStatus.checkFalse)();
        }
      })["catch"](function (err) {
        (0, _checkStatus.checkStatus)(err);
      });
    }
  }
};
exports["default"] = _default;