fakeRegistration.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div class="fake_registration">
  3. <u-navbar class="nav-bar" title="假货登记" :autoBack="true" :placeholder="true" v-hideNav></u-navbar>
  4. <view class="fake_table_wrap">
  5. <view class="btn_wrap">
  6. <u-button :type="(!isAdd && !isEdit) ? 'primary' : 'error'" :icon="(!isAdd && !isEdit) ? 'plus' : 'close'"
  7. size="mini" :text="(!isAdd && !isEdit) ? '新增' : '取消'"
  8. @click="(!isAdd && !isEdit) ? handleAdd() : handleCancle()"></u-button>
  9. <u-button v-if="isAdd || isEdit" type="primary" size="mini" icon="checkmark" text="确定"
  10. @click="handleSubmit"></u-button>
  11. </view>
  12. <view class="custom-table__body">
  13. <Table ref="customTable" :tableData="tableData" :columns="columns" stripe @loadMore="handleLoadMore">
  14. <template #cell-name="{ row, rowIndex }">
  15. <view v-double-tap="() => editCell(row, rowIndex)">
  16. <u--input v-if="row.edit" border="surround" v-model="row.name"></u--input>
  17. <view v-else>{{ row.name }}</view>
  18. </view>
  19. </template>
  20. <template #cell-idCard="{ row, rowIndex }">
  21. <view v-double-tap="() => editCell(row, rowIndex)">
  22. <u--input v-if="row.edit" border="surround" v-model="row.idCard"></u--input>
  23. <view v-else>{{ row.idCard }}</view>
  24. </view>
  25. </template>
  26. <template #cell-phone="{ row, rowIndex }">
  27. <view v-double-tap="() => editCell(row, rowIndex)"">
  28. <u--input v-if="row.edit" border="surround" v-model="row.phone"></u--input>
  29. <view v-else>{{ row.phone }}</view>
  30. </view>
  31. </template>
  32. <template #cell-itemName="{ row, rowIndex }">
  33. <view v-double-tap="() => editCell(row, rowIndex)"">
  34. <u--input v-if="row.edit" border="surround" v-model="row.itemName"></u--input>
  35. <view v-else>{{ row.itemName }}</view>
  36. </view>
  37. </template>
  38. <template #cell-remark="{ row, rowIndex }">
  39. <view v-double-tap="() => editCell(row, rowIndex)"">
  40. <u--input v-if="row.edit" border="surround" v-model="row.remark"></u--input>
  41. <view v-else>{{ row.remark }}</view>
  42. </view>
  43. </template>
  44. </Table>
  45. </view>
  46. </view>
  47. </div>
  48. </template>
  49. <script>
  50. import Table from '@/components/custom-table/index.vue'
  51. export default {
  52. name: 'FakeRegistration',
  53. components: {
  54. Table
  55. },
  56. data() {
  57. return {
  58. tableData: [],
  59. columns: [
  60. { label: '姓名', prop: 'name', isRequire: true },
  61. { label: '身份证号', prop: 'idCard', isRequire: true},
  62. { label: '电话', prop: 'phone', isRequire: true },
  63. { label: '物品', prop: 'itemName', isRequire: true },
  64. { label: '备注', prop: 'remark' },
  65. ],
  66. isAdd: false,
  67. isEdit: false,
  68. editIndex: null,
  69. pageNum: 1,
  70. pageSize: 10,
  71. total:0
  72. }
  73. },
  74. mounted() {
  75. this.getWareHouseFakeList()
  76. },
  77. methods: {
  78. handleLoadMore() {
  79. if (this.pageNum * this.pageSize >= this.total) {
  80. uni.$u.toast('没有更多数据了')
  81. return
  82. }
  83. this.pageNum++
  84. this.getWareHouseFakeList()
  85. },
  86. getWareHouseFakeList() {
  87. uni.$u.api.wareHouseFakeList({
  88. pageNum: this.pageNum,
  89. pageSize: this.pageSize,
  90. }).then(res => {
  91. if(this.pageNum == 1){
  92. this.tableData = res.rows
  93. }else{
  94. this.tableData = this.tableData.concat(res.rows)
  95. }
  96. this.total = res.total
  97. })
  98. },
  99. editCell(row, rowIndex) {
  100. this.editIndex = rowIndex
  101. this.$set(this.tableData[rowIndex], 'edit', true);
  102. this.isEdit = true
  103. },
  104. handleSubmit() {
  105. if (this.isAdd) {
  106. if (this.checkEmpty(this.tableData[0])) {
  107. uni.$u.api.wareHouseFakeAdd(this.tableData[0]).then(res => {
  108. if (res.code == 200) {
  109. this.$set(this.tableData[0], 'edit', false)
  110. this.isAdd = false
  111. uni.$u.toast('新增成功')
  112. }
  113. })
  114. }
  115. }
  116. if (this.isEdit) {
  117. if (this.checkEmpty(this.tableData[this.editIndex])) {
  118. uni.$u.api.wareHouseFakeEdit(this.tableData[this.editIndex]).then(res => {
  119. if (res.code == 200) {
  120. this.$set(this.tableData[this.editIndex], 'edit', false)
  121. this.isEdit = false
  122. uni.$u.toast('编辑成功')
  123. }
  124. })
  125. }
  126. }
  127. },
  128. checkEmpty(row) {
  129. if (row.name == '') {
  130. uni.$u.toast('请输入姓名')
  131. return false
  132. }
  133. if (row.idCard == '') {
  134. uni.$u.toast('请输入身份证号')
  135. return false
  136. }
  137. if (row.phone == '') {
  138. uni.$u.toast('请输入电话')
  139. return false
  140. }
  141. if (row.itemName == '') {
  142. uni.$u.toast('请输入物品')
  143. return false
  144. }
  145. return true
  146. },
  147. addNewRow() {
  148. this.$refs.customTable.addNewRow();
  149. },
  150. handleUpdate(data) {
  151. console.log('数据更新:', data);
  152. },
  153. handleAdd() {
  154. this.tableData.unshift({
  155. edit: true,
  156. name: '',
  157. idCard: '',
  158. phone: '',
  159. itemName: '',
  160. remark: ''
  161. })
  162. this.isAdd = true
  163. },
  164. handleCancle() {
  165. if (this.isAdd) {
  166. this.tableData.shift(1)
  167. this.isAdd = false
  168. }
  169. if (this.isEdit) {
  170. this.$set(this.tableData[this.editIndex], 'edit', false)
  171. this.isEdit = false
  172. }
  173. },
  174. }
  175. }
  176. </script>
  177. <style lang="scss" scoped>
  178. @import '../styles/fakeRegistration.scss';
  179. </style>