addfood.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <view class='content'>
  3. <view class='wrap'>
  4. <u--form labelPosition="left" :model="form" ref="uForm">
  5. <u-form-item labelWidth='120' labelPosition='left' label="店铺名称">
  6. <view style='text-align:right'>{{form.shopNames}}</view>
  7. </u-form-item>
  8. <u-form-item
  9. label="分类"
  10. prop="classify"
  11. borderBottom
  12. labelWidth='120'
  13. ref="item1">
  14. <view style='flex-direction:row-reverse ;' class='flex align-item-center'>
  15. <view class='add' @click='add'>新增</view>
  16. <view style='margin-right:10rpx;' @click='openClassify'>{{form.classify?form.classify:'选择分类'}}<image src="@/static/image/yjt.png" mode=""
  17. style="margin-left:10rpx;width:12rpx;height: 21rpx;"></image></view>
  18. </view>
  19. </u-form-item>
  20. <u-form-item
  21. label="菜品名称"
  22. labelWidth='120'
  23. prop="dishName"
  24. borderBottom
  25. ref="item1">
  26. <u--input inputAlign='right' v-model="form.dishName" placeholder="输入菜品名称.2-8个字" border="none"></u--input>
  27. </u-form-item>
  28. <u-form-item
  29. labelWidth='150'
  30. label="菜品单价(选填)"
  31. prop="userInfo"
  32. ref="item1">
  33. <view class='flex align-item-center'>
  34. <u--input inputAlign='right' v-model="form.dishPrice" placeholder="输入菜品单价" border="none"></u--input>元
  35. </view>
  36. </u-form-item>
  37. <view class='caution'>注:如不想用户查看价格可在店铺设置中关闭查看功能。</view>
  38. <u-form-item labelWidth='240' labelPosition='top' label="上传菜品图片(清晰、美观)">
  39. <u-upload :fileList="fileList1" @afterRead="afterRead($event)" @delete="deletePic" name="1" multiple
  40. :maxCount="1">
  41. </u-upload>
  42. </u-form-item>
  43. </u--form>
  44. <view class="footer">
  45. <button @click='submit' class="submit">提交</button>
  46. </view>
  47. </view>
  48. <u-overlay :show="show" @click="show = false">
  49. <view style='flex-wrap: wrap;' class='wrap flex'>
  50. <view v-for='item in classifyList' style='width:33.3333%;'>
  51. <view @click='selectClassify(item)' class='classifyItem' :class='form.classify==item.classifyName?"active":""'>{{item.classifyName}}</view>
  52. </view>
  53. </view>
  54. </u-overlay>
  55. <u-modal :show="isSubmit" content='确认添加菜品信息?' @confirm="$u.debounce(confirmSubmit, 500)" showCancelButton
  56. @cancel="isSubmit=false" @close="isSubmit=false" closeOnClickOverlay></u-modal>
  57. <u-modal :show="show1" title='添加分类' @confirm="$u.debounce(classifySubmit, 500)" showCancelButton
  58. @cancel="show1=false" @close="show1=false" closeOnClickOverlay>
  59. <view class="slot-content">
  60. <view>
  61. <u--input inputAlign='center' v-model="classifyName" placeholder="输入分类名称" border="none"></u--input>
  62. </view>
  63. </view>
  64. </u-modal>
  65. </view>
  66. </template>
  67. <script>
  68. var that = this
  69. import uploadImage from '@/components/ossutil/uploadFile.js';
  70. export default {
  71. data() {
  72. return {
  73. form:{
  74. foodId:'',
  75. classify:'',
  76. },
  77. classifyName:'',
  78. show:false,
  79. show1:false,
  80. isSubmit:false,
  81. dataList:[],
  82. classifyList:[],
  83. fileList1:[]
  84. }
  85. },
  86. onLoad(options) {
  87. that = this
  88. this.form.foodId=options.foodId
  89. this.form.shopNames=options.shopNames
  90. this.$request.baseRequest('admin.tourism.dishClassifyInfo', 'list', {
  91. foodId:this.form.foodId,
  92. page:1,
  93. limit:9999
  94. }, failres => {
  95. uni.showToast({
  96. icon: "none",
  97. title: failres.errmsg,
  98. duration: 3000
  99. });
  100. }).then(res => {
  101. this.classifyList = res.data.items
  102. this.form.classify = res.data.items[0].classifyName
  103. })
  104. },
  105. onShow(){
  106. },
  107. methods: {
  108. add(){
  109. this.show1 = true
  110. },
  111. openClassify(){
  112. this.show = true
  113. },
  114. selectClassify(item){
  115. console.log(item)
  116. this.form.classify = item.classifyName
  117. },
  118. submit(){
  119. if(this.form.dishName.length<2||this.form.dishName.length>8){
  120. uni.showToast({
  121. icon: "none",
  122. title: '菜品名称2-8个字!',
  123. duration: 3000
  124. });
  125. return
  126. }
  127. if(this.form.dishPrice<=0){
  128. uni.showToast({
  129. icon: "none",
  130. title: '菜品单价输入错误!',
  131. duration: 3000
  132. });
  133. return
  134. }
  135. if(!this.form.dishImage){
  136. uni.showToast({
  137. icon: "none",
  138. title: '菜品图片不能为空!',
  139. duration: 3000
  140. });
  141. return
  142. }
  143. this.isSubmit = true
  144. },
  145. classifySubmit() {
  146. console.log(this.form)
  147. uni.showLoading({
  148. title: '加载中',
  149. mask: true
  150. })
  151. this.$request.baseRequest('admin.tourism.dishClassifyInfo', 'add', {
  152. dishClassifyInfo: JSON.stringify({foodId:this.form.foodId,classifyName:this.classifyName})
  153. }, failres => {
  154. uni.showToast({
  155. icon: "none",
  156. title: failres.errmsg,
  157. duration: 3000
  158. });
  159. uni.hideLoading()
  160. }).then(res => {
  161. this.show1 = false
  162. uni.showToast({
  163. icon: "success",
  164. title: '添加分类成功',
  165. duration: 2000
  166. });
  167. })
  168. },
  169. confirmSubmit() {
  170. console.log(this.form)
  171. uni.showLoading({
  172. title: '加载中',
  173. mask: true
  174. })
  175. this.$request.baseRequest('admin.tourism.foodDishesInfo', 'add', {
  176. foodDishesInfo: JSON.stringify(this.form)
  177. }, failres => {
  178. uni.showToast({
  179. icon: "none",
  180. title: failres.errmsg,
  181. duration: 3000
  182. });
  183. uni.hideLoading()
  184. }).then(res => {
  185. this.isSubmit = false
  186. uni.showToast({
  187. icon: "success",
  188. title: '提交成功',
  189. duration: 2000
  190. });
  191. uni.navigateBack()
  192. })
  193. },
  194. // 删除图片
  195. deletePic(event,status) {
  196. this[`fileList${event.name}`].splice(event.index, 1)
  197. },
  198. // 新增图片
  199. async afterRead(event,status) {
  200. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  201. let lists = [].concat(event.file)
  202. let fileListLen = this[`fileList${event.name}`].length
  203. lists.map((item) => {
  204. this[`fileList${event.name}`].push({
  205. ...item,
  206. status: 'uploading',
  207. message: '上传中'
  208. })
  209. })
  210. for (let i = 0; i < lists.length; i++) {
  211. const result = await this.uploadFilePromise(lists[i].url,status)
  212. let item = this[`fileList${event.name}`][fileListLen]
  213. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  214. status: 'success',
  215. message: '',
  216. url: result
  217. }))
  218. fileListLen++
  219. console.log(that.form, this[`fileList${event.name}`])
  220. }
  221. },
  222. uploadFilePromise(res,status) {
  223. return new Promise((resolve, reject) => {
  224. uploadImage(res, 'cardImages/',
  225. result => {
  226. that.form.dishImage = result
  227. resolve(res)
  228. }
  229. )
  230. })
  231. },
  232. }
  233. }
  234. </script>
  235. <style lang='scss' scoped>
  236. .add,.active{
  237. background: #5F7DE9;
  238. color: #fff;
  239. padding: 10rpx 20rpx;
  240. border-radius: 10rpx;
  241. font-size: 26rpx;
  242. }
  243. .classifyItem{
  244. padding: 10rpx 20rpx;
  245. font-size: 26rpx;
  246. text-align: center;
  247. margin: 0 30px;
  248. }
  249. </style>