foodInfomation.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view class='content'>
  3. <view class='wrap'>
  4. <view v-for='item in foodInfomations'>
  5. <view>{{item.classify}}</view>
  6. <view style='margin:10rpx;' class='flex justify-space-between align-item-center' v-for='(item1,index) in item.data'>
  7. <view class='flex align-item-center'>
  8. <u-checkbox-group
  9. placement="column"
  10. @change="checkboxChange($event,item1)">
  11. <u-checkbox
  12. :customStyle="{marginBottom: '8px'}"
  13. :key="index"
  14. :name='item1.dishName'
  15. :checked='item1.checked'
  16. >
  17. </u-checkbox>
  18. </u-checkbox-group>
  19. <image v-if='!item1.edit' style='width:200rpx;height:200rpx;margin-right:20rpx;' :src="item1.dishImage" mode="aspectFill"></image>
  20. <u-upload v-else height='100' width='100' :fileList="item1[`fileList${item1.id}`]" @afterRead="afterRead($event,item1,item)" @delete="deletePic($event,item1,item)" :name="item1.id" multiple
  21. :maxCount="1">
  22. </u-upload>
  23. <view>
  24. <view v-if='!item1.edit'>{{item1.dishName}}</view>
  25. <u--input v-else inputAlign='right' v-model="item1.dishName" placeholder="输入菜品名称" border="none"></u--input>
  26. <view v-if='!item1.edit'>{{item1.dishPrice}}</view>
  27. <u--input v-else inputAlign='right' v-model="item1.dishPrice" placeholder="输入菜品单价" border="none"></u--input>
  28. </view>
  29. </view>
  30. <view>
  31. <view v-if='!item1.edit' @click='edit(item1)' class='button1 button'>编辑</view>
  32. <view v-if='item1.edit' @click='submit(item1)' class='button1 button'>确定</view>
  33. <view v-if='item1.edit' @click='item1.edit = false' class='default_button'>取消</view>
  34. <view v-if='!item1.edit' class='default_button'>置顶</view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view style='padding:10px;' class='footer flex justify-space-between align-item-center'>
  40. <u-checkbox-group
  41. placement="column"
  42. @change="checkboxAllChange">
  43. <u-checkbox
  44. :customStyle="{marginBottom: '8px'}"
  45. name='全选'
  46. label='全选'
  47. :checked="checkAll"
  48. >
  49. </u-checkbox>
  50. </u-checkbox-group>
  51. <view class='flex align-item-center'>
  52. <view @click='del' style='margin-right:10rpx;' class='caution_button'>删除</view>
  53. <view @click='add' class='button'>添加</view>
  54. </view>
  55. </view>
  56. <u-modal :show="isSubmit" content='确定删除菜品?' @confirm="$u.debounce(confirmSubmit, 500)" showCancelButton
  57. @cancel="isSubmit=false" @close="isSubmit=false" closeOnClickOverlay></u-modal>
  58. </view>
  59. </template>
  60. <script>
  61. var that
  62. import uploadImage from '@/components/ossutil/uploadFile.js';
  63. export default {
  64. data() {
  65. return {
  66. foodInfomations:[],
  67. currect:{},
  68. checkList:[],
  69. checkAll:false,
  70. dataList:[],
  71. isSubmit:false,
  72. }
  73. },
  74. onLoad() {
  75. that = this
  76. if(uni.getStorageSync('myCateringdustry')){
  77. this.currect=JSON.parse(uni.getStorageSync('myCateringdustry'))
  78. this.getList()
  79. }
  80. },
  81. onShow(){
  82. },
  83. methods: {
  84. // 删除图片
  85. deletePic(event,item1,item) {
  86. console.log(item1,item)
  87. item1[`fileList${item1.id}`].splice(event.index, 1)
  88. this.$forceUpdate()
  89. // that.indoorImageArray.splice(event.index, 1)
  90. // that.currectData.indoorImage =that.indoorImageArray.toString()
  91. },
  92. // 新增图片
  93. async afterRead(event,item1,item) {
  94. console.log(item1,item)
  95. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  96. let lists = [].concat(event.file)
  97. let fileListLen = item1[`fileList${item1.id}`].length
  98. lists.map((item2) => {
  99. item1[`fileList${item1.id}`].push({
  100. ...item2,
  101. status: 'uploading',
  102. message: '上传中'
  103. })
  104. })
  105. for (let i = 0; i < lists.length; i++) {
  106. const result = await this.uploadFilePromise(lists[i].url,item1)
  107. let item = item1[`fileList${item1.id}`][fileListLen]
  108. item1[`fileList${item1.id}`].splice(fileListLen, 1, Object.assign(item, {
  109. status: 'success',
  110. message: '',
  111. url: result
  112. }))
  113. fileListLen++
  114. this.$forceUpdate()
  115. }
  116. },
  117. uploadFilePromise(res,item) {
  118. return new Promise((resolve, reject) => {
  119. uploadImage(res, 'cardImages/',
  120. result => {
  121. item.dishImage = result
  122. resolve(res)
  123. }
  124. )
  125. })
  126. },
  127. submit(item){
  128. this.$request.baseRequest('admin.tourism.foodDishesInfo', 'update', {
  129. foodDishesInfo:JSON.stringify(item)
  130. }, failres => {
  131. uni.showToast({
  132. icon: "none",
  133. title: failres.errmsg,
  134. duration: 3000
  135. });
  136. }).then(res => {
  137. uni.showToast({
  138. icon: "success",
  139. title: '编辑菜品成功',
  140. duration: 2000
  141. });
  142. this.getList()
  143. })
  144. },
  145. del(){
  146. uni.showModal({
  147. title: '提示',
  148. content: '确定删除菜品?',
  149. success (res) {
  150. if (res.confirm) {
  151. that.$u.debounce(confirmSubmit, 500)
  152. } else if (res.cancel) {
  153. console.log('用户点击取消')
  154. }
  155. }
  156. })
  157. },
  158. confirmSubmit(){
  159. uni.showLoading({
  160. title: '加载中',
  161. mask: true
  162. })
  163. for(var i = 0;i<this.checkList.length;i++){
  164. this.$request.baseRequest('admin.tourism.foodDishesInfo', 'delete', {
  165. id:this.checkList[i].id
  166. }, failres => {
  167. uni.showToast({
  168. icon: "none",
  169. title: failres.errmsg,
  170. duration: 3000
  171. });
  172. uni.hideLoading()
  173. }).then(res => {
  174. this.isSubmit = false
  175. if(this.checkList.length==1||i==this.checkList.length-1){
  176. uni.hideLoading()
  177. uni.showToast({
  178. icon: "success",
  179. title: '删除菜品成功',
  180. duration: 2000
  181. });
  182. this.getList()
  183. }
  184. })
  185. }
  186. },
  187. checkboxAllChange(e){
  188. console.log(e)
  189. this.checkAll = !this.checkAll;
  190. for(var i = 0; i < this.foodInfomations.length; i++){
  191. for(var q = 0; q < this.foodInfomations[i].data.length; q++){
  192. this.foodInfomations[i].data[q].checked = this.checkAll
  193. }
  194. }
  195. console.log(this.foodInfomations)
  196. this.$forceUpdate()
  197. },
  198. edit(item){
  199. console.log(item)
  200. item.edit = true
  201. this.$forceUpdate()
  202. },
  203. checkboxChange(e,item1){
  204. console.log(e,item1)
  205. var checkData = this.checkList.filter((item)=>{return item.id==item1.id})
  206. item1.checked = !item1.checked
  207. if(e[0]){
  208. if(checkData.length==0){
  209. this.checkList.push(item1)
  210. }else{
  211. var checkindex = this.checkList.findIndex((item)=>{return item.id==item1.id})
  212. this.checkList[checkindex]=item1
  213. }
  214. }else{
  215. var checkindex = this.checkList.findIndex((item)=>{return item.id==item1.id})
  216. this.checkList.splice(checkindex,1)
  217. }
  218. },
  219. add(){
  220. uni.navigateTo({
  221. url:'/pageA/enter/myCateringdustry/addfood?foodId='+this.currect.id+'&shopNames='+this.currect.shopNames
  222. })
  223. },
  224. deWeightFour(arr) {
  225. var obj = {};
  226. arr = arr.reduce(function(a, b) {
  227. obj[b.classify] ? '' : obj[b.classify] = true && a.push({classify:b.classify,data:[]});
  228. return a;
  229. }, [])
  230. return arr;
  231. },
  232. getList(){
  233. this.$request.baseRequest('admin.tourism.foodDishesInfo', 'list', {
  234. foodId:this.currect.id,
  235. page:1,
  236. limit:9999
  237. }, failres => {
  238. uni.showToast({
  239. icon: "none",
  240. title: failres.errmsg,
  241. duration: 3000
  242. });
  243. }).then(res => {
  244. var arr = res.data.items
  245. var newArr = this.deWeightFour(arr);
  246. for(var i=0;i<arr.length;i++){
  247. this.dataList=res.data.items
  248. var currectList=newArr.filter((item)=>{return item.classify==arr[i].classify})
  249. arr[i].checked = false
  250. arr[i].edit = false
  251. arr[i][`fileList${arr[i].id}`]=[{url:arr[i].dishImage}]
  252. currectList[0].data.push(arr[i])
  253. }
  254. this.foodInfomations = newArr
  255. console.log(this.foodInfomations)
  256. })
  257. },
  258. }
  259. }
  260. </script>
  261. <style lang='scss' scoped>
  262. .button1{
  263. margin-bottom:20rpx;
  264. }
  265. </style>