PresentRegister.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <div>
  3. <nav-bar path="index" title="上传礼物"/>
  4. <div class='card'>
  5. <h3><strong>礼物匹配</strong></h3>
  6. <p>希望对方的性别是</p>
  7. <van-radio-group v-model="gender">
  8. <van-radio name="1" checked-color="#fd6740" style="float: left; margin-right: 20px">男</van-radio>
  9. <van-radio name="2" checked-color="#fd6740">女</van-radio>
  10. </van-radio-group>
  11. <p>礼物名称</p>
  12. <van-field
  13. placeholder="给你的礼物起个名字吧"
  14. v-model="presentName"
  15. :error="pnError"
  16. @click="pnError=false"
  17. required
  18. maxlength="10"
  19. />
  20. <p>我的礼物丨走心介绍</p>
  21. <van-cell-group>
  22. <van-field
  23. type="textarea"
  24. placeholder="请在此输入你的礼物介绍和礼物故事"
  25. rows="5"
  26. autosize
  27. v-model="desc"
  28. :error="descError"
  29. @click="descError=false"
  30. required
  31. maxlength="300"
  32. />
  33. </van-cell-group>
  34. <p>礼物标签</p>
  35. <van-radio-group v-model="tag">
  36. <div
  37. v-for="i in [0, 1 , 2, 3]"
  38. :key="i"
  39. style="height: 40px"
  40. >
  41. <div
  42. v-for="j in [0, 1, 2, 3]"
  43. :key="j"
  44. style="float: left; width: 25%"
  45. >
  46. <van-radio
  47. v-if="i * 4 + j < tags.length"
  48. :name="i * 4 + j"
  49. checked-color="#fd6740"
  50. >{{tags[i * 4 + j]}}
  51. </van-radio>
  52. </div>
  53. </div>
  54. </van-radio-group>
  55. </div>
  56. <div class="card" style="margin-bottom: 10px">
  57. <p>上传礼物照片</p>
  58. <div style="margin-bottom: 10px">
  59. <add-photo :photoURL="imgUrl" @onRead="onRead"/>
  60. </div>
  61. </div>
  62. <van-button
  63. type="primary"
  64. class="submit_button"
  65. @click="publishPresent"
  66. :loading="loading"
  67. >下一步
  68. </van-button>
  69. </div>
  70. </template>
  71. <script>
  72. import {
  73. Uploader, Icon,
  74. CellGroup, Field,
  75. RadioGroup, Radio,
  76. CheckboxGroup, Checkbox,
  77. Picker,
  78. Button,
  79. Toast
  80. } from 'vant';
  81. import {BasicFunction} from "../connector/basic-service";
  82. import AddPhoto from "../components/addPhoto";
  83. import NavBar from "../components/navBar";
  84. export default {
  85. name: "PresentRegister",
  86. components: {
  87. AddPhoto,
  88. NavBar,
  89. [Uploader.name]: Uploader, [Icon.name]: Icon,
  90. [CellGroup.name]: CellGroup, [Field.name]: Field,
  91. [RadioGroup.name]: RadioGroup, [Radio.name]: Radio,
  92. [CheckboxGroup.name]: CheckboxGroup, [Checkbox.name]: Checkbox,
  93. [Picker.name]: Picker,
  94. [Button.name]: Button
  95. },
  96. data() {
  97. return {
  98. gender: '1',
  99. presentId: '',
  100. presentName: '',
  101. pnError: false,
  102. desc: '',
  103. descError: false,
  104. tags: [
  105. "情怀","复古", "有趣", "学霸", "实用",
  106. "童年", "吃货", "佛系", "土味", "活力",
  107. "洋气", "精致", "轻奢", "其它",
  108. ],
  109. tag: 0,
  110. photo: null,
  111. loading: false
  112. }
  113. },
  114. methods: {
  115. publishPresent() {
  116. this.loading = true;
  117. // 检验输入
  118. if (isEmojiCharacter(this.presentName)) {
  119. Toast.fail('不支持表情哦');
  120. this.pnError = true;
  121. this.loading = false;
  122. return;
  123. }
  124. else if (this.presentName.length === 0) {
  125. this.pnError = true;
  126. this.loading = false;
  127. return;
  128. }
  129. else if (isEmojiCharacter(this.desc)) {
  130. Toast.fail('不支持表情哦');
  131. this.descError = true;
  132. this.loading = false;
  133. return;
  134. } else if (this.desc.length <= 15) {
  135. this.descError = true;
  136. Toast.fail('请输入至少15个字的礼物介绍');
  137. this.loading = false;
  138. return;
  139. } else if (this.photo === null) {
  140. Toast.fail('请上传礼物照片');
  141. this.loading = false;
  142. return;
  143. }
  144. // 上传礼物信息
  145. let userId = localStorage.getItem("frontend-userid");
  146. let tag = this.tag;
  147. let gender = this.gender;
  148. // console.log('------- photo -------');
  149. // console.log(this.photo);
  150. let that = this;
  151. // 如果没有改变图片,直接上传
  152. if (this.imgUrl && this.imgUrl === this.photo) {
  153. let imgURL = this.imgUrl;
  154. imgURL = '/' + imgURL.split('/')[3] + '/' + imgURL.split('/')[4] + '/' + imgURL.split('/')[5];
  155. let present = [{
  156. goodid: this.presentId,
  157. name: this.presentName,
  158. goodsNo: "0", modelId: "0",
  159. ownerId: userId.toString(),
  160. goodFirstKind: gender,
  161. goodSecondKind: tag.toString(),
  162. sellPrice: "0.0", marketPrice: "0.0", costPrice: "0.0",
  163. upTime: getNowFormatDate(), downTime: getNowFormatDate(), createTime: getNowFormatDate(),
  164. storeNums: "0",
  165. img: imgURL,
  166. isDel: "0", content: "none", keywords: "none",
  167. description: that.desc,
  168. searchWords: "", weight: "0.0", point: "0", unit: "0", brandId: "0",
  169. visit: "0", favorite: "0", sort: "0", listImg: "xx.jpg",
  170. smallImg: "xx.jpg", specArray: "{}", exp: "0"
  171. }];
  172. // console.log(present);
  173. let url = "updateBatch";
  174. if (that.presentId === '') url = "saveBatch";
  175. BasicFunction.get_data("smartGoods/" + url, function (response) {
  176. // console.log("------ Data Rcvd in PresentReg --------");
  177. // console.log(response);
  178. if (response.ret === "10000") {
  179. that.$router.push('share');
  180. } else {
  181. Toast.fail("上传失败,请检查网络");
  182. that.loading = false;
  183. }
  184. }, present);
  185. }
  186. else {
  187. let formData = new FormData();
  188. formData.append('file', this.photo);
  189. let imgURL = '';
  190. // 先上传图片
  191. BasicFunction.get_data("fileserver/upload?sign=abcdefg", function (res) {
  192. // console.log('----- upload photo result -----');
  193. // console.log(res);
  194. if (res.model === undefined || res.model.length === 0) {
  195. Toast.fail('上传失败,请重试');
  196. return;
  197. }
  198. if (res.ret === '10000') {
  199. imgURL = res.model;
  200. // console.log('img:' + imgURL);
  201. let present = [{
  202. goodid: that.presentId,
  203. name: that.presentName,
  204. goodsNo: "0",
  205. modelId: "0",
  206. ownerId: userId.toString(),
  207. goodFirstKind: gender,
  208. goodSecondKind: tag.toString(),
  209. sellPrice: "0.0",
  210. marketPrice: "0.0",
  211. costPrice: "0.0",
  212. upTime: getNowFormatDate(),
  213. downTime: getNowFormatDate(),
  214. createTime: getNowFormatDate(),
  215. storeNums: "0",
  216. img: imgURL,
  217. isDel: "0",
  218. content: "none",
  219. keywords: "none",
  220. description: that.desc,
  221. searchWords: "",
  222. weight: "0.0",
  223. point: "0",
  224. unit: "0",
  225. brandId: "0",
  226. visit: "0",
  227. favorite: "0",
  228. sort: "0",
  229. listImg: "xx.jpg",
  230. smallImg: "xx.jpg",
  231. specArray: "{}",
  232. exp: "0"
  233. }];
  234. // console.log(present);
  235. let url = "updateBatch";
  236. if (that.presentId === '') url = "saveBatch";
  237. BasicFunction.get_data("smartGoods/" + url, function (response) {
  238. // console.log("------ Data Rcvd in PresentReg --------");
  239. // console.log(response);
  240. if (response.ret === "10000") {
  241. that.$router.push('share');
  242. } else {
  243. Toast.fail("上传失败,请检查网络");
  244. that.loading = false;
  245. }
  246. }, present);
  247. } else {
  248. Toast.fail('上传图片失败,请检查网络');
  249. that.loading = false;
  250. }
  251. }, formData);
  252. }
  253. },
  254. onRead: function (e) {
  255. this.photo = e;
  256. }
  257. },
  258. created: function () {
  259. if (!localStorage.getItem('frontend-userid')) {
  260. this.$router.push('login');
  261. return;
  262. }
  263. if(this.$route.query.present) {
  264. let present = this.$route.query.present;
  265. // console.log('----- Present Info -----');
  266. // console.log(present);
  267. this.presentId = present.id;
  268. this.gender = present.gender.toString();
  269. this.presentName = present.name;
  270. this.desc = present.desc_long;
  271. this.tag = present.tags;
  272. this.imgUrl = present.imgUrl;
  273. this.photo = present.imgUrl;
  274. }
  275. }
  276. }
  277. function getNowFormatDate() {
  278. let date = new Date();
  279. let seperator = "-";
  280. let year = date.getFullYear();
  281. let month = date.getMonth() + 1;
  282. let strDate = date.getDate();
  283. let hour = date.getHours();
  284. let minutes = date.getMinutes();
  285. let seconds = date.getSeconds();
  286. if (month >= 1 && month <= 9) {
  287. month = "0" + month;
  288. }
  289. if (strDate >= 0 && strDate <= 9) {
  290. strDate = "0" + strDate;
  291. }
  292. if (hour >= 0 && hour <= 9) {
  293. hour = "0" + hour;
  294. }
  295. if (minutes >= 0 && minutes <= 9) {
  296. minutes = "0" + minutes;
  297. }
  298. if (seconds >= 0 && seconds <= 9) {
  299. seconds = "0" + seconds;
  300. }
  301. let currentdate = year + seperator + month + seperator + strDate;
  302. currentdate = currentdate + ' ' + hour + ':' + minutes + ':' + seconds;
  303. return currentdate;
  304. }
  305. // 判断是否有emoji
  306. function isEmojiCharacter(substring) {
  307. for (var i = 0; i < substring.length; i++) {
  308. var hs = substring.charCodeAt(i);
  309. if (0xd800 <= hs && hs <= 0xdbff) {
  310. if (substring.length > 1) {
  311. var ls = substring.charCodeAt(i + 1);
  312. var uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
  313. if (0x1d000 <= uc && uc <= 0x1f77f) {
  314. return true;
  315. }
  316. }
  317. } else if (substring.length > 1) {
  318. var ls = substring.charCodeAt(i + 1);
  319. if (ls == 0x20e3) {
  320. return true;
  321. }
  322. } else {
  323. if (0x2100 <= hs && hs <= 0x27ff) {
  324. return true;
  325. } else if (0x2B05 <= hs && hs <= 0x2b07) {
  326. return true;
  327. } else if (0x2934 <= hs && hs <= 0x2935) {
  328. return true;
  329. } else if (0x3297 <= hs && hs <= 0x3299) {
  330. return true;
  331. } else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030
  332. || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b
  333. || hs == 0x2b50) {
  334. return true;
  335. }
  336. }
  337. }
  338. }
  339. </script>
  340. <style scoped>
  341. p, h3 {
  342. color: #fd6740;
  343. }
  344. h3 {
  345. padding: 5px;
  346. border-bottom: solid 1px #e4e4e4;
  347. }
  348. .card {
  349. background-color: white;
  350. margin: 20px 20px;
  351. border: solid 1px #e4e4e4;
  352. padding: 15px;
  353. text-align: left;
  354. }
  355. .submit_button {
  356. margin-bottom: 10px;
  357. margin-left: auto;
  358. margin-right: auto;
  359. background-color: #fd6740;
  360. border-color: #fd6740;
  361. width: 85%;
  362. }
  363. </style>