giftDetail.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <div>
  3. <nav-bar path="index" title="礼品卡"/>
  4. <!--对方的礼物信息-->
  5. <!--<p>{{myPresent.name}}-{{receivedPresent.name}}</p>-->
  6. <gift-card
  7. v-if="myPresent.status === 2 || myPresent.status === 3"
  8. :present-img="receivedPresent.img"
  9. :present-name="receivedPresent.name"
  10. :present-desc="receivedPresent.desc"
  11. :owner="1"
  12. :placeId="receivedPresent.placeId"
  13. :gender="receivedPresent.gender"
  14. :status="-1"
  15. :wechat="receivedPresent.wechat"
  16. />
  17. <!--我写的感谢信-->
  18. <div class="letter" v-if="RcommentDo.content.length !== 0">
  19. <p style="font-size: 110%"><strong>我送出的感谢信</strong></p>
  20. <van-rate
  21. icon="like"
  22. void-icon="like-o"
  23. readonly
  24. v-model="RcommentDo.rate"
  25. color="red"
  26. />
  27. <p>{{RcommentDo.content}}</p>
  28. </div>
  29. <!--我的礼物信息-->
  30. <gift-card
  31. :present-img="myPresent.img"
  32. :present-name="myPresent.name"
  33. :present-desc="myPresent.desc"
  34. :owner="0"
  35. :placeId="myPresent.placeId"
  36. :gender="myPresent.gender"
  37. :status="myPresent.status"
  38. :wechat="myPresent.wechat"
  39. />
  40. <div class="letter" v-if="commentDo.content.length !== 0">
  41. <p style="font-size: 110%"><strong>我收到的感谢信</strong></p>
  42. <van-rate
  43. icon="like"
  44. void-icon="like-o"
  45. readonly
  46. v-model="commentDo.rate"
  47. color="red"
  48. />
  49. <p>{{commentDo.content}}</p>
  50. </div>
  51. <div class="letter" v-if="myPresent.status === 4">
  52. <p><strong>审核未通过,请前往首页重新发布礼物!</strong></p>
  53. <p v-if="reason.length !== 0">原因:{{reason}}</p>
  54. </div>
  55. <div style="height: 100px; width: 100%"></div>
  56. <img src="http://szugift.oss-cn-shenzhen.aliyuncs.com/present_card_bottom.png"
  57. style="position: fixed; bottom: 100px; max-width: 100%; z-index: -1"
  58. />
  59. <div
  60. v-if="myPresent.status === 2"
  61. style="position: fixed; bottom: 0; width: 100%; background-color: #fff6e3"
  62. >
  63. <van-button
  64. type="primary" size="large"
  65. style="background-color: #fd6740; border-color: #fd6740; width: 85%;"
  66. @click="toWriteComment"
  67. >确认交换成功</van-button>
  68. <p>交换成功可以开始接收对方发来的感谢信哦</p>
  69. </div>
  70. <div
  71. v-if="myPresent.status === 0 || myPresent.status === 1 || myPresent.status === 4"
  72. style="position: fixed; bottom: 0; width: 100%"
  73. >
  74. <van-button
  75. type="default" size="large"
  76. style="width: 85%;"
  77. @click="editPresent"
  78. v-if="myPresent.status !== 4"
  79. >修改礼物</van-button>
  80. <van-button
  81. type="warning" size="large"
  82. style="width: 85%; margin: 10px 0 10px"
  83. @click="deletePresent"
  84. >删除礼物</van-button>
  85. </div>
  86. </div>
  87. </template>
  88. <script>
  89. import GiftCard from "../components/giftCard";
  90. import {Button, Dialog, Toast, Rate} from 'vant'
  91. import NavBar from "../components/navBar";
  92. import {BasicFunction} from "../connector/basic-service";
  93. export default {
  94. name: "giftDetail",
  95. components: {
  96. NavBar,
  97. GiftCard,
  98. [Button.name]: Button,
  99. [Rate.name]: Rate
  100. },
  101. data() {
  102. return {
  103. myPresent: {},
  104. reason: '',
  105. receivedPresent: {},
  106. giftDo: {},
  107. identityDo: {},
  108. commentDo: {
  109. content: '',
  110. rate: 5
  111. },
  112. RgiftDo: {},
  113. RidentityDo: {},
  114. RcommentDo: {
  115. content: '',
  116. rate: 5
  117. },
  118. orderId: -1
  119. }
  120. },
  121. methods:{
  122. editPresent: function() {
  123. Toast.loading({
  124. mask: true,
  125. message: '加载中...',
  126. duration: 500
  127. });
  128. let p = this.myPresent;
  129. this.$router.push({path: 'presentRegister', query: {presentId: p.id}});
  130. },
  131. deletePresent: function() {
  132. Dialog.confirm({
  133. message: '确认删除礼物吗?'
  134. }).then(() => {
  135. // 删除礼物:将isDel设为1
  136. Toast.loading({
  137. mask: true,
  138. message: '加载中...',
  139. duration: 1000
  140. });
  141. let that = this;
  142. BasicFunction.get_data("smartGoods/list?goodid=" + this.myPresent.id, function (response) {
  143. // console.log("------ Data Rcvd in detail --------");
  144. // console.log(response);
  145. try {
  146. let list = response.model.list;
  147. if (response.ret === "10000") {
  148. list[0].isDel = 1;
  149. // console.log(list);
  150. BasicFunction.get_data("smartGoods/updateBatch", function (response) {
  151. // console.log(response);
  152. if (response.ret === '10000') {
  153. Toast.success('删除成功');
  154. that.$router.push('index');
  155. } else {
  156. Toast.fail('删除失败,请检查网络');
  157. }
  158. }, list)
  159. } else Toast.fail('获取资源失败');
  160. } catch (e) {
  161. console.warn(e);
  162. Toast.fail('获取资源失败');
  163. }
  164. }, {});
  165. }).catch(() => {
  166. // on cancel
  167. });
  168. },
  169. toWriteComment: function () {
  170. let myId = this.myPresent.id;
  171. let goodid = this.receivedPresent.id;
  172. let orderId = this.orderId;
  173. this.$router.push({
  174. path: 'assess',
  175. query: {myId: myId, goodId: goodid, orderId: orderId}
  176. });
  177. },
  178. loadGift(){
  179. let presentId = this.$route.query.presentId;
  180. if(presentId == null || presentId == undefined){
  181. presentId = BasicFunction.utils_get_param("presentId");
  182. }
  183. if(presentId == undefined || presentId == null){
  184. Toast.fail('请重新进入礼物页哦');
  185. this.$router.push('index');
  186. }
  187. let that = this;
  188. BasicFunction.get_data('smartGoods/list?goodid=' + presentId, function (res) {
  189. if (res.ret === '10000') {
  190. if(res.model === undefined || res.model == null || res.model.list == undefined || res.model.list.length <= 0){
  191. Toast.fail('礼物查看遇到问题,请稍等一下再试吧');
  192. that.$router.push('index');
  193. return;
  194. }
  195. that.giftDo = res.model.list[0];
  196. that.onloadGift(that.giftDo);
  197. }
  198. }, {});
  199. },
  200. initGifts() {
  201. if (this.RgiftDo.goodid !== undefined) {
  202. let rpresent = {};
  203. let ridentity = this.RidentityDo;
  204. rpresent.id = this.RgiftDo.goodid;
  205. rpresent.name = this.RgiftDo.name;
  206. rpresent.desc = this.RgiftDo.description;
  207. rpresent.gender = ridentity.userSex;
  208. rpresent.placeId = ridentity.dormDistrict;
  209. rpresent.wechat = ridentity.userWxAccount;
  210. rpresent.img = "http://szugift.oss-cn-shenzhen.aliyuncs.com/mysterious%20gift.jpg";
  211. this.receivedPresent = rpresent;
  212. }
  213. let present = {};
  214. let identity = {};
  215. identity = this.identityDo;
  216. present.id = this.giftDo.goodid;
  217. present.name = this.giftDo.name;
  218. present.desc = this.giftDo.description;
  219. present.status = this.giftDo.sort;
  220. present.gender = this.giftDo.goodFirstKind;
  221. present.placeId = identity.dormDistrict;
  222. present.wechat = identity.userWxAccount;
  223. present.img = "http://gift.fogice.com" + this.giftDo.img;
  224. this.myPresent = present;
  225. },
  226. onloadGift(){
  227. let that = this;
  228. let status = this.giftDo.sort;
  229. let id = this.giftDo.goodid;
  230. // console.log(that.myPresent);
  231. if (status >= 2) {
  232. if (status === 4) that.onloadReview(id);
  233. let userid = localStorage.getItem('frontend-userid');
  234. BasicFunction.get_data('smartOrder/list?userId=' + userid, function (orderRes) {
  235. try {
  236. console.log('----- order res -----');
  237. console.log(orderRes);
  238. if (orderRes.ret === '10000' && orderRes.model.list !== undefined && orderRes.model.list.length !== 0) {
  239. let order = orderRes.model.list[0];
  240. let receiverId = parseInt(order.note);
  241. that.orderId = order.id;
  242. BasicFunction.get_data('smartGoods/list?goodid=' + receiverId, function (receiverRes) {
  243. console.log('----- received gift -----');
  244. try {
  245. console.log(receiverRes);
  246. if (receiverRes.ret === '10000') {
  247. if (receiverRes.model === undefined || receiverRes.model == null || receiverRes.model.list == undefined || receiverRes.model.list.length <= 0) {
  248. Toast.fail('礼物查看遇到问题,请稍等一下再试吧');
  249. that.$router.push('index');
  250. return;
  251. }
  252. that.RgiftDo = receiverRes.model.list[0];
  253. that.onloadReceiveGift(id, status);
  254. }
  255. } catch (e) {
  256. console.warn(e);
  257. Toast.fail('获取数据失败,请重试');
  258. }
  259. }, {});
  260. }
  261. } catch (e) {
  262. console.warn(e);
  263. Toast.fail('数据异常!请重试');
  264. }
  265. }, {})
  266. } else this.initGifts();
  267. },
  268. onloadReceiveGift(myid, status) {
  269. let receiverId = this.RgiftDo.ownerId;
  270. let goodid = this.RgiftDo.goodid;
  271. let that = this;
  272. BasicFunction.get_data('smartIdentity/list?userId=' + receiverId, function (recvRes) {
  273. try {
  274. console.log("----- receiver's identity");
  275. console.log(recvRes);
  276. if (recvRes.ret === '10000' && recvRes.model !== undefined && recvRes.model.list.length !== 0) {
  277. that.RidentityDo = recvRes.model.list[0];
  278. if (status === 3) that.onloadFeedback(myid, goodid);
  279. else that.initGifts();
  280. } else {
  281. Toast.fail('获取数据失败,请重试');
  282. }
  283. } catch (e) {
  284. console.log(e);
  285. Toast.fail('获取数据失败,请重试');
  286. }
  287. }, {});
  288. },
  289. onloadFeedback(myid, rgoodId) {
  290. let that = this;
  291. BasicFunction.get_data('smartOrderFeedback/list?goodId=' + myid, function (res) {
  292. console.log('----- received feedback -----');
  293. console.log(res);
  294. try {
  295. if (res.ret === '10000') {
  296. let comment = {
  297. content: '暂未收到'
  298. };
  299. if (res.model.list !== undefined && res.model.list.length !== 0) {
  300. comment = res.model.list[0];
  301. that.commentDo.rate = comment.ratingMajor;
  302. }
  303. that.commentDo.content = comment.content;
  304. // 对方的评价
  305. BasicFunction.get_data('smartOrderFeedback/list?goodId=' + rgoodId, function (recvRes) {
  306. console.log('----- sent feedback -----');
  307. console.log(res);
  308. try {
  309. if (recvRes.ret === '10000') {
  310. let comment = {
  311. content: '感谢信未发送或发送失败'
  312. };
  313. if (recvRes.model.list !== undefined && recvRes.model.list.length !== 0) {
  314. comment = recvRes.model.list[0];
  315. that.RcommentDo.rate = comment.ratingMajor;
  316. }
  317. that.RcommentDo.content = comment.content;
  318. that.initGifts();
  319. } else {
  320. Toast.fail('获取信息失败');
  321. that.initGifts();
  322. }
  323. } catch (e) {
  324. console.warn(e);
  325. Toast.fail('获取信息失败');
  326. that.initGifts();
  327. }
  328. }, {});
  329. } else {
  330. Toast.fail('获取信息失败');
  331. that.initGifts();
  332. }
  333. } catch (e) {
  334. console.warn(e);
  335. Toast.fail('获取信息失败');
  336. that.initGifts();
  337. }
  338. }, {});
  339. },
  340. onloadReview(goodid) {
  341. let that = this;
  342. BasicFunction.get_data('smartGoodReview/list?goodId=' + goodid, function (res) {
  343. if (res.ret === '10000' && res.model.list !== undefined) {
  344. if (res.model.list.length !== 0) {
  345. let i = sortReason(res.model.list);
  346. that.reason = res.model.list[i].displayNote;
  347. }
  348. } else Toast.fail('获取信息失败');
  349. }, {});
  350. }
  351. },
  352. created: function () {
  353. if (!localStorage.getItem('frontend-userid')) {
  354. this.$router.push('login');
  355. return;
  356. }
  357. // let presentId = this.$route.query.presentId;
  358. // console.log(this.$route.query.present);
  359. let userid = localStorage.getItem('frontend-userid');
  360. let that = this;
  361. BasicFunction.get_data('smartIdentity/list?userId=' + userid, function (res) {
  362. // console.log(res);
  363. try {
  364. if (res.ret === '10000' && !(res.model === undefined || res.model == null || res.model.list == undefined || res.model.list.length <= 0)){
  365. that.identityDo = res.model.list[0];
  366. that.loadGift();
  367. } else Toast.fail('获取信息失败');
  368. } catch (e) {
  369. console.warn(e);
  370. Toast.fail('获取信息失败');
  371. }
  372. }, {});
  373. }
  374. }
  375. // 找最后建立的那条审核单
  376. function sortReason(list) {
  377. // console.log('-----review list-----');
  378. // console.log(list);
  379. let last = 0;
  380. let lastTime = new Date((list[0].reviewTime).replace(/-/g, "/"));
  381. for (let i = 1; i < list.length; i++) {
  382. let time = new Date((list[i].reviewTime).replace(/-/g, "/"));
  383. if (lastTime < time) {
  384. lastTime = time;
  385. last = i;
  386. }
  387. }
  388. return last;
  389. }
  390. </script>
  391. <style scoped>
  392. .letter {
  393. background-color: white;
  394. margin: 20px 20px;
  395. border: solid 1px #e4e4e4;
  396. padding: 0 15px;
  397. text-align: left;
  398. }
  399. </style>