subOrder.vue 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709
  1. <template>
  2. <view v-if="isShowView">
  3. <!--pages/subOrder/subOrder.wxml-->
  4. <view class="pdlr20 pd">
  5. <view class="peisong r10">
  6. <view class="pstit">
  7. <view class="psfs">配送方式</view>
  8. </view>
  9. <view class="ztaddr" v-if="isZiti || orderType == 2">
  10. <view class="mdinfo dflex user">
  11. <view class="dflex username">
  12. 提货人:
  13. <input class placeholder="请填写姓名" type="text" @input="getusername" :value="realName" />
  14. </view>
  15. <view class="dflex">
  16. 提货电话:
  17. <input v-if="show" class placeholder="请填写提货电话" type="text" @input="getphone" maxlength="11" :value="phone" />
  18. <button open-type="getPhoneNumber" @getphonenumber="getphonenumber" class="mobile" v-else>填写手机号</button>
  19. </view>
  20. </view>
  21. <view class="ztaddrs dflex">
  22. <view class="info">
  23. <view class="name" @tap="updateShop">自提点:{{ merchant.title ? merchant.title : '请选择门店' }}</view>
  24. <view class="area" @tap="checkMap">
  25. <image src="/static/pages/images/dzico.png" class="dzico"></image>
  26. <text class="address">{{ merchant.address }}</text>
  27. </view>
  28. </view>
  29. <view class="rbox" @tap="updateShop"><image src="/static/pages/images/more.png" class="rico"></image></view>
  30. </view>
  31. <image src="/static/pages/images/dzbg.png" class="dzbg"></image>
  32. </view>
  33. <view class=" psaddr" v-else>
  34. <view class="addr " @tap="addOrUpdateAddress">
  35. <image src="/static/pages/images/dzico.png" class="dzico"></image>
  36. <view class="flex" v-if="address.address || address.house">
  37. <view class="name">{{ address.address }}{{ address.house }}</view>
  38. <view class="text" v-if="address.name">
  39. {{ address.name }}
  40. <text>{{ address.phone }}</text>
  41. </view>
  42. </view>
  43. <view class="flex" v-else>请添加收货地址</view>
  44. <image src="/static/pages/images/more.png" class="rico"></image>
  45. </view>
  46. <view class="addr " @tap="updateShop" v-if="merchant">
  47. <image src="/static/pages/images/dzico.png" class="dzico"></image>
  48. <view class="flex">
  49. <view class="name">{{ isJs && merchant.isDefault != 1 ? '配送点:' : '服务点:' }}{{ merchant.title ? merchant.title : '请选择门店' }}</view>
  50. <view class="text" v-if="address.name">{{ merchant.address }}</view>
  51. </view>
  52. <image src="/static/pages/images/more.png" class="rico"></image>
  53. </view>
  54. <image src="/static/pages/images/dzbg.png" class="dzbg"></image>
  55. </view>
  56. </view>
  57. <!-- 送达时间 -->
  58. <view class="sendtime dflex" @tap="serviceTime" v-if="isJs && !isZiti && !activity" style="display: none;">
  59. <text>送达时间</text>
  60. <view class="flex">{{ sendTimes ? sendTimes : '请选择时间' }}</view>
  61. <image src="/static/pages/images/more.png" class="rico"></image>
  62. </view>
  63. <view class="list mt20">
  64. <view class="li">
  65. <view class="cimgs">
  66. <image :src="mergeProduct.pic" mode="aspectFit" class="cimg"></image>
  67. </view>
  68. <view class="zhinfo">
  69. <view class="zhtit">{{ mergeProduct.title }}</view>
  70. <view class="guigecontent">
  71. 规格:<text class="guige" decode="true">{{ mergeProductPrice.title }}</text>
  72. </view>
  73. <view class="jiage">
  74. <view class="zhjia">
  75. <text>¥</text>
  76. {{ mergeProductPrice.salePrice }}
  77. </view>
  78. <view class="num">
  79. <text class="nums">×{{ query.mergeQuantity }}</text>
  80. </view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. <!-- 海外购 -->
  86. <view class="overseasPurchase" v-if="orderType == 10 || isHwg">
  87. <view class="li">
  88. <text>购买人:</text>
  89. <view class="item"><input name="hwgName" placeholder="必填" :value="hwgName" @input="gethwgName" /></view>
  90. <image src="/product/static/product/image/bi.png" class="bi"></image>
  91. </view>
  92. <view class="li">
  93. <text>身份证号:</text>
  94. <view class="item"><input name="cardNo" placeholder="必填" :value="cardNo" @input="getcardNo" /></view>
  95. <image src="/product/static/product/image/bi.png" class="bi"></image>
  96. </view>
  97. <view class="dflex info">
  98. <image src="/product/static/product/image/hwg.png" class="hwg"></image>
  99. <text>海关规定,购买跨境商品需验证支付人身份证信息,否则将 导致无法清关,请确认您的身份证信息。</text>
  100. </view>
  101. </view>
  102. <view class="ddinfo">
  103. <view class="li">
  104. <text>商品数量</text>
  105. <view>共{{ count >= 0 ? count : '0' }}件</view>
  106. </view>
  107. <view class="li">
  108. <text>订单金额</text>
  109. <view>¥{{ money > 0 ? money : '0' }}</view>
  110. </view>
  111. <view class="li" v-if="orderType == 11">
  112. <text>使用积分</text>
  113. <view>{{ integral }}</view>
  114. </view>
  115. <view class="li" v-if="!isZiti && feeMoney">
  116. <text>邮费</text>
  117. <view>¥{{ feeMoney }}</view>
  118. </view>
  119. <navigator url="/product/coupon/coupon?isChoose=true" hover-class="none" class="li" v-if="couponList && couponList.length > 0">
  120. <text>优惠券</text>
  121. <view class="quan" v-if="couponter.length > 0">
  122. {{ isUseCoupon && coupon ? '-¥' : '不使用优惠券' }}<block v-if="isUseCoupon&&coupon">{{ couponList[couponIndex].couponAmount ? couponList[couponIndex].couponAmount : '' }}</block>
  123. </view>
  124. <view class="quan" v-else>暂无可用优惠券</view>
  125. <image src="/static/pages/images/more.png" class="rico"></image>
  126. </navigator>
  127. <view class="li" v-if="(is_open_wallet.isOpenWallet == 1&&balanceMoney>0) || (isOfflinePayment&&kybalanceMoney>0)" @tap="balanceShow">
  128. <text>余额</text>
  129. <view class="quan">
  130. {{ (balance && checked) || (kybalances && kychecked) ? '-¥' : '不使用余额'
  131. }}{{ balance && checked ? balanceMoney : kybalances && kychecked ? kybalanceMoney : '' }}
  132. </view>
  133. <image src="/static/pages/images/more.png" class="rico"></image>
  134. </view>
  135. </view>
  136. <view class="ddinfo">
  137. <view class="li">
  138. <text>备注:</text>
  139. <input name="node" placeholder="给卖家留言..." placeholder-class="placeholder" class="flex" @input="noteInput" />
  140. </view>
  141. </view>
  142. </view>
  143. <view class="placeholder-view" :style="'height:' + (bottomBlankHeight + 120) + 'rpx'"></view>
  144. <view class="bot" :style="'padding-bottom:' + bottomBlankHeight + 'rpx'">
  145. <view class="heji" v-if="orderType != 11">
  146. <text>{{ payMoney > 0 ? payMoney : '0' }}</text>
  147. </view>
  148. <view v-if="orderType == 11" class="integral zong">
  149. <text class="intnum">{{ integral }}积分</text>
  150. <text class="money">+¥{{ payMoney }}</text>
  151. </view>
  152. <view class="jiesuan" @tap="isBusiness ? tab() : ''">提交订单</view>
  153. </view>
  154. <view class="chufangy" v-if="!isRx">订单中包含处方药,需咨询医生开具处方购买</view>
  155. <!-- 选择送达时间 -->
  156. <view class="ceng" :hidden="isTimeShow" @tap="closeTime"></view>
  157. <view class="time-pop" :hidden="isTimeShow">
  158. <image src="/static/pages/images/close.png" class="close" @tap="closeTime"></image>
  159. <view class="pop-tit">选择送达时间</view>
  160. <view class="pop-tits">选择送达时间</view>
  161. <view class="pop-con dflex">
  162. <view class="pop-left">
  163. <view v-for="(item, index) in aWeek" :key="index" :class="'li ' + (dateIndex == index ? 'active' : '')" @tap="dateDay" :data-index="index" v-if="index < 7">
  164. {{ item.newday }}{{ item.day }}
  165. </view>
  166. <view class="li" @tap="moreDate">更多日期</view>
  167. </view>
  168. <view class="pop-right">
  169. <view v-for="(item, index) in timeList" :key="index" :class="'li ' + (timeIndex == index ? 'active' : '')" @tap="dataTime" :data-index="index">
  170. {{ item }}
  171. <image src="/static/pages/images/sjgou.png" class="gou"></image>
  172. </view>
  173. </view>
  174. </view>
  175. <view class="pop-btn" @tap="timeConfirm">确定</view>
  176. </view>
  177. <!-- 更多送达日期 -->
  178. <view class="time-pop" :hidden="isMoreTimeShow">
  179. <view class="backtime dflex" @tap="closeMoreTime">
  180. <image src="/static/pages/images/back.png"></image>
  181. 返回
  182. </view>
  183. <image src="/static/pages/images/close.png" class="close" @tap="closeMoreTime"></image>
  184. <view class="pop-tit">选择送达时间</view>
  185. <view class="pop-list">
  186. <picker-view indicator-style="height:40px;" :value="value" @change="bindChange">
  187. <picker-view-column>
  188. <view v-for="(item, index) in aWeek" :key="index" class="li">{{ item.newday }}{{ item.day }}</view>
  189. </picker-view-column>
  190. <picker-view-column>
  191. <view v-for="(item, index) in timeList" :key="index" class="li">{{ item }}</view>
  192. </picker-view-column>
  193. </picker-view>
  194. </view>
  195. <view class="pop-btn" @tap="timeConfirm">确定</view>
  196. </view>
  197. <view class="ceng" :hidden="isBalanceShow" @tap="closeBalance"></view>
  198. <view class="time-pop" :hidden="isBalanceShow">
  199. <view class="balance-tit">余额</view>
  200. <view class="balances">
  201. <view class="dflex balance">
  202. <view>
  203. 账户余额
  204. <text>¥{{ userMoney }}</text>
  205. </view>
  206. <view class="dflex reduced">
  207. 本单
  208. <text>已减¥{{ balanceMoney ? balanceMoney : '0' }}</text>
  209. <radio-group @change="radioChange"><radio :value="balanceMoney" :checked="checked" class="radios" color="#EF4A37" @tap="checkedFun"></radio></radio-group>
  210. </view>
  211. </view>
  212. <view class="dflex balance" v-if="isOfflinePayment && kybalance > 0">
  213. <view>
  214. 线下余额
  215. <text>¥{{ kybalance }}</text>
  216. </view>
  217. <view class="dflex reduced">
  218. 本单
  219. <text>已减¥{{ kybalanceMoney ? kybalanceMoney : '0' }}</text>
  220. <radio-group @change="radioChangeKy">
  221. <radio :value="kybalanceMoney" :checked="kychecked" class="radios" color="#EF4A37" @tap="checkedFunKy"></radio>
  222. </radio-group>
  223. </view>
  224. </view>
  225. </view>
  226. <view class="pop-btn" @tap="balanceConfirm">确定</view>
  227. </view>
  228. </view>
  229. </template>
  230. <script>
  231. // pages/subOrder/subOrder.js
  232. const app = getApp();
  233. const req = require('../../utils/request.js');
  234. var QQMapWX = require('../../utils/qqmap.js');
  235. const requsetmessage = require('../../utils/requestmessage.js');
  236. const util = require('../../utils/util.js');
  237. const route = require('../../utils/route');
  238. export default {
  239. data() {
  240. return {
  241. isShowView: false,
  242. bottomBlankHeight: app.globalData.isIPhoneX ? 68 : 0,
  243. isJs: false,
  244. isZiti: false,
  245. merchant: {},
  246. address: {},
  247. ids: '',
  248. pageList: [],
  249. count: 0,
  250. money: 0,
  251. note: '',
  252. couponIndex: 0,
  253. couponList: [],
  254. couponter: [],
  255. isRx: true,
  256. phone: '',
  257. coupon: true,
  258. show: false,
  259. isTimeShow: true,
  260. //送达时间
  261. isMoreTimeShow: true,
  262. //更多送达时间
  263. dateIndex: 0,
  264. //当前选择送达日期
  265. aWeek: [],
  266. //未来七天
  267. timeList: [
  268. '9:00-10:00',
  269. '10:00-11:00',
  270. '11:00-12:00',
  271. '12:00-13:00',
  272. '13:00-14:00',
  273. '14:00-15:00',
  274. '15:00-16:00',
  275. '16:00-17:00',
  276. '17:00-18:00',
  277. '18:00-19:00',
  278. '19:00-20:00',
  279. '20:00-21:00',
  280. '21:00-22:00',
  281. '22:00-23:00',
  282. '23:00-24:00'
  283. ],
  284. //时间段
  285. timeIndex: 0,
  286. //当前选择时间
  287. checked: false,
  288. isBalanceShow: true,
  289. orderType: '',
  290. is_customer_pick_up: '',
  291. query: '',
  292. userInfo: '',
  293. realName: '',
  294. userMoney: '',
  295. ziti: false,
  296. youji: false,
  297. deliver_way: '',
  298. is_open_wallet: '',
  299. // fee: "",
  300. // free: "",
  301. onlyPeisong: '',
  302. Is_Store_Price_Stock: '',
  303. is_open_shop: '',
  304. cardNo: '',
  305. hwgName: '',
  306. isGys: false,
  307. feeMoney: '',
  308. balance: false,
  309. balanceMoney: '',
  310. payMoney: '',
  311. integral: '',
  312. sendTimes: '',
  313. userIntegral: '',
  314. overTime: true,
  315. isHwg: false,
  316. isBusiness: true,
  317. User_Limit_Store: '',
  318. about: {},
  319. kychecked: false,
  320. kybalance: 0, //线下余额
  321. kybalances: false,
  322. kybalanceMoney: '',
  323. isOfflinePayment: false ,//是否开启线下支付
  324. isUseCoupon: true,//是否使用优惠券
  325. isUpdateMoney: false,//是否重新计算金额
  326. mergeProduct: {},//套餐详情
  327. mergeProductPrice: {},//套餐详情
  328. };
  329. },
  330. components: {},
  331. props: {},
  332. onLoad: function(options) {
  333. console.log('参数' + JSON.stringify(options));
  334. this.query = options;
  335. QQMapWX.initMap(req.public.mapLBSKEY);
  336. this.getMy();
  337. this.init();
  338. app.globalData.getCheckSessoin(json => {
  339. this.sessionKey = json.session_key;
  340. });
  341. },
  342. onShow() {
  343. this.mergeProductPrice = req.getStorage('mergeProduct');
  344. this.getMerchant();
  345. // console.log(this.merchant); // let merchant = req.getStorage("MERCHANT");
  346. // this.setData({ merchant: merchant });
  347. //重新计算价格
  348. // this.CalculationMoney();
  349. if(this.isUpdateMoney){
  350. this.CalculationMoney();
  351. }
  352. this.getFreightMoney();//重新获取运费(用于切换收货地址)
  353. let userInfo = req.getStorage('userInfo');
  354. this.setData({
  355. userInfo: userInfo
  356. });
  357. if (userInfo.realName) {
  358. this.setData({
  359. realName: req.excludeSpecial(userInfo.realName)
  360. });
  361. } else if (userInfo.nickName) {
  362. this.setData({
  363. realName: req.excludeSpecial(userInfo.nickName)
  364. });
  365. } //*****************/改动
  366. this.setData({
  367. phone: userInfo.mobile
  368. });
  369. var arr = [];
  370. for (let i = 0; i < 30; i++) {
  371. arr.push(this.dealTime(i));
  372. }
  373. arr[0].day = '(今天)';
  374. arr[1].day = '(明天)';
  375. arr[2].day = '(后天)';
  376. let myDate = new Date();
  377. let hour = myDate.getHours();
  378. let timeList = this.timeList;
  379. arr.map((item, index) => {
  380. if (index == 0) {
  381. item.timeList = timeList.slice(hour - 8);
  382. } else {
  383. item.timeList = timeList;
  384. }
  385. return item;
  386. });
  387. this.setData({
  388. aWeek: arr,
  389. timeList: timeList.slice(hour - 8)
  390. });
  391. },
  392. methods: {
  393. checkRequire(formItemList){//判断是否存在实物产品
  394. console.log('formItemList==',formItemList)
  395. for(var i = 0; i < formItemList.length; i++){
  396. if(formItemList[i].product.productForm == 1){
  397. return false;
  398. }
  399. }
  400. return true;
  401. },
  402. loadProudct() {
  403. let that = this;
  404. let form = {
  405. id: that.query.id
  406. };
  407. let isShowLoading = false;
  408. if (!isShowLoading) {
  409. req.loadIng('加载中');
  410. isShowLoading = true;
  411. }
  412. req.getRequest('/api/v3/merge/detail', form, data => {
  413. // productForm=1 实物, 2 线下服务, 3 虚拟物
  414. that.isShowView = true;
  415. that.mergeProduct = data;
  416. let nodeList = data.nodeList;
  417. this.isZiti = this.checkRequire(nodeList);
  418. console.log('是否存在实物==',this.checkRequire(nodeList))
  419. that.getFreightMoney();
  420. that.loadCoupon();
  421. that.CalculationMoney();
  422. if (isShowLoading) {
  423. uni.hideLoading();
  424. isShowLoading = false;
  425. }
  426. })
  427. },
  428. async init() {
  429. await this.getUserAddress();
  430. await this.getConfig();
  431. await this.loadProudct();
  432. // await this.getList();
  433. await this.getuserMoney();
  434. if (this.isOfflinePayment) {
  435. await this.getUserInformation();
  436. }
  437. },
  438. getUserInformation() {
  439. let _ts = this;
  440. req.postRequest('/api/order/userInformation', {}, res => {
  441. if (res) {
  442. _ts.kybalance = res.kybalance;
  443. if (_ts.userMoney == 0 && res.kybalance > 0) {
  444. _ts.kychecked = true;
  445. _ts.CalculationMoney();
  446. }
  447. }
  448. });
  449. },
  450. // 余额查询
  451. getuserMoney() {
  452. let _ts = this;
  453. let is_open_wallet = JSON.parse(req.getStorage('configRes')).is_open_wallet;
  454. if (is_open_wallet) {
  455. if (JSON.parse(is_open_wallet).isOpenWallet == 1 || this.is_open_wallet.isOpenWallet == 1) {
  456. route.extendNew({}, res => {
  457. if (res) {
  458. this.setData({
  459. userMoney: parseFloat(res.all).toFixed(2)
  460. });
  461. if (res.all > 0) {
  462. _ts.checked = true;
  463. _ts.CalculationMoney();
  464. }
  465. }
  466. });
  467. }
  468. }
  469. },
  470. getMerchant() {
  471. if (!this.query.merchantId || this.about.Many_Store == 0) {
  472. // 总店
  473. let defaultMerchant = req.getStorage('defaultMerchant');
  474. this.setData({
  475. merchant: defaultMerchant
  476. });
  477. // let merchant = req.getStorage('MERCHANT')
  478. // this.setData({ merchant: merchant })
  479. } else {
  480. let from = {};
  481. if (this.query.shopId != null && this.query.shopId != undefined && this.query.shopId != '') {
  482. from.id = this.query.shopId;
  483. } else {
  484. from.id = this.query.merchantId;
  485. }
  486. req.getRequest('/api/merchant/detail', from, res => {
  487. if (!res.id) {
  488. if (this.Is_Store_Price_Stock == 1) {
  489. this.isBusiness = false;
  490. return req.msg('该门店不存在' + (this.User_Limit_Store != 1 ? ',因各门店价格不同,请重新下单' : ''));
  491. } else {
  492. return req.msg('该门店不存在' + (this.User_Limit_Store != 1 ? ',请切换门店' : ''));
  493. }
  494. } else {
  495. var timestamp = Date.parse(new Date());
  496. if (!res.isBusiness) {
  497. if (this.Is_Store_Price_Stock == 1) {
  498. this.isBusiness = false;
  499. return req.msg('该门店暂未营业' + (this.User_Limit_Store != 1 ? ',因各门店价格不同,请重新下单' : ''));
  500. } else {
  501. return req.msg('该门店暂未营业' + (this.User_Limit_Store != 1 ? ',请切换门店' : ''));
  502. }
  503. } else {
  504. if (!res.isGoods && res.type != 5) {
  505. if (this.Is_Store_Price_Stock == 1) {
  506. this.isBusiness = false;
  507. return req.msg('该门店暂不发货' + (this.User_Limit_Store != 1 ? ',因各门店价格不同,请重新下单' : ''));
  508. } else {
  509. return req.msg('该门店暂不发货' + (this.User_Limit_Store != 1 ? ',请切换门店' : ''));
  510. }
  511. }
  512. if (res.type == 5 && !res.isDistance) {
  513. if (this.Is_Store_Price_Stock == 1) {
  514. this.isBusiness = false;
  515. return req.msg('该门店暂不发货' + (this.User_Limit_Store != 1 ? ',因各门店价格不同,请重新下单' : ''));
  516. } else {
  517. return req.msg('该门店暂不发货' + (this.User_Limit_Store != 1 ? ',请切换门店' : ''));
  518. }
  519. }
  520. if (res.isDefault == 1 && this.query.orderType != '2') {
  521. // this.setData({ isZiti: false, youji: true })
  522. } else if (res.type == 5) {
  523. res.time = timestamp + 60 * 60 * 1000;
  524. res.merchantDTO.time = timestamp + 60 * 60 * 1000;
  525. req.setStorage('smallShop', res);
  526. // req.setStorage('MERCHANT', res.merchantDTO);
  527. req.getRequest(
  528. '/api/params/value',
  529. {
  530. type: 'shop_config'
  531. },
  532. res => {
  533. // JSON.parse(res)
  534. // console.log(res)
  535. if (!res || !res.deliverWay) {
  536. this.setData({
  537. isZiti: true,
  538. ziti: true
  539. });
  540. } else {
  541. let deliver_way = res.deliverWay;
  542. if (deliver_way.length >= 2) {
  543. if ((deliver_way[0] == '2' && deliver_way[1] == '3') || (deliver_way[0] == '3' && deliver_way[1] == '2')) {
  544. this.setData({
  545. isZiti: false,
  546. youji: true
  547. });
  548. }
  549. } else if (deliver_way.length == 1) {
  550. deliver_way.forEach(it => {
  551. if (it == 1) {
  552. this.setData({
  553. isZiti: true,
  554. ziti: true
  555. });
  556. }
  557. if (it == 2 || it == 3) {
  558. this.setData({
  559. isZiti: false,
  560. youji: true
  561. });
  562. }
  563. });
  564. }
  565. this.setData({
  566. deliver_way: res.deliverWay
  567. });
  568. }
  569. }
  570. );
  571. } else {
  572. // this.setData({ isZiti: true })
  573. res.time = timestamp + 60 * 60 * 1000;
  574. // req.setStorage('MERCHANT', res);
  575. req.removeStorage('smallShop');
  576. }
  577. this.setData({
  578. merchant: res
  579. });
  580. }
  581. }
  582. });
  583. }
  584. },
  585. selZiti() {
  586. if (this.isZiti == false && this.isGys) {
  587. req.msg('您选择的部分商品,不提供自提服务');
  588. return false;
  589. }
  590. if (this.isZiti == false && this.merchant.isGoods == 0) {
  591. req.msg('该门店,不提供自提服务');
  592. return false;
  593. }
  594. this.setData({
  595. isZiti: !this.isZiti
  596. });
  597. this.CalculationMoney();
  598. if (this.isZiti == true && this.isJs) {
  599. req.msg('您选择的是门店自提,不享受及时达服务');
  600. }
  601. },
  602. // 选择余额
  603. balanceShow() {
  604. this.setData({
  605. isBalanceShow: false
  606. });
  607. },
  608. closeBalance() {
  609. this.setData({
  610. isBalanceShow: true
  611. });
  612. this.CalculationMoney();
  613. },
  614. checkedFun() {
  615. this.setData({
  616. checked: !this.checked,
  617. kychecked: false
  618. });
  619. },
  620. checkedFunKy() {
  621. this.setData({
  622. checked: false,
  623. kychecked: !this.kychecked
  624. });
  625. },
  626. balanceConfirm() {
  627. this.setData({
  628. isBalanceShow: true
  629. });
  630. this.CalculationMoney();
  631. },
  632. getConfig() {
  633. var _this = this;
  634. return new Promise((resolve, reject) => {
  635. req.getRequest('/api/config', {}, function(res) {
  636. if (res.is_open_wallet) {
  637. let is_open_wallet = JSON.parse(res.is_open_wallet);
  638. _this.is_open_wallet = is_open_wallet;
  639. _this.setData({
  640. is_open_wallet: is_open_wallet
  641. });
  642. }
  643. _this.setData({
  644. // fee: res.Express_Fee, //zxb 12.20日屏蔽,调用邮费模板
  645. // free: res.Free_Shipping,//zxb 12.20日屏蔽,调用邮费模板
  646. onlyPeisong: res.is_customer_pick_up == 1 ? true : false,
  647. isOfflinePayment: res.is_open_OfflinePayment == 1 ? true : false,
  648. Is_Store_Price_Stock: res.Is_Store_Price_Stock,
  649. is_open_shop: res.is_open_shop,
  650. User_Limit_Store: res.User_Limit_Store,
  651. about: res
  652. });
  653. resolve();
  654. });
  655. });
  656. },
  657. // 获取身份证号
  658. getcardNo(e) {
  659. this.setData({
  660. cardNo: e.detail.value
  661. });
  662. },
  663. // 获取购买人姓名
  664. gethwgName(e) {
  665. this.setData({
  666. hwgName: e.detail.value
  667. });
  668. },
  669. checkMap() {
  670. let url = 'product/map/map';
  671. app.globalData.openPage(url);
  672. },
  673. updateShop() {
  674. if (!this.isBusiness) {
  675. } else {
  676. if (this.Is_Store_Price_Stock == 1 && this.merchant.id && !this.query.activityId) {
  677. uni.navigateTo({
  678. url: '/pages/nearbyDetails/nearbyDetails?id=' + this.merchant.id
  679. });
  680. } else {
  681. let url = 'merchant/nearby/nearby?isChoose=true';
  682. app.globalData.openPage(url);
  683. }
  684. }
  685. },
  686. getList() {
  687. let that = this;
  688. req.getRequest(
  689. '/api/purchase/list',
  690. {
  691. ids: this.ids // merchantId: this.data.merchant.id
  692. },
  693. data => {
  694. if (!data || data.length == 0) return req.msg('数据不存在');
  695. data = data.map(it => {
  696. if (it.deliverWay && JSON.parse(it.deliverWay).indexOf(3) != -1) it.isJs = true;
  697. return it;
  698. });
  699. that.setData({
  700. pageList: data
  701. });
  702. this.getFreightMoney();
  703. this.pageList.forEach(res => {
  704. if (res.isOtc == '1') {
  705. this.setData({
  706. isRx: false
  707. });
  708. }
  709. if (res.isOtc == '5') {
  710. if (!this.activityId && that.query.orderType != 20) {
  711. this.setData({
  712. orderType: 10,
  713. youji: true,
  714. isZiti: false
  715. });
  716. } else {
  717. this.youji = true;
  718. this.isZiti = false;
  719. this.isHwg = true;
  720. }
  721. }
  722. if (res.isTimely == '2') {
  723. this.setData({
  724. isGys: true
  725. });
  726. }
  727. if (JSON.parse(res.deliverWay) && res.isOtc != '5' && that.query.orderType != 2) {
  728. // 判断有发货方式有几种
  729. let deliverWay = JSON.parse(res.deliverWay).find((value, index, arr) => {
  730. return value >= 2;
  731. });
  732. // 发货方式大于2,并且没有1 就是只有邮寄
  733. if (deliverWay && JSON.parse(res.deliverWay).indexOf(1) == -1) {
  734. that.setData({
  735. youji: true,
  736. isZiti: false
  737. });
  738. }
  739. // 发货方式只有1中,并且是1 就是只有自提
  740. if (JSON.parse(res.deliverWay).indexOf(1) != -1 && JSON.parse(res.deliverWay).length == 1) {
  741. that.setData({
  742. ziti: true,
  743. isZiti: true
  744. });
  745. }
  746. // 发货方式中有3,或者4 并且不是社区团购订单,并且没有活动id 就是极速达
  747. if ((JSON.parse(res.deliverWay).indexOf(3) != -1 || JSON.parse(res.deliverWay).indexOf(4) != -1) && this.orderType != 2) {
  748. that.setData({
  749. isJs: true
  750. // orderType: 5
  751. });
  752. if (JSON.parse(res.deliverWay).indexOf(2) == -1 && JSON.parse(res.deliverWay).indexOf(1) == -1) {
  753. that.setData({
  754. onelyJsd: true
  755. });
  756. }
  757. if (JSON.parse(res.deliverWay).indexOf(2) != -1) {
  758. that.setData({
  759. Jsdyouji: true
  760. });
  761. }
  762. if (JSON.parse(res.deliverWay).indexOf(1) != -1) {
  763. that.setData({
  764. Jsdziti: true
  765. });
  766. }
  767. }
  768. }
  769. });
  770. if(!that.pageList[0].activityType){
  771. that.loadCoupon();
  772. }
  773. that.CalculationMoney(); // let count = 0;
  774. // let money = 0;
  775. // data.forEach(dt => {
  776. // count += dt.quantity;
  777. // money += dt.quantity * dt.price;
  778. // })
  779. // that.setData({
  780. // pageList: data,
  781. // count: count,
  782. // money: money,
  783. // payMoney: payMoney
  784. // })
  785. this.isShowView = true;
  786. }
  787. );
  788. },
  789. adjustmentQuantity(id, quantity, skuId, success) {
  790. req.postRequest(
  791. '/api/purchase/quantity',
  792. {
  793. id: id,
  794. skuId: skuId,
  795. quantity: quantity
  796. },
  797. () => {
  798. success.call(this);
  799. }
  800. );
  801. },
  802. jianQuantity(event) {
  803. const index = event.currentTarget.dataset.index;
  804. const page = this.pageList[index];
  805. if (page.quantity <= 1) return false;
  806. const q = page.quantity - 1;
  807. let that = this;
  808. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  809. let d = {};
  810. d['pageList[' + index + '].quantity'] = q;
  811. that.setData(d);
  812. that.CalculationMoney();
  813. });
  814. },
  815. jiaQuantity(event) {
  816. const index = event.currentTarget.dataset.index;
  817. const page = this.pageList[index];
  818. const q = page.quantity + 1;
  819. let that = this;
  820. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  821. let d = {};
  822. d['pageList[' + index + '].quantity'] = q;
  823. that.setData(d);
  824. that.CalculationMoney();
  825. });
  826. },
  827. //调用接口获取邮费
  828. getFreightMoney() {
  829. if (this.pageList && this.pageList.length > 0 && this.address && this.address.id) {
  830. this.feeMoney='';
  831. this.CalculationMoney();
  832. req.getRequest(
  833. '/api/purchase/freight',
  834. {
  835. ids: this.pageList.map(it => it.id).join(','), //购物车id
  836. addressId: this.address.id //收货地址ID
  837. },
  838. res => {
  839. console.log('快递运费>>>>=====' + res);
  840. this.feeMoney=res;
  841. this.CalculationMoney();
  842. }
  843. );
  844. }
  845. },
  846. CalculationM() {
  847. //计算商品总价格
  848. let count = this.query.mergeQuantity;
  849. let money = this.mergeProductPrice.salePrice * count;
  850. let payMoney = 0;
  851. if (this.isZiti) {
  852. payMoney = money;
  853. this.setData({
  854. feeMoney: '0'
  855. });
  856. } else {
  857. money = parseFloat(money).toFixed(2);
  858. // zxb 12.20屏蔽 使用了运费模板,故老的逻辑屏蔽
  859. // let fee = 0;
  860. // if (this.free > 0) fee = Number(money) - Number(this.free);
  861. // else fee = Number(money);
  862. // this.setData({
  863. // feeMoney: fee >= 0 ? 0 : this.fee
  864. // });
  865. if (this.feeMoney > 0) payMoney = Number(money) + Number(this.feeMoney);
  866. else payMoney = Number(money);
  867. }
  868. if(this.isUseCoupon){
  869. //获取优惠券价格
  870. if (this.couponList.length > 0 && this.couponter.length > 0) {
  871. const coupon = this.couponList[this.couponIndex];
  872. if (coupon == undefined) {
  873. (payMoney = payMoney),
  874. this.setData({
  875. coupon: false
  876. });
  877. } else {
  878. if (payMoney >= coupon.couponFull) {
  879. (payMoney = payMoney - parseFloat(coupon.couponAmount)),
  880. this.setData({
  881. coupon: true
  882. });
  883. } else {
  884. payMoney = payMoney;
  885. this.coupon = false;
  886. };
  887. }
  888. }
  889. }else{
  890. payMoney = money;
  891. }
  892. this.setData({
  893. count: count,
  894. money: parseFloat(money).toFixed(2),
  895. // payMoney: parseFloat(payMoney).toFixed(2),
  896. });
  897. return payMoney;
  898. },
  899. CalculationMoney() {
  900. let _ts = this;
  901. let payMoney = _ts.CalculationM();
  902. //获取余额
  903. if (_ts.checked) {
  904. if (_ts.userMoney > 0) {
  905. const coupon = _ts.userMoney;
  906. if (payMoney >= coupon) {
  907. (payMoney = payMoney - parseFloat(coupon)),
  908. _ts.setData({
  909. balance: true,
  910. balanceMoney: coupon
  911. });
  912. } else {
  913. if (payMoney <= 0) {
  914. _ts.setData({
  915. balance: true,
  916. balanceMoney: '0'
  917. });
  918. } else {
  919. console.log('额度',parseFloat(Number(coupon) + (payMoney - Number(coupon))))
  920. let balanceMoney = parseFloat(Number(coupon) + (payMoney - Number(coupon))).toFixed(2);
  921. payMoney = payMoney - parseFloat(Number(coupon) + (payMoney - Number(coupon))).toFixed(2);
  922. _ts.setData({
  923. balance: true,
  924. balanceMoney: balanceMoney
  925. });
  926. }
  927. } // payMoney = payMoney - parseFloat(coupon), this.setData({ balance: true })
  928. } else {
  929. (payMoney = payMoney),
  930. _ts.setData({
  931. balance: false,
  932. balanceMoney: 0
  933. });
  934. }
  935. }
  936. if (_ts.kychecked) {
  937. //获取线下余额
  938. if (_ts.kybalance > 0) {
  939. const coupon = _ts.kybalance;
  940. if (payMoney >= coupon) {
  941. (payMoney = payMoney - parseFloat(coupon)),
  942. _ts.setData({
  943. kybalances: true,
  944. kybalanceMoney: coupon
  945. });
  946. } else {
  947. if (payMoney <= 0) {
  948. _ts.setData({
  949. kybalances: true,
  950. kybalanceMoney: '0'
  951. });
  952. } else {
  953. let kybalanceMoney = parseFloat(parseFloat(coupon) + (payMoney - parseFloat(coupon))).toFixed(2);
  954. payMoney = payMoney - parseFloat(parseFloat(coupon) + (payMoney - parseFloat(coupon))).toFixed(2);
  955. _ts.setData({
  956. kybalances: true,
  957. kybalanceMoney: kybalanceMoney
  958. });
  959. }
  960. } // payMoney = payMoney - parseFloat(coupon), this.setData({ balance: true })
  961. } else {
  962. (payMoney = payMoney),
  963. _ts.setData({
  964. kybalances: false,
  965. kybalanceMoney: 0
  966. });
  967. }
  968. }
  969. _ts.setData({
  970. payMoney: parseFloat(payMoney).toFixed(2)
  971. });
  972. },
  973. noteInput(event) {
  974. this.note = event.detail.value;
  975. },
  976. // 选择余额
  977. radioChange(e) {
  978. // console.log('radio发生change事件,携带value值为:', e.detail.value);
  979. },
  980. // 选择线下支付
  981. radioChangeKy(e) {
  982. // console.log('radio发生change事件,携带value值为:', e.detail.value);
  983. },
  984. async loadCoupon() {
  985. let _ts = this;
  986. req.getRequest(
  987. '/api/v3/coupon/use',
  988. {
  989. ids: _ts.ids
  990. },
  991. data => {
  992. _ts.couponter = data;
  993. if(data&&data.length>0){
  994. let coupon = data.filter(it=>{return it.isUse});
  995. console.log('coupon',coupon)
  996. _ts.setData({
  997. couponList: coupon
  998. });
  999. }
  1000. if (data&&data.length > 0) _ts.CalculationMoney();
  1001. }
  1002. );
  1003. },
  1004. async loadCoupons() {
  1005. let _ts = this;
  1006. req.getRequest(
  1007. '/api/coupon/user',
  1008. {
  1009. page: 1,
  1010. limit: 100,
  1011. couponState: 1
  1012. },
  1013. res => {
  1014. let contunt = res;
  1015. if (_ts.query.activityId || _ts.query.aprId || _ts.query.orderType == 11) return false;
  1016. req.getRequest(
  1017. '/api/coupon/use',
  1018. {
  1019. ids: _ts.ids
  1020. },
  1021. data => {
  1022. _ts.couponter = data;
  1023. let couponObj = [];
  1024. contunt.forEach((it, index) => {
  1025. data.forEach(el => {
  1026. if (it.id == el.id) {
  1027. it.acitve = true;
  1028. }
  1029. });
  1030. });
  1031. var objectArraySort = function(keyName) {
  1032. return function(objectN, objectM) {
  1033. var valueN = objectN[keyName];
  1034. var valueM = objectM[keyName];
  1035. if (valueN < valueM) return 1;
  1036. else if (valueN > valueM) return -1;
  1037. else return 0;
  1038. };
  1039. };
  1040. contunt.sort(objectArraySort('couponAmount'));
  1041. contunt.forEach((it, index) => {
  1042. if (it.acitve && couponObj.length <= 0) {
  1043. _ts.couponIndex = index;
  1044. couponObj.push(index);
  1045. }
  1046. });
  1047. _ts.setData({
  1048. couponList: contunt
  1049. });
  1050. if (data.length > 0) _ts.CalculationMoney();
  1051. }
  1052. );
  1053. }
  1054. );
  1055. },
  1056. getUserAddress() {
  1057. // req.g('/api/address/default', data => {
  1058. req.g('/api/address/get/default', data => {
  1059. this.setData({
  1060. address: data
  1061. });
  1062. this.getFreightMoney();
  1063. });
  1064. },
  1065. addOrUpdateAddress() {
  1066. let url = 'mine/addAddress/addAddress?isChoose=true&orderType=' + this.orderType;
  1067. if (this.address && this.address.id) {
  1068. url = 'mine/address/address?isChoose=true&orderType=' + this.orderType + '&addressId=' + this.address.id;
  1069. }
  1070. app.globalData.openPage(url);
  1071. },
  1072. getMy() {
  1073. let that = this;
  1074. req.getRequest('/api/user/my', {}, data => {
  1075. that.setData({
  1076. userInfo: req.getStorage('userInfo'),
  1077. // realName: req.getStorage('userInfo').realName,
  1078. phone: data.mobile
  1079. });
  1080. let _userinfo = req.getStorage('userInfo');
  1081. if (_userinfo.mobile) {
  1082. this.setData({
  1083. show: true
  1084. });
  1085. }
  1086. _userinfo.mobile = data.mobile;
  1087. req.setStorage('userInfo', _userinfo);
  1088. });
  1089. },
  1090. getphonenumber(event) {
  1091. const detail = event.detail;
  1092. const _ts = this;
  1093. if (!detail || !detail.encryptedData || !detail.iv) return false;
  1094. req.postRequest(
  1095. '/api/weixin/mobile',
  1096. {
  1097. encryptedData: detail.encryptedData,
  1098. iv: detail.iv,
  1099. sessionKey: _ts.sessionKey
  1100. },
  1101. res => {
  1102. _ts.setData({
  1103. phone: res.mobile,
  1104. show: true
  1105. });
  1106. let userInfo = req.getStorage('userInfo');
  1107. if(!userInfo.mobile){
  1108. userInfo.mobile = res.mobile;
  1109. req.setStorage('userInfo',userInfo);
  1110. }
  1111. _ts.getMy();
  1112. }
  1113. );
  1114. },
  1115. payOrder(res) {
  1116. // this.setData({ btn: 1 })
  1117. req.payOrder(res, success => {
  1118. if (success) {
  1119. //支付成功
  1120. if (!this.isRx) {
  1121. app.globalData.redirectTab('product/pay/pay?isSuccess=true&&orderId=' + this.orderId + '&isRx=1');
  1122. } else if (this.orderType == 4) {
  1123. //拼团订单,
  1124. if (this.pay == 1) {
  1125. uni.navigateBack();
  1126. } else {
  1127. //支付成功之后跳入到拼团页面
  1128. app.globalData.redirectTab('activity/group/ptDetail/ptDetail?acid=' + this.activityId + '&id=' + this.aprId + '&merchantId=' + this.query.merchantId);
  1129. }
  1130. } else {
  1131. app.globalData.redirectTab('product/pay/pay?isSuccess=true');
  1132. }
  1133. } else {
  1134. app.globalData.redirectTab('product/pay/pay?money=' + this.money + '&id=' + res);
  1135. }
  1136. });
  1137. },
  1138. tab: util.throttle(async function() {
  1139. let _ts = this;
  1140. let tipMsg = ''
  1141. if(this.isZiti){
  1142. let merchant = req.getStorage('MERCHANT');
  1143. console.log('merchant.range',merchant.range)
  1144. if(merchant.range && merchant.range!=50000){
  1145. tipMsg = '当前下单门店为'+ merchant.title + ',距离您' + (merchant.mDistance < 1000 ? merchant.mDistance+'m' : merchant.range+'km') + ',下单后如需修改门店,请联系客服'
  1146. }else{
  1147. tipMsg = '当前下单门店为' + merchant.title +',下单后如需修改门店,请联系客服'
  1148. }
  1149. req.msgConfirm(tipMsg,async res=>{
  1150. this.confirmOrder()
  1151. })
  1152. }else{
  1153. this.confirmOrder()
  1154. }
  1155. }, 3000),
  1156. async confirmOrder(){
  1157. let mode = this.isZiti ? 1 : 2;
  1158. if (!this.isZiti && this.isJs) {
  1159. mode = 3;
  1160. }
  1161. if (!this.isRx) {
  1162. await requsetmessage.recipel(mode).then(res => {});
  1163. } else if (mode == 1) {
  1164. await requsetmessage.selfRaising().then(res => {
  1165. // console.log("自提", res);
  1166. });
  1167. } else if (mode == 2) {
  1168. await requsetmessage.distribution().then(res => {
  1169. // console.log("配送", res);
  1170. });
  1171. } else {
  1172. await requsetmessage.jisda().then(res => {
  1173. // console.log("及时达", res);
  1174. });
  1175. }
  1176. this.createOrder();
  1177. },
  1178. async createOrder() {
  1179. let _ts = this;
  1180. await this.submitOrder(data => {
  1181. if (_ts.orderId) {
  1182. _ts.payOrder(_ts.orderId);
  1183. return false;
  1184. }
  1185. let isShowLoading = false;
  1186. if (!isShowLoading) {
  1187. req.loadIng('加载中');
  1188. isShowLoading = true;
  1189. }
  1190. req.postRequest('/api/v3/merge/buy', data, res => {
  1191. _ts.orderId = res;
  1192. // if (!this.isRx) {
  1193. // console.log("13545541565");
  1194. // // uni.redirectTo({
  1195. // // url: '/prescription/Consultation/index?orderId=' + this.orderId
  1196. // // });
  1197. // _ts.payOrder(_ts.orderId);
  1198. // } else {
  1199. _ts.payOrder(_ts.orderId);
  1200. if (isShowLoading) {
  1201. uni.hideLoading();
  1202. isShowLoading = false;
  1203. }
  1204. // } // })
  1205. });
  1206. });
  1207. },
  1208. // 获取身份证号
  1209. getcardNo(e) {
  1210. this.setData({
  1211. cardNo: e.detail.value
  1212. });
  1213. },
  1214. // 获取购买人姓名
  1215. gethwgName(e) {
  1216. this.setData({
  1217. hwgName: e.detail.value
  1218. });
  1219. },
  1220. //获取用户输入的名字 改动
  1221. getusername(event) {
  1222. // console.log(event.detail.value)
  1223. this.setData({
  1224. realName: req.excludeSpecial(event.detail.value)
  1225. });
  1226. },
  1227. //获取用户输入的电话 改动
  1228. getphone(event) {
  1229. this.setData({
  1230. phone: event.detail.value
  1231. });
  1232. },
  1233. // 选择送达时间
  1234. serviceTime() {
  1235. this.setData({
  1236. isTimeShow: false
  1237. });
  1238. },
  1239. closeTime() {
  1240. this.setData({
  1241. isTimeShow: true,
  1242. isMoreTimeShow: true
  1243. });
  1244. },
  1245. moreDate() {
  1246. this.setData({
  1247. isMoreTimeShow: false
  1248. });
  1249. },
  1250. closeMoreTime() {
  1251. this.setData({
  1252. isMoreTimeShow: true
  1253. });
  1254. },
  1255. //处理未来七天的函数
  1256. dealTime: function(num) {
  1257. // num:未来天数
  1258. var time = new Date(); // 获取当前时间日期
  1259. var date = new Date(time.setDate(time.getDate() + num)).getDate(); //这里先获取日期,在按需求设置日期,最后获取需要的
  1260. var year = time.getFullYear(); // 获取年份
  1261. var month = time.getMonth() + 1; // 获取月份
  1262. var day = time.getDay(); // 获取星期
  1263. switch (day) {
  1264. // 格式化
  1265. case 0:
  1266. day = '(周日)';
  1267. break;
  1268. case 1:
  1269. day = '(周一)';
  1270. break;
  1271. case 2:
  1272. day = '(周二)';
  1273. break;
  1274. case 3:
  1275. day = '(周三)';
  1276. break;
  1277. case 4:
  1278. day = '(周四)';
  1279. break;
  1280. case 5:
  1281. day = '(周五)';
  1282. break;
  1283. case 6:
  1284. day = '(周六)';
  1285. break;
  1286. }
  1287. var obj = {
  1288. date: date,
  1289. year: year,
  1290. day: day,
  1291. month: month,
  1292. newday: month + '-' + date
  1293. };
  1294. return obj; // 返回对象
  1295. },
  1296. dateDay(event) {
  1297. //选择送达日期
  1298. let index = event.currentTarget.dataset.index;
  1299. let aWeek = this.aWeek[index];
  1300. if (index == 7) return false;
  1301. this.sendDate = aWeek.newday;
  1302. this.setData({
  1303. dateIndex: index,
  1304. timeList: aWeek.timeList
  1305. });
  1306. },
  1307. dataTime(event) {
  1308. //选择送达时间
  1309. let index = event.currentTarget.dataset.index;
  1310. let sendTime = this.timeList[index];
  1311. this.sendTime = sendTime;
  1312. this.setData({
  1313. timeIndex: index
  1314. });
  1315. },
  1316. timeConfirm() {
  1317. //确定送达时间
  1318. if (!this.sendDate) {
  1319. this.sendDate = this.aWeek[0].newday;
  1320. }
  1321. if (!this.sendTime) {
  1322. this.sendTime = this.aWeek[0].timeList[0];
  1323. }
  1324. this.setData({
  1325. isTimeShow: true,
  1326. isMoreTimeShow: true,
  1327. sendTimes: this.sendDate + ' ' + this.sendTime
  1328. });
  1329. },
  1330. bindChange(e) {
  1331. //更多时间确定
  1332. const val = e.detail.value;
  1333. let aWeek = this.aWeek[val[0]];
  1334. this.setData({
  1335. timeList: aWeek.timeList
  1336. });
  1337. this.sendDate = this.aWeek[val[0]].newday;
  1338. this.sendTime = this.timeList[val[1]];
  1339. },
  1340. // 用户积分余额查询
  1341. getUserintegral() {
  1342. req.getRequest('/api/integral/returnIntegral', {}, data => {
  1343. this.setData({
  1344. userIntegral: data
  1345. });
  1346. });
  1347. },
  1348. //
  1349. submitOrder(success) {
  1350. let that = this;
  1351. let mode = this.isZiti ? 1:2
  1352. let pidCode = req.getStorage('pidCode');
  1353. let data = {
  1354. ids: [0],
  1355. mergePriceId: this.mergeProductPrice.id,
  1356. mode: mode,
  1357. node: this.note,
  1358. phone: this.phone,
  1359. userName: req.excludeSpecial(this.realName),
  1360. scene: req.getStorage('scene'),
  1361. quantity: this.count
  1362. };
  1363. if (this.is_open_wallet && this.is_open_wallet.isOpenWallet == 1 && this.checked) {
  1364. //this.balance
  1365. data.balancePayMoney = this.balanceMoney;
  1366. }
  1367. if (this.kychecked) {
  1368. //线下余额支付
  1369. data.offlinePaymentMoney = this.kybalanceMoney;
  1370. }
  1371. if (this.merchant && this.merchant.type == 5) {
  1372. data.shopId = this.merchant.id;
  1373. data.merchantId = this.merchant.merchantDTO.id;
  1374. } else {
  1375. data.merchantId = this.merchant.id;
  1376. }
  1377. // 获取推荐人
  1378. if (pidCode && req.getStorage('userInfo').id != pidCode) {
  1379. data.pid = pidCode;
  1380. }
  1381. this.setData({
  1382. phone: data.phone,
  1383. realName: req.excludeSpecial(data.userName)
  1384. }); //添加电话正则
  1385. let myreg = /^1[3456789]\d{9}$/; // 真实姓名正则
  1386. let reg = /^[\u4E00-\u9FA5A-Za-z0-9]{1,20}$/; // 海外购真实姓名正则
  1387. let hwgreg = /^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/; // 身份证正则
  1388. let sfz = /^[1-9]\d{5}(18|19|20|(3\d))\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
  1389. if (this.couponList && this.couponList.length > 0 && this.couponter.length > 0) {
  1390. if (this.coupon&&this.isUseCoupon) data.couponId = this.couponList[this.couponIndex].id;
  1391. }
  1392. // 获取营业时间
  1393. var time = [];
  1394. var start;
  1395. var end;
  1396. var current;
  1397. // if (this.merchant && mode != 2) {
  1398. // if (this.merchant.businessTime) {
  1399. // time = this.merchant.businessTime.split('-');
  1400. // if (time.length == 2) {
  1401. // this.overTime = true;
  1402. // var myDate = new Date();
  1403. // var hours = myDate.getHours(); //获取当前小时
  1404. // var minutes = myDate.getMinutes(); //获取当前分钟
  1405. // var timeState;
  1406. // var timeEnd;
  1407. // if (time[0].indexOf(':') != '-1') {
  1408. // timeState = time[0].split(':');
  1409. // }
  1410. // if (time[1].indexOf(':') != '-1') {
  1411. // timeEnd = time[1].split(':');
  1412. // }
  1413. // if (time[0].indexOf(':') != '-1') {
  1414. // timeState = time[0].split(':');
  1415. // }
  1416. // if (time[1].indexOf(':') != '-1') {
  1417. // timeEnd = time[1].split(':');
  1418. // }
  1419. // start = +timeState[0] * (60000 * 60) + +timeState[1] * 60000; //营业开始时间转毫秒
  1420. // end = +timeEnd[0] * (60000 * 60) + +timeEnd[1] * 60000; //营业结束时间转毫秒
  1421. // current = +hours * (60000 * 60) + +minutes * 60000; //当前时间转毫秒
  1422. // }
  1423. // }
  1424. // }
  1425. if (this.isZiti) {
  1426. //自提
  1427. //*******************************
  1428. if (!data.merchantId) return req.msg('请选择提货门店');
  1429. if (!this.realName || !this.phone) return req.msg('请填写提货人和提货电话'); //判断电话是否正确
  1430. if (!myreg.test(this.phone)) {
  1431. return req.msg('请填写正确的手机号码!');
  1432. } //判断名字是否正确
  1433. // if (!reg.test(data.userName)) return req.msg('请输入正确提货人姓名');
  1434. data.addressId = this.merchant.id;
  1435. if (current < start) {
  1436. uni.showModal({
  1437. content: '本店暂末营业,请于' + this.merchant.businessTime + '期间提货!',
  1438. confirmText: '同意',
  1439. cancelText: '不同意',
  1440. success(res) {
  1441. if (res.confirm) {
  1442. success.call(that, data);
  1443. }
  1444. }
  1445. });
  1446. } else if (current > end) {
  1447. uni.showModal({
  1448. content: '本店已歇业,请于次日' + this.merchant.businessTime + '期间提货!',
  1449. confirmText: '同意',
  1450. cancelText: '不同意',
  1451. success(res) {
  1452. if (res.confirm) {
  1453. success.call(that, data);
  1454. }
  1455. }
  1456. });
  1457. } else {
  1458. success.call(this, data);
  1459. }
  1460. } else {
  1461. if (!data.merchantId) return req.msg('请选择发货门店');
  1462. if (!that.address || !that.address.id) return req.msg('请选择收货地址');
  1463. if (data.orderType == 10 || this.isHwg) {
  1464. if (data.userName == '' || data.userName == undefined || data.userName == null) {
  1465. return req.msg('请填写购买人');
  1466. } else {
  1467. if (!hwgreg.test(this.hwgName)) return req.msg('请输入正确真实姓名(至少2位汉字)');
  1468. }
  1469. if (data.idcard == '' || data.idcard == undefined || data.idcard == null) {
  1470. return req.msg('请填写身份证号码');
  1471. } else {
  1472. if (!sfz.test(data.idcard)) return req.msg('请输入正确的身份证');
  1473. }
  1474. }
  1475. let address = that.address;
  1476. data.addressId = address.id;
  1477. let merchant = this.merchant; //只有及时达的订单才需要校验地址范围
  1478. // if (this.data.orderType == 5) {
  1479. // if (data.jsonDate == "" || data.jsonDate == undefined) return req.msg("请选择送达时间")
  1480. // }
  1481. if (!this.isZiti) {//data.mode == 3
  1482. if (!address.lat || !address.lng) return req.msg('收货地址未解析,请重新选择收货地址');
  1483. let formAddress = {
  1484. latitude: merchant.lat,
  1485. longitude: merchant.lng
  1486. }; //判断用户收货地址是否在门店发货距离之内
  1487. QQMapWX.calculateDistance(
  1488. formAddress,
  1489. [
  1490. {
  1491. latitude: address.lat,
  1492. longitude: address.lng
  1493. }
  1494. ],
  1495. res => {
  1496. //超出了订单范围,并且是及时达订单
  1497. if (merchant.isDistans == 1 && res.elements[0].distance / 1000 > merchant.distance) {
  1498. console.log('超过距离')
  1499. // console.log("发货距离", res.elements[0].distance / 1000, "门店范围距离", merchant
  1500. // .distance); // return req.msg('非常抱歉,您的配送地址超出我们的配送服务范围');
  1501. let content = '';
  1502. // if (!this.onelyJsd) {
  1503. // if (this.Jsdyouji) {
  1504. // content = '您的及时达订单超过了配送服务范围,是否同意转为邮寄发货?';
  1505. // } else if (this.Jsdziti && !this.Jsdyouji) {
  1506. // content = '您的及时达订单超过了配送服务范围,是否同意转为自提?';
  1507. // }
  1508. // } else {
  1509. content = '您的订单超过了配送服务范围!暂不提供服务';
  1510. // }
  1511. uni.showModal({
  1512. content: content,
  1513. confirmText: '同意',
  1514. success(res) {
  1515. if (res.confirm) {
  1516. if (that.Jsdyouji && !that.onelyJsd) {
  1517. // if(that.query.orderType==20){
  1518. // data.orderType = 20;
  1519. // }else{
  1520. // data.orderType = 1; //设置为普通订单
  1521. // }
  1522. data.mode = 2; //方式为邮寄
  1523. that.setData({
  1524. isJs: false
  1525. });
  1526. success.call(that, data);
  1527. } else if (that.Jsdziti && !that.Jsdyouji && !that.onelyJsd && !that.onlyPeisong) {
  1528. // if(that.query.orderType==20){
  1529. // data.orderType = 20;
  1530. // }else{
  1531. // data.orderType = 1; //设置为普通订单
  1532. // }
  1533. data.mode = 1; //方式为自提
  1534. that.setData({
  1535. isJs: true,
  1536. isZiti: true
  1537. });
  1538. // success.call(that, data);
  1539. } else if (that.onelyJsd) {
  1540. return false;
  1541. }
  1542. } else if (res.cancel) {
  1543. }
  1544. }
  1545. });
  1546. } else {
  1547. if (current < start) {
  1548. console.log('未上班')
  1549. uni.showModal({
  1550. content: '对不起,工作人员末上班,您的订单将于' + time[0] + '后进行配送!',
  1551. confirmText: '同意',
  1552. cancelText: '不同意',
  1553. success(res) {
  1554. if (res.confirm) {
  1555. success.call(that, data);
  1556. } else if (res.cancel) {
  1557. }
  1558. }
  1559. });
  1560. } else if (current > end) {
  1561. console.log('歇业')
  1562. uni.showModal({
  1563. content: '本店已歇业,您的订单将于次日' + time[0] + '后进行配送!',
  1564. confirmText: '同意',
  1565. cancelText: '不同意',
  1566. success(res) {
  1567. if (res.confirm) {
  1568. success.call(that, data);
  1569. } else if (res.cancel) {
  1570. }
  1571. }
  1572. });
  1573. } else {
  1574. success.call(that, data);
  1575. }
  1576. // success.call(this, data);
  1577. }
  1578. }
  1579. );
  1580. } else {
  1581. success.call(this, data);
  1582. }
  1583. }
  1584. }
  1585. }
  1586. };
  1587. </script>
  1588. <style>
  1589. @import './subOrder.css';
  1590. </style>