inventoryTable.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <template>
  2. <el-form ref="form" :model="form" :rules="rules">
  3. <ele-pro-table ref="table" :needPage="false" :columns="columns" :toolkit="[]" :datasource="form.datasource"
  4. cache-key="systemRoleTable17" class="time-form">
  5. <!-- 表头工具栏 -->
  6. <template v-slot:toolbar>
  7. <div class="headbox">
  8. <el-button size="small" type="primary" icon="el-icon-plus" class="ele-btn-icon" @click="handlAdd">
  9. 新增
  10. </el-button>
  11. <div class="pricebox">
  12. <span class="amount">总计:{{allPrice}}元</span>
  13. <span>优惠总金额:</span>
  14. <el-input v-model="discountTotalPrice" style="width:150px" placeholder="请输入" @input="discountInput" >
  15. <template slot="append">元</template></el-input>
  16. </div>
  17. </div>
  18. </template>
  19. <template v-slot:productName="{ row, $index }">
  20. <el-form-item style="margin-bottom: 20px;" :prop="'datasource.' + $index + '.productName'" :rules="{
  21. required: true,
  22. message: '请输入',
  23. trigger: 'change'
  24. }">
  25. <el-input v-model="row.productName" placeholder="请输入" @click.native="handParent(row, $index)"></el-input>
  26. </el-form-item>
  27. </template>
  28. <template v-slot:productCode="scope">
  29. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + scope.$index + '.productCode'" :rules="{
  30. required: true,
  31. message: '请输入',
  32. trigger: 'change'
  33. }">
  34. <el-input v-model="scope.row.productCode" disabled></el-input>
  35. </el-form-item>
  36. </template>
  37. <template v-slot:productCategoryName="scope">
  38. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + scope.$index + '.productCategoryName'" :rules="{
  39. required: true,
  40. message: '请输入',
  41. trigger: 'change'
  42. }">
  43. <el-input v-model="scope.row.productCategoryName" disabled ></el-input>
  44. </el-form-item>
  45. </template>
  46. <template v-slot:totalCount="scope">
  47. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + scope.$index + '.totalCount'" :rules="{
  48. required: true,
  49. pattern:numberReg,
  50. message: '请输入数字',
  51. trigger: 'blur'
  52. }">
  53. <el-input v-model="scope.row.totalCount" placeholder="请输入" @input="getTotalPrice"></el-input>
  54. </el-form-item>
  55. </template>
  56. <template v-slot:totalPrice="scope">
  57. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + scope.$index + '.totalPrice'" >
  58. {{(scope.row.totalCount*scope.row.singlePrice||0).toFixed(2)}}元
  59. </el-form-item>
  60. </template>
  61. <template v-slot:productBrand="scope">
  62. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + scope.$index + '.productBrand'">
  63. <el-input v-model="scope.row.productBrand" disabled></el-input>
  64. </el-form-item>
  65. </template>
  66. <template v-slot:modelType="scope">
  67. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + scope.$index + '.modelType'" >
  68. <el-input v-model="scope.row.modelType" disabled ></el-input>
  69. </el-form-item>
  70. </template>
  71. <template v-slot:specification="scope">
  72. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + scope.$index + '.specification'" >
  73. <el-input v-model="scope.row.specification" disabled></el-input>
  74. </el-form-item>
  75. </template>
  76. <template v-slot:deliveryDays="scope">
  77. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + scope.$index + '.deliveryDays'" :rules="{
  78. pattern:numberReg,
  79. message: '请输入数字',
  80. trigger: 'blur'
  81. }">
  82. <el-input v-model="scope.row.deliveryDays" placeholder="请输入"></el-input>
  83. </el-form-item>
  84. </template>
  85. <template v-slot:guaranteePeriod="scope">
  86. <div class="period">
  87. <div class="borderleftnone">
  88. <el-form-item style="margin-bottom: 20px;" :prop="'datasource.' + scope.$index + '.guaranteePeriod'" :rules="{
  89. pattern:numberReg,
  90. message: '请输入数字',
  91. trigger: 'blur'
  92. }">
  93. <el-input v-model="scope.row.guaranteePeriod" placeholder="请输入"></el-input>
  94. </el-form-item>
  95. </div>
  96. <div class="borderrightnone">
  97. <DictSelection dictName="质保期单位" clearable v-model="scope.row.guaranteePeriodUnitCode">
  98. </DictSelection>
  99. </div>
  100. </div>
  101. </template>
  102. <!-- <template v-slot:guaranteePeriodUnitCode="scope"> </template> -->
  103. <template v-slot:measuringUnit="scope">
  104. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + scope.$index + '.measuringUnit'">
  105. <el-input v-model="scope.row.measuringUnit" placeholder="请输入"></el-input>
  106. </el-form-item>
  107. </template>
  108. <template v-slot:remark="scope">
  109. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + scope.$index + '.remark'">
  110. <el-input v-model="scope.row.remark" type="textarea" placeholder="请输入"></el-input>
  111. </el-form-item>
  112. </template>
  113. <template v-slot:singlePrice="scope">
  114. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + scope.$index + '.singlePrice'" :rules="{
  115. required: true,
  116. pattern:numberReg,
  117. message: '请输入正确的单价',
  118. trigger: 'change'
  119. }">
  120. <el-input v-model="scope.row.singlePrice" placeholder="请输入" @input="getTotalPrice">
  121. <template slot="append">元</template>
  122. </el-input>
  123. </el-form-item>
  124. </template>
  125. <template v-slot:technicalAnswerName="{ row, $index }">
  126. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + $index + '.technicalAnswerName'">
  127. <el-input v-model="row.technicalAnswerName" placeholder="请输入" @click.native="handHead(row, $index)"></el-input>
  128. </el-form-item>
  129. </template>
  130. <template v-slot:technicalParams="scope">
  131. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + scope.$index + '.technicalParams'" >
  132. <el-input type="textarea" v-model="scope.row.technicalParams" placeholder="请输入"></el-input>
  133. </el-form-item>
  134. </template>
  135. <template v-slot:technicalDrawings="scope">
  136. <el-form-item style="margin-bottom: 20px" :prop="'datasource.' + scope.$index + '.technicalDrawings'" >
  137. <fileUpload
  138. v-model="scope.row.technicalDrawings"
  139. module="main"
  140. :showLib="false"
  141. :limit="5"
  142. />
  143. </el-form-item>
  144. </template>
  145. <!-- 操作列 -->
  146. <template v-slot:action="{ row }">
  147. <el-popconfirm class="ele-action" title="确定要删除吗?" @confirm="remove(row)">
  148. <template v-slot:reference>
  149. <el-link type="danger" :underline="false" icon="el-icon-delete">
  150. 删除
  151. </el-link>
  152. </template>
  153. </el-popconfirm>
  154. </template>
  155. </ele-pro-table>
  156. <product-list ref="productListRef" classType="1" @changeParent="changeParent"></product-list>
  157. <head-list ref="headRef" @changeParent="changeAnswer"></head-list>
  158. </el-form>
  159. </template>
  160. <script>
  161. import { emailReg, phoneReg,numberReg } from 'ele-admin';
  162. import productList from './product-list.vue'
  163. import dictMixins from '@/mixins/dictMixins';
  164. import store from '@/store';
  165. import fileUpload from '@/components/upload/fileUpload';
  166. import headList from '@/views/saleManage/businessOpportunity/components/headList.vue'
  167. export default {
  168. mixins: [dictMixins],
  169. components: {
  170. productList,
  171. fileUpload,
  172. headList
  173. },
  174. data() {
  175. const defaultForm = {
  176. key: null,
  177. endTime: '',
  178. isFirst: 0,
  179. name: '',
  180. startTime: '',
  181. workHour: '',
  182. technicalDrawings:[]
  183. };
  184. return {
  185. discountTotalPrice:0.00,
  186. allPrice:0.00,
  187. numberReg,
  188. defaultForm,
  189. form: {
  190. datasource: []
  191. },
  192. rules: {},
  193. columns: [
  194. {
  195. width: 45,
  196. type: 'index',
  197. columnKey: 'index',
  198. align: 'center',
  199. fixed: 'left'
  200. },
  201. {
  202. width: 200,
  203. prop: 'productName',
  204. label: '名称',
  205. slot: 'productName'
  206. },
  207. {
  208. width: 120,
  209. prop: 'productCode',
  210. label: '编码',
  211. slot: 'productCode'
  212. },
  213. {
  214. width: 200,
  215. prop: 'productCategoryName',
  216. label: '类型',
  217. slot: 'productCategoryName'
  218. },
  219. {
  220. width: 160,
  221. prop: 'productBrand',
  222. label: '牌号',
  223. slot: 'productBrand'
  224. },
  225. {
  226. width: 120,
  227. prop: 'modelType',
  228. label: '型号',
  229. slot: 'modelType'
  230. },
  231. {
  232. width: 120,
  233. prop: 'specification',
  234. label: '规格',
  235. slot: 'specification'
  236. },
  237. {
  238. width: 160,
  239. prop: 'singlePrice',
  240. label: '单价',
  241. slot: 'singlePrice'
  242. },
  243. {
  244. width: 80,
  245. prop: 'totalCount',
  246. label: '数量',
  247. slot: 'totalCount'
  248. },
  249. {
  250. width: 80,
  251. prop: 'measuringUnit',
  252. label: '计量单位',
  253. slot: 'measuringUnit'
  254. },
  255. {
  256. width: 120,
  257. prop: 'totalPrice',
  258. label: '合计',
  259. slot: 'totalPrice'
  260. },
  261. {
  262. width: 80,
  263. prop: 'deliveryDays',
  264. label: '交期(天)',
  265. slot: 'deliveryDays'
  266. },
  267. {
  268. width: 200,
  269. prop: 'guaranteePeriod',
  270. label: '质保期',
  271. slot: 'guaranteePeriod'
  272. },
  273. // {
  274. // width: 120,
  275. // prop: 'guaranteePeriodUnitCode',
  276. // label: '',
  277. // slot: 'guaranteePeriodUnitCode'
  278. // },
  279. {
  280. width: 130,
  281. prop: 'technicalAnswerName',
  282. label: '技术答疑人',
  283. slot: 'technicalAnswerName'
  284. },
  285. {
  286. width: 220,
  287. prop: 'technicalParams',
  288. label: '技术参数',
  289. slot: 'technicalParams'
  290. },
  291. {
  292. width:240,
  293. prop: 'technicalDrawings',
  294. label: '技术图纸',
  295. slot: 'technicalDrawings'
  296. },
  297. {
  298. width: 220,
  299. prop: 'remark',
  300. label: '备注',
  301. slot: 'remark'
  302. },
  303. {
  304. columnKey: 'action',
  305. label: '操作',
  306. width: 120,
  307. align: 'center',
  308. resizable: false,
  309. slot: 'action',
  310. fixed:'right',
  311. showOverflowTooltip: true
  312. }
  313. ],
  314. };
  315. },
  316. computed: {
  317. canHandl() {
  318. return this.form.datasource.length;
  319. },
  320. },
  321. methods: {
  322. // 返回列表数据
  323. getTableValue(){
  324. let comitDatasource=this.form.datasource
  325. if(comitDatasource.length===0) return []
  326. comitDatasource.forEach(v=>{
  327. v.totalPrice=(v.totalCount*v.singlePrice)?.toFixed(2)||0
  328. v.guaranteePeriodUnitName=this.getDictValue('质保期单位', v.guaranteePeriodUnitCode)
  329. v.technicalDrawings=v.technicalDrawings?v.technicalDrawings:null
  330. })
  331. return comitDatasource
  332. },
  333. getPrice(){
  334. return [this.allPrice,this.discountTotalPrice]
  335. },
  336. //计算总金额
  337. getTotalPrice(){
  338. if(this.form.datasource.length){
  339. let datasource=this.form.datasource,sum=0
  340. datasource.forEach(r=>{
  341. if(r.singlePrice&&r.totalCount){
  342. sum+=r.singlePrice*r.totalCount
  343. }
  344. })
  345. let allsum=sum.toFixed(2)
  346. this.allPrice=allsum
  347. this.discountTotalPrice=allsum
  348. this.$store.commit('concact/setDiscountAmount',allsum);
  349. return allsum
  350. }else{
  351. this.allPrice=0.00
  352. this.discountTotalPrice=0.00
  353. return 0.00
  354. }
  355. },
  356. //更新优惠总金额
  357. discountInput(val){
  358. this.$store.commit('concact/setDiscountAmount',val);
  359. },
  360. //修改回显
  361. putTableValue(data){
  362. if(data&&data?.length){
  363. this.form.datasource=data
  364. this.getTotalPrice()
  365. }
  366. },
  367. //选择产品
  368. handParent(row,index) {
  369. let item={
  370. id:row.productCode
  371. }
  372. this.$refs.productListRef.open(item,index)
  373. },
  374. //选择技术人回调
  375. changeAnswer(obj,idx) {
  376. this.$set( this.form.datasource[idx], 'technicalAnswerId', obj.id)
  377. this.$set(this.form.datasource[idx], 'technicalAnswerName', obj.name)
  378. },
  379. handHead(row,index){
  380. let item={
  381. id:row.technicalAnswerId
  382. }
  383. this.$refs.headRef.open(item,index)
  384. },
  385. //选择产品回调
  386. changeParent(obj,idx) {
  387. console.log(obj,'33333')
  388. this.$set(this.form.datasource[idx], 'categoryName', obj.name)
  389. this.$set(this.form.datasource[idx], 'productCategoryId', obj.categoryLevelId)
  390. this.$set(this.form.datasource[idx], 'productBrand', obj.brandNum)
  391. this.$set(this.form.datasource[idx], 'productCategoryName', obj.categoryLevelPath)
  392. this.$set(this.form.datasource[idx], 'productCode', obj.code)
  393. this.$set(this.form.datasource[idx], 'productName', obj.name)
  394. this.$set(this.form.datasource[idx], 'modelType', obj.modelType)
  395. this.$set(this.form.datasource[idx], 'measuringUnit', obj.measuringUnit)
  396. this.$set(this.form.datasource[idx], 'specification', obj.specification)
  397. },
  398. remove(row) {
  399. let index = this.form.datasource.findIndex((n) => n.key == row.key);
  400. if (index !== -1) {
  401. this.form.datasource.splice(index, 1);
  402. this.setSort();
  403. }
  404. },
  405. // 清空表格
  406. restTable() {
  407. this.form.datasource = [];
  408. },
  409. // 重新排序
  410. setSort() {
  411. this.form.datasource.forEach((n, index) => {
  412. n.key = index + 1;
  413. });
  414. },
  415. // 添加
  416. handlAdd() {
  417. let item = JSON.parse(JSON.stringify(this.defaultForm));
  418. item.key = this.form.datasource.length + 1;
  419. this.form.datasource.push(item);
  420. },
  421. validateForm (callback) {
  422. //开始表单校验
  423. this.$refs.form.validate((valid) => {
  424. callback(valid);
  425. });
  426. },
  427. }
  428. };
  429. </script>
  430. <style lang="scss" scoped>
  431. .headbox{
  432. display: flex;
  433. justify-content: space-between;
  434. align-items: center;
  435. .amount{
  436. font-size: 14px;
  437. font-weight: bold;
  438. padding-right: 30px;
  439. }
  440. }
  441. .time-form .el-form-item {
  442. margin-bottom: 0 !important;
  443. }
  444. ::v-deep .period{
  445. display: flex;
  446. .borderleftnone{
  447. .el-input--medium .el-input__inner{
  448. border-top-right-radius: 0;
  449. border-bottom-right-radius: 0;
  450. }
  451. }
  452. .borderrightnone{
  453. .el-input--medium .el-input__inner{
  454. border-top-left-radius: 0;
  455. border-bottom-left-radius: 0;
  456. }
  457. }
  458. }
  459. ::v-deep .time-form tbody > tr:hover>td {
  460. background-color: transparent !important;
  461. }
  462. ::v-deep .time-form .el-table tr{
  463. background-color: #ffffff;
  464. }
  465. .pricebox{
  466. display: flex;
  467. justify-content: flex-start;
  468. align-items: center;
  469. font-weight: bold;
  470. }
  471. </style>