"use strict";

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

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

var _baseinfoDialog = _interopRequireDefault(require("./components/baseinfoDialog.vue"));

var _babyinfoDialog = _interopRequireDefault(require("./components/babyinfoDialog.vue"));

var _customergradeDialog = _interopRequireDefault(require("./components/customergradeDialog.vue"));

var _customermainstoreDialog = _interopRequireDefault(require("./components/customermainstoreDialog.vue"));

var _customersubstoreDialog = _interopRequireDefault(require("./components/customersubstoreDialog.vue"));

var _customerlabelDialog = _interopRequireDefault(require("./components/customerlabelDialog.vue"));

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

var _vuex = require("vuex");

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

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

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: 'customersDetail',
  mixins: [_auth["default"]],
  data: function data() {
    return {
      navpath: [{
        name: '首页',
        path: ''
      }, {
        name: '客户列表',
        path: '/allCustomers'
      }, {
        name: '客户详情',
        path: ''
      }],
      pageName: 'allCustomer',
      // 请求参数
      memberId: '',
      member: {
        // 会员基础信息
        memberProtocolInfo: {
          // 会员协议信息
          visitConsentPrivacyProtocolTime: null,
          // 微盟访问同意协议的时间
          loginConsentPrivacyProtocolTime: null,
          // 微盟登录同意协议的时间
          consentPrivacyProtocolTime: null // 达摩同意协议的时间

        },
        thirdImgUrl: '' // 头像

      },
      memberInfo: {},
      // 会员卡信息
      extendInfo: {
        // 开卡字段、扩展字段
        openField: [],
        fieldList: [],
        openChildrenField: [],
        babyConfigTemplate: {}
      },
      babyStr: '',
      // 宝宝信息
      // 标签备注
      tagAndRemarkInfo: {
        // 会员分组
        memberGroup: {
          // 金字塔分层
          memberGradeGroup: {},
          // 客户分组
          memberTagGroupList: {}
        },
        // 手工标签
        tag: {
          tagsList: [],
          // 导购标签
          otherTagsList: [],
          // 其他标签
          weimobTagsList: [] // 微盟标签

        },
        // 导购备注
        remarkList: [],
        // 身形字段
        dictFigureList: []
      },
      tableData: [],
      logPageParam: {
        pageSize: 20,
        currentPage: 1
      },
      totalCount: 0,
      defaultImg: _default2["default"],
      labelTabsActive: 'memberTagGroup',
      fullscreenLoading: false,
      // 全局loading
      tableLoading: false,
      // 用户日志列表loading
      imgLoading: false,
      // 刷新头像loading
      popoverVisible: false,
      // 修改等级popover
      toggleTag: false,
      // 拓展信息展开按钮
      showFieldType: 1,
      // 1开卡拓展字段 2会员信息字段
      showClique: false,
      // 集团权限
      baseinfoDialogVisible: false,
      // 修改基本信息弹窗
      gradeDialogVisible: false,
      // 修改等级弹窗
      mainStoreDialogVisible: false,
      // 修改服务门店、专属导购弹窗
      subStoreDialogVisible: false,
      // 修改协管门店弹窗
      labelDialogVisible: false,
      // 修改手工标签弹窗
      babyDialogVisible: false,
      // 宝宝信息弹窗
      nationCodeList: [],
      // 手机区号列表
      gradeList: [],
      // 等级列表
      cliqueGradeList: [],
      // 集团等级列表
      count: 0,
      // 模块列表
      customerInfoItemList: [{
        title: '基本信息',
        name: 'basic',
        "class": 'basic-info-contain'
      }, {
        title: '会员卡信息',
        name: 'card',
        "class": 'card-info-contain max1600'
      }, {
        title: '客户记录',
        name: 'customerRecord',
        "class": 'customer-record-contain max1600',
        childrenList: {
          // 资产信息
          assets: [{
            label: '集团积分',
            icon: 'icon-jifenjiabei',
            iconTheme: 'integral_clique',
            key: 'cliqueMemberIntegral',
            path: ''
          }, {
            label: '商户积分',
            icon: 'icon-jifenduihuan',
            iconTheme: 'integral',
            key: 'accumulatPoints',
            path: '/integralDataPage'
          }, {
            label: '卡券',
            icon: 'icon-01_kaquanguanli',
            iconTheme: 'coupon',
            key: 'couponCount',
            path: '/cardvoucher'
          }, {
            label: '储值余额',
            icon: 'icon-chuzhizhanghu',
            iconTheme: 'balance',
            key: 'storedValue',
            path: ''
          }],
          // 交易记录
          transaction: [{
            label: '门店订单',
            icon: 'icon-mendianbaojiadan',
            key: 'numOfSale',
            path: '/consumption'
          }, {
            label: '微盟订单',
            icon: 'icon-a-weimeng2',
            key: 'weimobMallNum',
            path: '/wmDetail'
          }, {
            label: '达摩商城订单',
            icon: '',
            key: 'wechatMallNum',
            path: '/infoMall'
          }, {
            label: '其他订单',
            icon: 'icon-dingdan-copy',
            key: 'otherMallNum',
            path: '/otherDetail'
          }],
          // 交互记录
          interactive: [{
            label: '营销记录',
            icon: 'icon-yingxiaojilu',
            iconTheme: 'market',
            key: 'numOfMarket',
            path: '/marketing-record'
          }, {
            label: '通话记录',
            icon: 'icon-tonghuajilu1',
            iconTheme: 'tel',
            key: 'numOfTel',
            path: '/talkLogPage'
          }]
        }
      }, {
        title: '归属信息',
        name: 'ascription',
        "class": 'ascription-info-contain max160'
      }, {
        title: '标签备注',
        name: 'label',
        "class": 'label-remarks-contain',
        childrenList: [{
          title: '导购标签',
          key: 'tagsList'
        }, {
          title: '其他标签',
          key: 'otherTagsList'
        }, {
          title: '微盟标签',
          key: 'weimobTagsList'
        }]
      }, {
        title: '客户日志',
        name: 'log',
        "class": 'log-info-contain'
      }],
      marketingRecordNum: 0
    };
  },
  watch: {
    count: function count(n, o) {
      if (n === 4) this.fullscreenLoading = false;
    }
  },
  filters: {
    customerTypeFilter: function customerTypeFilter(v) {
      switch (v) {
        case 'wxOpenCarMember':
          return '微信会员';

        case 'posMember':
          return 'POS会员';

        default:
          return '非会员';
      }
    },
    genderFilter: function genderFilter(v) {
      switch (v) {
        case 1:
          return '男';

        case 2:
          return '女';

        default:
          return '--';
      }
    }
  },
  computed: _objectSpread({
    toggleShow: function toggleShow() {
      if (this.showFieldType === 2 && this.extendInfo && this.extendInfo.fieldList && this.extendInfo.fieldList.length > 3) return true;

      if (this.showFieldType === 1 && this.extendInfo && this.extendInfo.openField) {
        return this.babyStr ? this.extendInfo.openField.length > 2 : this.extendInfo.openField.length > 3;
      }

      return false;
    }
  }, (0, _vuex.mapState)(['showEditClique'])),
  created: function created() {
    this.$store.commit('mutations-slide', true);
    this.memberId = this.$route.query.memberId;
    this.getMarketingRecordNum();
  },
  mounted: function mounted() {
    var rightWrap = document.querySelector('.dm-layout-page');
    rightWrap.scrollTo(0, 0);
    this.initData();
    this.getEnterpriseInfo();
    this.getcodeList();
    this.getGradeList();
    this.getCliqueGradeList();
  },
  methods: {
    initData: function initData() {
      this.count = 0;
      this.fullscreenLoading = true;
      this.getAllDetail();
      this.getLogPage();
    },
    getAllDetail: function getAllDetail() {
      var _this = this;

      var param = {
        memberId: this.memberId,
        pageName: this.pageName
      };
      var urlArr = ['memberLoadBaseDetail', 'memberLoadmemberInfo', 'memberLoadTagDetail'];
      urlArr.forEach(function (api) {
        (0, _api.doFetch)(_url["default"][api], param).then(function (res) {
          if (res.data.errorCode === 0) {
            var ret = res.data.result;

            if (api === 'memberLoadBaseDetail') {
              _this.member = Object.assign({}, ret.member);
              var extendInfo = {
                babyConfigTemplate: ret.extendInfo.babyConfigTemplate || {},
                fieldList: ret.extendInfo.fieldList || [],
                openChildrenField: ret.extendInfo.openChildrenField || [],
                openField: ret.extendInfo.openField || []
              };
              var babyArr = [];
              extendInfo.openChildrenField.forEach(function (el) {
                var item = el.sonFields.find(function (e) {
                  return e.unifiedIdentification == 'k20301';
                });
                babyArr.push(item && item.fieldValue ? "".concat(el.bName, "\uFF08").concat(item.fieldValue, "\uFF09") : el.bName);
              });
              _this.extendInfo = Object.assign({}, ret.extendInfo);
              _this.babyStr = babyArr.join('；');
            }

            if (api === 'memberLoadmemberInfo') {
              _this.memberInfo = Object.assign({}, ret.memberInfo);
            }

            if (api === 'memberLoadTagDetail') {
              _this.tagAndRemarkInfo = Object.assign({}, {
                memberGroup: {
                  memberGradeGroup: ret.tagAndRemarkInfo.memberGroup.memberGradeGroup || {},
                  memberTagGroupList: ret.tagAndRemarkInfo.memberGroup.memberTagGroupList || {}
                },
                tag: {
                  tagsList: ret.tagAndRemarkInfo.tag.tagsList || [],
                  otherTagsList: ret.tagAndRemarkInfo.tag.otherTagsList || [],
                  weimobTagsList: ret.tagAndRemarkInfo.tag.weimobTagsList || []
                },
                remarkList: ret.tagAndRemarkInfo.remarkList || [],
                dictFigureList: ret.tagAndRemarkInfo.dictFigureList || []
              });
            }
          } else {
            (0, _checkStatus.checkFalse)(res.data.message);
          }
        })["catch"](function (err) {
          (0, _checkStatus.checkStatus)(err);
        })["finally"](function (_) {
          return _this.count++;
        });
      });
    },
    getLogPage: function getLogPage() {
      var _this2 = this;

      this.tableLoading = true;
      (0, _api.doFetch)(_url["default"].logPage, _objectSpread({}, this.logPageParam, {
        memberId: this.memberId
      })).then(function (res) {
        _this2.tableLoading = false;

        if (res.data.errorCode === 0) {
          _this2.tableData = res.data.result.page.result || [];
          _this2.tableData = _this2.tableData.map(function (el) {
            if (typeof el.operRemark == 'string') {
              el.operRemark = el.operRemark.replace(/\n/g, ' <br />');
            }

            return el;
          });
          _this2.totalCount = res.data.result.page.totalCount;
        } else {
          (0, _checkStatus.checkFalse)(res.data.message);
          return false;
        }
      })["catch"](function (err) {
        _this2.tableLoading = false;
        (0, _checkStatus.checkStatus)(err);
      })["finally"](function (_) {
        return _this2.count++;
      });
    },
    updateImgUrl: function updateImgUrl() {
      var _this3 = this;

      this.imgLoading = true;
      (0, _api.doFetch)(_url["default"].updateImgUrl, {
        memberId: this.memberId
      }).then(function (res) {
        if (res.data.errorCode === 0) {
          (0, _checkStatus.checkSuccess)();
          var ret = res.data.result;
          _this3.member = Object.assign({}, _this3.member, {
            thirdImgUrl: ret.thirdImgUrl ? ret.thirdImgUrl : ''
          });
        } else {
          (0, _checkStatus.checkFalse)(res.data.message);
        }
      })["catch"](function (err) {
        (0, _checkStatus.checkStatus)(err);
      })["finally"](function (_) {
        return _this3.imgLoading = false;
      });
    },
    changeExtendFieldTab: function changeExtendFieldTab(type) {
      this.showFieldType = type;
      this.toggleTag = true;
    },
    goLink: function goLink(v) {
      if (v) this.$router.push({
        path: v,
        query: {
          memberId: this.memberId
        }
      });
    },
    goStoreValue: function goStoreValue() {
      if (this.memberInfo.storedValueFlag) {
        this.$router.push({
          path: '/storedValue',
          query: {
            memberId: this.memberId
          }
        });
      }
    },
    handleSizeChange: function handleSizeChange(v) {
      this.logPageParam.pageSize = v;
      this.logPageParam.currentPage = 1;
      this.getLogPage();
    },
    handleCurrentChange: function handleCurrentChange(v) {
      this.logPageParam.currentPage = v;
      this.getLogPage();
    },
    // 集团配置
    getEnterpriseInfo: function getEnterpriseInfo() {
      var _this4 = this;

      (0, _api.doFetchqs)(_url["default"].enterpriseInfo).then(function (res) {
        if (res.data.errorCode === 0) {
          _this4.showClique = res.data.result.enterpriseInfo.showClique;
        }
      });
    },
    // 手机区号列表
    getcodeList: function getcodeList() {
      var _this5 = this;

      (0, _api.doFetch)(_url["default"].codeList).then(function (res) {
        if (res.data.errorCode === 0) {
          _this5.nationCodeList = res.data.result.nationCodeList.map(function (item) {
            item.dictName += " +".concat(item.dictCode);
            return {
              dictName: item.dictName,
              dictCode: item.dictCode
            };
          });
        } else {
          (0, _checkStatus.checkFalse)(res.data.message);
        }
      })["catch"](function (err) {
        (0, _checkStatus.checkStatus)(err);
      });
    },
    showGradeDialog: function showGradeDialog(type) {
      this.isClique = type;
      this.gradeDialogVisible = true;
    },
    // 等级列表
    getGradeList: function getGradeList() {
      var _this6 = this;

      (0, _api.doFetch)(_url["default"].gradeList).then(function (res) {
        if (res.data.errorCode === 0) {
          _this6.gradeList = res.data.result || [];
        } else {
          (0, _checkStatus.checkFalse)(res.data.message);
          return false;
        }
      })["catch"](function (err) {
        (0, _checkStatus.checkStatus)(err);
      });
    },
    // 集团等级列表
    getCliqueGradeList: function getCliqueGradeList() {
      var _this7 = this;

      (0, _api.doFetch)(_url["default"].cliqueGradeList).then(function (res) {
        if (res.data.errorCode === 0) {
          _this7.cliqueGradeList = res.data.result || [];
        } else {
          (0, _checkStatus.checkFalse)(res.data.message);
          return false;
        }
      })["catch"](function (err) {
        (0, _checkStatus.checkStatus)(err);
      });
    },
    getMarketingRecordNum: function getMarketingRecordNum() {
      var param, res;
      return regeneratorRuntime.async(function getMarketingRecordNum$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.prev = 0;
              param = {
                memberId: this.memberId
              };
              _context.next = 4;
              return regeneratorRuntime.awrap((0, _api.doFetchGet)(_url["default"].getMarketingRecordNum, param));

            case 4:
              res = _context.sent;

              if (res.data.errorCode == 0) {
                this.marketingRecordNum = res.data.result || 0;
                console.log(this.marketingRecordNum);
              } else {
                (0, _checkStatus.checkFalse)(res.data.message);
              }

              _context.next = 11;
              break;

            case 8:
              _context.prev = 8;
              _context.t0 = _context["catch"](0);
              (0, _checkStatus.checkStatus)(_context.t0);

            case 11:
            case "end":
              return _context.stop();
          }
        }
      }, null, this, [[0, 8]]);
    }
  },
  components: {
    'v-nav': _navbar["default"],
    baseinfoDialog: _baseinfoDialog["default"],
    babyinfoDialog: _babyinfoDialog["default"],
    customergradeDialog: _customergradeDialog["default"],
    customermainstoreDialog: _customermainstoreDialog["default"],
    customersubstoreDialog: _customersubstoreDialog["default"],
    customerlabelDialog: _customerlabelDialog["default"]
  }
};
exports["default"] = _default;