chooseImportModal.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <a-modal
  3. centered
  4. class="chooseImport-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="导入"
  8. :closable="false"
  9. v-model="isShow"
  10. @cancle="isShow=false"
  11. :width="900">
  12. <a-spin :spinning="spinning" tip="Loading...">
  13. <div class="chooseImport-con">
  14. <!-- 可导入数据 -->
  15. <p class="chooseImport-tit">可导入数据{{ loadData.length }}条</p>
  16. <a-table
  17. class="sTable"
  18. ref="table"
  19. size="small"
  20. :rowKey="(record) => record.purchaseBillSn"
  21. :columns="nowColumns"
  22. :dataSource="loadData"
  23. :loading="loading"
  24. :scroll="{ y: 200 }"
  25. :pagination="false"
  26. bordered>
  27. </a-table>
  28. <a-divider />
  29. <!-- 不可导入数据 -->
  30. <p class="chooseImport-tit red">不可导入数据{{ unLoadData.length }}条</p>
  31. <a-table
  32. class="unTable sTable"
  33. ref="unTable"
  34. size="small"
  35. :rowClassName="(record, index) => 'yellowBg-row'"
  36. :rowKey="(record) => record.errorDesc"
  37. :columns="nowUnColumns"
  38. :dataSource="unLoadData"
  39. :loading="loading"
  40. :scroll="{ y: 200 }"
  41. :pagination="false"
  42. bordered>
  43. </a-table>
  44. <!-- 按钮 -->
  45. <div class="btn-con">
  46. <a-button
  47. type="primary"
  48. id="chooseImport-submit"
  49. size="large"
  50. :class="loadData.length==0?'button-grey':'button-primary'"
  51. @click="handleSubmit"
  52. style="padding: 0 60px;">确认导入</a-button>
  53. <a-button
  54. id="chooseImport-cancel"
  55. size="large"
  56. class="button-cancel"
  57. @click="isShow=false"
  58. style="padding: 0 60px;margin-left: 15px;">取消</a-button>
  59. </div>
  60. </div>
  61. </a-spin>
  62. </a-modal>
  63. </template>
  64. <script>
  65. import { purchaseDetailParseProducts, purchaseDetailBatchInsert } from '@/api/purchase'
  66. export default {
  67. name: 'ChooseImportModal',
  68. props: {
  69. openModal: { // 弹框显示状态
  70. type: Boolean,
  71. default: false
  72. },
  73. paramsData: {
  74. type: Object,
  75. default: () => {
  76. return {}
  77. }
  78. }
  79. },
  80. data () {
  81. return {
  82. spinning: false,
  83. isShow: this.openModal, // 是否打开弹框
  84. nowColumns: [ // 正品
  85. { title: '序号', dataIndex: 'no', width: '15%', align: 'center' },
  86. { title: '产品编码', dataIndex: 'productCode', width: '27%', align: 'center', customRender: function (text) { return text || '--' } },
  87. { title: '产品名称', dataIndex: 'productName', width: '28%', align: 'center', customRender: function (text) { return text || '--' } },
  88. { title: '数量', dataIndex: 'qtyText', width: '15%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  89. { title: '单位', dataIndex: 'productUnit', width: '15%', align: 'center', customRender: function (text) { return text || '--' } }
  90. ],
  91. nowUnColumns: [ // 促销品
  92. { title: '序号', dataIndex: 'no', width: '13%', align: 'center' },
  93. { title: '产品编码', dataIndex: 'productCode', width: '26%', align: 'center', customRender: function (text) { return text || '--' } },
  94. { title: '产品名称', dataIndex: 'productName', width: '26%', align: 'center', customRender: function (text) { return text || '--' } },
  95. { title: '数量', dataIndex: 'qtyText', width: '15%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  96. { title: '单位', dataIndex: 'productUnit', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  97. { title: '备注', dataIndex: 'errorDesc', width: '30%', align: 'center', customRender: function (text) { return text || '--' } }
  98. ],
  99. loadData: [],
  100. unLoadData: [],
  101. loading: false
  102. }
  103. },
  104. methods: {
  105. getData () {
  106. const _this = this
  107. this.loading = true
  108. purchaseDetailParseProducts(this.paramsData).then(res => {
  109. this.loading = false
  110. if (res.status == 200) {
  111. if (res.data.okList && res.data.okList.length > 0) {
  112. res.data.okList.map((item, index) => {
  113. item.no = index + 1
  114. })
  115. }
  116. if (res.data.failList && res.data.failList.length > 0) {
  117. res.data.failList.map((item, index) => {
  118. item.no = index + 1
  119. })
  120. }
  121. _this.loadData = res.data.okList || []
  122. _this.unLoadData = res.data.failList || []
  123. }
  124. })
  125. },
  126. // 确认导入
  127. handleSubmit () {
  128. if (this.loadData.length == 0) {
  129. this.$message.warning('无可导入产品!')
  130. } else {
  131. this.spinning = true
  132. purchaseDetailBatchInsert(this.loadData).then(res => {
  133. this.spinning = false
  134. if (res.status == 200) {
  135. this.$emit('ok', '')
  136. this.isShow = false
  137. }
  138. })
  139. }
  140. }
  141. },
  142. watch: {
  143. // 父页面传过来的弹框状态
  144. openModal (newValue, oldValue) {
  145. this.isShow = newValue
  146. },
  147. // 重定义的弹框状态
  148. isShow (newValue, oldValue) {
  149. if (!newValue) {
  150. this.$emit('close')
  151. this.loadData = []
  152. this.unLoadData = []
  153. } else {
  154. this.getData()
  155. }
  156. }
  157. }
  158. }
  159. </script>
  160. <style lang="less">
  161. .chooseImport-modal{
  162. .chooseImport-con{
  163. .chooseImport-tit{
  164. font-size: 14px;
  165. font-weight: bold;
  166. }
  167. .unTable{
  168. box-shadow: 0px 0px 4px rgb(89,89,89,.9);
  169. .ant-table-bordered .ant-table-tbody > tr > td, .ant-table-bordered .ant-table-thead > tr > th{
  170. border-right: 1px solid #595959;
  171. }
  172. .ant-table-tbody > tr > td, .ant-table-thead > tr > th{
  173. border-bottom: 1px solid #595959;
  174. }
  175. }
  176. .red{
  177. color: #f30;
  178. }
  179. .btn-con{
  180. text-align: center;
  181. margin: 30px 0 20px;
  182. .button-cancel{
  183. font-size: 12px;
  184. }
  185. }
  186. }
  187. }
  188. .yellowBg-row{
  189. background-color: #ffe58f;
  190. }
  191. </style>