addGroupBuyingNext.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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='merchants_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='merchants_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="mercharts_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. uni.showModal({
  155. title: '提示',
  156. content: '确认添加团购信息?',
  157. success (res) {
  158. if (res.confirm) {
  159. that.$u.debounce(confirmSubmit, 500)
  160. } else if (res.cancel) {
  161. console.log('用户点击取消')
  162. }
  163. }
  164. })
  165. },
  166. confirmSubmit() {
  167. uni.showLoading({
  168. title: '加载中',
  169. mask: true
  170. })
  171. this.form.foodGroupDetailInfoList=[]
  172. for(var i=0;i<this.categorizationOfDishes.length;i++){
  173. this.form.foodGroupDetailInfoList=this.form.foodGroupDetailInfoList.concat(this.categorizationOfDishes[i].list)
  174. }
  175. console.log(this.form)
  176. this.$request.baseRequest('admin.tourism.foodGroupInfo', 'add', {
  177. foodGroupInfo: JSON.stringify(this.form)
  178. }, failres => {
  179. uni.showToast({
  180. icon: "none",
  181. title: failres.errmsg,
  182. duration: 3000
  183. });
  184. uni.hideLoading()
  185. }).then(res => {
  186. uni.hideLoading()
  187. this.isSubmit = false
  188. uni.showToast({
  189. icon: "success",
  190. title: '提交成功',
  191. duration: 2000
  192. });
  193. this.categorizationOfDishes = []
  194. this.dishImageArray=[]
  195. uni.navigateBack({delta: 2})
  196. })
  197. },
  198. groupPriceInput(){
  199. if(this.form.originalPrice){
  200. this.form.discount = Number(this.form.groupPrice/this.form.originalPrice).toFixed(2)
  201. }
  202. },
  203. compute(){
  204. var prices=0
  205. for(var i=0;i<this.categorizationOfDishes.length;i++){
  206. for(var q=0;q<this.categorizationOfDishes[i].list.length;q++){
  207. if(this.categorizationOfDishes[i].list[q].dishPrice&&this.categorizationOfDishes[i].list[q].number){
  208. var price=this.categorizationOfDishes[i].list[q].dishPrice*this.categorizationOfDishes[i].list[q].number
  209. prices+=price
  210. }
  211. }
  212. }
  213. if(prices){
  214. this.form.originalPrice=prices.toFixed(2)
  215. }else{
  216. this.form.originalPrice=0
  217. }
  218. if(this.form.groupPrice){
  219. this.form.discount = Number(this.form.groupPrice/this.form.originalPrice).toFixed(2)
  220. }
  221. console.log(prices)
  222. },
  223. del(item,index){
  224. console.log(11111)
  225. for(var i=0;i<this.categorizationOfDishes.length;i++){
  226. if(this.categorizationOfDishes[i].classifyName==item.classifyName){
  227. this.categorizationOfDishes[i].list.splice(index,1)
  228. }
  229. }
  230. this.compute()
  231. },
  232. classifycancelSubmit(){
  233. var index = this.categorizationOfDishes.findIndex((item)=>{return item.classifyName == this.currectClassify.classifyName})
  234. this.categorizationOfDishes.splice(index,1)
  235. },
  236. addList(item){
  237. item.list.push({classify:item.classifyName,dishName:'',dishPrice:'',number:''})
  238. },
  239. addClassify(){
  240. this.show = true
  241. },
  242. classifySubmit() {
  243. console.log(this.form)
  244. uni.showLoading({
  245. title: '加载中',
  246. mask: true
  247. })
  248. this.$request.baseRequest('admin.tourism.dishClassifyInfo', 'add', {
  249. dishClassifyInfo: JSON.stringify({foodId:this.form.foodId,classifyName:this.classifyName})
  250. }, failres => {
  251. uni.showToast({
  252. icon: "none",
  253. title: failres.errmsg,
  254. duration: 3000
  255. });
  256. uni.hideLoading()
  257. }).then(res => {
  258. this.show = false
  259. uni.showToast({
  260. icon: "success",
  261. title: '添加分类成功',
  262. duration: 2000
  263. });
  264. })
  265. },
  266. switchClassify(item){
  267. if(item.select){
  268. var arr = this.categorizationOfDishes.filter((items)=>{return items.classifyName==item.classifyName})
  269. if(arr.length>0&&arr.list.length>0){
  270. this.currectClassify = item
  271. uni.showModal({
  272. title: '提示',
  273. content: '确认取消该分类?',
  274. success (res) {
  275. if (res.confirm) {
  276. that.$u.debounce(classifycancelSubmit, 500)
  277. } else if (res.cancel) {
  278. console.log('用户点击取消')
  279. }
  280. }
  281. })
  282. }else{
  283. item.select=!item.select
  284. }
  285. // if()
  286. }else{
  287. item.select=!item.select
  288. this.categorizationOfDishes.push({
  289. classifyName:item.classifyName,
  290. status:false,
  291. list:[{classify:item.classifyName,dishName:'',dishPrice:'',number:'',}]})
  292. }
  293. },
  294. // 删除图片
  295. deletePic(event,status) {
  296. this[`fileList${event.name}`].splice(event.index, 1)
  297. },
  298. // 新增图片
  299. async afterRead(event,status) {
  300. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  301. let lists = [].concat(event.file)
  302. let fileListLen = this[`fileList${event.name}`].length
  303. lists.map((item) => {
  304. this[`fileList${event.name}`].push({
  305. ...item,
  306. status: 'uploading',
  307. message: '上传中'
  308. })
  309. })
  310. for (let i = 0; i < lists.length; i++) {
  311. const result = await this.uploadFilePromise(lists[i].url,status)
  312. let item = this[`fileList${event.name}`][fileListLen]
  313. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  314. status: 'success',
  315. message: '',
  316. url: result
  317. }))
  318. fileListLen++
  319. console.log(that.form, this[`fileList${event.name}`])
  320. }
  321. },
  322. uploadFilePromise(res,status) {
  323. return new Promise((resolve, reject) => {
  324. uploadImage(res, 'cardImages/',
  325. result => {
  326. that.dishImageArray.push(result)
  327. that.form.dishImage =that.dishImageArray.toString()
  328. resolve(res)
  329. }
  330. )
  331. })
  332. },
  333. }
  334. }
  335. </script>
  336. <style lang='scss' scoped>
  337. .classify_item{
  338. border:1px solid #999;
  339. padding: 5rpx 10rpx;
  340. margin: 10rpx;
  341. border-radius: 10rpx;
  342. }
  343. .classify_item.active{
  344. background:#5F7DE9;
  345. border: 1px solid #5F7DE9;
  346. color:#fff;
  347. }
  348. .icon_merchants_enterjianshao{
  349. font-size:48rpx;
  350. }
  351. </style>