index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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.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'" 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. console.log(item);
  217. }
  218. }
  219. });
  220. },
  221. //券码
  222. async toFile(item) {
  223. const that = this;
  224. UQrcode.make({
  225. canvasId: 'qrcode', //切记canvasId 里边的内容需要跟canvas里边canvas-id="qrcode"的名字一样
  226. componentInstance: this,
  227. text: item._id,
  228. // text: `${that.$config.serverUrl}/oederInfo?id=${item._id}`, //跳转小程序指定页面
  229. size: 200,
  230. margin: 0,
  231. backgroundColor: '#ffffff',
  232. foregroundColor: '#000000',
  233. fileType: 'jpg',
  234. errorCorrectLevel: UQrcode.errorCorrectLevel.H,
  235. success: res => {}
  236. })
  237. that.$refs.popup.open();
  238. },
  239. //申请退款
  240. async toOut(item) {
  241. const that = this;
  242. uni.showModal({
  243. title: '提示',
  244. content: '确定申请退款吗?',
  245. success: async function(res) {
  246. if (res.confirm) {
  247. console.log(item);
  248. }
  249. }
  250. });
  251. },
  252. // 评价
  253. async toRate(item) {
  254. const that = this;
  255. console.log(item);
  256. },
  257. async searchOther() {
  258. const that = this;
  259. let res;
  260. //状态
  261. res = await that.$api('/dictData', 'GET', {
  262. type: 'order_status',
  263. is_use: '0'
  264. })
  265. if (res.errcode == '0') {
  266. that.$set(that, `statusList`, res.data);
  267. const menu = res.data.map((item) => {
  268. return {
  269. title: item.label,
  270. active: item.value
  271. }
  272. })
  273. menu.unshift({
  274. title: '全部',
  275. active: '-1'
  276. })
  277. that.$set(that.tabs, `menu`, menu)
  278. }
  279. },
  280. // 分页
  281. toPage(e) {
  282. const that = this;
  283. let list = that.list;
  284. let limit = that.limit;
  285. if (that.total > list.length) {
  286. uni.showLoading({
  287. title: '加载中',
  288. mask: true
  289. })
  290. let page = that.page + 1;
  291. that.$set(that, `page`, page)
  292. let skip = page * limit;
  293. that.$set(that, `skip`, skip)
  294. that.search();
  295. uni.hideLoading();
  296. } else that.$set(that, `is_bottom`, true)
  297. },
  298. toScroll(e) {
  299. const that = this;
  300. let up = that.scrollTop;
  301. that.$set(that, `scrollTop`, e.detail.scrollTop);
  302. let num = Math.sign(up - e.detail.scrollTop);
  303. if (num == 1) that.$set(that, `is_bottom`, false);
  304. },
  305. // 清空列表
  306. clearPage() {
  307. const that = this;
  308. that.$set(that, `list`, [])
  309. that.$set(that, `skip`, 0)
  310. that.$set(that, `limit`, 6)
  311. that.$set(that, `page`, 0)
  312. }
  313. }
  314. }
  315. </script>
  316. <style lang="scss" scoped>
  317. .main {
  318. display: flex;
  319. flex-direction: column;
  320. width: 100vw;
  321. height: 100vh;
  322. .one {
  323. padding: 2vw;
  324. input {
  325. padding: 2vw;
  326. background-color: var(--f1Color);
  327. font-size: var(--font14Size);
  328. border-radius: 5px;
  329. }
  330. }
  331. .two {
  332. position: relative;
  333. flex-grow: 1;
  334. background-color: var(--f9Color);
  335. .tabsList {
  336. position: relative;
  337. width: 100vw;
  338. height: 82vh;
  339. .list {
  340. background-color: var(--mainColor);
  341. border: 1px solid var(--f5Color);
  342. padding: 2vw;
  343. margin: 0 2vw 2vw 2vw;
  344. border-radius: 5px;
  345. .list_1 {
  346. padding: 2vw 0;
  347. font-size: var(--font16Size);
  348. .top {
  349. width: 100%;
  350. display: flex;
  351. justify-content: space-between;
  352. .left {
  353. display: flex;
  354. align-items: center;
  355. .image {
  356. width: 8vw;
  357. height: 8vw;
  358. border-radius: 8vw;
  359. }
  360. text {
  361. padding: 0 0 0 2vw;
  362. }
  363. }
  364. .right {
  365. font-size: var(--font14Size);
  366. color: var(--fF0Color);
  367. }
  368. }
  369. .center {
  370. width: 100%;
  371. display: flex;
  372. justify-content: space-between;
  373. margin: 2vw 0 0 0;
  374. .left {
  375. width: 20vw;
  376. .image {
  377. width: 20vw;
  378. height: 20vw;
  379. border-radius: 1vw;
  380. }
  381. }
  382. .right {
  383. width: 70vw;
  384. margin: 0 0 0 2vw;
  385. .name {
  386. font-size: var(--font14Size);
  387. }
  388. .other {
  389. padding: 2px 0 0 0;
  390. font-size: var(--font12Size);
  391. color: var(--f85Color);
  392. }
  393. }
  394. }
  395. }
  396. .bottom {
  397. text-align: center;
  398. padding: 1vw 0;
  399. button {
  400. margin: 0 5px 0 0;
  401. }
  402. }
  403. }
  404. }
  405. }
  406. .canvas {
  407. padding: 2vw;
  408. .qrcode {
  409. width: 200px;
  410. height: 200px;
  411. }
  412. }
  413. }
  414. .scroll-view {
  415. position: absolute;
  416. top: 0;
  417. left: 0;
  418. right: 0;
  419. bottom: 0;
  420. .list-scroll-view {
  421. display: flex;
  422. flex-direction: column;
  423. }
  424. }
  425. .is_bottom {
  426. width: 100%;
  427. text-align: center;
  428. text {
  429. padding: 2vw 0;
  430. display: inline-block;
  431. color: var(--f85Color);
  432. font-size: var(--font14Size);
  433. }
  434. }
  435. </style>