printModal.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <a-modal
  3. centered
  4. :footer="null"
  5. :maskClosable="false"
  6. class="sales-print-type-modal"
  7. :title="modalTit"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="600">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <a-form-model
  13. id="sales-print-form"
  14. ref="ruleForm"
  15. :model="form"
  16. :rules="rules"
  17. :label-col="formItemLayout.labelCol"
  18. :wrapper-col="formItemLayout.wrapperCol"
  19. >
  20. <a-form-model-item label="销售单号">{{ itemData&&itemData.salesBillNo || '--' }}</a-form-model-item>
  21. <a-form-model-item label="客户名称">{{ itemData&&itemData.buyerName || '--' }}</a-form-model-item>
  22. <a-form-model-item label="产品分类" prop="id" v-if="nowType=='SALES_BILL_TYPE'">
  23. <a-select id="sales-print-form" v-model="form.id" placeholder="请选择产品分类">
  24. <a-select-option v-for="item in typeList" :value="item.id" :key="item.id">
  25. <span v-if="item.id != 'all'">{{ item.productBrandName }} - {{ item.productTypeName3 }}</span>
  26. <span v-else>全部</span>
  27. </a-select-option>
  28. </a-select>
  29. </a-form-model-item>
  30. <a-form-model-item label="是否缺货产品" prop="dataScope" v-if="nowType=='export'">
  31. <a-radio-group v-model="form.dataScope">
  32. <a-radio value="all">全部</a-radio>
  33. <a-radio value="ENOUGH">有库存</a-radio>
  34. <a-radio value="LESS">缺货</a-radio>
  35. </a-radio-group>
  36. </a-form-model-item>
  37. <a-form-model-item label="产品售价" prop="priceType">
  38. <!-- 分类打印 -->
  39. <a-radio-group v-model="form.priceType" v-if="nowType=='SALES_BILL_TYPE'">
  40. <a-radio value="SALES_BILL_TYPE_COST">打印</a-radio>
  41. <a-radio value="SALES_BILL_TYPE">不打印</a-radio>
  42. </a-radio-group>
  43. <!-- 销售打印 -->
  44. <a-radio-group v-model="form.priceType" v-if="nowType=='SALES_BILL'">
  45. <a-radio value="SALES_BILL_COST">打印</a-radio>
  46. <a-radio value="SALES_BILL">不打印</a-radio>
  47. </a-radio-group>
  48. <!-- 销售导出 -->
  49. <a-radio-group v-model="form.priceType" v-if="nowType=='export'">
  50. <a-radio value="SALES_BILL_COST_NOT_LACK">导出</a-radio>
  51. <a-radio value="SALES_BILL_NOT_LACK">不导出</a-radio>
  52. </a-radio-group>
  53. </a-form-model-item>
  54. </a-form-model>
  55. <div class="btn-cont">
  56. <a-button :type="nowType=='export'?'primary':''" id="sales-print-save" @click="handleSave()">{{ nowType=='export' ? '导出' : '打印预览' }}</a-button>
  57. <a-button :type="nowType=='export'?'':'primary'" id="sales-print-back" @click="handleCancel" style="margin-left: 15px;">{{ nowType=='export' ? '取消' : '快捷打印' }}</a-button>
  58. </div>
  59. </a-spin>
  60. </a-modal>
  61. </template>
  62. <script>
  63. import { salesDetailProductType } from '@/api/sales'
  64. export default {
  65. props: {
  66. openModal: { // 弹框显示状态
  67. type: Boolean,
  68. default: false
  69. },
  70. itemData: {
  71. type: Object,
  72. default: () => {
  73. return null
  74. }
  75. },
  76. nowType: {
  77. type: String,
  78. default: ''
  79. }
  80. },
  81. data () {
  82. return {
  83. isShow: this.openModal, // 是否打开弹框
  84. form: {
  85. id: 'all',
  86. dataScope: 'all',
  87. priceType: undefined
  88. },
  89. rules: {
  90. id: [{ required: true, message: '请选择产品分类', trigger: 'change' }],
  91. dataScope: [{ required: true, message: '请选择是否缺货产品', trigger: 'change' }],
  92. priceType: [{ required: true, message: '请选择产品售价', trigger: 'change' }]
  93. },
  94. formItemLayout: {
  95. labelCol: { span: 6 },
  96. wrapperCol: { span: 15 }
  97. },
  98. spinning: false,
  99. typeList: []
  100. }
  101. },
  102. computed: {
  103. modalTit () {
  104. let title = ''
  105. if (this.nowType == 'SALES_BILL') {
  106. title = '销售打印'
  107. } else if (this.nowType == 'SALES_BILL_TYPE') {
  108. title = '销售分类打印'
  109. } else if (this.nowType == 'export') {
  110. title = '导出Excel'
  111. }
  112. return title
  113. }
  114. },
  115. methods: {
  116. // 确认
  117. handleSave (isPrint) {
  118. const _this = this
  119. this.$refs.ruleForm.validate(valid => {
  120. if (valid) {
  121. if (_this.nowType == 'SALES_BILL_TYPE') {
  122. const item = _this.typeList.find(item => item.id == _this.form.id)
  123. if (item) {
  124. const obj = {
  125. salesBillSn: _this.itemData.salesBillSn,
  126. productBrandSn: item.productBrandSn,
  127. productTypeSn3: item.productTypeSn3,
  128. priceType: _this.form.priceType,
  129. type: isPrint || 'preview'
  130. }
  131. _this.$emit('ok', obj)
  132. }
  133. } else if (_this.nowType == 'SALES_BILL') {
  134. const obj = {
  135. salesBillSn: _this.itemData.salesBillSn,
  136. priceType: _this.form.priceType,
  137. type: isPrint || 'preview'
  138. }
  139. _this.$emit('ok', obj)
  140. } else if (_this.nowType == 'export') {
  141. const obj = {
  142. salesBillSn: _this.itemData.salesBillSn,
  143. priceType: _this.form.priceType,
  144. dataScope: _this.form.dataScope == 'all' ? '' : _this.form.dataScope,
  145. type: isPrint || 'preview'
  146. }
  147. _this.$emit('ok', obj)
  148. }
  149. _this.isShow = false
  150. } else {
  151. console.log('error submit!!')
  152. return false
  153. }
  154. })
  155. },
  156. // 取消选择分类
  157. handleCancel () {
  158. if (this.nowType == 'export') {
  159. this.isShow = false
  160. } else {
  161. this.handleSave('print')
  162. }
  163. },
  164. // 获取该销售单产品二级分类
  165. getTypeData () {
  166. this.typeList = [{ id: 'all' }]
  167. salesDetailProductType({ sn: this.itemData.salesBillSn || null }).then(res => {
  168. if (res.status == 200) {
  169. if (res.data && res.data.length > 0) {
  170. this.typeList = [...this.typeList, ...res.data]
  171. }
  172. }
  173. })
  174. }
  175. },
  176. watch: {
  177. // 父页面传过来的弹框状态
  178. openModal (newValue, oldValue) {
  179. this.isShow = newValue
  180. },
  181. // 重定义的弹框状态
  182. isShow (newValue, oldValue) {
  183. if (!newValue) {
  184. this.$emit('close')
  185. this.$refs.ruleForm.resetFields()
  186. } else {
  187. if (this.nowType == 'SALES_BILL_TYPE') {
  188. this.getTypeData()
  189. }
  190. }
  191. }
  192. }
  193. }
  194. </script>
  195. <style lang="less">
  196. .sales-print-type-modal{
  197. .btn-cont {
  198. text-align: center;
  199. margin: 35px 0 10px;
  200. }
  201. }
  202. </style>