addfood.vue 7.5 KB

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