selectForm.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <view class="container_input">
  3. <view class="container_input_item" v-for="(item, index) in platformClassification" :key="index" @click="selectItem(item)" v-if="!item.DoNotShow">
  4. <view class="select_and_input" v-if="item.type == 'select' || item.type == 'input' || item.type == 'switch'">
  5. <view class="container_input_item_label">
  6. <text class="select_check" :class="{ select: item.select }" @click.stop="selectRadio(item)" v-if="Object.keys(item).indexOf('select') != -1">
  7. <text v-if="item.select" class="iconfont">&#xe646;</text>
  8. </text>
  9. <text class="select_label line1">{{ item.label }}</text>
  10. </view>
  11. <view class="container_input_item_value greyColor" v-if="item.type == 'select'">
  12. <text v-if="item.value" class="text">{{ item.value }}</text>
  13. <text v-else>{{ item.holder }}</text>
  14. <text class="iconfont">&#xe6bd;</text>
  15. </view>
  16. <view class="container_input_item_value" v-if="item.type == 'input'">
  17. <input v-model="formData[item.model]" type="text" value="" :placeholder="item.holder" placeholder-class="inputPlaceHolder" />
  18. </view>
  19. <view class="container_input_item_value" v-if="item.type == 'switch'">
  20. <switch :checked="formData[item.model] == 1" color="#E93323" style="transform:scale(0.8)" @change="switchChange($event, item)" />
  21. </view>
  22. </view>
  23. <view class="radio" v-if="item.type == 'radio' || item.type == 'check'">
  24. <view class="container_input_item_label">{{ item.label }}</view>
  25. <view class="container_input_item_value flex_start" v-if="item.type == 'radio'">
  26. <radio-group class="select_group" @change="radioChange($event, item)">
  27. <label class="container_input_item_value_select" v-for="(val, i) in item.radioList" :key="val.value">
  28. <view>
  29. <radio :value="val.value" :checked="val.value == item.inforValue" />
  30. </view>
  31. <view>{{ val.name }}</view>
  32. </label>
  33. </radio-group>
  34. </view>
  35. <view class="container_input_item_value flex_start" v-if="item.type == 'check'">
  36. <checkbox-group class="select_group" @change="checkChange($event, item)">
  37. <label class="container_input_item_value_select" v-for="(val, i) in item.checkList" :key="val.value">
  38. <view>
  39. <checkbox class="chenk_list" :value="val.value" :checked="val.value == item.inforValue" />
  40. </view>
  41. <view>{{ val.name }}</view>
  42. </label>
  43. </checkbox-group>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. /*
  51. item参数
  52. id:
  53. type: select
  54. label: '标题'
  55. jumpLogic: 是否自定义跳转逻辑
  56. select 有此key值时,可进行选择逻辑
  57. */
  58. export default {
  59. // model: {
  60. // prop: 'value',
  61. // event: 'input'
  62. // },
  63. props: {
  64. platformClassification: {
  65. type: Array,
  66. default() {
  67. return [];
  68. }
  69. },
  70. form: {
  71. type: Object,
  72. default: () => {
  73. return {};
  74. }
  75. }
  76. },
  77. data() {
  78. return {
  79. value: '',
  80. formData: {}
  81. };
  82. },
  83. watch: {
  84. formData: {
  85. handler(val) {
  86. this.$emit('input',val)
  87. },
  88. deep: true
  89. },
  90. form: {
  91. handler(val) {
  92. this.formData = val
  93. },
  94. deep: true
  95. }
  96. },
  97. created() {
  98. this.platformClassification.forEach(item => {
  99. if(item.inforValue) {
  100. this.$emit('formInitData', item.inforValue, item.model);
  101. }
  102. });
  103. },
  104. methods: {
  105. selectItem(item) {
  106. if(item.jumpLogic) {
  107. // 执行跳转新界面逻辑暴露的方法
  108. this.$emit('handleJumpLogic', item);
  109. return;
  110. }
  111. this.$emit('handleSelectItem', item);
  112. },
  113. radioChange(e, item) {
  114. this.$emit('radioChange', e.detail.value, item);
  115. },
  116. // switch组件切换
  117. switchChange(e, item) {
  118. this.$emit('switchChange', e.detail.value, item);
  119. },
  120. // 可选择条框模式
  121. // 选择事件
  122. selectRadio(item) {
  123. item.select = !item.select;
  124. },
  125. // 多选按钮
  126. checkChange(e, item) {
  127. this.$emit('checkChange', e.detail.value, item);
  128. }
  129. }
  130. };
  131. </script>
  132. <style lang="scss" scoped>
  133. .container_input {
  134. background: #fff;
  135. padding: 0 20rpx;
  136. width: 710rpx;
  137. margin: auto;
  138. margin-top: 31rpx;
  139. border-radius: 10rpx;
  140. &_item {
  141. .select_and_input {
  142. height: 106rpx;
  143. display: flex;
  144. align-items: center;
  145. justify-content: space-between;
  146. .greyColor {
  147. color: #bbbbbb;
  148. }
  149. }
  150. .radio {
  151. padding: 30rpx 0;
  152. }
  153. &_label {
  154. padding-left: 10rpx;
  155. color: #333333;
  156. font-size: 30rpx;
  157. display: flex;
  158. align-items: center;
  159. .select_label{
  160. max-width: 520rpx;
  161. }
  162. .select_check {
  163. display: flex;
  164. align-items: center;
  165. justify-content: center;
  166. width: 40rpx;
  167. height: 40rpx;
  168. border: 1px solid #cccccc;
  169. border-radius: 50%;
  170. margin-right: 20rpx;
  171. .iconfont {
  172. font-size: 24rpx;
  173. }
  174. }
  175. .select {
  176. background: #e93323;
  177. border: none;
  178. .iconfont {
  179. color: #fff;
  180. }
  181. }
  182. }
  183. &_value {
  184. padding-right: 10rpx;
  185. flex: 1;
  186. display: flex;
  187. align-items: center;
  188. justify-content: flex-end;
  189. > span:nth-child(1) {
  190. display: inline-block;
  191. margin-right: 15rpx;
  192. }
  193. .text {
  194. color: #000;
  195. display: inline-block;
  196. max-width: 400rpx;
  197. overflow: hidden;
  198. white-space: nowrap;
  199. text-overflow: ellipsis;
  200. }
  201. input {
  202. text-align: right;
  203. }
  204. .select_group {
  205. display: flex;
  206. }
  207. &_select {
  208. display: flex;
  209. margin-right: 110rpx;
  210. }
  211. }
  212. .flex_start {
  213. padding: 0 10rpx;
  214. margin-top: 40rpx;
  215. justify-content: flex-start;
  216. }
  217. }
  218. > view:not(:last-child) {
  219. border-bottom: 1px solid #eeeeee;
  220. }
  221. }
  222. .inputPlaceHolder {
  223. color: #bbbbbb;
  224. }
  225. </style>