goods-card.vue 13 KB

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