accessoryList.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <view class="scheme">
  3. <u-list class="listContent">
  4. <view v-for="(item, index) in tableList" :key="index" style="position: relative;">
  5. <myCard :item="item" @del="del(index)" @edit="add('edit',item,index)" :index="index+1"
  6. :columns="columns" :btnList="btnData">
  7. <u--input :disabled="isDisable" placeholder="请输入" type="number"
  8. @input="(val) =>inputChange(val,'totalCount',index)" slot="totalCount"
  9. v-model="item.totalCount">
  10. </u--input>
  11. <u--input :disabled="isDisable" placeholder="请输入" type="number" @input="(val) =>inputChange(val,'singlePrice',index)"
  12. slot="singlePrice" v-model="item.singlePrice">
  13. </u--input>
  14. </myCard>
  15. </view>
  16. </u-list>
  17. <view class="add" @click="add('add')" v-if="type != 'view'">
  18. <u-icon name="plus" color="#fff"></u-icon>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import myCard from '@/pages/saleManage/components/myCard.vue';
  24. import {
  25. getWarehouseOutStock,
  26. getIdWarehouseList
  27. } from '@/api/salesServiceManagement/workOrder/index.js';
  28. export default {
  29. components: {
  30. myCard
  31. },
  32. props: {
  33. type: {
  34. type: String,
  35. default: 'edit'
  36. },
  37. itemList: {
  38. type: Array,
  39. default: () => []
  40. },
  41. title: {
  42. type: String,
  43. default: ''
  44. }
  45. },
  46. watch: {
  47. itemList: {
  48. handler(newVal) {
  49. let list = JSON.parse(JSON.stringify(newVal));
  50. this.tableList = list;
  51. },
  52. deep: true,
  53. immediate: true
  54. }
  55. },
  56. data() {
  57. return {
  58. columns: [
  59. [{
  60. label: '物品名称:',
  61. prop: 'categoryName',
  62. type: 'title',
  63. className: 'perce100',
  64. }],
  65. [{
  66. label: '物品编码:',
  67. prop: 'categoryCode'
  68. }],
  69. [{
  70. label: '型号:',
  71. prop: 'categoryModel'
  72. }, {
  73. label: '规格:',
  74. prop: 'specification',
  75. }],
  76. [{
  77. label: '级别:',
  78. prop: 'level',
  79. }],
  80. [{
  81. label: '数量:',
  82. prop: 'totalCount',
  83. slot: 'totalCount',
  84. }],
  85. [{
  86. label: '单价:',
  87. prop: 'singlePrice',
  88. slot: 'singlePrice',
  89. }],
  90. [{
  91. label: '总价:',
  92. prop: 'totalPrice'
  93. }],
  94. [{
  95. label: '计量单位:',
  96. prop: 'measureUnit'
  97. }],
  98. [{
  99. label: '仓库:',
  100. prop: 'warehouseName'
  101. }],
  102. [{
  103. label: '操作:',
  104. prop: 'action',
  105. type: 'action',
  106. className: 'perce100',
  107. }],
  108. ],
  109. btnList: [{
  110. name: '删除',
  111. apiName: 'del',
  112. btnType: 'primary',
  113. type: '2',
  114. pageUrl: '',
  115. }],
  116. tableList: []
  117. }
  118. },
  119. computed: {
  120. // 按钮
  121. btnData() {
  122. if (this.type == 'view') {
  123. return []
  124. }
  125. return this.btnList;
  126. },
  127. isDisable() {
  128. return this.type === 'view'
  129. }
  130. },
  131. created() {
  132. uni.$off('updateAddessory');
  133. uni.$on('updateAddessory', (data) => {
  134. let obj = {}
  135. this.tableList.map((el) => {
  136. obj[el.categoryCode] = true
  137. });
  138. data.map((el) => {
  139. if (!obj[el.categoryCode]) {
  140. this.tableList.push(el);
  141. }
  142. })
  143. })
  144. },
  145. onShow() {
  146. },
  147. methods: {
  148. add() {
  149. let dataSources = this.title == '配件回收清单' ? '1' : '0';
  150. uni.navigateTo({
  151. url: `/pages/salesServiceManagement/workOrder/components/accessoryAdd?dataSources=${dataSources}`
  152. })
  153. },
  154. del(index) {
  155. uni.showModal({
  156. title: '确认删除',
  157. content: '确定要删除所选配件数据吗?',
  158. confirmText: '删除',
  159. confirmColor: '#FF4D4F',
  160. success: (res) => {
  161. if (res.confirm) {
  162. this.tableList.splice(index, 1)
  163. } else if (res.cancel) {
  164. // 用户点击了取消按钮
  165. console.log('用户取消删除');
  166. }
  167. }
  168. });
  169. },
  170. inputChange(e, field, index) {
  171. let value = '';
  172. if (field == 'singlePrice') {
  173. value = e.replace(/[^\d.]/g, '');
  174. const parts = value.split('.');
  175. if (parts.length > 2) {
  176. value = parts[0] + '.' + parts.slice(1).join('');
  177. }
  178. if (value.startsWith('0') && value.length > 1 && value[1] !== '.') {
  179. value = value.replace(/^0+/, '');
  180. }
  181. } else {
  182. value = e.replace(/[^\d]/g, '')
  183. if (value.startsWith('0') && value.length > 1) {
  184. value = value.replace(/^0+/, '');
  185. }
  186. }
  187. let obj = this.tableList[index];
  188. obj[field] = value;
  189. let num1 = obj.totalCount ? obj.totalCount - 0 : 0;
  190. let num2 = obj.singlePrice ? obj.singlePrice - 0 : 0;
  191. let total = (num1 * num2).toFixed(1);
  192. obj.totalPrice = total;
  193. },
  194. getTabData() {
  195. return this.tableList || [];
  196. }
  197. }
  198. }
  199. </script>
  200. <style lang="scss" scoped>
  201. @import url('@/pages/salesServiceManagement/demandList/components/invoice.scss');
  202. .scheme {
  203. padding: 10rpx 20rpx 88rpx;
  204. }
  205. .add {
  206. width: 96rpx;
  207. height: 96rpx;
  208. border-radius: 48rpx;
  209. background: #3c9cff;
  210. position: fixed;
  211. bottom: 100rpx;
  212. right: 24rpx;
  213. display: flex;
  214. align-items: center;
  215. justify-content: center;
  216. }
  217. </style>