goods-card.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <view style="position: absolute;width: 100%;height: 100%;top: 0;left: 0;background-color: #fff">
  3. <app-layout>
  4. <view class="title">{{list.length > 0 ? '已添加卡券' : '未添加卡券'}}</view>
  5. <view class="card-list">
  6. <view class='main-between card-item' v-for="(item,index) in list" :key="item.id">
  7. <view class='card-info dir-left-nowrap' style="width: 80%">
  8. <view @click="close(index)" class="card-img">
  9. <image src='./../image/low.png'></image>
  10. </view>
  11. <view @click="add(index,item)" class="t-omit">{{item.name}}</view>
  12. </view>
  13. <view>{{item.num}}</view>
  14. </view>
  15. </view>
  16. <view :class="['add main-between', `${iphone_x? 'iphone_x':''}`]">
  17. <view class="add-btn" @click="add">添加卡券</view>
  18. <view class="save-btn" @click="save">保存</view>
  19. </view>
  20. <view class="dialog" v-if="to_add">
  21. <view class="dialog-content">
  22. <view class="dialog-title">选择卡券</view>
  23. <view class="main-between choose-item">
  24. <view class='label'>选择卡券</view>
  25. <view @click='showDialog' class='cat-info dir-right-nowrap cross-center'>
  26. <image class="to-more" src='/static/image/icon/arrow-right.png'></image>
  27. <text class="t-omit" v-if="beCard && beCard.id > 0">{{beCard.name}}</text>
  28. <text v-else>未选择</text>
  29. </view>
  30. </view>
  31. <view class="main-between choose-item" style="border-bottom: 0">
  32. <view class='label'>填写张数(张)</view>
  33. <input type="number" maxlength="3" class="number-input" v-model="num">
  34. </view>
  35. <view class="main-center btn-area">
  36. <view class="submit-btn" @click='cancel'>取消</view>
  37. <view class="line"></view>
  38. <view class="submit-btn be-submit" @click='submit'>确认</view>
  39. </view>
  40. </view>
  41. </view>
  42. <view :class="['dialog', `${iphone_x?'iphone_x':''}`]" v-if="dialog">
  43. <view class="picker-list">
  44. <view class="main-between picker-header">
  45. <view @click="toggle">取消</view>
  46. <view @click="toggle(1)">确定</view>
  47. </view>
  48. <picker-view class="picker" :value="[newIndex]" @change="bindChange">
  49. <picker-view-column>
  50. <view
  51. v-for="(item,idx) in card" :key="item.id"
  52. :class="[`picker-item`,{
  53. 'sure-color': newIndex == idx,
  54. 'cardinal-color': newIndex == idx + 1 || newIndex == idx - 1,
  55. 'even-color': newIndex == idx + 2 || newIndex == idx - 2,
  56. }]">
  57. {{item.name}}
  58. </view>
  59. </picker-view-column>
  60. </picker-view>
  61. </view>
  62. </view>
  63. </app-layout>
  64. </view>
  65. </template>
  66. <script>
  67. import { mapState } from "vuex";
  68. export default {
  69. data() {
  70. return {
  71. iphone_x: false,
  72. card: [],
  73. list: [],
  74. modal: false,
  75. page_loading: true,
  76. to_add: false,
  77. num: 1,
  78. beCard: null,
  79. index: -1,
  80. dialog: false,
  81. newIndex: 0,
  82. }
  83. },
  84. computed: {
  85. ...mapState({
  86. userInfo: state => state.user.info,
  87. adminImg: state => state.mallConfig.__wxapp_img.app_admin
  88. })
  89. },
  90. methods: {
  91. showDialog() {
  92. this.dialog = !this.dialog;
  93. },
  94. getCard() {
  95. let that = this;
  96. that.$request({
  97. url: that.$api.app_admin.card,
  98. }).then(response=>{
  99. that.$hideLoading();
  100. if(response.code === 0) {
  101. that.cat = response.data.list;
  102. }else {
  103. uni.showToast({
  104. title: response.msg,
  105. icon: 'none',
  106. duration: 1000
  107. });
  108. }
  109. }).catch(() => {
  110. that.$hideLoading();
  111. });
  112. },
  113. bindChange(e) {
  114. this.newIndex = e.detail.value[0];
  115. },
  116. toggle(status) {
  117. this.dialog = false;
  118. if (status == 1) {
  119. this.beCard = this.card[this.newIndex];
  120. this.newIndex = 0;
  121. }
  122. },
  123. close(index) {
  124. this.list.splice(index, 1);
  125. },
  126. submit() {
  127. if (this.beCard != null) {
  128. this.beCard.num = this.num;
  129. if(this.index > -1) {
  130. this.list[this.index] = this.beCard;
  131. }else {
  132. this.list.push(this.beCard);
  133. }
  134. this.num = null;
  135. this.to_add = false;
  136. }else {
  137. uni.showToast({
  138. title: '请选择卡券',
  139. icon: 'none',
  140. duration: 1000
  141. });
  142. }
  143. },
  144. save() {
  145. this.$storage.setStorageSync('goods_card', this.list);
  146. setTimeout(function() {
  147. uni.navigateBack();
  148. }, 500);
  149. },
  150. cancel() {
  151. this.to_add = false;
  152. this.beCard = null;
  153. },
  154. add(index,item) {
  155. this.$request({
  156. url: this.$api.app_admin.card,
  157. }).then(response => {
  158. this.$hideLoading();
  159. if(response.code === 0) {
  160. let card = response.data.list;
  161. this.num = 1;
  162. if (card.length > 0) {
  163. this.to_add = true;
  164. if(index > -1) {
  165. this.beCard = this.list[index];
  166. this.num = item.num;
  167. this.index = index;
  168. for(let i in card) {
  169. if(card[i].id == this.beCard.id) {
  170. this.newIndex = i;
  171. }
  172. }
  173. }else {
  174. this.index = -1;
  175. this.newIndex = 0;
  176. this.beCard = null;
  177. }
  178. } else {
  179. uni.showToast({
  180. title: '暂无可添加卡券',
  181. icon: 'none',
  182. duration: 1000
  183. });
  184. }
  185. this.card = card;
  186. }else {
  187. uni.showToast({
  188. title: response.msg,
  189. icon: 'none',
  190. duration: 1000
  191. });
  192. }
  193. }).catch(() => {
  194. this.$hideLoading();
  195. });
  196. },
  197. },
  198. onLoad() { this.$commonLoad.onload();
  199. let that = this;
  200. that.$showLoading({
  201. type: 'global',
  202. text: '加载中...'
  203. });
  204. this.list = this.$storage.getStorageSync('goods_card') ? this.$storage.getStorageSync('goods_card') : [];
  205. uni.getSystemInfo({
  206. success: function (res) {
  207. if(res.model.indexOf('iPhone X') > -1 || res.model.indexOf('iPhone 11') > -1 || res.model.indexOf('iPhone11') > -1 || res.model.indexOf('iPhone12') > -1 || res.model.indexOf('Unknown Device') > -1) {
  208. that.iphone_x = true;
  209. }
  210. }
  211. })
  212. that.getCard();
  213. }
  214. }
  215. </script>
  216. <style scoped lang="scss">
  217. .title {
  218. font-size: #{32rpx};
  219. color: #999999;
  220. padding-top: #{36rpx};
  221. background-color: #fff;
  222. text-align: center;
  223. }
  224. .add.iphone_x {
  225. height: #{170rpx};
  226. padding-bottom: #{50rpx};
  227. }
  228. .add {
  229. height: #{120rpx};
  230. padding: 0 #{24rpx};
  231. margin: 0 auto;
  232. position: fixed;
  233. bottom: 0;
  234. left: 0;
  235. right: 0;
  236. border-top: #{2rpx} solid #e2e2e2;
  237. background-color: #fff;
  238. .add-btn {
  239. background-color: #fff;
  240. color: #446dfd;
  241. border: #{2rpx} solid #446dfd;
  242. }
  243. }
  244. .add>view {
  245. height: #{80rpx};
  246. width: #{300rpx};
  247. margin-top: #{20rpx};
  248. border-radius: #{40rpx};
  249. background-color: #446dfd;
  250. color: #fff;
  251. font-size: #{28rpx};
  252. text-align: center;
  253. line-height: #{80rpx};
  254. }
  255. .card-item {
  256. height: #{64rpx};
  257. line-height: #{40rpx};
  258. padding-bottom: #{24rpx};
  259. font-size: #{32rpx};
  260. background-color: #fff;
  261. }
  262. .card-list {
  263. background-color: #fff;
  264. padding: #{40rpx};
  265. padding-bottom: #{120rpx};
  266. overflow: auto;
  267. }
  268. .card-info {
  269. color: #353535;
  270. }
  271. .card-img {
  272. height: #{40rpx};
  273. width: #{40rpx};
  274. margin-right: #{20rpx};
  275. }
  276. .card-img image {
  277. height: #{40rpx};
  278. width: #{40rpx};
  279. }
  280. .cat-info {
  281. width: #{300rpx};
  282. color: #666;
  283. font-size: #{28rpx};
  284. padding-right: #{8rpx};
  285. }
  286. .to-more {
  287. height: #{24rpx};
  288. width: #{12rpx};
  289. margin-left: #{10rpx};
  290. }
  291. .label {
  292. width: #{240rpx};
  293. font-size: #{28rpx};
  294. color: #353535;
  295. text-align: left;
  296. padding-left: #{8rpx};
  297. }
  298. .dialog {
  299. position: fixed;
  300. height: 100%;
  301. width: 100%;
  302. bottom: 0;
  303. left: 0;
  304. z-index: 9999;
  305. background-color: rgba(0, 0, 0, .3);
  306. }
  307. .dialog.iphone_x .picker-list{
  308. padding-bottom: #{50rpx};
  309. }
  310. .picker {
  311. width: 100%;
  312. height: #{440rpx};
  313. color:#999999;
  314. }
  315. .dialog.iphone_x .picker{
  316. height:#{490rpx};
  317. }
  318. .picker-list {
  319. background-color: #fff;
  320. padding-top: #{20rpx};
  321. position: fixed;
  322. bottom: 0;
  323. left: 0;
  324. width: 100%;
  325. z-index: 9999;
  326. }
  327. .picker-header {
  328. padding: 0 #{24rpx};
  329. color: #446dfd;
  330. font-size: #{32rpx};
  331. }
  332. .dialog-title {
  333. font-size: #{32rpx};
  334. color: #353535;
  335. margin: 0 auto #{30rpx};
  336. text-align: center;
  337. }
  338. .dialog-content {
  339. margin: 40% auto;
  340. padding-top: #{35rpx};
  341. width: #{620rpx};
  342. border-radius: #{16rpx};
  343. background-color: #fff;
  344. .choose-item {
  345. margin: 0 #{40rpx};
  346. height: #{90rpx};
  347. line-height: #{90rpx};
  348. border-bottom: #{2rpx} solid #e2e2e2;
  349. input {
  350. height: #{90rpx};
  351. line-height: #{90rpx};
  352. font-size: #{28rpx};
  353. color: #666;
  354. }
  355. }
  356. }
  357. .submit-btn {
  358. height: #{88rpx};
  359. line-height: #{88rpx};
  360. font-size: #{32rpx};
  361. color: #666;
  362. width: #{310rpx};
  363. text-align: center;
  364. }
  365. .submit-btn.be-submit {
  366. color: #446dfd;
  367. }
  368. .btn-area {
  369. height: #{88rpx};
  370. position: relative;
  371. border-top: #{2rpx} solid #e2e2e2;
  372. width: 100%;
  373. margin-top: #{30rpx};
  374. }
  375. .btn-area .line {
  376. height: #{32rpx};
  377. width: #{1rpx};
  378. background-color: #e2e2e2;
  379. position: absolute;
  380. top: #{28rpx};
  381. left: 0;
  382. right: 0;
  383. margin: 0 auto;
  384. }
  385. .dialog {
  386. position: fixed;
  387. height: 100%;
  388. width: 100%;
  389. bottom: 0;
  390. left: 0;
  391. z-index: 9999;
  392. background-color: rgba(0, 0, 0, .3);
  393. }
  394. .picker-item {
  395. line-height: #{88rpx};
  396. font-size: #{32rpx};
  397. padding-left: #{24rpx};
  398. }
  399. .picker-item.sure-color {
  400. color: #446dfd;
  401. }
  402. .picker-item.cardinal-color {
  403. color: #999999;
  404. }
  405. .picker-item.even-color {
  406. color: #cdcdcd;
  407. }
  408. </style>