otherSet.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view class="other" style="background: #F7F8FC;">
  3. <cu-custom bgColor="bg-fff" :isBack="true">
  4. <block slot="content"> 其他</block>
  5. </cu-custom>
  6. <view class="center">
  7. <view class=" cu-form-group" style="margin: 0;">
  8. <view class="content ">
  9. <text class="text-bold">其他 </text>
  10. <i class="text-bg " style="width: 100%;"></i>
  11. </view>
  12. </view>
  13. <view>
  14. <view class="" style="display: flex;align-items: center;height: 55rpx;margin-bottom: 16rpx;">
  15. <text style="width: 104rpx;font-size: 26rpx;">选择分类</text>
  16. <view class="" style="flex: 1; text-align: end;" @click="isShow = true">
  17. <span style="color: #333333;font-size: 24rpx;margin-right: 15rpx;" v-if="name">{{name}}</span>
  18. <span style="color: #999999;font-size: 24rpx;margin-right: 15rpx;" v-else>去选择</span>
  19. </view>
  20. <u-icon name="arrow-right" style="margin-left: 17rpx;color: #C7C6CA"></u-icon>
  21. </view>
  22. <view class="" v-for="(item,index) in tags" :key="item.id" style="display: flex;align-items: center;height: 55rpx;margin-bottom: 20rpx;" v-if="tags.length>0">
  23. <text style="width: 104rpx;font-size: 26rpx;">{{item.attribute}}</text>
  24. <view class="" style="flex: 1; text-align: end;" @click="open(index)">
  25. <span v-if="activeTag.length>0">{{showTags}}</span>
  26. <span style="color: #999999;font-size: 24rpx;margin-right: 15rpx;" v-if="activeTag.length==0">去选择</span>
  27. </view>
  28. <u-icon name="arrow-right" style="margin-left: 17rpx;color: #C7C6CA"></u-icon>
  29. </view>
  30. </view>
  31. </view>
  32. <selectService v-if="isShow" @transmitType="confirmLocality" @cutPopup="isShow = false" />
  33. <uni-popup ref="popup" type="bottom">
  34. <view class="popup-box">
  35. <view class="popup-title">
  36. <text>请选择门店支持的用餐场景</text>
  37. <image src="/static/store/detele.png" mode="aspectFit" @click=" $refs.popup.close()"></image>
  38. </view>
  39. <view style="padding-bottom:20upx;border-bottom: 1px solid #EEEEEE;">
  40. <!-- <text v-for="(tag, index) in tags" :key="index" class="tag-type"
  41. :class="{ 'selected-background': isSelected(tag) }" :style="tag == '空调' ? 'margin-right:0' : ''"
  42. @click="toggleSelection(tag)">
  43. {{ tag }}
  44. </text> -->
  45. <view class="" >
  46. <view class="item-box" v-if="tags.length>0">
  47. <view class="item" :class="row.select?'active':''" v-for="(row,index) in tags[levelIndex].attributeValueList"
  48. :key="index" @click="selectItem(row)">
  49. {{row.value}}
  50. <image src="/static/index/select.png" mode="" v-if="row.select"></image>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <view class=" flex sub-bottom justify-between" style="padding:16rpx 24rpx;">
  56. <button style="width:100%;background: linear-gradient( 90deg, #77B6FF 0%, #449AFF 100%);"
  57. class="cu-btn bg-blue round shadow" @click="submit">确定</button>
  58. </view>
  59. </view>
  60. </uni-popup>
  61. </view>
  62. </template>
  63. <script>
  64. import selectService from '../../components/selectService.vue'
  65. export default {
  66. components: {
  67. selectService
  68. },
  69. data() {
  70. return {
  71. isShow: false,
  72. form: {},
  73. id: '',
  74. name: '',
  75. selectTags: [],
  76. isTag: false,
  77. tags: [],
  78. selectedIndices: [], // 用于存储被选中的标签索引
  79. activeTag: [],
  80. showTags: '',
  81. levelIndex:0
  82. }
  83. },
  84. methods: {
  85. open(index){
  86. this.$refs.popup.open(),
  87. this.levelIndex = index
  88. },
  89. //选择类型
  90. confirmLocality(data) {
  91. this.id = data.id
  92. this.name = data.name
  93. this.isShow = false
  94. let merchantId = uni.getStorageSync('login_user_info').merchantId
  95. this.$http.get("/localOther/localProductClassValue/queryByClassId?id=" + this.id + '&merchantId=' + merchantId)
  96. .then(res => {
  97. console.log(res)
  98. if (res.data.success) {
  99. this.tags = res.data.result
  100. } else {}
  101. })
  102. },
  103. selectItem(row) {
  104. row.select = !row.select
  105. },
  106. submit() {
  107. // 提前获取 merchantId
  108. const merchantId = uni.getStorageSync('login_user_info').merchantId;
  109. // 处理选中的标签
  110. let selectedTags = this.tags.flatMap(item => {
  111. return item.attributeValueList
  112. .filter(row => row.select)
  113. .map(row => ({
  114. tag: row.value
  115. }));
  116. });
  117. this.activeTag.push(...selectedTags);
  118. this.showTags = this.activeTag.slice(0, 3).map(tag => tag.tag).join(',');
  119. const lastItem = this.tags[this.tags.length - 1];
  120. console.log(merchantId)
  121. let data = {
  122. attribute: lastItem?.attribute,
  123. attributeValue: this.activeTag.map(tag => tag.tag).join(','),
  124. classId: lastItem?.classId,
  125. merchantId: merchantId // 确保merchantId包含在数据中
  126. };
  127. this.$http.post('/localOther/localMerchantOther/add', data)
  128. .then(res => {
  129. console.log(res);
  130. if(res.data.code == 200){
  131. this.$refs.popup.close()
  132. // uni.navigateTo({
  133. // url:'/pages/store/settings'
  134. // })
  135. }
  136. })
  137. .catch(err => {
  138. console.error(err);
  139. });
  140. },
  141. // 检查一个标签是否被选中
  142. isSelected(tag) {
  143. return this.selectedIndices.includes(tag);
  144. },
  145. // 切换标签的选中状态
  146. toggleSelection(tag) {
  147. const indexIndex = this.selectedIndices.indexOf(tag);
  148. if (indexIndex > -1) {
  149. // 如果标签已经被选中,则移除它
  150. this.selectedIndices.splice(indexIndex, 1);
  151. } else {
  152. // 如果标签没有被选中,则添加它
  153. this.selectedIndices.push(tag);
  154. }
  155. },
  156. },
  157. onLoad(options) {
  158. // let dat = JSON.parse(options.params)
  159. // console.log(dat)
  160. }
  161. }
  162. </script>
  163. <style scoped lang="scss">
  164. .other {
  165. width: 100vw;
  166. height: 100vh;
  167. }
  168. .center {
  169. border-top: 1px solid #f0f3f5;
  170. padding: 0px 40rpx;
  171. background-color: #fff;
  172. }
  173. .popup-box {
  174. background: #FFFFFF;
  175. padding: 0 27upx;
  176. border-radius: 20px 20px 0px 0px;
  177. .popup-title {
  178. padding: 22upx 0;
  179. position: relative;
  180. text-align: center;
  181. font-weight: 500;
  182. font-size: 34upx;
  183. color: #333333;
  184. border-bottom: 1px solid #EEEEEE;
  185. image {
  186. position: absolute;
  187. right: 0;
  188. width: 42upx;
  189. height: 42upx;
  190. }
  191. }
  192. }
  193. .item-box {
  194. display: flex;
  195. justify-content: space-between;
  196. flex-wrap: wrap;
  197. padding-top: 24rpx;
  198. .item {
  199. width: 144rpx;
  200. height: 52rpx;
  201. border-radius: 4rpx;
  202. border: 1px solid #C2C2C2;
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. font-size: 24rpx;
  207. margin-bottom: 24rpx;
  208. position: relative;
  209. image {
  210. width: 20rpx;
  211. height: 20rpx;
  212. position: absolute;
  213. top: 0;
  214. right: 0;
  215. }
  216. }
  217. .active {
  218. background: rgba(68, 154, 255, 0.1);
  219. border: 1px solid #449AFF;
  220. color: #2983EC;
  221. }
  222. }
  223. </style>