accessoryList.vue 4.7 KB

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