index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. <input type="text" v-model="searchInfo.source_name" @input="toInput" placeholder="搜索名称">
  5. </view>
  6. <view class="two">
  7. <tabs :tabs="tabs" @tabsChange="tabsChange">
  8. <view class="tabsList">
  9. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  10. <view class="list-scroll-view">
  11. <view class="list" v-for="(item, index) in list" :key="index" @tap="toInfo(item)">
  12. <view class="list_1">
  13. <view class="top">
  14. <view class="left">
  15. <image v-if="item.source.file.length>0" class="image"
  16. :src="item.source.file&&item.source.file.length>0?item.source.file[0].url:''">
  17. </image>
  18. <image v-else class="image"
  19. :src="config.logo_url&&config.logo_url.length>0?config.logo_url[0].url:''">
  20. </image>
  21. <text v-if="item.type=='0'">酒店民宿</text>
  22. <text v-else>景区门票</text>
  23. </view>
  24. <view class="right">{{item.zhStatus}}</view>
  25. </view>
  26. <view class="center">
  27. <view class="left">
  28. <image v-if="item.source.file.length>0" class="image"
  29. :src="item.source.file&&item.source.file.length>0?item.source.file[0].url:''">
  30. </image>
  31. <image v-else class="image"
  32. :src="config.logo_url&&config.logo_url.length>0?config.logo_url[0].url:''">
  33. </image>
  34. </view>
  35. <view class="right">
  36. <view class="name textOne">{{item.source_name||'暂无'}}</view>
  37. <view class="other">
  38. 下单时间:{{item.buy_time||'暂无'}}
  39. </view>
  40. <view class="other">
  41. 数量:{{item.num||'0'}}
  42. </view>
  43. <view class="other">
  44. 总价:¥{{item.total_money||'0'}}
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <view class="bottom">
  50. <button v-if="item.status=='0'" size="mini" type="default"
  51. @tap.stop="toPay(item)">支付</button>
  52. <button v-if="item.status=='0'" size="mini" type="default"
  53. @tap.stop="toCancel(item)">取消订单</button>
  54. <button v-if="item.status=='1'" size="mini" type="default"
  55. @tap.stop="toFile(item)">券码</button>
  56. <button v-if="item.status=='1'||item.status=='6'" size="mini" type="default"
  57. @tap.stop="toOut(item)">申请退款</button>
  58. <button v-if="item.status=='2'" size="mini" type="default"
  59. @tap.stop="toRate(item)">评价</button>
  60. </view>
  61. </view>
  62. </view>
  63. <view class="is_bottom" v-if="is_bottom">
  64. <text>{{config.bottom_title||'到底了!'}}</text>
  65. </view>
  66. </scroll-view>
  67. </view>
  68. </tabs>
  69. </view>
  70. <uni-popup ref="popup" background-color="#fff" type="center">
  71. <div class="canvas">
  72. <canvas canvas-id="qrcode" class="qrcode"></canvas>
  73. </div>
  74. </uni-popup>
  75. </view>
  76. </template>
  77. <script>
  78. import tabs from '../../components/tabs/index.vue';
  79. import UQrcode from '../../common/uqrcode.js';
  80. export default {
  81. components: {
  82. tabs
  83. },
  84. data() {
  85. return {
  86. searchInfo: {},
  87. config: {},
  88. user: {},
  89. status: '',
  90. tabs: {
  91. active: '0',
  92. bgColor: '#ffffff',
  93. menu: []
  94. },
  95. list: [],
  96. total: 0,
  97. skip: 0,
  98. limit: 6,
  99. page: 0,
  100. // 数据是否触底
  101. is_bottom: false,
  102. scrollTop: 0,
  103. // 字典表
  104. statusList: [],
  105. }
  106. },
  107. onLoad: async function(e) {
  108. const that = this;
  109. that.$set(that, `status`, e.status || '-1');
  110. that.$set(that.tabs, `active`, e.status || '-1');
  111. that.searchToken();
  112. that.searchConfig();
  113. await that.searchOther();
  114. },
  115. onShow: async function() {
  116. const that = this;
  117. that.clearPage();
  118. await that.search();
  119. },
  120. onPullDownRefresh: async function() {
  121. const that = this;
  122. that.clearPage();
  123. await that.search();
  124. uni.stopPullDownRefresh();
  125. },
  126. methods: {
  127. searchToken() {
  128. const that = this;
  129. try {
  130. const res = uni.getStorageSync('token');
  131. if (res) that.$set(that, `user`, res);
  132. } catch (e) {
  133. uni.showToast({
  134. title: err.errmsg,
  135. icon: 'error',
  136. duration: 2000
  137. });
  138. }
  139. },
  140. searchConfig() {
  141. const that = this;
  142. try {
  143. const res = uni.getStorageSync('config');
  144. if (res) that.$set(that, `config`, res);
  145. } catch (e) {
  146. uni.showToast({
  147. title: err.errmsg,
  148. icon: 'error',
  149. duration: 2000
  150. });
  151. }
  152. },
  153. async search() {
  154. const that = this;
  155. let user = that.user;
  156. let status = that.status;
  157. let info = {
  158. skip: that.skip,
  159. limit: that.limit,
  160. user: that.user._id,
  161. }
  162. if (status != '-1') info.status = status
  163. const res = await that.$api(`/order`, 'GET', {
  164. ...info,
  165. ...that.searchInfo
  166. })
  167. if (res.errcode == '0') {
  168. let list = [...that.list, ...res.data];
  169. for (let val of list) {
  170. const status = that.statusList.find(i => i.value == val.status)
  171. if (status) val.zhStatus = status.label
  172. }
  173. that.$set(that, `list`, list)
  174. that.$set(that, `total`, res.total)
  175. } else {
  176. uni.showToast({
  177. title: res.errmsg,
  178. });
  179. }
  180. },
  181. // 输入框
  182. toInput(e) {
  183. const that = this;
  184. if (that.searchInfo.source_name) that.$set(that.searchInfo, `source_name`, e.detail.value)
  185. else that.$set(that, `searchInfo`, {})
  186. that.clearPage();
  187. that.search();
  188. },
  189. // 选择选项卡
  190. tabsChange(e) {
  191. const that = this;
  192. that.$set(that.tabs, `active`, e.active)
  193. that.$set(that, `status`, e.active)
  194. that.clearPage();
  195. that.search()
  196. },
  197. // 查看详情
  198. toInfo(item) {
  199. uni.navigateTo({
  200. url: `/pagesIndex/order/detail?id=${item._id||item.id}`
  201. })
  202. },
  203. // 支付
  204. async toPay(item) {
  205. const that = this;
  206. console.log(item);
  207. },
  208. // 取消支付
  209. async toCancel(item) {
  210. const that = this;
  211. uni.showModal({
  212. title: '提示',
  213. content: '确定取消订单吗?',
  214. success: async function(res) {
  215. if (res.confirm) {
  216. const res = await that.$api(`/order/${item._id}`, 'POST', {
  217. status: "4"
  218. })
  219. if (res.errcode == '0') {
  220. uni.showToast({
  221. title: `取消订单成功`,
  222. });
  223. that.clearPage();
  224. that.search();
  225. } else {
  226. uni.showToast({
  227. title: res.errmsg,
  228. });
  229. }
  230. }
  231. }
  232. });
  233. },
  234. //券码
  235. async toFile(item) {
  236. const that = this;
  237. UQrcode.make({
  238. canvasId: 'qrcode', //切记canvasId 里边的内容需要跟canvas里边canvas-id="qrcode"的名字一样
  239. componentInstance: this,
  240. text: item._id,
  241. // text: `${that.$config.serverUrl}/oederInfo?id=${item._id}`, //跳转小程序指定页面
  242. size: 200,
  243. margin: 0,
  244. backgroundColor: '#ffffff',
  245. foregroundColor: '#000000',
  246. fileType: 'jpg',
  247. errorCorrectLevel: UQrcode.errorCorrectLevel.H,
  248. success: res => {}
  249. })
  250. that.$refs.popup.open();
  251. },
  252. //申请退款
  253. async toOut(item) {
  254. const that = this;
  255. uni.showModal({
  256. title: '提示',
  257. content: '确定申请退款吗?',
  258. success: async function(res) {
  259. if (res.confirm) {
  260. if (item.status == '1') {
  261. const res = await that.$api(`/order/${item._id}`, 'POST', {
  262. status: "5"
  263. })
  264. if (res.errcode == '0') {
  265. uni.showToast({
  266. title: `申请退款成功`,
  267. });
  268. that.clearPage();
  269. that.search();
  270. } else {
  271. uni.showToast({
  272. title: res.errmsg,
  273. });
  274. }
  275. } else {
  276. uni.navigateTo({
  277. url: `/pagesIndex/order/after?id=${item._id||item.id}`
  278. })
  279. }
  280. }
  281. }
  282. });
  283. },
  284. // 评价
  285. async toRate(item) {
  286. const that = this;
  287. uni.navigateTo({
  288. url: `/pagesIndex/order/rate?id=${item._id||item.id}`
  289. })
  290. },
  291. async searchOther() {
  292. const that = this;
  293. let res;
  294. //状态
  295. res = await that.$api('/dictData', 'GET', {
  296. type: 'order_status',
  297. is_use: '0'
  298. })
  299. if (res.errcode == '0') {
  300. that.$set(that, `statusList`, res.data);
  301. const menu = res.data.map((item) => {
  302. return {
  303. title: item.label,
  304. active: item.value
  305. }
  306. })
  307. menu.unshift({
  308. title: '全部',
  309. active: '-1'
  310. })
  311. that.$set(that.tabs, `menu`, menu)
  312. }
  313. },
  314. // 分页
  315. toPage(e) {
  316. const that = this;
  317. let list = that.list;
  318. let limit = that.limit;
  319. if (that.total > list.length) {
  320. uni.showLoading({
  321. title: '加载中',
  322. mask: true
  323. })
  324. let page = that.page + 1;
  325. that.$set(that, `page`, page)
  326. let skip = page * limit;
  327. that.$set(that, `skip`, skip)
  328. that.search();
  329. uni.hideLoading();
  330. } else that.$set(that, `is_bottom`, true)
  331. },
  332. toScroll(e) {
  333. const that = this;
  334. let up = that.scrollTop;
  335. that.$set(that, `scrollTop`, e.detail.scrollTop);
  336. let num = Math.sign(up - e.detail.scrollTop);
  337. if (num == 1) that.$set(that, `is_bottom`, false);
  338. },
  339. // 清空列表
  340. clearPage() {
  341. const that = this;
  342. that.$set(that, `list`, [])
  343. that.$set(that, `skip`, 0)
  344. that.$set(that, `limit`, 6)
  345. that.$set(that, `page`, 0)
  346. }
  347. }
  348. }
  349. </script>
  350. <style lang="scss" scoped>
  351. .main {
  352. display: flex;
  353. flex-direction: column;
  354. width: 100vw;
  355. height: 100vh;
  356. .one {
  357. padding: 2vw;
  358. input {
  359. padding: 2vw;
  360. background-color: var(--f1Color);
  361. font-size: var(--font14Size);
  362. border-radius: 5px;
  363. }
  364. }
  365. .two {
  366. position: relative;
  367. flex-grow: 1;
  368. background-color: var(--f9Color);
  369. .tabsList {
  370. position: relative;
  371. width: 100vw;
  372. height: 82vh;
  373. .list:first-child {
  374. margin: 2vw;
  375. }
  376. .list {
  377. background-color: var(--mainColor);
  378. border: 1px solid var(--f5Color);
  379. padding: 2vw;
  380. margin: 0 2vw 2vw 2vw;
  381. border-radius: 5px;
  382. .list_1 {
  383. padding: 2vw 0;
  384. font-size: var(--font16Size);
  385. .top {
  386. width: 100%;
  387. display: flex;
  388. justify-content: space-between;
  389. .left {
  390. display: flex;
  391. align-items: center;
  392. .image {
  393. width: 8vw;
  394. height: 8vw;
  395. border-radius: 8vw;
  396. }
  397. text {
  398. padding: 0 0 0 2vw;
  399. }
  400. }
  401. .right {
  402. font-size: var(--font14Size);
  403. color: var(--fF0Color);
  404. }
  405. }
  406. .center {
  407. width: 100%;
  408. display: flex;
  409. justify-content: space-between;
  410. margin: 2vw 0 0 0;
  411. .left {
  412. width: 20vw;
  413. .image {
  414. width: 20vw;
  415. height: 20vw;
  416. border-radius: 1vw;
  417. }
  418. }
  419. .right {
  420. width: 70vw;
  421. margin: 0 0 0 2vw;
  422. .name {
  423. font-size: var(--font14Size);
  424. }
  425. .other {
  426. padding: 2px 0 0 0;
  427. font-size: var(--font12Size);
  428. color: var(--f85Color);
  429. }
  430. }
  431. }
  432. }
  433. .bottom {
  434. text-align: center;
  435. padding: 1vw 0;
  436. button {
  437. margin: 0 5px 0 0;
  438. }
  439. }
  440. }
  441. }
  442. }
  443. .canvas {
  444. padding: 2vw;
  445. .qrcode {
  446. width: 200px;
  447. height: 200px;
  448. }
  449. }
  450. }
  451. .scroll-view {
  452. position: absolute;
  453. top: 0;
  454. left: 0;
  455. right: 0;
  456. bottom: 0;
  457. .list-scroll-view {
  458. display: flex;
  459. flex-direction: column;
  460. }
  461. }
  462. .is_bottom {
  463. width: 100%;
  464. text-align: center;
  465. text {
  466. padding: 2vw 0;
  467. display: inline-block;
  468. color: var(--f85Color);
  469. font-size: var(--font14Size);
  470. }
  471. }
  472. </style>