chooseImportModal.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <a-modal
  3. centered
  4. class="chooseImport-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="导入"
  8. v-model="isShow"
  9. :closable="!spinning"
  10. @cancel="isShow = false"
  11. :width="900">
  12. <div class="chooseImport-con">
  13. <!-- 可导入数据 -->
  14. <p class="">可导入数据{{ loadData.length }}条</p>
  15. <a-table
  16. class="sTable"
  17. ref="table"
  18. size="small"
  19. :rowKey="(record) => record.no"
  20. :columns="nowColumns"
  21. :dataSource="loadData"
  22. :loading="spinning"
  23. :scroll="{ y: 200 }"
  24. :pagination="false"
  25. bordered>
  26. </a-table>
  27. <a-divider />
  28. <!-- 不可导入数据 -->
  29. <p class="red">不可导入数据{{ unLoadData.length }}条</p>
  30. <a-table
  31. class="unTable"
  32. ref="unTable"
  33. size="small"
  34. :rowKey="(record) => record.no"
  35. :columns="nowUnColumns"
  36. :dataSource="unLoadData"
  37. :loading="spinning"
  38. :scroll="{ y: 200 }"
  39. :pagination="false"
  40. bordered>
  41. </a-table>
  42. <!-- 按钮 -->
  43. <div class="btn-con">
  44. <a-button
  45. type="primary"
  46. id="chooseImport-submit"
  47. size="large"
  48. :loading="spinning"
  49. :class="loadData.length==0?'button-grey':'button-primary'"
  50. @click="handleSubmit"
  51. style="padding: 0 40px;">确认导入</a-button>
  52. <a-button
  53. id="chooseImport-cancel"
  54. size="large"
  55. class="button-cancel"
  56. :disabled="spinning"
  57. @click="isShow=false"
  58. style="padding: 0 40px;margin-left: 15px;">取消</a-button>
  59. <a-button
  60. type="primary"
  61. id="chooseImport-error"
  62. size="large"
  63. class="button-error"
  64. :disabled="spinning"
  65. @click="handleError"
  66. style="padding: 0 40px;margin-left: 15px;">导出错误项</a-button>
  67. </div>
  68. </div>
  69. </a-modal>
  70. </template>
  71. <script>
  72. import { commonMixin } from '@/utils/mixin'
  73. import { hdExportExcel } from '@/libs/exportExcel'
  74. // 接口
  75. import { allocateBillParseProducts, allocateBillFailExcel, allocateBillBatchInsert } from '@/api/allocateBill'
  76. export default {
  77. name: 'TransferOutChooseImportModal',
  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. isShow: this.openModal, // 是否打开弹框
  94. spinning: false,
  95. nowColumns: [ // 正品
  96. { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
  97. { title: '产品编码', dataIndex: 'productCode', align: 'center', customRender: function (text) { return text || '--' } },
  98. { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' } },
  99. { title: '数量', dataIndex: 'qtyText', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  100. { title: '库存', dataIndex: 'currentStockQty', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  101. { title: '单位', dataIndex: 'productUnit', width: 60, align: 'center', customRender: function (text) { return text || '--' } }
  102. ],
  103. nowUnColumns: [ // 促销品
  104. { title: '序号', dataIndex: 'no', width: 70, align: 'center' },
  105. { title: '产品编码', dataIndex: 'productCode', align: 'center', customRender: function (text) { return text || '--' } },
  106. { title: '产品名称', dataIndex: 'productName', align: 'center', customRender: function (text) { return text || '--' } },
  107. { title: '数量', dataIndex: 'qtyText', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  108. { title: '库存', dataIndex: 'currentStockQty', width: 80, align: 'center', customRender: function (text) { return ((text || text == 0) ? text : '--') } },
  109. { title: '单位', dataIndex: 'productUnit', width: 60, align: 'center', customRender: function (text) { return text || '--' } },
  110. { title: '备注', dataIndex: 'errorDesc', width: 180, align: 'center', customRender: function (text) { return text || '--' } }
  111. ],
  112. loadData: [], // 可导入数据
  113. unLoadData: [], // 错误数据
  114. loading: false// 表格加载状态
  115. }
  116. },
  117. methods: {
  118. // 获取表格数据
  119. getData () {
  120. const _this = this
  121. this.spinning = true
  122. // 获取列表数据 无分页
  123. allocateBillParseProducts(this.paramsData).then(res => {
  124. this.spinning = false
  125. if (res.status == 200) {
  126. if (res.data.okList && res.data.okList.length > 0) {
  127. res.data.okList.map((item, index) => {
  128. item.no = index + 1
  129. })
  130. }
  131. if (res.data.failList && res.data.failList.length > 0) {
  132. res.data.failList.map((item, index) => {
  133. item.no = index + 1
  134. })
  135. }
  136. _this.loadData = res.data.okList || []
  137. _this.unLoadData = res.data.failList || []
  138. }
  139. })
  140. },
  141. // 确认导入
  142. handleSubmit () {
  143. if (this.loadData.length == 0) {
  144. this.$message.warning('无可导入产品!')
  145. } else {
  146. this.handleGuideOk(this.loadData)
  147. }
  148. },
  149. // 导入产品
  150. handleGuideOk (obj) {
  151. this.spinning = true
  152. allocateBillBatchInsert(obj).then(res => {
  153. this.spinning = false
  154. if (res.status == 200) {
  155. this.isShow = false
  156. this.$emit('ok')
  157. this.$message.success('导入成功!')
  158. }
  159. })
  160. },
  161. // 导出
  162. handleError () {
  163. const _this = this
  164. if (_this.unLoadData.length < 1) {
  165. _this.$message.info('暂无可导出错误项~')
  166. return
  167. }
  168. _this.spinning = true
  169. hdExportExcel(allocateBillFailExcel, _this.unLoadData, '产品导入错误项', function () {
  170. _this.spinning = false
  171. })
  172. }
  173. },
  174. watch: {
  175. // 父页面传过来的弹框状态
  176. openModal (newValue, oldValue) {
  177. this.isShow = newValue
  178. },
  179. // 重定义的弹框状态
  180. isShow (newValue, oldValue) {
  181. if (!newValue) {
  182. this.$emit('close')
  183. this.loadData = []
  184. this.unLoadData = []
  185. } else {
  186. this.getData()
  187. }
  188. }
  189. }
  190. }
  191. </script>
  192. <style lang="less" scoped>
  193. .chooseImport-modal{
  194. .chooseImport-con{
  195. .red{
  196. color: #f30;
  197. }
  198. .btn-con{
  199. text-align: center;
  200. margin: 30px 0 20px;
  201. .button-cancel,.button-error{
  202. font-size: 12px;
  203. }
  204. }
  205. }
  206. }
  207. </style>