addGroupBuyingNext.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <template>
  2. <view class='content'>
  3. <view>
  4. <view class='flex'>
  5. <view v-for='(item,index) in classifyList' class='classify_item' :class='item.select?"active":""' @click='switchClassify(item)'>{{item.classifyName}}</view>
  6. </view>
  7. <view class='button' @click='addClassify'>自定义分类</view>
  8. </view>
  9. <view class="wrap">
  10. <view style='padding: 10rpx 0 40rpx 0;' v-for='item in categorizationOfDishes'>
  11. <view style='margin-bottom:20rpx;' class='flex justify-space-between align-item-center'>
  12. <view class='flex align-item-center'>
  13. <view>{{item.classifyName}}</view>
  14. <view class='iconfont_no' @click='switchStatus(item)' :class='item.status?"icon_merchants_entershouqi":"icon_merchants_enterzhankai"'></view>
  15. </view>
  16. <view class='button' @click='addList(item)'>新增</view>
  17. </view>
  18. <view v-if='item.status'>
  19. <view class='flex align-item-center' v-for='(item1,index1) in item.list'>
  20. <view>
  21. <view style='margin: 10rpx 20rpx;' class='flex justify-space-between align-item-center'>
  22. <view>菜品名称</view>
  23. <u-input inputAlign='right' border='none' placeholder='输入菜品名称,不超过10个字' v-model="item1.dishName" />
  24. </view>
  25. <view class='flex'>
  26. <view class='flex align-item-center'>
  27. <u-input @input='compute' inputAlign='right' border='none' placeholder='输入单价' v-model="item1.dishPrice" />
  28. (元/份)
  29. </view>
  30. <view class="flex align-item-center">
  31. <u-input @input='compute' inputAlign='right' border='none' placeholder='输入单价' v-model="item1.number" />
  32. (份)
  33. </view>
  34. </view>
  35. </view>
  36. <view>
  37. <view @click='del(item,index1)' class="iconfont_no icon_merchants_enterjianshao"></view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view class='flex align-item-center justify-space-between'>
  43. 原价合计(元)<view>{{form.originalPrice}}</view>
  44. </view>
  45. <view class='flex align-item-center'>
  46. 团购价(元)<u-input @input='groupPriceInput' inputAlign='right' border='none' placeholder='输入团购价格' v-model="form.groupPrice" />
  47. </view>
  48. <view class='flex align-item-center justify-space-between'>
  49. 折扣<view class='flex align-item-center'><view>{{form.discount?form.discount:'自动计算折扣'}}</view><view>折</view></view>
  50. </view>
  51. <view>
  52. <view>上传图片</view>
  53. <view>
  54. <u-upload :fileList="fileList1" @afterRead="afterRead($event)" @delete="deletePic" name="1" multiple
  55. :maxCount="9">
  56. </u-upload>
  57. </view>
  58. </view>
  59. </view>
  60. <u-modal :show="isSubmit" content='确认添加团购信息?' @confirm="$u.debounce(confirmSubmit, 500)" showCancelButton
  61. @cancel="isSubmit=false" @close="isSubmit=false" closeOnClickOverlay></u-modal>
  62. <u-modal :show="show1" content='确认取消该分类?' @confirm="$u.debounce(classifycancelSubmit, 500)" showCancelButton
  63. @cancel="show1=false" @close="show1=false" closeOnClickOverlay>
  64. </u-modal>
  65. <u-modal :show="show" title='添加分类' @confirm="$u.debounce(classifySubmit, 500)" showCancelButton
  66. @cancel="show=false" @close="show=false" closeOnClickOverlay>
  67. <view class="slot-content">
  68. <view>
  69. <u--input inputAlign='center' v-model="classifyName" placeholder="输入分类名称" border="none"></u--input>
  70. </view>
  71. </view>
  72. </u-modal>
  73. <view class="footer">
  74. <button @click='submit' class="submit">提交</button>
  75. </view>
  76. </view>
  77. </template>
  78. <script>
  79. var that = this
  80. import uploadImage from '@/components/ossutil/uploadFile.js';
  81. export default {
  82. data() {
  83. return {
  84. form:{},
  85. show:false,
  86. show1:false,
  87. classifyList:[],
  88. categorizationOfDishes:[],
  89. currectClassify:{},
  90. dishImageArray:[],
  91. fileList1:[],
  92. isSubmit:false
  93. }
  94. },
  95. onLoad(options) {
  96. that = this
  97. this.form.foodId=options.foodId
  98. this.form.shopNames=options.shopNames
  99. this.$request.baseRequest('admin.tourism.dishClassifyInfo', 'list', {
  100. foodId:this.form.foodId,
  101. page:1,
  102. limit:9999
  103. }, failres => {
  104. uni.showToast({
  105. icon: "none",
  106. title: failres.errmsg,
  107. duration: 3000
  108. });
  109. }).then(res => {
  110. for(var i=0;i<res.data.items.length;i++){
  111. res.data.items[i].select=false
  112. }
  113. this.classifyList = res.data.items
  114. })
  115. this.form=JSON.parse(uni.getStorageSync('groupBuying'))
  116. },
  117. onShow(){
  118. },
  119. methods: {
  120. switchStatus(item){
  121. item.status= !item.status
  122. this.$forceUpdate()
  123. console.log(item,1111111)
  124. },
  125. submit(){
  126. for(var i=0;i<this.categorizationOfDishes.length;i++){
  127. for(var q=0;q<this.categorizationOfDishes[i].list.length;q++){
  128. if(!this.categorizationOfDishes[i].list[q].dishName){
  129. uni.showToast({
  130. icon: "none",
  131. title: '请输入菜品名称!',
  132. duration: 3000
  133. });
  134. return
  135. }
  136. if(!this.categorizationOfDishes[i].list[q].dishPrice){
  137. uni.showToast({
  138. icon: "none",
  139. title: '请输入菜品单价!',
  140. duration: 3000
  141. });
  142. return
  143. }
  144. if(!this.categorizationOfDishes[i].list[q].number){
  145. uni.showToast({
  146. icon: "none",
  147. title: '请输入菜品份数!',
  148. duration: 3000
  149. });
  150. return
  151. }
  152. }
  153. }
  154. this.isSubmit = true
  155. },
  156. confirmSubmit() {
  157. uni.showLoading({
  158. title: '加载中',
  159. mask: true
  160. })
  161. this.form.foodGroupDetailInfoList=[]
  162. for(var i=0;i<this.categorizationOfDishes.length;i++){
  163. this.form.foodGroupDetailInfoList=this.form.foodGroupDetailInfoList.concat(this.categorizationOfDishes[i].list)
  164. }
  165. console.log(this.form)
  166. this.$request.baseRequest('admin.tourism.foodGroupInfo', 'add', {
  167. foodGroupInfo: JSON.stringify(this.form)
  168. }, failres => {
  169. uni.showToast({
  170. icon: "none",
  171. title: failres.errmsg,
  172. duration: 3000
  173. });
  174. uni.hideLoading()
  175. }).then(res => {
  176. uni.hideLoading()
  177. this.isSubmit = false
  178. uni.showToast({
  179. icon: "success",
  180. title: '提交成功',
  181. duration: 2000
  182. });
  183. this.categorizationOfDishes = []
  184. this.dishImageArray=[]
  185. uni.navigateBack({delta: 2})
  186. })
  187. },
  188. groupPriceInput(){
  189. if(this.form.originalPrice){
  190. this.form.discount = Number(this.form.groupPrice/this.form.originalPrice).toFixed(2)
  191. }
  192. },
  193. compute(){
  194. var prices=0
  195. for(var i=0;i<this.categorizationOfDishes.length;i++){
  196. for(var q=0;q<this.categorizationOfDishes[i].list.length;q++){
  197. if(this.categorizationOfDishes[i].list[q].dishPrice&&this.categorizationOfDishes[i].list[q].number){
  198. var price=this.categorizationOfDishes[i].list[q].dishPrice*this.categorizationOfDishes[i].list[q].number
  199. prices+=price
  200. }
  201. }
  202. }
  203. if(prices){
  204. this.form.originalPrice=prices.toFixed(2)
  205. }else{
  206. this.form.originalPrice=0
  207. }
  208. if(this.form.groupPrice){
  209. this.form.discount = Number(this.form.groupPrice/this.form.originalPrice).toFixed(2)
  210. }
  211. console.log(prices)
  212. },
  213. del(item,index){
  214. console.log(11111)
  215. for(var i=0;i<this.categorizationOfDishes.length;i++){
  216. if(this.categorizationOfDishes[i].classifyName==item.classifyName){
  217. this.categorizationOfDishes[i].list.splice(index,1)
  218. }
  219. }
  220. this.compute()
  221. },
  222. classifycancelSubmit(){
  223. var index = this.categorizationOfDishes.findIndex((item)=>{return item.classifyName == this.currectClassify.classifyName})
  224. this.categorizationOfDishes,splice(index,1)
  225. },
  226. addList(item){
  227. item.list.push({classify:item.classifyName,dishName:'',dishPrice:'',number:''})
  228. },
  229. addClassify(){
  230. this.show = true
  231. },
  232. classifySubmit() {
  233. console.log(this.form)
  234. uni.showLoading({
  235. title: '加载中',
  236. mask: true
  237. })
  238. this.$request.baseRequest('admin.tourism.dishClassifyInfo', 'add', {
  239. dishClassifyInfo: JSON.stringify({foodId:this.form.foodId,classifyName:this.classifyName})
  240. }, failres => {
  241. uni.showToast({
  242. icon: "none",
  243. title: failres.errmsg,
  244. duration: 3000
  245. });
  246. uni.hideLoading()
  247. }).then(res => {
  248. this.show = false
  249. uni.showToast({
  250. icon: "success",
  251. title: '添加分类成功',
  252. duration: 2000
  253. });
  254. })
  255. },
  256. switchClassify(item){
  257. if(item.select){
  258. var arr = this.categorizationOfDishes.filter((items)=>{return items.classifyName==item.classifyName})
  259. if(arr.length>0&&arr.list.length>0){
  260. this.currectClassify = item
  261. this.show1 = true
  262. }else{
  263. item.select=!item.select
  264. }
  265. // if()
  266. }else{
  267. item.select=!item.select
  268. this.categorizationOfDishes.push({
  269. classifyName:item.classifyName,
  270. status:false,
  271. list:[{classify:item.classifyName,dishName:'',dishPrice:'',number:'',}]})
  272. }
  273. },
  274. // 删除图片
  275. deletePic(event,status) {
  276. this[`fileList${event.name}`].splice(event.index, 1)
  277. },
  278. // 新增图片
  279. async afterRead(event,status) {
  280. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  281. let lists = [].concat(event.file)
  282. let fileListLen = this[`fileList${event.name}`].length
  283. lists.map((item) => {
  284. this[`fileList${event.name}`].push({
  285. ...item,
  286. status: 'uploading',
  287. message: '上传中'
  288. })
  289. })
  290. for (let i = 0; i < lists.length; i++) {
  291. const result = await this.uploadFilePromise(lists[i].url,status)
  292. let item = this[`fileList${event.name}`][fileListLen]
  293. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  294. status: 'success',
  295. message: '',
  296. url: result
  297. }))
  298. fileListLen++
  299. console.log(that.form, this[`fileList${event.name}`])
  300. }
  301. },
  302. uploadFilePromise(res,status) {
  303. return new Promise((resolve, reject) => {
  304. uploadImage(res, 'cardImages/',
  305. result => {
  306. that.dishImageArray.push(result)
  307. that.form.dishImage =that.dishImageArray.toString()
  308. resolve(res)
  309. }
  310. )
  311. })
  312. },
  313. }
  314. }
  315. </script>
  316. <style lang='scss' scoped>
  317. .classify_item{
  318. border:1px solid #999;
  319. padding: 5rpx 10rpx;
  320. margin: 10rpx;
  321. border-radius: 10rpx;
  322. }
  323. .classify_item.active{
  324. background:#5F7DE9;
  325. border: 1px solid #5F7DE9;
  326. color:#fff;
  327. }
  328. .icon_merchants_enterjianshao{
  329. font-size:48rpx;
  330. }
  331. </style>