foodxuangou.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. <label class="querenBt" @click="jiagouwuche()">{{$t('gouwu.jiarugouwc')}}</label>
  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:"foodxuangou",
  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 = 1;
  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. "remarks": "", //备注
  117. "type": 0, //订单类型:0外送,1自取,2堂食
  118. "zuohao":'',
  119. "delryTime": "", //配送时间
  120. "food":[] //订单商品
  121. }
  122. this.gouwuche=[];
  123. this.gouwuche.push(item);
  124. }
  125. else{
  126. this.gouwuche = JSON.parse(gwc);
  127. }
  128. var mark=0;
  129. for(var i=0;i<this.gouwuche.length;i++){
  130. var item = this.gouwuche[i];
  131. if(item.mdId==sp.store.id){
  132. mark = 1;
  133. for(var j=0;j<item.food.length;j++){
  134. var gwf = item.food[j];
  135. var ask = JSON.stringify(gwf.ask);
  136. var tempsku = JSON.stringify(this.tempsku);
  137. if(gwf.id == sp.id &&ask === tempsku){
  138. item.food[j].number = this.shuliang;
  139. this.tongjigouwuche();
  140. return;
  141. }
  142. }
  143. var f={
  144. "id": sp.id,
  145. "name": sp.name,
  146. "image": sp.image,
  147. "price": sp.price,
  148. "otherPrice":this.otherPrice,
  149. "number": this.shuliang,
  150. "ask": this.tempsku,
  151. "beizhu":this.beizhu
  152. }
  153. item.food.push(f);
  154. this.gouwuche[i]=item;
  155. this.tongjigouwuche();
  156. return;
  157. }
  158. }
  159. if(mark==0){
  160. var item={
  161. "shId":sp.store.userId, //商家id
  162. "mdId": sp.store.id, //门店id
  163. "logo":sp.store.logo,
  164. "posName":sp.store.posName,
  165. "lat": sp.store.latitude, //
  166. "lng": sp.store.longitude, //
  167. "jvli": 0, //
  168. "freight": 0, //
  169. "amount": 0, //订单合计金额
  170. "remarks": "", //备注
  171. "zuohao":'',
  172. "type": 0, //订单类型:0外送,1自取,2堂食
  173. "delryTime": "", //配送时间
  174. "food":[] //订单商品
  175. }
  176. var f={
  177. "id": sp.id,
  178. "name": sp.name,
  179. "image": sp.image,
  180. "price": sp.price,
  181. "otherPrice":this.otherPrice,
  182. "number": this.shuliang,
  183. "ask": this.tempsku,
  184. "beizhu":this.beizhu
  185. }
  186. item.food.push(f);
  187. this.gouwuche.push(item);
  188. this.tongjigouwuche();
  189. }
  190. },
  191. tongjigouwuche(){
  192. for(var i=0;i<this.gouwuche.length;i++){
  193. var item = this.gouwuche[i];
  194. var goumaijine=0;
  195. for (var j=0;j<item.food.length;j++) {
  196. var food = item.food[j];
  197. var yidongjine=food.number*(parseFloat(food.price)+parseFloat(food.otherPrice));
  198. goumaijine = goumaijine+yidongjine;
  199. }
  200. this.gouwuche[i].amount=goumaijine;
  201. }
  202. let tgwc = JSON.stringify(this.gouwuche);
  203. uni.setStorageSync('gouwuche',tgwc);
  204. },
  205. jiajian(e){
  206. this.shuliang = this.shuliang+e;
  207. console.log(this.food);
  208. },
  209. listDatachange(listData){
  210. this.tempsku = this.gettempSKU(listData);
  211. this.otherPrice = this.getotherPrice(listData);
  212. //console.log(this.tempsku,this.otherPrice)
  213. },
  214. gettempSKU(foodSku){
  215. var selectsku=[];
  216. if(''==foodSku||null==foodSku||undefined==foodSku){
  217. return selectsku;
  218. }
  219. for(var i=0;i<foodSku.length;i++){
  220. if(foodSku[i].objects.length>0){
  221. for(var j=0;j<foodSku[i].objects.length;j++){
  222. if(foodSku[i].objects[j].state==1){
  223. selectsku.push(foodSku[i].objects[j].name);
  224. }
  225. }
  226. }
  227. }
  228. return selectsku;
  229. },
  230. getotherPrice(foodSku){
  231. console.log('getotherPrice',foodSku);
  232. var jiner=0;
  233. if(''==foodSku||null==foodSku||undefined==foodSku){
  234. return 0;
  235. }
  236. for(var i=0;i<foodSku.length;i++){
  237. if(foodSku[i].objects.length>0){
  238. for(var j=0;j<foodSku[i].objects.length;j++){
  239. if(foodSku[i].objects[j].state==1){
  240. if(foodSku[i].objects[j].price==0||!foodSku[i].objects[j].price){
  241. jiner=jiner+0;
  242. }
  243. else{
  244. jiner=jiner+parseFloat(foodSku[i].objects[j].price);
  245. }
  246. }
  247. }
  248. }
  249. }
  250. if(parseFloat(jiner)){
  251. console.log('111',jiner);
  252. return parseFloat(jiner);
  253. }
  254. else{
  255. console.log('222',jiner);
  256. return 0;
  257. }
  258. },
  259. editBeizhu(){
  260. console.log('11111111')
  261. this.$refs.bzPop.open('top');
  262. },
  263. mineSendBT(){
  264. console.log(this.beizhu)
  265. this.$refs.bzPop.close();
  266. },
  267. querenBZ(){
  268. console.log(this.beizhu)
  269. this.$refs.bzPop.close();
  270. },
  271. },
  272. }
  273. </script>
  274. <style>
  275. .querenBt{
  276. margin-top: 30rpx;
  277. width: 100%;
  278. height: 60rpx;
  279. line-height: 60rpx;
  280. padding: 10rpx;
  281. border-radius: 20rpx;
  282. border: solid #00A6FF;
  283. border-width: 0px 0px 6rpx 0px;
  284. text-align: center;
  285. justify-content: center;
  286. background-color: #00A6FF;
  287. color: white;
  288. box-shadow: 0rpx 0rpx 10rpx 0rpx #00A6FF;
  289. }
  290. .beizhuBt{
  291. padding: 10rpx 16rpx 10rpx 16rpx;
  292. color: white;
  293. border-radius: 8rpx;
  294. background-color:chocolate;
  295. }
  296. .beizhutext{
  297. color:darkgray;
  298. font-size: 30rpx;
  299. margin-left: 30rpx;
  300. width: 500rpx;
  301. }
  302. .textinput{
  303. margin-left: 8rpx;
  304. padding-top: 10rpx;
  305. padding-bottom: 10rpx;
  306. width: 80%;
  307. border-radius: 6rpx;
  308. border: 1rpx solid darkgray;
  309. font-size: 32upx;
  310. background-color: white;
  311. }
  312. </style>