more.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view class="app-content">
  3. <view v-if="!$util.isEmpty(list.data)" style="padding-bottom:120upx;">
  4. <t-table :headerBackgroundColor="'#F0F2F6'">
  5. <t-tr header>
  6. <t-th>名称</t-th>
  7. <t-th>排序</t-th>
  8. <t-th>保持期(天)</t-th>
  9. </t-tr>
  10. <view v-for="(item, index) in list.data" :key="index">
  11. <t-tr>
  12. <t-td align="center" color="info"><view>{{item.name}}</view></t-td>
  13. <t-td align="center" color="info">
  14. <view><input v-model="item.inTurn" @focus="item.inTurn=''" name="inTurn" type="number" style="border:1upx solid #cccccc;" /></view>
  15. </t-td>
  16. <t-td align="center" color="info">
  17. <view><input v-model="item.shelfLife" @focus="item.shelfLife=''" name="shelfLife" type="digit" style="border:1upx solid #cccccc;" /></view>
  18. </t-td>
  19. </t-tr>
  20. </view>
  21. </t-table>
  22. </view>
  23. <view v-else>
  24. <AppWrapperEmpty title="暂无数据" :is-empty="$util.isEmpty(list.data)" />
  25. </view>
  26. <view class="app-footer">
  27. <view class="admin-button-com middle blue" @click="showBatchUpdate('add')">整列累加</view>
  28. <view style="margin-left:20upx;" class="admin-button-com middle blue" @click="showBatchUpdate('update')">整列改为</view>
  29. <view style="margin-left:20upx;" class="admin-button-com middle blue" @click="savePrice">全部保存</view>
  30. </view>
  31. <modal-module :show="batchModel" @click="affirmBatch" title="批量操作" color="#333" :size="32" padding="30upx 30upx" >
  32. <template slot="customContent">
  33. <view class="select-cmd_bx">
  34. <view class="num_bx" style="margin:60upx 0 60upx 0;font-size:35upx;">
  35. <view class="flex">数值:<input v-model="batchNum" type="digit" style="border:1upx solid #CCCCCC;height:60upx;" /></view>
  36. </view>
  37. </view>
  38. </template>
  39. </modal-module>
  40. </view>
  41. </template>
  42. <script>
  43. import AppWrapperEmpty from "@/components/app-wrapper-empty";
  44. import { productList,batchChangeMore } from '@/api/product'
  45. import list from '@/mixins/list'
  46. import ModalModule from "@/components/plugin/modal";
  47. export default {
  48. name: "more",
  49. components: {
  50. AppWrapperEmpty,ModalModule
  51. },
  52. mixins:[list],
  53. data() {
  54. return {
  55. batchModel:false,
  56. batchStyle:'add',
  57. batchNum:'',
  58. focusOn:false,
  59. levelIndex:0
  60. };
  61. },
  62. methods: {
  63. showBatchUpdate(styleInfo){
  64. if (this.$util.isEmpty(this.list.data)){
  65. this.$msg('没有花材')
  66. return false
  67. }
  68. this.batchStyle = styleInfo
  69. let self = this
  70. let levelList = ['请选择列:','排序', '保持期']
  71. uni.showActionSheet({
  72. itemList: levelList,
  73. success: function (respond) {
  74. self.levelIndex = respond.tapIndex
  75. self.batchModel = true
  76. }
  77. })
  78. },
  79. affirmBatch(val) {
  80. let that = this
  81. if (val.index === 0) {
  82. this.batchNum = ''
  83. this.batchModel = false;
  84. } else {
  85. if(this.$util.isMoney(this.batchNum) == false){
  86. this.$msg('请填写数值')
  87. return false
  88. }
  89. let currentNum = Number(this.batchNum)
  90. this.list.data.forEach(function(value,index,array){
  91. if(that.batchStyle =='add'){
  92. if(that.levelIndex == 1){
  93. array[index].inTurn = parseFloat((Number(array[index].inTurn) + currentNum).toFixed(2))
  94. }else if(that.levelIndex == 2){
  95. array[index].shelfLife = parseFloat((Number(array[index].shelfLife) + currentNum).toFixed(2))
  96. }else{
  97. }
  98. }else{
  99. if(that.levelIndex == 1){
  100. array[index].inTurn = parseFloat((currentNum).toFixed(2))
  101. }else if(that.levelIndex == 2){
  102. array[index].shelfLife = parseFloat((currentNum).toFixed(2))
  103. }else{
  104. }
  105. }
  106. });
  107. this.batchNum = ''
  108. this.batchModel = false;
  109. }
  110. },
  111. savePrice(){
  112. let that = this
  113. let addData = [];
  114. uni.showLoading({mask:true})
  115. this.list.data.forEach(function(value,index,array){
  116. if(that.$util.isMoney(value.inTurn) == false){
  117. that.$msg('【'+value.name+'】的排序值填写错误')
  118. return false
  119. }
  120. if(that.$util.isMoney(value.shelfLife) == false){
  121. that.$msg('【'+value.name+'】的保持期填写错误')
  122. return false
  123. }
  124. addData.push({id:value.id,inTurn:value.inTurn,shelfLife:value.shelfLife})
  125. })
  126. let addString = JSON.stringify(addData)
  127. batchChangeMore({addData:addString}).then(res=>{
  128. uni.hideLoading()
  129. if(res.code == 1){
  130. setTimeout(function(){
  131. that.$msg(res.msg)
  132. },500)
  133. }
  134. })
  135. },
  136. async init(){
  137. const res = await productList({
  138. page:this.list.page,showPage:1,pageSize:2000,classId:this.option.classId
  139. })
  140. this.completes(res)
  141. }
  142. },
  143. async onPullDownRefresh() {
  144. this.resetList();
  145. await this.init()
  146. uni.stopPullDownRefresh();
  147. },
  148. async onReachBottom() {
  149. if (!this.list.finished) {
  150. await this.init()
  151. uni.stopPullDownRefresh();;
  152. } else {
  153. uni.stopPullDownRefresh();
  154. }
  155. },
  156. };
  157. </script>
  158. <style lang="scss" scoped>
  159. </style>