record-order.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <view class="record-order">
  3. <custom-nav ref="ltm" :title="title" color @rTap="hisOrders">
  4. <text style="margin-right: 16px;">历史记录</text>
  5. </custom-nav>
  6. <w-picker ref="Selector" mode="selector" themeColor="#F76454" :selectList="typeList" @confirm="onConfirm" />
  7. <view class="content">
  8. <view class="app-item picker" @tap="choosePicker">
  9. <text class="title">商品款式</text>
  10. <text class="name">{{ choosedIndex === -1 ? '请选择要录入商品名称' : typeList[choosedIndex].label }}</text>
  11. <text class="cuIcon-right"></text>
  12. </view>
  13. <view class="app-item">
  14. <text>数量</text>
  15. <custom-counter v-model="choosedNum" />
  16. </view>
  17. <view class="app-item item-space">
  18. <text>总计金额</text>
  19. <input type="number" maxlength="7" v-model="money" placeholder="请输入订单金额" />
  20. </view>
  21. <view class="big-btn bg" @tap="record">录入订单</view>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import { _API_GoodList } from '@/apis/good.js'
  27. import { _API_FortuneRecordOrder } from '@/apis/fortune.js'
  28. import WPicker from '@/components/w-picker/w-picker.vue'
  29. import customCounter from '../../components/public/custom-counter.vue'
  30. export default {
  31. components: { WPicker, customCounter },
  32. data() {
  33. return {
  34. title: '零售录单',
  35. typeList: [], // 可选的商品列表
  36. choosedIndex: -1, // 当前已选类型下标
  37. choosedNum: 0, // 商品数量
  38. goodId: '', // 商品id
  39. typeId: '' ,// type id,
  40. money: '', // 订单金额
  41. requesting: false // 是否正在网路请求
  42. }
  43. },
  44. mounted() { // 获取商品列表
  45. this.$refs.ltm.loading()
  46. _API_GoodList().then(res => {
  47. console.log(JSON.stringify(res.data.list, null, 2))
  48. res.data.list.forEach(good => {
  49. good.type.forEach((typeName, typeIndex) => this.typeList.push({
  50. id: good.id,
  51. type_id: good.type_id[typeIndex],
  52. label: good.name + '-' + typeName,
  53. value: good.name + '-' + typeName
  54. }))
  55. })
  56. })
  57. },
  58. methods: {
  59. hisOrders() { // 点击历史记录
  60. uni.navigateTo({ url: `../record-record/record-record?id=${this.$store.state.userinfo.id}` })
  61. },
  62. choosePicker() { // 点击选择商品
  63. this.$refs.Selector.show()
  64. },
  65. onConfirm(e) { // 点击提交选择
  66. this.choosedIndex = e.defaultVal[0]
  67. this.goodId = e.checkArr.id
  68. this.typeId = e.checkArr.type_id
  69. },
  70. record() { // 点击录入订单
  71. if (this.choosedIndex === -1) {
  72. this.$refs.ltm.toast('请您选择要录入的商品类型')
  73. return
  74. }
  75. if (+this.choosedNum === 0) {
  76. this.$refs.ltm.toast('请您选择要录入的商品数量')
  77. return
  78. }
  79. if (+this.money === 0) {
  80. this.$refs.ltm.toast('请您输入订单金额')
  81. return
  82. }
  83. if (!this.requesting) {
  84. this.$refs.ltm.loading()
  85. this.requesting = true
  86. _API_FortuneRecordOrder({
  87. id: this.goodId,
  88. type_id: this.typeId,
  89. num: this.choosedNum,
  90. total: this.money,
  91. }).then(res => {
  92. this.requesting = false
  93. this.choosedIndex = -1
  94. this.choosedNum = 0
  95. this.typeId = ''
  96. this.goodId = ''
  97. this.money = ''
  98. this.$refs.ltm.modal('提示', ['录单成功'], 'noCancle')
  99. })
  100. }
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="scss">
  106. .record-order {
  107. @include page();
  108. .content {
  109. .picker {
  110. display: block;
  111. height: 90rpx;
  112. width: 750rpx;
  113. text-align: center;
  114. line-height: 90rpx;
  115. .title {
  116. float: left;
  117. }
  118. .cuIcon-right {
  119. float: right;
  120. }
  121. }
  122. .app-item {
  123. font-size: 26rpx;
  124. }
  125. .big-btn {
  126. width: 480rpx;
  127. }
  128. .num {
  129. color: $app-base-color;
  130. }
  131. }
  132. }
  133. </style>