PresentRegister.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div>
  3. <div class='card'>
  4. <h3><strong>礼物匹配</strong></h3>
  5. <p>希望对方的性别是</p>
  6. <van-radio-group v-model="radio">
  7. <van-radio name="0" checked-color="#fd6740" style="float: left; margin-right: 20px">男</van-radio>
  8. <van-radio name="1" checked-color="#fd6740">女</van-radio>
  9. </van-radio-group>
  10. <p>礼物名称</p>
  11. <van-field
  12. placeholder="给你的礼物起个名字吧"
  13. v-model="presentName"
  14. :error="pnError"
  15. @click="pnError=false"
  16. required
  17. maxlength="10"
  18. />
  19. <p>我的礼物丨走心介绍</p>
  20. <van-cell-group>
  21. <van-field
  22. type="textarea"
  23. placeholder="请在此输入你的礼物介绍和礼物故事"
  24. rows="5"
  25. autosize
  26. v-model="desc"
  27. :error="descError"
  28. @click="descError=false"
  29. required
  30. maxlength="300"
  31. />
  32. </van-cell-group>
  33. <p>礼物标签</p>
  34. <div style="margin-bottom: 20px">
  35. <van-checkbox-group v-model="result">
  36. <van-checkbox
  37. v-for="(item, index) in tags"
  38. :key="index"
  39. :name="index"
  40. :style="(index+1) % 4 === 0 ? br : nobr"
  41. >{{ item }}</van-checkbox>
  42. </van-checkbox-group>
  43. </div>
  44. </div>
  45. <div class="card">
  46. <p>上传礼物照片</p>
  47. <add-photo @uploadPhoto="onReadPhoto"/>
  48. </div>
  49. <van-button size="large" type="primary" @click="publishPresent">下一步</van-button>
  50. </div>
  51. </template>
  52. <script>
  53. import {
  54. Uploader, Icon,
  55. CellGroup, Field,
  56. RadioGroup, Radio,
  57. CheckboxGroup, Checkbox,
  58. Picker,
  59. Button,
  60. Toast
  61. } from 'vant'
  62. import AddPhoto from "../components/addPhoto";
  63. export default {
  64. name: "PresentRegister",
  65. components: {
  66. AddPhoto,
  67. [Uploader.name]: Uploader, [Icon.name]: Icon,
  68. [CellGroup.name]: CellGroup, [Field.name]: Field,
  69. [RadioGroup.name]: RadioGroup, [Radio.name]: Radio,
  70. [CheckboxGroup.name]: CheckboxGroup, [Checkbox.name]: Checkbox,
  71. [Picker.name]: Picker,
  72. [Button.name]: Button
  73. },
  74. data() {
  75. return {
  76. radio: '0',
  77. presentName: '',
  78. pnError: false,
  79. desc: '',
  80. descError: false,
  81. tags: [
  82. "情怀","复古", "有趣", "学霸", "实用",
  83. "同年", "吃货", "佛系", "土味", "活力",
  84. "洋气", "精致", "轻奢", "其它",
  85. ],
  86. result: [],
  87. photo: null,
  88. nobr: "float: left; margin-right: 5px",
  89. br: ""
  90. }
  91. },
  92. methods: {
  93. publishPresent() {
  94. // 检验输入
  95. if (this.presentName.length === 0) {
  96. this.pnError = true;
  97. return;
  98. } else if (this.desc.length <= 15) {
  99. this.descError = true;
  100. Toast.fail('请输入至少15个字的礼物介绍');
  101. return;
  102. } else if (this.photo === null) {
  103. Toast.fail('请上传礼物照片');
  104. return;
  105. }
  106. // post_present()
  107. let present = {
  108. name: this.presentName,
  109. gender: parseInt(this.radio),
  110. desc: this.desc,
  111. tags: this.result,
  112. photo: this.photo
  113. };
  114. console.log(present);
  115. BasicFunction.get_data("ajaxpostpresent", function (response) {
  116. console.log("------ Data Rcvd in PresentReg --------");
  117. console.log(response);
  118. if(response.ret === "10000"){
  119. // 不需要 设置 SessionID, 已经自动保存在jSessionID中
  120. this.$router.push('index');
  121. } else {
  122. // 注册失败的处理
  123. Toast.fail("上传失败,请检查网络");
  124. }
  125. }, {});
  126. // this.$router.push('index');
  127. },
  128. onReadPhoto(file) {
  129. this.photo = file;
  130. }
  131. },
  132. created: function () {
  133. if(this.$route.query.present) {
  134. let present = this.$route.query.present;
  135. console.log(present);
  136. this.radio = present.gender.toString();
  137. this.presentName = present.presentName;
  138. this.desc = present.presentDesc;
  139. }
  140. }
  141. }
  142. </script>
  143. <style scoped>
  144. p, h3 {
  145. color: #fd6740;
  146. }
  147. h3 {
  148. padding: 5px;
  149. border-bottom: solid 1px #e4e4e4;
  150. }
  151. .card {
  152. background-color: white;
  153. margin: 20px 20px;
  154. border: solid 1px #e4e4e4;
  155. padding: 15px;
  156. text-align: left;
  157. }
  158. .van-button {
  159. background-color: #fd6740;
  160. border-color: #fd6740;
  161. margin: 10px 0 10px;
  162. width: 85%;
  163. }
  164. </style>