popupContainer.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view class="select_popup_container">
  3. <view class="popup_title">
  4. <view class="popup_title_msn">{{ selectProductTitle }}</view>
  5. <view class="close" @click="close"><span class="iconfont">&#xe761;</span></view>
  6. </view>
  7. <view v-if="selectProductItem.showTap">
  8. <scroll-view scroll-x="true" class="popup_tap">
  9. <view class="popup_tap_content">
  10. <view
  11. class="popup_tap_item"
  12. v-for="(item, index) in selectProductItem.singleCaseChild"
  13. :key="index"
  14. :class="{ selectTapEd: selectProductId == item.id }"
  15. @click="selectTapId(item)"
  16. >
  17. <view>{{ item.label }}</view>
  18. </view>
  19. </view>
  20. </scroll-view>
  21. </view>
  22. <scroll-view scroll-y="true" class="popup_sroll">
  23. <view class="popup_container" v-if="selectProductItem.showTap && selectSingleCase.children">
  24. <view
  25. class="popup_container_item"
  26. v-for="(item, index) in selectSingleCase.children"
  27. :key="index"
  28. @click="handleSelectProductItem(item)"
  29. :class="{ selectSingleCaseChild: selectProductItem.multiple ? multiple.indexOf(item.id) != -1 : selectSingleCaseChild == item.id }"
  30. >
  31. <view>{{ item.label }}</view>
  32. </view>
  33. </view>
  34. <view class="popup_container" v-if="!selectProductItem.showTap">
  35. <view
  36. class="popup_container_item"
  37. v-for="(item, index) in selectProductItem.singleCaseChild"
  38. :key="index"
  39. @click="handleSelectProductItem(item)"
  40. :class="{ selectSingleCaseChild: selectSingleCaseChild == item.brand_id || item.id }"
  41. >
  42. <view>{{ item.label }}</view>
  43. </view>
  44. </view>
  45. </scroll-view>
  46. </view>
  47. </template>
  48. <script>
  49. // +----------------------------------------------------------------------
  50. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  51. // +----------------------------------------------------------------------
  52. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  53. // +----------------------------------------------------------------------
  54. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  55. // +----------------------------------------------------------------------
  56. // | Author: CRMEB Team <admin@crmeb.com>
  57. // +----------------------------------------------------------------------
  58. export default {
  59. props: {
  60. selectProductTitle: {
  61. type: String,
  62. default: ''
  63. },
  64. selectProductItem: {
  65. type: Object | Array,
  66. default() {
  67. return [] || {};
  68. }
  69. },
  70. form: {
  71. type: Object,
  72. default:() => {
  73. return {}
  74. }
  75. }
  76. },
  77. data() {
  78. return {
  79. selectProductId: '', // 标签tap页ID
  80. selectSingleCase: [], // 选中标签下的子项
  81. selectSingleCaseChild: '', // 选项id
  82. multiple: [] // 多选时,使用该字段
  83. };
  84. },
  85. created() {
  86. this.initData();
  87. },
  88. watch: {
  89. selectProductId: {
  90. handler(val) {
  91. this.selectSingleCase = this.selectProductItem.singleCaseChild.find(item => item.id == val);
  92. },
  93. deep: true
  94. }
  95. },
  96. methods: {
  97. initData() {
  98. if(this.form[this.selectProductItem.model]) {
  99. this[this.selectProductItem.multiple ? 'multiple' : 'selectSingleCaseChild'] = this.form[this.selectProductItem.model];
  100. }
  101. if (this.selectProductItem.showTap && this.selectProductItem.singleCaseChild.length) {
  102. this.selectProductId = this.selectProductItem.singleCaseChild[0].id;
  103. this.selectSingleCase = this.selectProductItem.singleCaseChild.find(item => item.id == this.selectProductId);
  104. }
  105. },
  106. // 选择标签ID
  107. selectTapId(item) {
  108. this.selectProductId = item.id;
  109. },
  110. // 选择选项id
  111. handleSelectProductItem(item) {
  112. if (this.selectProductItem.multiple) {
  113. if (this.multiple.indexOf(item.id) != -1) {
  114. this.multiple.splice(this.multiple.indexOf(item.id), 1);
  115. } else {
  116. this.multiple.push(item.brand_id || item.id);
  117. }
  118. this.multiple = this.unique(this.multiple);
  119. this.$emit('multipleData', this.multiple, this.selectProductItem.model);
  120. return;
  121. }
  122. this.selectSingleCaseChild = item.brand_id || item.id;
  123. this.$emit('singleChoiceData', this.selectSingleCaseChild, this.selectProductItem.model);
  124. },
  125. unique(arr) {
  126. var obj = {};
  127. return arr.filter(ele => {
  128. if (!obj[ele]) {
  129. obj[ele] = true;
  130. return true;
  131. }
  132. });
  133. },
  134. //关闭按钮
  135. close() {
  136. this.$emit('close');
  137. }
  138. }
  139. };
  140. </script>
  141. <style lang="scss" scoped>
  142. .select_popup_container {
  143. background: #fff;
  144. border-radius: 16rpx 16rpx 0 0;
  145. }
  146. .popup_title {
  147. display: flex;
  148. justify-content: flex-end;
  149. padding: 36rpx 30rpx;
  150. position: relative;
  151. &_msn {
  152. position: absolute;
  153. top: 50%;
  154. left: 50%;
  155. transform: translate(-50%, -50%);
  156. color: #282828;
  157. font-size: 32rpx;
  158. font-weight: bold;
  159. }
  160. .close {
  161. position: relative;
  162. z-index: 10;
  163. font-size: 28rpx;
  164. color: #8a8a8a;
  165. }
  166. }
  167. .popup_tap {
  168. display: flex;
  169. padding: 0 30rpx;
  170. color: #333333;
  171. font-size: 28rpx;
  172. border-bottom: 1px solid #eeeeee;
  173. .popup_tap_content {
  174. display: flex;
  175. }
  176. &_item {
  177. margin-right: 60rpx;
  178. padding-bottom: 21rpx;
  179. white-space: nowrap;
  180. }
  181. .selectTapEd {
  182. color: #e93323;
  183. border-bottom: 3rpx solid #e93323;
  184. }
  185. }
  186. .popup_sroll {
  187. max-height: 742rpx;
  188. min-height: 300rpx;
  189. }
  190. .popup_container {
  191. &_item {
  192. padding: 40rpx 0 30rpx 40rpx;
  193. }
  194. .selectSingleCaseChild {
  195. color: #e93323;
  196. }
  197. }
  198. </style>