foodInfomation.vue 8.1 KB

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