Commit ebaa2481f1a1234e77db3601e03294428bc08a7f
1 parent
8b7a41d5
拼单尾款优惠券使用优化
Showing
1 changed file
with
340 additions
and
15 deletions
packageE/pages/cart/cart_wk/cart_wk.js
... | ... | @@ -68,7 +68,11 @@ Page({ |
68 | 68 | isget_by_quan: {}, //是否调用了接口获取包邮券 |
69 | 69 | is_by:{}, |
70 | 70 | get_by_quan_list: null, //立即购买的 |
71 | - | |
71 | + first_entry: 0,//进入次数,如果是第一次进入,进行判断是否进行优惠券是否直接使用 | |
72 | + def_coupon1: null,//购物车优惠券列表 | |
73 | + def_coupon2: null,//直接购买优惠券列表 | |
74 | + def_coupon3: null,//购物车包邮券列表 | |
75 | + def_coupon4: null,//直接购买包邮券列表 | |
72 | 76 | }, |
73 | 77 | |
74 | 78 | /** |
... | ... | @@ -616,6 +620,7 @@ Page({ |
616 | 620 | allpice = allpice.toFixed(2); |
617 | 621 | |
618 | 622 | th.setData({exp_price: 0, allpice: allpice, submit: 0, show_submit: 1}) |
623 | + th.def_coupon_fn() | |
619 | 624 | wx.hideLoading(); |
620 | 625 | } |
621 | 626 | }, |
... | ... | @@ -643,7 +648,7 @@ Page({ |
643 | 648 | set_wuliu: function (e) { |
644 | 649 | var type = e.currentTarget.dataset.type, th = this; |
645 | 650 | this.setData({ |
646 | - exp_type: type,same_ok:1 | |
651 | + exp_type: type,same_ok:1,first_entry:0 | |
647 | 652 | }); |
648 | 653 | //--计算物流的值-- |
649 | 654 | if (th.data.goods) { |
... | ... | @@ -916,7 +921,7 @@ Page({ |
916 | 921 | arr.push(item); |
917 | 922 | } |
918 | 923 | if (arr) { |
919 | - th.setData({ get_by_quan_list: arr }); | |
924 | + th.setData({ get_by_quan_list: arr,def_coupon3: arr }); | |
920 | 925 | } |
921 | 926 | th.data.isget_by_quan[th.data.bn_pick] = 1; |
922 | 927 | } |
... | ... | @@ -1182,7 +1187,7 @@ Page({ |
1182 | 1187 | allpice = allpice.toFixed(2); |
1183 | 1188 | th.setData({exp_price: 0, allpice: allpice, submit: 0, show_submit: 1}) |
1184 | 1189 | } |
1185 | - | |
1190 | + th.def_coupon_fn() | |
1186 | 1191 | wx.hideLoading(); |
1187 | 1192 | //}); |
1188 | 1193 | |
... | ... | @@ -1350,7 +1355,7 @@ Page({ |
1350 | 1355 | allpice = allpice.toFixed(2); |
1351 | 1356 | th.setData({ exp_price: 0, allpice: allpice,submit:0,show_submit:1}) |
1352 | 1357 | } |
1353 | - | |
1358 | + th.def_coupon_fn() | |
1354 | 1359 | wx.hideLoading(); |
1355 | 1360 | |
1356 | 1361 | |
... | ... | @@ -1537,7 +1542,7 @@ Page({ |
1537 | 1542 | quanlist = res.data.data.pageData; |
1538 | 1543 | if (quanlist) { |
1539 | 1544 | quanlist = th.check_is_frozenQuan(quanlist, frozenQuan); |
1540 | - th.setData({ selected_quan_list: quanlist }) | |
1545 | + th.setData({ selected_quan_list: quanlist,def_coupon2: quanlist }) | |
1541 | 1546 | } |
1542 | 1547 | } |
1543 | 1548 | } |
... | ... | @@ -1624,6 +1629,111 @@ Page({ |
1624 | 1629 | th.setData({ open_quan: 0, disabled: 0 }); |
1625 | 1630 | }, |
1626 | 1631 | |
1632 | + /*--点击选择券--*/ | |
1633 | + sele_quan_item_befor: function (e) { | |
1634 | + | |
1635 | + var ind = 0; | |
1636 | + var quan_item = this.data.selected_quan_list[ind]; | |
1637 | + var pickid = this.data.selected_quan_pick; //现在选择的是哪一个门店 | |
1638 | + //--如果券是单品使用的时候-- | |
1639 | + if (quan_item && quan_item.UseObjectType && quan_item.UseObjectType == "20") { | |
1640 | + //---只有多件购买的时候才要计算,//购物车购买和搭配勾的时候--- | |
1641 | + var gg = getApp().get_b_now(); | |
1642 | + if (this.data.is_b_now == 0 || gg.prom_type == 5) { | |
1643 | + var arr = this.data.order_prom_list_cart; | |
1644 | + var t_pk_item = null; | |
1645 | + for (var ii in arr) { | |
1646 | + var ep = arr[ii]; | |
1647 | + if (pickid == ep.pickup_id) { | |
1648 | + t_pk_item = ep; | |
1649 | + break; | |
1650 | + } | |
1651 | + } | |
1652 | + //--寻找券指定的商品-- | |
1653 | + var gd = null; | |
1654 | + if (t_pk_item) { | |
1655 | + var goods = t_pk_item.goods; | |
1656 | + for (var gid in goods) { | |
1657 | + if (quan_item.UseObjectID == goods[gid].erpwareid) { | |
1658 | + gd = goods[gid]; | |
1659 | + } | |
1660 | + } | |
1661 | + } | |
1662 | + if (!gd) { | |
1663 | + // getApp().my_warnning("未找到指定商品使用", 0, this, 600); | |
1664 | + return false; | |
1665 | + } | |
1666 | + //计算价格,如果有平摊的实收要计算实收的金额 | |
1667 | + var item_price = gd.goods_price * gd.goods_num; | |
1668 | + //-- 如果有平摊下去,有实收价格的时候,就要用account_fir来计算价格 -- | |
1669 | + if (gd.account_fir != null && gd.account_fir != undefined) { | |
1670 | + item_price = gd.account_fir * gd.goods_num; | |
1671 | + } | |
1672 | + | |
1673 | + if (item_price < parseFloat(quan_item.BuySum)) { | |
1674 | + // getApp().my_warnning("该单品金额没有大于等于" + quan_item.BuySum + "元时不能使用优惠券", 0, this, 600); | |
1675 | + return false; | |
1676 | + } | |
1677 | + } | |
1678 | + } | |
1679 | + | |
1680 | + var quanlist = this.data.selected_quan_list; | |
1681 | + //---所有的券的显示红色选择都清理一遍--- | |
1682 | + for (var i in quanlist) { | |
1683 | + quanlist[i].show_red = 0; | |
1684 | + } | |
1685 | + this.setData({ selected_quan_list: quanlist }); | |
1686 | + var by_quanlist = this.data.get_by_quan_list; | |
1687 | + if (by_quanlist) { | |
1688 | + //---所有的券的显示红色选择都清理一遍--- | |
1689 | + for (var inb in by_quanlist) { | |
1690 | + by_quanlist[inb].show_red = 0; | |
1691 | + } | |
1692 | + this.setData({ get_by_quan_list: by_quanlist }); | |
1693 | + } | |
1694 | + | |
1695 | + var by_cart_list = this.data.by_quan_list_cart; | |
1696 | + if (by_cart_list) { | |
1697 | + //---所有的券的显示红色选择都清理一遍--- | |
1698 | + for (var inc in by_cart_list) { | |
1699 | + by_cart_list[inc].show_red = 0; | |
1700 | + } | |
1701 | + this.setData({ by_quan_list_cart: by_cart_list }); | |
1702 | + } | |
1703 | + | |
1704 | + var using_quan = this.data.using_quan; | |
1705 | + var th = this; | |
1706 | + //---如果是不使用优惠券--- | |
1707 | + // if (no_use == 1) { | |
1708 | + // console.log("有进来吗券", no_use); | |
1709 | + // if (using_quan[th.data.selected_quan_pick]) { | |
1710 | + // using_quan[th.data.selected_quan_pick].is_nouse_red = 1; | |
1711 | + // } | |
1712 | + // else { | |
1713 | + // using_quan[th.data.selected_quan_pick] = { is_nouse_red: 1 }; | |
1714 | + // } | |
1715 | + // this.setData({ using_quan: using_quan, is_coupon: th.is_coupon }); | |
1716 | + // return; | |
1717 | + // } | |
1718 | + | |
1719 | + | |
1720 | + var txt = "selected_quan_list[" + ind + "].show_red"; | |
1721 | + var obj = {}; | |
1722 | + obj[txt] = 1; | |
1723 | + if (quan_item.show_red) { | |
1724 | + obj[txt] = 0; | |
1725 | + } | |
1726 | + this.setData(obj); | |
1727 | + console.log(this.data.selected_quan_list, "选中的券的下标", quan_item, "数据都在这里", txt); | |
1728 | + if (using_quan[th.data.selected_quan_pick]) { | |
1729 | + using_quan[th.data.selected_quan_pick].is_nouse_red = 0; | |
1730 | + } | |
1731 | + else { | |
1732 | + using_quan[th.data.selected_quan_pick] = { is_nouse_red: 0 }; | |
1733 | + } | |
1734 | + this.setData({ using_quan: using_quan }); | |
1735 | + return true | |
1736 | + }, | |
1627 | 1737 | /*--点击选择券--*/ |
1628 | 1738 | sele_quan_item: function (e) { |
1629 | 1739 | |
... | ... | @@ -1731,6 +1841,66 @@ Page({ |
1731 | 1841 | }, |
1732 | 1842 | |
1733 | 1843 | /*----- 点击选择包邮券 -----*/ |
1844 | + sele_quan_item_by_befor: function (e) { | |
1845 | + // var no_use = e.currentTarget.dataset.no; | |
1846 | + //立即购买的包邮券 | |
1847 | + var by_quanlist = this.data.get_by_quan_list; | |
1848 | + if (by_quanlist) { | |
1849 | + //---所有的券的显示红色选择都清理一遍--- | |
1850 | + for (var ind in by_quanlist) { | |
1851 | + by_quanlist[ind].show_red = 0; | |
1852 | + } | |
1853 | + this.setData({ get_by_quan_list: by_quanlist }); | |
1854 | + } | |
1855 | + | |
1856 | + //普通券 | |
1857 | + var quanlist = this.data.selected_quan_list; | |
1858 | + if (quanlist) { | |
1859 | + //---所有的券的显示红色选择都清理一遍--- | |
1860 | + for (var ind in quanlist) { | |
1861 | + quanlist[ind].show_red = 0; | |
1862 | + } | |
1863 | + this.setData({ selected_quan_list: quanlist }); | |
1864 | + } | |
1865 | + | |
1866 | + var th = this; | |
1867 | + var using_quan = this.data.using_quan; | |
1868 | + //---如果是不使用优惠券--- | |
1869 | + // if (no_use == 1) { | |
1870 | + // if (using_quan[th.data.selected_quan_pick]) { | |
1871 | + // using_quan[th.data.selected_quan_pick].is_nouse_red = 1; | |
1872 | + // } | |
1873 | + // else { | |
1874 | + // using_quan[th.data.selected_quan_pick] = { is_nouse_red: 1 }; | |
1875 | + // } | |
1876 | + // this.setData({ using_quan: using_quan, is_coupon: th.is_coupon }); | |
1877 | + // return; | |
1878 | + // } | |
1879 | + | |
1880 | + var pickid = th.data.selected_quan_pick; //现在选择的是哪一个门店 | |
1881 | + var ind = 0; | |
1882 | + //--如果是立即购买的部分-- | |
1883 | + var txt = ""; | |
1884 | + var txt1 = ""; | |
1885 | + var quan_item = null; | |
1886 | + | |
1887 | + quan_item = this.data.get_by_quan_list[ind]; | |
1888 | + txt = "get_by_quan_list[" + ind + "].show_red"; | |
1889 | + var obj = {}; | |
1890 | + obj[txt] = 1; | |
1891 | + this.setData(obj); | |
1892 | + | |
1893 | + | |
1894 | + if (using_quan[th.data.selected_quan_pick]) { | |
1895 | + using_quan[th.data.selected_quan_pick].is_nouse_red = 0; | |
1896 | + } | |
1897 | + else { | |
1898 | + using_quan[th.data.selected_quan_pick] = { is_nouse_red: 0 }; | |
1899 | + } | |
1900 | + this.setData({ using_quan: using_quan }); | |
1901 | + }, | |
1902 | + | |
1903 | + /*----- 点击选择包邮券 -----*/ | |
1734 | 1904 | sele_quan_item_by: function (e) { |
1735 | 1905 | var no_use = e.currentTarget.dataset.no; |
1736 | 1906 | //立即购买的包邮券 |
... | ... | @@ -1791,6 +1961,71 @@ Page({ |
1791 | 1961 | }, |
1792 | 1962 | |
1793 | 1963 | //--确认使用券--- |
1964 | + confirm_quan_befor: function () { | |
1965 | + var using_quan = this.data.using_quan; //正在使用中的券列表 | |
1966 | + var pickid = this.data.selected_quan_pick; //选中的门店ID | |
1967 | + var th = this; | |
1968 | + var selected_quan_list = this.data.selected_quan_list; //选择了那个门店的券列表 | |
1969 | + var get_by_quan_list = this.data.get_by_quan_list; //立即购买的包邮券列表 | |
1970 | + var by_quan_list_cart = this.data.by_quan_list_cart; //购物车购买的包邮券列表 | |
1971 | + //选择了的券 | |
1972 | + var sele_quan = null; | |
1973 | + | |
1974 | + //循环普通的券 | |
1975 | + for (var i in selected_quan_list) { | |
1976 | + var item = selected_quan_list[i]; | |
1977 | + if (item.show_red) { | |
1978 | + th.insert_into_using_quan(item, using_quan, pickid,0,false); | |
1979 | + return; | |
1980 | + } | |
1981 | + } | |
1982 | + //循环包邮的券,立即购买的 | |
1983 | + for (var i in get_by_quan_list) { | |
1984 | + var item = get_by_quan_list[i]; | |
1985 | + if (item.show_red) { | |
1986 | + if (th.data.is_no_by[pickid] == 1) { | |
1987 | + // getApp().my_warnning("已全场不能包邮,不能选择包邮券", 0, th); | |
1988 | + return false; | |
1989 | + } | |
1990 | + if (th.data.is_by[pickid] == 1) { | |
1991 | + // getApp().my_warnning("已全场包邮,不能选择包邮券", 0, th); | |
1992 | + return false; | |
1993 | + } | |
1994 | + | |
1995 | + th.insert_into_using_quan(item, using_quan, pickid, 1,false); | |
1996 | + return; | |
1997 | + } | |
1998 | + } | |
1999 | + | |
2000 | + //循环包邮的券 | |
2001 | + for (var i in by_quan_list_cart) { | |
2002 | + var item = by_quan_list_cart[i]; | |
2003 | + if (item.show_red) { | |
2004 | + if (th.data.is_no_by[pickid] == 1) { | |
2005 | + // getApp().my_warnning("已全场不能包邮,不能选择包邮券", 0, th); | |
2006 | + return false; | |
2007 | + } | |
2008 | + if (th.data.is_by[pickid] == 1) { | |
2009 | + // getApp().my_warnning("已全场包邮,不能选择包邮券", 0, th); | |
2010 | + return false; | |
2011 | + } | |
2012 | + th.insert_into_using_quan(item, using_quan, pickid, 1,false); | |
2013 | + return; | |
2014 | + } | |
2015 | + } | |
2016 | + | |
2017 | + //选择了的券,看是不是点击了不使用券,点击了不使用优惠券 | |
2018 | + if (using_quan[pickid]) { | |
2019 | + if (using_quan[pickid].is_nouse_red == 1) { | |
2020 | + using_quan[pickid] = { is_nouse_red: 1 }; | |
2021 | + th.setData({ using_quan: using_quan }); | |
2022 | + th.calculatePrice2(); | |
2023 | + th.setData({ open_quan: 0 }); | |
2024 | + return; | |
2025 | + } | |
2026 | + } | |
2027 | + }, | |
2028 | + //--确认使用券--- | |
1794 | 2029 | confirm_quan: function () { |
1795 | 2030 | var using_quan = this.data.using_quan; //正在使用中的券列表 |
1796 | 2031 | var pickid = this.data.selected_quan_pick; //选中的门店ID |
... | ... | @@ -1855,9 +2090,99 @@ Page({ |
1855 | 2090 | } |
1856 | 2091 | } |
1857 | 2092 | }, |
2093 | + //默认选择优惠券 | |
2094 | + def_coupon_fn() { | |
2095 | + // setTimeout(() => { | |
2096 | + // this.def_coupon_fn_aft() | |
2097 | + // }, 100); | |
2098 | + try { | |
2099 | + setTimeout(() => { | |
2100 | + this.def_coupon_fn_aft() | |
2101 | + }, 1000); | |
2102 | + } catch (error) { } | |
2103 | + | |
2104 | +}, | |
2105 | + //默认选择优惠券 | |
2106 | + def_coupon_fn_aft() { | |
2107 | + console.error('进入默认优惠券选择'); | |
2108 | + let th = this; | |
2109 | + let first_entry = th.data.first_entry; | |
2110 | + console.error(first_entry); | |
2111 | + if (first_entry > 0) { | |
2112 | + return | |
2113 | + } | |
2114 | + first_entry += 1; | |
2115 | + th.setData({ | |
2116 | + first_entry | |
2117 | + }) | |
2118 | + let length1 = th.data.def_coupon1 ? th.data.def_coupon1.length : 0 | |
2119 | + let length2 = th.data.def_coupon2 ? th.data.def_coupon2.length : 0 | |
2120 | + let length3 = th.data.def_coupon3 ? th.data.def_coupon3.length : 0 | |
2121 | + let length4 = th.data.def_coupon4 ? th.data.def_coupon4.length : 0 | |
2122 | + let length = length1 + length2 | |
2123 | + if (th.data.exp_type==0) { | |
2124 | + length+= length3 + length4 | |
2125 | + } | |
2126 | + console.error(length); | |
2127 | + if (length != 1) { | |
2128 | + return | |
2129 | + } | |
2130 | + if (length1 == 1) { | |
2131 | + console.error('优惠券1'); | |
2132 | + let first_entry = th.data.first_entry; | |
2133 | + let quan_list = th.data.def_coupon1 | |
2134 | + if (quan_list && quan_list.length == 1 && first_entry == 1) { | |
2135 | + // first_entry += 1; | |
2136 | + th.setData({ | |
2137 | + sele_cart_ind: 0, | |
2138 | + sele_exp_type: th.data.cartlist[0].exp_type, | |
2139 | + selected_quan_pick: th.data.cartlist[0].pickup_id, | |
2140 | + selected_quan_list: th.data.cartlist[0].quan_list, | |
2141 | + // first_entry | |
2142 | + }) | |
2143 | + let quan_off = th.sele_quan_item_befor(); | |
2144 | + if (quan_off) { | |
2145 | + th.confirm_quan_befor() | |
2146 | + } | |
2147 | + } | |
2148 | + } | |
2149 | + if (length2 == 1) { | |
2150 | + console.error('优惠券2'); | |
2151 | + let first_entry = th.data.first_entry; | |
2152 | + let quanlist = th.data.def_coupon2 | |
2153 | + if (quanlist && quanlist.length == 1 && first_entry == 1) { | |
2154 | + // first_entry += 1; | |
2155 | + th.setData({ | |
2156 | + selected_quan_pick: th.data.bn_pick, | |
2157 | + // first_entry | |
2158 | + }) | |
2159 | + let quan_off = th.sele_quan_item_befor(); | |
2160 | + if (quan_off) { | |
2161 | + th.confirm_quan_befor() | |
2162 | + } | |
1858 | 2163 | |
2164 | + } | |
2165 | + } | |
2166 | + if (length3 == 1 && th.data.exp_type == 0) { | |
2167 | + console.error('优惠券3'); | |
2168 | + let first_entry = th.data.first_entry; | |
2169 | + let quanlist = th.data.def_coupon3 | |
2170 | + if (quanlist && quanlist.length == 1 && first_entry == 1) { | |
2171 | + // first_entry += 1; | |
2172 | + th.setData({ | |
2173 | + selected_quan_pick: th.data.bn_pick, | |
2174 | + // first_entry | |
2175 | + }) | |
2176 | + | |
2177 | + th.sele_quan_item_by_befor(); | |
2178 | + th.confirm_quan_befor() | |
2179 | + | |
2180 | + } | |
2181 | + } | |
2182 | + | |
2183 | + }, | |
1859 | 2184 | //----把券插入之后的操作,同时还要重新计算价格---- |
1860 | - insert_into_using_quan: async function (item, using_quan, pickid, isby) { | |
2185 | + insert_into_using_quan: async function (item, using_quan, pickid, isby, showToast = true) { | |
1861 | 2186 | |
1862 | 2187 | |
1863 | 2188 | var th = this; |
... | ... | @@ -1880,14 +2205,14 @@ Page({ |
1880 | 2205 | |
1881 | 2206 | th.calculatePrice2(function () { |
1882 | 2207 | |
1883 | - if (old_quan) using_quan[pickid] = old_quan; | |
1884 | - else using_quan[pickid] = null; | |
1885 | - th.setData({ using_quan: using_quan, submit: 0 }); | |
1886 | - wx.showToast({ | |
1887 | - title: "不能使用优惠券,同城起送价不足", | |
1888 | - icon: 'none', | |
1889 | - duration: 2000 | |
1890 | - }) | |
2208 | + // if (old_quan) using_quan[pickid] = old_quan; | |
2209 | + // else using_quan[pickid] = null; | |
2210 | + // th.setData({ using_quan: using_quan, submit: 0 }); | |
2211 | + // wx.showToast({ | |
2212 | + // title: "不能使用优惠券,同城起送价不足", | |
2213 | + // icon: 'none', | |
2214 | + // duration: 2000 | |
2215 | + // }) | |
1891 | 2216 | |
1892 | 2217 | }); |
1893 | 2218 | ... | ... |