pdPurchase.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <view>
  3. <foodItem style="width:100%;" :food="spindexSP" :shuliang="shuliang" :otherPrice="otherPrice" v-on:Ejiajian="jiajian"></foodItem>
  4. <danxuanlist style="width:100%;" :infolistD="skuGuige" :isedit="false" v-on:ElistDatachange="listDatachange"></danxuanlist>
  5. <view class="contentInRowL" style="margin-top: 10rpx;margin-left:6%;align-items: center;">
  6. <text>{{$t('order.beizhu')}}</text>
  7. <textarea class="textinput" auto-height="true"
  8. :always-embed='false'
  9. :adjust-position='true'
  10. cursor-spacing='30'
  11. confirm-hold='true'
  12. confirm-type='done'
  13. :focus='false'
  14. maxlength='100'
  15. v-model='beizhu'
  16. @confirm='mineSendBT'
  17. ></textarea>
  18. </view>
  19. <view style="display: flex;width:88%;margin-left:6%; margin-bottom: 20rpx;">
  20. <text class="querenBt" @click="jiagouwuche()">{{$t('gouwu.jiarugouwc')}}</text>
  21. </view>
  22. <uni-popup ref="bzPop":maskClick="false">
  23. <view class="contentColumnC" style="width:700rpx;background-color: white;margin-left: 25rpx;border-radius: 10rpx;">
  24. <view class="contentInRowS" style="width: 90%;margin-top: 16rpx;">
  25. <text style="color: chocolate;">{{$t('order.quxiao')}}</text>
  26. <text style="font-weight: bold;">{{$t('order.beizhu')}}</text>
  27. <text style="color: #00A6FF;" @click="querenBZ">{{$t('comp.queren')}}</text>
  28. </view>
  29. <textarea class="textinput" auto-height="true"
  30. :always-embed='false'
  31. :adjust-position='true'
  32. cursor-spacing='30'
  33. confirm-hold='true'
  34. confirm-type='done'
  35. :focus='false'
  36. maxlength='100'
  37. v-model='beizhu'
  38. @confirm='mineSendBT'
  39. ></textarea>
  40. <view style="height: 40rpx;"></view>
  41. </view>
  42. </uni-popup>
  43. </view>
  44. </template>
  45. <!--
  46. "shId": 1, //商家id
  47. "mdId": 1, //门店id
  48. "amount": 1, //订单合计金额
  49. "remarks": "", //备注
  50. "type": 1, //订单类型:0外送,1自取,2堂食
  51. "delryTime": "", //配送时间
  52. "food": "" //订单商品
  53. -->
  54. <script>
  55. export default {
  56. name:"pdPurchase",
  57. props: {
  58. food:'',
  59. mendId:''
  60. },
  61. data() {
  62. return {
  63. spindexSP:'',
  64. skuGuige:'',
  65. shuliang:1,
  66. otherPrice:0,
  67. tempsku:'',
  68. beizhu:'',
  69. gouwuche:{
  70. foodlist:[],
  71. mendid:'',
  72. userid:'',
  73. mendname:''
  74. }
  75. };
  76. },
  77. watch: {
  78. food(val){
  79. //console.log(this.food);
  80. this.spindexSP = this.food;
  81. this.skuGuige = this.food.shangpin.foodSku;
  82. this.otherPrice = this.getotherPrice(this.skuGuige);
  83. this.tempsku = this.gettempSKU(this.skuGuige);
  84. this.beizhu='';
  85. this.shuliang = this.food.shuliang==0?1:this.food.shuliang;
  86. this.$refs.bzPop.close();
  87. }
  88. },
  89. methods: {
  90. jiagouwuche(){
  91. this.gengxingouwuche();
  92. this.$emit('Ejiagouwuche');
  93. },
  94. gengxingouwuche(){
  95. if(this.shuliang<1){
  96. uni.showToast({
  97. title: this.$t('comp.qingxzsp'),
  98. icon: 'none',
  99. duration: 2500
  100. })
  101. return;
  102. }
  103. var sp = this.food.shangpin;
  104. var gwc = uni.getStorageSync('gouwuche');
  105. if(''==gwc||null==gwc||undefined==gwc){
  106. var item={
  107. "shId":sp.store.userId, //商家id
  108. "mdId": sp.store.id, //门店id
  109. "logo":sp.store.logo,
  110. "posName":sp.store.posName,
  111. "lat": sp.store.latitude, //
  112. "lng": sp.store.longitude, //
  113. "jvli": 0, //
  114. "freight": 0, //
  115. "amount": 0, //订单合计金额
  116. "foodAmount": 0, //商品金额
  117. "remarks": "", //备注
  118. "type": 0, //订单类型:0外送,1自取,2堂食
  119. "zuohao":'',
  120. "delryTime": "", //配送时间
  121. "food":[] //订单商品
  122. }
  123. this.gouwuche=[];
  124. this.gouwuche.push(item);
  125. }
  126. else{
  127. this.gouwuche = JSON.parse(gwc);
  128. }
  129. var mark=0;
  130. for(var i=0;i<this.gouwuche.length;i++){
  131. var item = this.gouwuche[i];
  132. if(item.mdId==sp.store.id){
  133. mark = 1;
  134. for(var j=0;j<item.food.length;j++){
  135. var gwf = item.food[j];
  136. var ask = JSON.stringify(gwf.ask);
  137. var tempsku = JSON.stringify(this.tempsku);
  138. if(gwf.id == sp.id &&ask === tempsku){
  139. item.food[j].number = this.shuliang;
  140. this.tongjigouwuche();
  141. return;
  142. }
  143. }
  144. var f={
  145. "id": sp.id,
  146. "name": sp.name,
  147. "image": sp.image,
  148. "price": sp.price,
  149. "otherPrice":this.otherPrice,
  150. "number": this.shuliang,
  151. "ask": this.tempsku,
  152. "beizhu":this.beizhu
  153. }
  154. item.food.push(f);
  155. this.gouwuche[i]=item;
  156. this.tongjigouwuche();
  157. return;
  158. }
  159. }
  160. if(mark==0){
  161. var item={
  162. "shId":sp.store.userId, //商家id
  163. "mdId": sp.store.id, //门店id
  164. "logo":sp.store.logo,
  165. "posName":sp.store.posName,
  166. "lat": sp.store.latitude, //
  167. "lng": sp.store.longitude, //
  168. "jvli": 0, //
  169. "freight": 0, //
  170. "amount": 0, //订单合计金额
  171. "foodAmount": 0, //商品金额
  172. "remarks": "", //备注
  173. "zuohao":'',
  174. "type": 0, //订单类型:0外送,1自取,2堂食
  175. "delryTime": "", //配送时间
  176. "food":[] //订单商品
  177. }
  178. var f={
  179. "id": sp.id,
  180. "name": sp.name,
  181. "image": sp.image,
  182. "price": sp.price,
  183. "otherPrice":this.otherPrice,
  184. "number": this.shuliang,
  185. "ask": this.tempsku,
  186. "beizhu":this.beizhu
  187. }
  188. item.food.push(f);
  189. this.gouwuche.push(item);
  190. this.tongjigouwuche();
  191. }
  192. },
  193. tongjigouwuche(){
  194. for(var i=0;i<this.gouwuche.length;i++){
  195. var item = this.gouwuche[i];
  196. var goumaijine=0;
  197. for (var j=0;j<item.food.length;j++) {
  198. var food = item.food[j];
  199. var yidongjine=food.number*(parseFloat(food.price)+parseFloat(food.otherPrice));
  200. goumaijine = goumaijine+yidongjine;
  201. }
  202. this.gouwuche[i].foodAmount=goumaijine;
  203. this.gouwuche[i].amount=goumaijine;
  204. }
  205. let tgwc = JSON.stringify(this.gouwuche);
  206. uni.setStorageSync('gouwuche',tgwc);
  207. },
  208. jiajian(e){
  209. this.shuliang = this.shuliang+e;
  210. console.log(this.food);
  211. },
  212. listDatachange(listData){
  213. this.tempsku = this.gettempSKU(listData);
  214. this.otherPrice = this.getotherPrice(listData);
  215. //console.log(this.tempsku,this.otherPrice)
  216. },
  217. gettempSKU(foodSku){
  218. var selectsku=[];
  219. if(''==foodSku||null==foodSku||undefined==foodSku){
  220. return selectsku;
  221. }
  222. for(var i=0;i<foodSku.length;i++){
  223. if(foodSku[i].objects.length>0){
  224. for(var j=0;j<foodSku[i].objects.length;j++){
  225. if(foodSku[i].objects[j].state==1){
  226. selectsku.push(foodSku[i].objects[j].name);
  227. }
  228. }
  229. }
  230. }
  231. return selectsku;
  232. },
  233. getotherPrice(foodSku){
  234. console.log('getotherPrice',foodSku);
  235. var jiner=0;
  236. if(''==foodSku||null==foodSku||undefined==foodSku){
  237. return 0;
  238. }
  239. for(var i=0;i<foodSku.length;i++){
  240. if(foodSku[i].objects.length>0){
  241. for(var j=0;j<foodSku[i].objects.length;j++){
  242. if(foodSku[i].objects[j].state==1){
  243. if(foodSku[i].objects[j].price==0||!foodSku[i].objects[j].price){
  244. jiner=jiner+0;
  245. }
  246. else{
  247. jiner=jiner+parseFloat(foodSku[i].objects[j].price);
  248. }
  249. }
  250. }
  251. }
  252. }
  253. if(parseFloat(jiner)){
  254. console.log('111',jiner);
  255. return parseFloat(jiner);
  256. }
  257. else{
  258. console.log('222',jiner);
  259. return 0;
  260. }
  261. },
  262. editBeizhu(){
  263. console.log('11111111')
  264. this.$refs.bzPop.open('top');
  265. },
  266. mineSendBT(){
  267. console.log(this.beizhu)
  268. this.$refs.bzPop.close();
  269. },
  270. querenBZ(){
  271. console.log(this.beizhu)
  272. this.$refs.bzPop.close();
  273. },
  274. },
  275. }
  276. </script>
  277. <style>
  278. .querenBt{
  279. margin-top: 30rpx;
  280. width: 100%;
  281. height: 60rpx;
  282. line-height: 60rpx;
  283. padding: 10rpx;
  284. border-radius: 20rpx;
  285. border: solid #40AE36;
  286. border-width: 0px 0px 6rpx 0px;
  287. text-align: center;
  288. justify-content: center;
  289. background-color: #40AE36;
  290. color: white;
  291. box-shadow: 0rpx 0rpx 10rpx 0rpx #40AE36;
  292. }
  293. .beizhuBt{
  294. padding: 10rpx 16rpx 10rpx 16rpx;
  295. color: white;
  296. border-radius: 8rpx;
  297. background-color:chocolate;
  298. }
  299. .beizhutext{
  300. color:darkgray;
  301. font-size: 30rpx;
  302. margin-left: 30rpx;
  303. width: 500rpx;
  304. }
  305. .textinput{
  306. margin-left: 8rpx;
  307. padding-top: 10rpx;
  308. padding-bottom: 10rpx;
  309. width: 80%;
  310. border-radius: 6rpx;
  311. border: 1rpx solid darkgray;
  312. font-size: 32upx;
  313. background-color: white;
  314. }
  315. </style>