form.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <view>
  3. <cu-custom bgColor="bg-gradual-pink" :isBack="true">
  4. <block slot="backText">返回</block>
  5. <block slot="content">表单</block>
  6. </cu-custom>
  7. <form>
  8. <view class="cu-form-group margin-top">
  9. <view class="title">邮件</view>
  10. <input placeholder="两字短标题" name="input"></input>
  11. </view>
  12. <view class="cu-form-group">
  13. <view class="title">输入框</view>
  14. <input placeholder="三字标题" name="input"></input>
  15. </view>
  16. <view class="cu-form-group">
  17. <view class="title">收货地址</view>
  18. <input placeholder="统一标题的宽度" name="input"></input>
  19. </view>
  20. <view class="cu-form-group">
  21. <view class="title">收货地址</view>
  22. <input placeholder="输入框带个图标" name="input"></input>
  23. <text class='cuIcon-locationfill text-orange'></text>
  24. </view>
  25. <view class="cu-form-group">
  26. <view class="title">验证码</view>
  27. <input placeholder="输入框带个按钮" name="input"></input>
  28. <button class='cu-btn bg-green shadow'>验证码</button>
  29. </view>
  30. <view class="cu-form-group">
  31. <view class="title">手机号码</view>
  32. <input placeholder="输入框带标签" name="input"></input>
  33. <view class="cu-capsule radius">
  34. <view class='cu-tag bg-blue '>
  35. +86
  36. </view>
  37. <view class="cu-tag line-blue">
  38. 中国大陆
  39. </view>
  40. </view>
  41. </view>
  42. <view class="cu-form-group margin-top">
  43. <view class="title">普通选择</view>
  44. <picker @change="PickerChange" :value="index" :range="picker">
  45. <view class="picker">
  46. {{index>-1?picker[index]:'禁止换行,超出容器部分会以 ... 方式截断'}}
  47. </view>
  48. </picker>
  49. </view>
  50. <!-- #ifndef MP-ALIPAY -->
  51. <view class="cu-form-group">
  52. <view class="title">多列选择</view>
  53. <picker mode="multiSelector" @change="MultiChange" @columnchange="MultiColumnChange" :value="multiIndex" :range="multiArray">
  54. <view class="picker">
  55. {{multiArray[0][multiIndex[0]]}},{{multiArray[1][multiIndex[1]]}},{{multiArray[2][multiIndex[2]]}}
  56. </view>
  57. </picker>
  58. </view>
  59. <!-- #endif -->
  60. <view class="cu-form-group">
  61. <view class="title">时间选择</view>
  62. <picker mode="time" :value="time" start="09:01" end="21:01" @change="TimeChange">
  63. <view class="picker">
  64. {{time}}
  65. </view>
  66. </picker>
  67. </view>
  68. <view class="cu-form-group">
  69. <view class="title">日期选择</view>
  70. <picker mode="date" :value="date" start="2015-09-01" end="2020-09-01" @change="DateChange">
  71. <view class="picker">
  72. {{date}}
  73. </view>
  74. </picker>
  75. </view>
  76. <!-- #ifndef H5 || APP-PLUS || MP-ALIPAY -->
  77. <view class="cu-form-group">
  78. <view class="title">地址选择</view>
  79. <picker mode="region" @change="RegionChange" :value="region">
  80. <view class="picker">
  81. {{region[0]}},{{region[1]}},{{region[2]}}
  82. </view>
  83. </picker>
  84. </view>
  85. <!-- #endif -->
  86. <view class="cu-form-group margin-top">
  87. <view class="title">开关选择</view>
  88. <switch @change="SwitchA" :class="switchA?'checked':''" :checked="switchA?true:false"></switch>
  89. </view>
  90. <view class="cu-form-group">
  91. <view class="title">定义颜色</view>
  92. <!-- #ifdef MP-ALIPAY -->
  93. <switch class='red' @change="SwitchB" :class="switchB?'checked':''" :checked="switchB?true:false" color="#e54d42"></switch>
  94. <!-- #endif -->
  95. <!-- #ifndef MP-ALIPAY -->
  96. <switch class='red' @change="SwitchB" :class="switchB?'checked':''" :checked="switchB?true:false"></switch>
  97. <!-- #endif -->
  98. </view>
  99. <view class="cu-form-group">
  100. <view class="title">定义图标</view>
  101. <switch class='switch-sex' @change="SwitchC" :class="switchC?'checked':''" :checked="switchC?true:false"></switch>
  102. </view>
  103. <!-- #ifndef MP-ALIPAY -->
  104. <view class="cu-form-group">
  105. <view class="title">方形开关</view>
  106. <switch class='orange radius' @change="SwitchD" :class="switchD?'checked':''" :checked="switchD?true:false"></switch>
  107. </view>
  108. <!-- #endif -->
  109. <radio-group class="block" @change="RadioChange">
  110. <view class="cu-form-group margin-top">
  111. <view class="title">单选操作(radio)</view>
  112. <radio :class="radio=='A'?'checked':''" :checked="radio=='A'?true:false" value="A"></radio>
  113. </view>
  114. <!-- #ifndef MP-ALIPAY -->
  115. <view class="cu-form-group">
  116. <view class="title">定义样式</view>
  117. <radio class='radio' :class="radio=='B'?'checked':''" :checked="radio=='B'?true:false" value="B"></radio>
  118. </view>
  119. <view class="cu-form-group">
  120. <view class="title">定义颜色</view>
  121. <view>
  122. <radio class='blue radio' :class="radio=='C'?'checked':''" :checked="radio=='C'?true:false" value="C"></radio>
  123. <radio class='red margin-left-sm' :class="radio=='D'?'checked':''" :checked="radio=='D'?true:false" value="D"></radio>
  124. </view>
  125. </view>
  126. <!-- #endif -->
  127. </radio-group>
  128. <checkbox-group class="block" @change="CheckboxChange">
  129. <view class="cu-form-group margin-top">
  130. <view class="title">复选选操作(checkbox)</view>
  131. <checkbox :class="checkbox[0].checked?'checked':''" :checked="checkbox[0].checked?true:false" value="A"></checkbox>
  132. </view>
  133. <!-- #ifndef MP-ALIPAY -->
  134. <view class="cu-form-group">
  135. <view class="title">定义形状</view>
  136. <checkbox class='round' :class="checkbox[1].checked?'checked':''" :checked="checkbox[1].checked?true:false" value="B"></checkbox>
  137. </view>
  138. <view class="cu-form-group">
  139. <view class="title">定义颜色</view>
  140. <checkbox class='round blue' :class="checkbox[2].checked?'checked':''" :checked="checkbox[2].checked?true:false"
  141. value="C"></checkbox>
  142. </view>
  143. <!-- #endif -->
  144. </checkbox-group>
  145. <view class="cu-bar bg-white margin-top">
  146. <view class="action">
  147. 图片上传
  148. </view>
  149. <view class="action">
  150. {{imgList.length}}/4
  151. </view>
  152. </view>
  153. <view class="cu-form-group">
  154. <view class="grid col-4 grid-square flex-sub">
  155. <view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage" :data-url="imgList[index]">
  156. <image :src="imgList[index]" mode="aspectFill"></image>
  157. <view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
  158. <text class='cuIcon-close'></text>
  159. </view>
  160. </view>
  161. <view class="solids" @tap="ChooseImage" v-if="imgList.length<4">
  162. <text class='cuIcon-cameraadd'></text>
  163. </view>
  164. </view>
  165. </view>
  166. <view class="cu-form-group margin-top">
  167. <view class="title">头像</view>
  168. <view class="cu-avatar radius bg-gray"></view>
  169. </view>
  170. <!-- !!!!! placeholder 在ios表现有偏移 建议使用 第一种样式 -->
  171. <view class="cu-form-group margin-top">
  172. <textarea maxlength="-1" :disabled="modalName!=null" @input="textareaAInput" placeholder="多行文本输入框"></textarea>
  173. </view>
  174. <view class="cu-form-group align-start">
  175. <view class="title">文本框</view>
  176. <textarea maxlength="-1" :disabled="modalName!=null" @input="textareaBInput" placeholder="多行文本输入框"></textarea>
  177. </view>
  178. </form>
  179. </view>
  180. </template>
  181. <script>
  182. export default {
  183. data() {
  184. return {
  185. index: -1,
  186. picker: ['喵喵喵', '汪汪汪', '哼唧哼唧'],
  187. multiArray: [
  188. ['无脊柱动物', '脊柱动物'],
  189. ['扁性动物', '线形动物', '环节动物', '软体动物', '节肢动物'],
  190. ['猪肉绦虫', '吸血虫']
  191. ],
  192. objectMultiArray: [
  193. [{
  194. id: 0,
  195. name: '无脊柱动物'
  196. },
  197. {
  198. id: 1,
  199. name: '脊柱动物'
  200. }
  201. ],
  202. [{
  203. id: 0,
  204. name: '扁性动物'
  205. },
  206. {
  207. id: 1,
  208. name: '线形动物'
  209. },
  210. {
  211. id: 2,
  212. name: '环节动物'
  213. },
  214. {
  215. id: 3,
  216. name: '软体动物'
  217. },
  218. {
  219. id: 3,
  220. name: '节肢动物'
  221. }
  222. ],
  223. [{
  224. id: 0,
  225. name: '猪肉绦虫'
  226. },
  227. {
  228. id: 1,
  229. name: '吸血虫'
  230. }
  231. ]
  232. ],
  233. multiIndex: [0, 0, 0],
  234. time: '12:01',
  235. date: '2018-12-25',
  236. region: ['广东省', '广州市', '海珠区'],
  237. switchA: false,
  238. switchB: true,
  239. switchC: false,
  240. switchD: false,
  241. radio: 'A',
  242. checkbox: [{
  243. value: 'A',
  244. checked: true
  245. }, {
  246. value: 'B',
  247. checked: true
  248. }, {
  249. value: 'C',
  250. checked: false
  251. }],
  252. imgList: [],
  253. modalName: null,
  254. textareaAValue: '',
  255. textareaBValue: ''
  256. };
  257. },
  258. methods: {
  259. PickerChange(e) {
  260. this.index = e.detail.value
  261. },
  262. MultiChange(e) {
  263. this.multiIndex = e.detail.value
  264. },
  265. MultiColumnChange(e) {
  266. let data = {
  267. multiArray: this.multiArray,
  268. multiIndex: this.multiIndex
  269. };
  270. data.multiIndex[e.detail.column] = e.detail.value;
  271. switch (e.detail.column) {
  272. case 0:
  273. switch (data.multiIndex[0]) {
  274. case 0:
  275. data.multiArray[1] = ['扁性动物', '线形动物', '环节动物', '软体动物', '节肢动物'];
  276. data.multiArray[2] = ['猪肉绦虫', '吸血虫'];
  277. break;
  278. case 1:
  279. data.multiArray[1] = ['鱼', '两栖动物', '爬行动物'];
  280. data.multiArray[2] = ['鲫鱼', '带鱼'];
  281. break;
  282. }
  283. data.multiIndex[1] = 0;
  284. data.multiIndex[2] = 0;
  285. break;
  286. case 1:
  287. switch (data.multiIndex[0]) {
  288. case 0:
  289. switch (data.multiIndex[1]) {
  290. case 0:
  291. data.multiArray[2] = ['猪肉绦虫', '吸血虫'];
  292. break;
  293. case 1:
  294. data.multiArray[2] = ['蛔虫'];
  295. break;
  296. case 2:
  297. data.multiArray[2] = ['蚂蚁', '蚂蟥'];
  298. break;
  299. case 3:
  300. data.multiArray[2] = ['河蚌', '蜗牛', '蛞蝓'];
  301. break;
  302. case 4:
  303. data.multiArray[2] = ['昆虫', '甲壳动物', '蛛形动物', '多足动物'];
  304. break;
  305. }
  306. break;
  307. case 1:
  308. switch (data.multiIndex[1]) {
  309. case 0:
  310. data.multiArray[2] = ['鲫鱼', '带鱼'];
  311. break;
  312. case 1:
  313. data.multiArray[2] = ['青蛙', '娃娃鱼'];
  314. break;
  315. case 2:
  316. data.multiArray[2] = ['蜥蜴', '龟', '壁虎'];
  317. break;
  318. }
  319. break;
  320. }
  321. data.multiIndex[2] = 0;
  322. break;
  323. }
  324. this.multiArray = data.multiArray;
  325. this.multiIndex = data.multiIndex;
  326. },
  327. TimeChange(e) {
  328. this.time = e.detail.value
  329. },
  330. DateChange(e) {
  331. this.date = e.detail.value
  332. },
  333. RegionChange(e) {
  334. this.region = e.detail.value
  335. },
  336. SwitchA(e) {
  337. this.switchA = e.detail.value
  338. },
  339. SwitchB(e) {
  340. this.switchB = e.detail.value
  341. },
  342. SwitchC(e) {
  343. this.switchC = e.detail.value
  344. },
  345. SwitchD(e) {
  346. this.switchD = e.detail.value
  347. },
  348. RadioChange(e) {
  349. this.radio = e.detail.value
  350. },
  351. CheckboxChange(e) {
  352. var items = this.checkbox,
  353. values = e.detail.value;
  354. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  355. items[i].checked = false;
  356. for (var j = 0, lenJ = values.length; j < lenJ; ++j) {
  357. if (items[i].value == values[j]) {
  358. items[i].checked = true;
  359. break
  360. }
  361. }
  362. }
  363. },
  364. ChooseImage() {
  365. uni.chooseImage({
  366. count: 4, //默认9
  367. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  368. sourceType: ['album'], //从相册选择
  369. success: (res) => {
  370. uni.uploadFile(res)
  371. console.log(res)
  372. if (this.imgList.length != 0) {
  373. this.imgList = this.imgList.concat(res.tempFilePaths)
  374. } else {
  375. this.imgList = res.tempFilePaths
  376. }
  377. }
  378. });
  379. },
  380. ViewImage(e) {
  381. uni.previewImage({
  382. urls: this.imgList,
  383. current: e.currentTarget.dataset.url
  384. });
  385. },
  386. DelImg(e) {
  387. uni.showModal({
  388. title: '召唤师',
  389. content: '确定要删除这段回忆吗?',
  390. cancelText: '再看看',
  391. confirmText: '再见',
  392. success: res => {
  393. if (res.confirm) {
  394. this.imgList.splice(e.currentTarget.dataset.index, 1)
  395. }
  396. }
  397. })
  398. },
  399. textareaAInput(e) {
  400. this.textareaAValue = e.detail.value
  401. },
  402. textareaBInput(e) {
  403. this.textareaBValue = e.detail.value
  404. }
  405. }
  406. }
  407. </script>
  408. <style>
  409. .cu-form-group .title {
  410. min-width: calc(4em + 15px);
  411. }
  412. </style>