index.js 29.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027
// packageEquity/pages/carQuotation/index/index.js
import {
  quotationPage,
  getQuotationStatistics,
  updateOrderStatus,
  merchantMode,
  orderStatistics,
  cancelOrderById,
  getQuotationInfoById,
  updateCustomerInfo,
  errorOrderById
} from "../../../api";
import { checkDailyReport } from "~/store/ModalToQueueControl";
import data from "../constant/data";
import constantData from "../constant/data";
import { ImgUrl as IMG_URL } from "~/config";
let timeoutId;
const IMG_URL2 =
  "https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/";
import carLifeApi from "../../../carEquityApi";
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    navBarHeight: {
      type: Number,
      value: 0,
    },
    mode: {
      type: Number,
    },
    staffUuid: {
      type: String
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    IMG_URL,
    IMG_URL2,
    showIcon1: true, // 初始显示图标
    orderObj: [
      {
        label: "销售顾问",
        arr: ["merchantName", "referrerName"],
      },
      {
        label: "转化人员",
        arr: ["parkMerchantName", "transferName"],
      },
      {
        label: "车架号",
        key: "carVin",
      },
      {
        label: "购买商品",
        key: "goodsNameAlias",
        otherKey: "goodsName",
      },
      {
        label: "工单编号",
        key: "payId",
      },
      {
        label: "交易流水号",
        key: "transactionNo",
        canCopy: true,
      },
      {
        label: "拒升原因",
        key: "remark",
      },
      {
        label: "支付时间",
        key: "payTime",
      },
      {
        label: "创建时间",
        key: "createdTime",
      },
      {
        label: "支付方式",
        key: "payType",
        mapValue: {
          1: "线上支付",
          2: "门店收款",
          5: "嘀加收款"
        },
      },
    ],
    // statisticsObj: {},
    btnTxt: {
      0: "去报价",
      1: "确认方案",
      2: "去支付",
      3: "去处理",
      "-1": "去报价",
      5: "去处理",
    },
    searchObj: {},
    customerName: "",
    list: [],
    tabIndex: 0,
    nothing: false,
    orderStatusObj: data.orderStatusObj,
    // 0待报价、1待确认、2待支付、3已支付、4已完成、-1战败 '已撤销','错误订单','已退款'
    tabListNor: [
      "全部",
      "待报价",
      "待确认",
      "待支付",
      "已支付",
      "已完成",
      "战败",
    ],
    tabListSimple: ["全部", "待报价", "待支付", "已支付", "已完成", "战败", "待上传协议"],
    tabList: ["全部", "待报价", "待确认", "待支付", "已支付", "已完成", "战败"],
    tabListTemplate: [
      "全部",
      "待报价",
      "待确认",
      "待支付",
      "已支付",
      "已完成",
      "战败",
    ],
    tabListTemplateSimple: [
      "全部",
      "待报价",
      "待支付",
      "已支付",
      "已完成",
      "战败",
    ],
    pageSize: 4,
    currentPage: 1,
    flag: true,
    total: 0,
    storeInfo: {},
    triggered: false,
    scrollTop: 0,
    userInfo: {},
    sufferReason: "",
    // mode: 0,
    showRendering: false,
    repealVisible: false,
    repealReason: '',
    repealId: '',
    zyPayStatus: '', // 延保协议状态
    selectType: 1
  },
  observers: {
    mode: function (value) {
      console.log(value, "mode");
      let { tabListNor, tabListSimple } = this.data;
      this.setData({
        tabList: value ? tabListSimple : tabListNor,
      });
    },
  },
  lifetimes: {
    attached() {
      this.setData({
        storeInfo: wx.$util.getUserInfo()?.default4SStoreInfo || {},
        userInfo: wx.$util.getUserInfo() || {},
      });
      // console.log(this.data.userInfo)

      this.onLoad(true);
      // this.getMerchant4SMode()
    },
    resize(res) { },
  },
  /**
   * 组件的方法列表
   */
  methods: {
    onScroll: function (e) {
      // console.log(e, 'onPageScroll');
      // const {
      //   scrollTop
      // } = e.detail
      // const animation = this.createAnimation(); // 创建动画实例
      // 滚动时隐藏第一个图标,显示第二个图标
      this.setData({
        showIcon1: false,
        showIcon2: true,
      });
      // 清除之前的定时器
      if (timeoutId) {
        clearTimeout(timeoutId);
      }
      // 设置一个定时器,在滚动停止后一定时间后恢复两个图标的显示状态
      timeoutId = setTimeout(() => {
        this.setData({
          showIcon1: true,
          showIcon2: false,
        });
      }, 1000); // 在这里设置等待的时间,单位是毫秒
    },
    jumpUpdate(e) {
      const { item: orderInfo } = e.currentTarget.dataset;
      // let { orderInfo } = this.data
      console.log(orderInfo, "orderInfo");
      wx.$router.go("updateOrderInfo", orderInfo.id);
    },
    // 获取数据
    onLoad(noGetList) {
      let userInfo = wx.$util.getUserInfo() || {};

      this.setData({
        nothing: false,
        currentPage: 1,
        storeInfo: wx.$util.getUserInfo()?.default4SStoreInfo || {},
        isOrder: !(userInfo?.isSuper || userInfo?.loginRole == 3 || userInfo.loginRole == 5),
        list: []
      });
      // this.getTotal()
      if (!noGetList) this.getList(true);
      this.getOrderStatistics();
      if (!userInfo?.isSuper && userInfo?.loginRole != 3) this.getMerchantCarBrandList();
    },
    async handleClickOrderBtn(e) {
      // 校验是否填写昨日日报
      let staffCheck = await checkDailyReport(true);
      if (staffCheck) return false;;
      // console.log(e)
      // let { target } = e.target.dataset
      let { mode, merchantBrand } = this.data;
      // wx.$router.go(mode ? 'createOrderCarQuotationSimple' : 'createOrderCarQuotation')
      if (merchantBrand.findIndex((i) => ["鸿蒙智行"].includes(i.name)) != -1)
        wx.$router.go("beforeCreate", {
          mode,
        });
      else
        wx.$router.go(
          mode ? "createOrderCarQuotationSimple" : "createOrderCarQuotation"
        );
    },
    onBottomRefresh() {
      this.getList();
    },
    getTotal() {
      let { storeInfo } = this.data;
      getQuotationStatistics({
        merchantId: storeInfo?.merchantId,
      }).then((res) => {
        console.log(res, "统计---");
        let { code, message } = res;
        let data = res.data
          ? {
            ...res.data,
            todayTurnover: res.data.todayTurnover
              ? ((res.data.todayTurnover / 100).toFixed(2) + "").split(".")[0]
              : "0",
            todayTurDecimal: res.data.todayTurnover
              ? ((res.data.todayTurnover / 100).toFixed(2) + "").split(".")[1]
              : "00",
            // totalTurnover: res.data.totalTurnover ? (Math.round()(res.data.totalTurnover / 100).toFixed(2) + '').split('.')[0] : '0',
            totalTurnover: res.data.totalTurnover
              ? Math.round(res.data.totalTurnover / 100)
              : "0",
            totalTurDecimal: res.data.totalTurnover
              ? ((res.data.totalTurnover / 100).toFixed(2) + "").split(".")[1]
              : "00",
            monthTurnover: res.data.monthTurnover
              ? ((res.data.monthTurnover / 100).toFixed(2) + "").split(".")[0]
              : "0",
            // monthTurnover: 12233,
            // monthTurDecimal: res.data.monthTurnover ? ((res.data.monthTurnover / 100).toFixed(2) + '').split('.')[1] : '00'
          }
          : {};
        if (code == "0") {
          this.setData({
            statisticsObj: data,
          });
          // console.log(this.data.statisticsObj)
        } else {
          wx.$util.showToast(message || "接口异常");
        }
      });
    },
    dealListData(arr) {
      if (!arr) {
        return arr;
      }
      var attrList = ["equityPrice", "quotedPrice", "quotedPriceUpdate"];
      arr.forEach((item) => {
        attrList.forEach((k) => {
          if (item[k]) {
            item[k] = (item[k] / 100).toFixed(2);
          }
        });
      });
      return arr;
    },
    getList(isReset = false) {
      let {
        pageSize,
        currentPage,
        orderStatus,
        customerName,
        userInfo,
        storeInfo,
        nothing,
        staffUuid,
        zyPayStatus
      } = this.data,
        { screenForm } = this,
        merchantId = "";
      if (!screenForm) screenForm = {};
      if (nothing) {
        return;
      }
      let params = {
        pageSize,
        currentPage,
        customerName,
        orderStatus,
        merchantId,
        zyPayStatus
      };

      if (!userInfo.isSuper && userInfo.loginRole != 3) {
        // debugger
        params.transferIds = [userInfo.uuid];
      }
      if (staffUuid) {
        params.transferIds = [staffUuid];
      } else {
        params.merchantId = storeInfo?.merchantId;
      }

      wx.$util.showLoading();
      quotationPage({ ...params, ...screenForm })
        .then((res) => {
          wx.hideLoading();
          if (res.code == "0") {
            let { list, pages } = res.data;
            let tempList = this.dealListData(list || [])
            console.log(tempList);
            tempList = tempList.map((item) => {
              item.createdTime = wx.$util.tsFormatTime(
                item.createdTime,
                "Y/M/D h:m:s"
              );
              if (item.payTime) {
                item.payTime = wx.$util.tsFormatTime(
                  item.payTime,
                  "Y/M/D h:m:s"
                );
              }
              item.isTouchMove = false;
              // onlyRepeal 战败且为超管,或者是待报价、待支付的非融合都可撤销
              item.onlyRepeal = ((item.orderStatus == 2 || item.orderStatus == 0) || (item.orderStatus == -1 && this.data.userInfo.isSuper)) && item.mode != 0;
              // 待上传的支持可撤销
              item.repeal =
                ((item.orderStatus == 3 || item.orderStatus == 5 || item.orderStatus == 7) &&
                  item.mode != 0) || item.onlyRepeal;
              return item;
            });
            this.setData({
              [`list[${currentPage - 1}]`]: tempList,
              currentPage: currentPage + 1,
              nothing: currentPage == pages,
              triggered: false,
              flag: true,
            });
            if (isReset) {
              this.setData({
                scrollTop: 0,
              });
            }
            // console.log(this.data.list)
          } else {
            this.setData({
              list: [],
              nothing: false,
              flag: true,
            });
            wx.$util.showToast(res.message || "接口异常");
          }
        })
        .catch((err) => {
          wx.hideLoading();
        });
    },
    search() {
      this.setData({
        currentPage: 1,
        nothing: false,
        flag: false,
      });
      this.getList(true);
      this.getOrderStatistics();
    },
    handleReset() {
      this.setData({
        customerName: "",
      });
      this.search();
    },
    input(e) {
      let { value } = e.detail;
      this.setData({
        customerName: value,
      });
    },
    // 首次进入会触发该方法,因此不需要在attached调getList
    tabClick(e) {
      let { tabList } = this.data,
        orderStatus = "";
      const tabIndex = e.detail || 0;
      if (tabIndex)
        orderStatus =
          constantData.orderStatusList.find(
            (item) =>
              item.confName == tabList[tabIndex].text ||
              item.confName == tabList[tabIndex]
          )?.confId || "";
      // 防止筛选条件回来后多次触发
      if (this.filterTag) {
        this.filterTag = false;
        return;
      }
      // 筛选页只会存在订单状态
      if (this.screenForm && e.orderStatus && !e.zyPayStatus) {
        this.screenForm.orderStatus = e.orderStatus;
        this.filterTag = true;
        setTimeout(() => {
          this.filterTag = false;
        }, 500);
      } else if (this.screenForm && !e.orderStatus && !tabIndex && !e.zyPayStatus) {
        this.screenForm.orderStatus = "";
        this.filterTag = false;
      } else if (this.screenForm && !e.orderStatus && tabIndex && !e.zyPayStatus) {
        this.screenForm.orderStatus = orderStatus;
        this.filterTag = false;
      }
      // 筛选页只会存在延保协议状态
      if (this.screenForm && e.zyPayStatus && !e.orderStatus) {
        this.screenForm.zyPayStatus = e.zyPayStatus
        this.filterTag = true;
        setTimeout(() => {
          this.filterTag = false;
        }, 500);
      } else if (this.screenForm && e.detail == (tabList?.length - 1) && !e.zyPayStatus && !e.orderStatus) {
        this.screenForm.zyPayStatus = 1
        this.filterTag = false;
      } else if (this.screenForm && e.detail != (tabList?.length - 1) && !e.zyPayStatus && !e.orderStatus) {
        this.screenForm.zyPayStatus = ''
        this.filterTag = false;
      }
      this.setData({
        tabIndex,
        orderStatus,
        currentPage: 1,
        zyPayStatus: e.detail == (tabList?.length - 1) && !e.zyPayStatus ? 1 : e.zyPayStatus ? e.zyPayStatus : '', // 当tab选中最后一项或筛选页面存在值
        list: []
      });
      const thisPage = wx.$router.getPageInstance();
      thisPage.setData({
        orderStatus,
        zyPayStatus: e.detail == (tabList?.length - 1) && !e.zyPayStatus ? 1 : e.zyPayStatus ? e.zyPayStatus : ''
      })
      this.search();
      this.getOrderStatistics();
    },
    // 按钮
    async handleClickBtn(e) {
      let { target, type } = e.currentTarget.dataset;
      console.log(target);
      // 上传延保协议
      if (target?.zyPayStatus == '1' && type == 'upload') {
        // 校验是否填写昨日日报
        let staffCheck = await checkDailyReport(true);
        if (staffCheck) return false;
        return this.setData({showZyPayPopup: true, showZyTarget: target})
      }
      // wx.$router.go('createOrderCarQuotation', {
      //   id: target.id
      // })
      // 0待报价、1待确认、2待支付、3已支付、-1战败 5已完成(已签名)
      // mode 0 融合 1 非融合
      switch (target.orderStatus + "") {
        // schemeConfirmation
        case "0":
          let staffCheck = await checkDailyReport(true);
          if (staffCheck) return false;;
          wx.$router.go(
            target.mode != 0
              ? "createOrderCarQuotationSimple"
              : "createOrderCarQuotation",
            {
              id: target.id,
            }
          );
          break;
        case "1":
          wx.$router.go("schemeConfirmation", {
            id: target.id,
          });
          break;
        case "2":
          staffCheck = await checkDailyReport(true);
          if (staffCheck) return false;;
          if (type == "pay") {
            // 去支付
            wx.$router.go("CarQuotationPay", {
              id: target.id,
            });
          } else {
            // 战败
            this.setData({
              showRemark: true,
              // sufferReason: ''
            });
            console.log("战败");
          }
          break;
        case "3":
          // wx.$router.go('serviceInfo', {
          //   orderId: target.orderId,
          //   apiName: 'handler'
          // })
          staffCheck = await checkDailyReport(true);
          if (staffCheck) return false;;
          if (type == "handle") {
            // 去处理
            wx.$router.go("serviceInfo", {
              orderId: target.orderId,
              apiName: "handler",
            });
          } else {
            wx.$router.go("signature", {
              id: target.id,
              orderId: target.orderId,
              equityGoodsFlag: target.equityGoodsFlag
            });
          }
          break;
        case "-1":
          // wx.$router.go('createOrderCarQuotation', {
          //   id: target.id
          // })
          staffCheck = await checkDailyReport(true);
          if (staffCheck) return false;;
          wx.$router.go(
            target.mode != 0
              ? "createOrderCarQuotationSimple"
              : "createOrderCarQuotation",
            {
              id: target.id,
            }
          );
          break;
        case "5":
          staffCheck = await checkDailyReport(true);
          if (staffCheck) return false;;
          wx.$router.go("serviceInfo", {
            orderId: target.orderId,
            apiName: "handler",
          });
          break;
      }
      this.setData({
        id: target.id,
      });
    },
    getInsurance(res) {
      let obj = wx.$util.deepClone(res), orderInfo = {};
      let { default4SStoreInfo } = wx.$util.getUserInfo();
      orderInfo.check = true
      orderInfo.id = obj.id
      orderInfo.orderId = obj.orderId
      orderInfo.merchantId4s = default4SStoreInfo?.merchantId;
      orderInfo.merchantName4s = default4SStoreInfo?.merchantName;
      orderInfo.referrer = obj.referrer
      orderInfo.referrerId = obj.referrerId
      return orderInfo;
    },
    // 延保协议上传确定
    zyPayConfirm(e) {
      let { showZyTarget } = this.data
      getQuotationInfoById({
        id: showZyTarget?.id
      }).then(res => {
        let { code, message, data } = res
        if (code == 0) {
          let orderInfo = this.getInsurance(data)
          // 更新客户信息
          updateCustomerInfo({...orderInfo, zyPayUrl: e.detail?.zyPayUrl?.join(',')}).then(result => {
            this.setData({
              showZyPayPopup: false
            }, () => {
              this.search()
            })
          })
        } else {
          wx.$util.showToast(message)
        }
      })
    },
    remarkCancel() {
      this.setData({
        showRemark: false,
      });
    },
    remarkConfirm(e) {
      let value = e.detail;
      let { id } = this.data;
      if (value) {
        updateOrderStatus({
          id,
          orderStatus: -1,
          remark: value,
        }).then((res) => {
          let { code, message } = res;
          if (code == 0) {
            wx.$util.showToast("提交成功");
            this.onLoad();
          } else {
            wx.$util.showToast(message);
          }
        });
      }
    },
    getOrderStatistics() {
      let {
        userInfo,
        storeInfo,
        tabList,
        tabListTemplate,
        tabListTemplateSimple,
        mode,
        staffUuid,
        customerName
      } = this.data,
        { screenForm } = this,
        obj = {}
      let searchTemp = wx.$util.deepClone(screenForm || {});
      if (!userInfo.isSuper && userInfo.loginRole != 3) {
        obj.transferIds = [userInfo.uuid];
      }
      if (staffUuid) {
        obj.transferIds = [staffUuid];
      } else if (storeInfo?.merchantId) {
        obj.merchantIds = [storeInfo?.merchantId];
      }
      // console.log({
      //   ...obj,
      //   ...searchTemp
      // }, '2222');
      orderStatistics({
        ...obj,
        ...searchTemp,
        customerName
      })
        .then((result) => {
          let { data, code } = result;
          // debugger
          if (code == 0) {
            let labelList = [
              "total",
              "waitQuotation",
              "waitPay",
              "paySuccess",
              "completed",
              "defeat",
            ];
            // const labelList = ['total', 'waitQuotation', 'waitCheck', 'waitPay', 'paySuccess', 'completed', 'defeat']
            if (!mode) {
              //  'waitCheck'
              labelList.splice(2, 0, "waitCheck");
            }
            // console.log(labelList, 'labelList');
            labelList.map((item, index) => {
              tabList[index] = {
                text: mode
                  ? tabListTemplateSimple[index]
                  : tabListTemplate[index],
                count: data[item] ? data[item] : 0,
              };
            });
            this.setData({
              tabList,
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    //手指触摸动作开始 记录起点X坐标
    touchstart(e) {

      let { ind } = e.currentTarget.dataset;
      //开始触摸时 重置所有删除
      this.data.list[ind].forEach((v) => {
        // console.log(item)
        if (v.isTouchMove)
          //只操作为true的
          v.isTouchMove = false;
        v.confirmIndex = false;
      });
      const listName = `list[${ind}]`
      this.setData({
        startX: e.changedTouches[0].clientX,
        startY: e.changedTouches[0].clientY,
        [listName]: this.data.list[ind],
      });
    },
    //滑动事件处理
    touchmove: function (e) {
      if (!this.data.isOrder) {
        return
      }
      // console.log(e)
      // if (condition) {
      // }
      // let { userInfo } = this.data
      let { item, ind } = e.currentTarget.dataset;
      // console.log(!li.repeal)
      if (!item.repeal) return;
      // let userType = !userInfo.isSuper && userInfo.merchantType
      // let orderType = userInfo.userType == 1 && li.status != 9 && li.status != 1 && li.selectPayType != 3 && li.selectPayType != 1
      // // 权限检验
      // // console.log(!userType || !orderType)
      // if (!userType || !orderType) return
      var that = this,
        index = e.currentTarget.dataset.index, //当前索引
        // ind = e.currentTarget.dataset.ind, //当前索引
        startX = that.data.startX, //开始X坐标
        startY = that.data.startY, //开始Y坐标
        touchMoveX = e.changedTouches[0].clientX, //滑动变化坐标
        touchMoveY = e.changedTouches[0].clientY, //滑动变化坐标
        //获取滑动角度
        angle = that.angle(
          {
            X: startX,
            Y: startY,
          },
          {
            X: touchMoveX,
            Y: touchMoveY,
          }
        );
      // console.log(that.data.list[index])
      const listName = `list[${ind}]`
      that.data.list[ind].forEach(function (v, i) {
        v.isTouchMove = false;
        //滑动超过30度角 return
        if (Math.abs(angle) > 30) return;
        if (i == index) {
          if (touchMoveX > startX)
            //右滑
            v.isTouchMove = false;
          //左滑
          else v.isTouchMove = true;
        }
      });
      //更新数据
      that.setData({
        [listName]: that.data.list[ind],
      });
    },
    touchE: function (e) {
      // console.log(e)
      var that = this;
      // console.log(e.changedTouches.length)
      // debugger
      let { item, ind } = e.currentTarget.dataset;
      // // console.log(!li.repeal)
      if (!item.repeal) return;
      if (e.changedTouches.length == 1) {
        //手指移动结束后触摸点位置的X坐标
        var endX = e.changedTouches[0].clientX;
        //触摸开始与结束,手指移动的距离
        var disX = that.data.startX - endX;
        // console.log(disX)
        var delBtnWidth = that.data.delBtnWidth;
        //如果距离小于删除按钮的1/2,不显示删除按钮
        var txtStyle =
          disX > delBtnWidth / 2 ? "left:-" + delBtnWidth + "rpx" : "left:0";
        //获取手指触摸的是哪一项
        var index = e.currentTarget.dataset.index;
        // var ind = e.currentTarget.dataset.ind
        var list = that.data.list[ind];
        const listName = `list[${ind}]`
        list[index].txtStyle = txtStyle;
        // console.log(list)
        //更新列表的状态
        // console.log(list)
        that.setData({
          [listName]: list,
        });
      }
    },
    angle: function (start, end) {
      var _X = end.X - start.X,
        _Y = end.Y - start.Y;
      //返回角度 /Math.atan()返回数字的反正切值
      return (360 * Math.atan(_Y / _X)) / (2 * Math.PI);
    },
    cancelRepeal() {
      this.clearData()
    },
    textareaInput(e) {
      let { value } = e.detail
      this.setData({
        repealReason: value
      })
    },
    confirmRepeal() {
      const { repealReason, repealId } = this.data
      if (!repealReason) {
        wx.showToast({
          title: '请填写撤销原因',
          duration: 2000,
          icon: 'none'
        })
        return
      }
      this.repeal(repealId, repealReason);
    },
    async toConfirmReturanOrder(e) {
      // 校验是否填写昨日日报
      let staffCheck = await checkDailyReport(true);
      if (staffCheck) return false;;
      console.log(e.currentTarget.dataset, 'e.currentTarget.dataset')
      const { id, repeal, status } = e.currentTarget.dataset;
      let _this = this;
      if (repeal && status == -1) {
        this.setData({
          repealVisible: true,
          repealId: id
        })
      } else {
        wx.showModal({
          title: "",
          content: "是否取撤销该工单?",
          confirmText: "是",
          confirmColor: "#347BFF",
          cancelText: "否",
          success(res) {
            if (res.confirm) {
              // _this.showLoading('取消中...')
              _this.repeal(id);
            }
          },
        });
      }
    },
    toCopyNumber(e) {
      let { ordernum } = e.currentTarget.dataset;
      ordernum = ordernum.replace(/,$/, "");
      wx.setClipboardData({
        data: ordernum.toString(),
        success(res) {
          wx.$util.showToast("已复制");
        },
      });
    },
    repeal(id, revokeReason) {
      let _this = this;
      let params = { id }
      if (revokeReason) {
        params.revokeReason = revokeReason
      }
      cancelOrderById(params).then((_res_) => {
        let { code, message } = _res_;
        if (code == 0) {
          _this.clearData()
          wx.showToast({
            title: "操作成功",
            icon: "success",
          });
          setTimeout(() => {
            _this.setData({
              list: []
            })
            _this.search();

            // _this.getList();
          }, 500);
        } else {
          wx.$util.showToast(message);
        }
      });
    },
    clearData() {
      this.setData({
        repealVisible: false,
        repealId: '',
        repealReason: ''
      })
    },
    async toshowErrorOrder(e) {
      // 校验是否填写昨日日报
      let staffCheck = await checkDailyReport(true);
      if (staffCheck) return false;;
      const { item } = e.currentTarget.dataset;
      this.setData(
        {
          showErrorId: item.payId,
        },
        () => {
          wx.$modal(this, {
            show: true,
            title: "工单标记",
            tabTitleShow: false,
            success: (res) => {
              this.showErrorType(item);
            },
            error: () => { },
          });
        }
      );
    },
    selectType(e) {
      let { type } = e.currentTarget.dataset;
      this.setData({
        selectType: type,
      });
    },
     // 确定是否要显示
    showErrorType(item) {
      wx.$modal(
        this,
        {
          show: true,
          title: "请选择录单入口",
          tabTitleShow: false,
          success: (res) => {
            // 跳转新增订单页面 并带特定参数
            let { selectType } = this.data;
            if (selectType == 1) {
              wx.$router.go(
                item.mode != 0
                  ? "createOrderCarQuotationSimple"
                  : "createOrderCarQuotation",
                {
                  id: item.id,
                  resetOrder: true,
                }
              );
            } else {
              // 无需补录
              errorOrderById({oldQuotationId: item.id, needCreateNewOrder: false}).then(res => {
                let { code, message } = res
                if (code == 0) {
                  this.search()
                } else {
                  wx.$util.showToast(message)
                }
              }).catch(() => {

              })
            }
          },
          error: () => { },
        },
        "#modal2"
      );
    },
    jumpReception(e) {
      const { item } = e.currentTarget.dataset;
      wx.$router.go("reception", item);
    },
    back() {
      const thisPage = wx.$router.getPageInstance();
      thisPage.setData({
        showScreen: false,
        show_order_confirm: false
      });
    },
    showConfirm() {
      const thisPage = wx.$router.getPageInstance();
      let { orderStatus, zyPayStatus } = this.data
      thisPage.setData({
        showScreen: true,
        showOrderRendering: true,
        show_order_confirm: true,
        orderStatus,
        zyPayStatus
      });
    },
    searchScreen(e) {
      const { tabList } = this.data;
      let tabIndex = 0;
      this.back();
      this.screenForm = e.detail;
      if (e.detail.orderStatus) {
        let name = constantData.orderStatusList.find(
          (item) => item.confId == e.detail.orderStatus
        )?.confName;
        tabIndex = tabList.findIndex((item) => item.text && item.text == name);
        if (tabIndex == -1) tabIndex = 0;
      }
      if (e.detail.zyPayStatus && e.detail.zyPayStatus[0] == 1) {
        tabIndex = tabList?.length - 1
      }
      this.filterTag = false;
      this.tabClick({
        detail: tabIndex,
        orderStatus: e.detail.orderStatus,
        zyPayStatus: e.detail.zyPayStatus
      });
    },
    /**获取门店主营品牌 */
    async getMerchantCarBrandList() {
      const { userInfo } = this.data,
        { shopMerchantId } = userInfo,
        { code, data } = await carLifeApi.getMerchantCarBrandList([
          shopMerchantId,
        ]);
      if (code == 0 && data) {
        let merchantBrand = data?.data[0]?.carBrandList || [];
        this.setData({
          merchantBrand,
        });
      }
    },
  },
});