form.vue 12 KB

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