chooseImportModal.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. @cancel="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. <a-button
  60. type="primary"
  61. id="chooseImport-error"
  62. size="large"
  63. class="button-error"
  64. @click="handleError"
  65. style="padding: 0 40px;margin-left: 15px;">导出错误项</a-button>
  66. </div>
  67. </div>
  68. </a-spin>
  69. </a-modal>
  70. </template>
  71. <script>
  72. import { commonMixin } from '@/utils/mixin'
  73. import { hdPrint } from '@/libs/JGPrint'
  74. import { purchaseDetailParseProducts, purchaseDetailBatchInsert } from '@/api/purchase'
  75. import { purchaseDetailDownloadFail } from '@/api/purchaseDetail'
  76. export default {
  77. name: 'ChooseImportModal',
  78. mixins: [commonMixin],
  79. props: {
  80. openModal: { // 弹框显示状态
  81. type: Boolean,
  82. default: false
  83. },
  84. paramsData: {
  85. type: Object,
  86. default: () => {
  87. return {}
  88. }
  89. }
  90. },
  91. data () {
  92. return {
  93. spinning: false,
  94. isShow: this.openModal, // 是否打开弹框
  95. nowColumns: [ // 正品
  96. { title: '序号', dataIndex: 'no', width: '15%', align: 'center' },
  97. { title: '产品编码', dataIndex: 'productCode', width: '27%', align: 'center', customRender: function (text) { return text || '--' } },
  98. { title: '产品名称', dataIndex: 'productName', width: '28%', align: 'center', customRender: function (text) { return text || '--' } },
  99. { title: '数量', dataIndex: 'qtyText', width: '15%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  100. { title: '单位', dataIndex: 'productUnit', width: '15%', align: 'center', customRender: function (text) { return text || '--' } }
  101. ],
  102. nowUnColumns: [ // 促销品
  103. { title: '序号', dataIndex: 'no', width: '13%', align: 'center' },
  104. { title: '产品编码', dataIndex: 'productCode', width: '26%', align: 'center', customRender: function (text) { return text || '--' } },
  105. { title: '产品名称', dataIndex: 'productName', width: '26%', align: 'center', customRender: function (text) { return text || '--' } },
  106. { title: '数量', dataIndex: 'qtyText', width: '15%', align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  107. { title: '单位', dataIndex: 'productUnit', width: '15%', align: 'center', customRender: function (text) { return text || '--' } },
  108. { title: '备注', dataIndex: 'errorDesc', width: '30%', align: 'center', customRender: function (text) { return text || '--' } }
  109. ],
  110. loadData: [],
  111. unLoadData: [],
  112. loading: false
  113. }
  114. },
  115. methods: {
  116. getData () {
  117. const _this = this
  118. this.loading = true
  119. purchaseDetailParseProducts(this.paramsData).then(res => {
  120. this.loading = false
  121. if (res.status == 200) {
  122. if (res.data.okList && res.data.okList.length > 0) {
  123. res.data.okList.map((item, index) => {
  124. item.no = index + 1
  125. })
  126. }
  127. if (res.data.failList && res.data.failList.length > 0) {
  128. res.data.failList.map((item, index) => {
  129. item.no = index + 1
  130. })
  131. }
  132. _this.loadData = res.data.okList || []
  133. _this.unLoadData = res.data.failList || []
  134. }
  135. })
  136. },
  137. // 确认导入
  138. handleSubmit () {
  139. if (this.loadData.length == 0) {
  140. this.$message.warning('无可导入产品!')
  141. } else {
  142. this.spinning = true
  143. purchaseDetailBatchInsert(this.loadData).then(res => {
  144. this.spinning = false
  145. if (res.status == 200) {
  146. this.$emit('ok', '')
  147. this.isShow = false
  148. }
  149. })
  150. }
  151. },
  152. // 导出
  153. handleError () {
  154. const _this = this
  155. if (_this.unLoadData.length < 1) {
  156. _this.$message.info('暂无可导出错误项~')
  157. return
  158. }
  159. _this.spinning = true
  160. // 导出
  161. hdPrint('', 'export', purchaseDetailDownloadFail, _this.unLoadData, '产品导入错误项', function () {
  162. _this.spinning = false
  163. })
  164. }
  165. },
  166. watch: {
  167. // 父页面传过来的弹框状态
  168. openModal (newValue, oldValue) {
  169. this.isShow = newValue
  170. },
  171. // 重定义的弹框状态
  172. isShow (newValue, oldValue) {
  173. if (!newValue) {
  174. this.$emit('close')
  175. this.loadData = []
  176. this.unLoadData = []
  177. } else {
  178. this.getData()
  179. }
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="less">
  185. .chooseImport-modal{
  186. .chooseImport-con{
  187. .chooseImport-tit{
  188. font-size: 14px;
  189. font-weight: bold;
  190. }
  191. .unTable{
  192. box-shadow: 0px 0px 4px rgb(89,89,89,.9);
  193. .ant-table-bordered .ant-table-tbody > tr > td, .ant-table-bordered .ant-table-thead > tr > th{
  194. border-right: 1px solid #595959;
  195. }
  196. .ant-table-tbody > tr > td, .ant-table-thead > tr > th{
  197. border-bottom: 1px solid #595959;
  198. }
  199. }
  200. .red{
  201. color: #f30;
  202. }
  203. .btn-con{
  204. text-align: center;
  205. margin: 30px 0 20px;
  206. .button-cancel{
  207. font-size: 12px;
  208. }
  209. }
  210. }
  211. }
  212. .yellowBg-row{
  213. background-color: #ffe58f;
  214. }
  215. </style>