PresentRegister.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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 (this.presentName.length === 0) {
  119. this.pnError = true;
  120. this.loading = false;
  121. return;
  122. } else if (this.desc.length <= 15) {
  123. this.descError = true;
  124. Toast.fail('请输入至少15个字的礼物介绍');
  125. this.loading = false;
  126. return;
  127. } else if (this.photo === null) {
  128. Toast.fail('请上传礼物照片');
  129. this.loading = false;
  130. return;
  131. }
  132. // 上传礼物信息
  133. let userId = localStorage.getItem("frontend-userid");
  134. let tag = this.tag;
  135. let gender = this.gender;
  136. console.log('------- photo -------');
  137. console.log(this.photo);
  138. let that = this;
  139. // 如果没有改变图片,直接上传
  140. if (this.imgUrl && this.imgUrl === this.photo) {
  141. let imgURL = this.imgUrl;
  142. imgURL = '/' + imgURL.split('/')[3] + '/' + imgURL.split('/')[4] + '/' + imgURL.split('/')[5];
  143. let present = [{
  144. goodid: this.presentId,
  145. name: this.presentName,
  146. goodsNo: "0", modelId: "0",
  147. ownerId: userId.toString(),
  148. goodFirstKind: gender,
  149. goodSecondKind: tag.toString(),
  150. sellPrice: "0.0", marketPrice: "0.0", costPrice: "0.0",
  151. upTime: getNowFormatDate(), downTime: getNowFormatDate(), createTime: getNowFormatDate(),
  152. storeNums: "0",
  153. img: imgURL,
  154. isDel: "0", content: "none", keywords: "none",
  155. description: that.desc,
  156. searchWords: "", weight: "0.0", point: "0", unit: "0", brandId: "0",
  157. visit: "0", favorite: "0", sort: "0", listImg: "xx.jpg",
  158. smallImg: "xx.jpg", specArray: "{}", exp: "0"
  159. }];
  160. console.log(present);
  161. let url = "updateBatch";
  162. if (that.presentId === '') url = "saveBatch";
  163. BasicFunction.get_data("smartGoods/" + url, function (response) {
  164. console.log("------ Data Rcvd in PresentReg --------");
  165. console.log(response);
  166. if (response.ret === "10000") {
  167. that.$router.push('share');
  168. } else {
  169. Toast.fail("上传失败,请检查网络");
  170. that.loading = false;
  171. }
  172. }, present);
  173. }
  174. else {
  175. let formData = new FormData();
  176. formData.append('file', this.photo);
  177. let imgURL = '';
  178. // 先上传图片
  179. BasicFunction.get_data("fileserver/upload?sign=abcdefg", function (res) {
  180. console.log('----- upload photo result -----');
  181. console.log(res);
  182. if (res.ret === '10000') {
  183. imgURL = res.model;
  184. console.log('img:' + imgURL);
  185. let present = [{
  186. goodid: that.presentId,
  187. name: that.presentName,
  188. goodsNo: "0",
  189. modelId: "0",
  190. ownerId: userId.toString(),
  191. goodFirstKind: gender,
  192. goodSecondKind: tag.toString(),
  193. sellPrice: "0.0",
  194. marketPrice: "0.0",
  195. costPrice: "0.0",
  196. upTime: getNowFormatDate(),
  197. downTime: getNowFormatDate(),
  198. createTime: getNowFormatDate(),
  199. storeNums: "0",
  200. img: imgURL,
  201. isDel: "0",
  202. content: "none",
  203. keywords: "none",
  204. description: that.desc,
  205. searchWords: "",
  206. weight: "0.0",
  207. point: "0",
  208. unit: "0",
  209. brandId: "0",
  210. visit: "0",
  211. favorite: "0",
  212. sort: "0",
  213. listImg: "xx.jpg",
  214. smallImg: "xx.jpg",
  215. specArray: "{}",
  216. exp: "0"
  217. }];
  218. console.log(present);
  219. let url = "updateBatch";
  220. if (that.presentId === '') url = "saveBatch";
  221. BasicFunction.get_data("smartGoods/" + url, function (response) {
  222. console.log("------ Data Rcvd in PresentReg --------");
  223. console.log(response);
  224. if (response.ret === "10000") {
  225. that.$router.push('share');
  226. } else {
  227. Toast.fail("上传失败,请检查网络");
  228. that.loading = false;
  229. }
  230. }, present);
  231. } else {
  232. Toast.fail('上传图片失败,请检查网络');
  233. that.loading = false;
  234. }
  235. }, formData);
  236. }
  237. },
  238. onRead: function (e) {
  239. this.photo = e;
  240. }
  241. },
  242. created: function () {
  243. if (!localStorage.getItem('frontend-userid')) {
  244. this.$router.push('login');
  245. return;
  246. }
  247. if(this.$route.query.present) {
  248. let present = this.$route.query.present;
  249. console.log('----- Present Info -----');
  250. console.log(present);
  251. this.presentId = present.id;
  252. this.gender = present.gender.toString();
  253. this.presentName = present.name;
  254. this.desc = present.desc_long;
  255. this.tag = present.tags;
  256. this.imgUrl = present.imgUrl;
  257. this.photo = present.imgUrl;
  258. }
  259. }
  260. }
  261. function getNowFormatDate() {
  262. let date = new Date();
  263. let seperator = "-";
  264. let year = date.getFullYear();
  265. let month = date.getMonth() + 1;
  266. let strDate = date.getDate();
  267. let hour = date.getHours();
  268. let minutes = date.getMinutes();
  269. let seconds = date.getSeconds();
  270. if (month >= 1 && month <= 9) {
  271. month = "0" + month;
  272. }
  273. if (strDate >= 0 && strDate <= 9) {
  274. strDate = "0" + strDate;
  275. }
  276. if (hour >= 0 && hour <= 9) {
  277. hour = "0" + hour;
  278. }
  279. if (minutes >= 0 && minutes <= 9) {
  280. minutes = "0" + minutes;
  281. }
  282. if (seconds >= 0 && seconds <= 9) {
  283. seconds = "0" + seconds;
  284. }
  285. let currentdate = year + seperator + month + seperator + strDate;
  286. currentdate = currentdate + ' ' + hour + ':' + minutes + ':' + seconds;
  287. return currentdate;
  288. }
  289. </script>
  290. <style scoped>
  291. p, h3 {
  292. color: #fd6740;
  293. }
  294. h3 {
  295. padding: 5px;
  296. border-bottom: solid 1px #e4e4e4;
  297. }
  298. .card {
  299. background-color: white;
  300. margin: 20px 20px;
  301. border: solid 1px #e4e4e4;
  302. padding: 15px;
  303. text-align: left;
  304. }
  305. .submit_button {
  306. margin-bottom: 10px;
  307. margin-left: auto;
  308. margin-right: auto;
  309. background-color: #fd6740;
  310. border-color: #fd6740;
  311. width: 85%;
  312. }
  313. </style>