accessoryList.vue 6.1 KB

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