printModal.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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="cancel"
  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. <!-- 如果是销售导出 -->
  31. <a-form-model-item label="是否缺货产品" prop="dataScope" v-if="nowType=='export'">
  32. <a-radio-group v-model="form.dataScope">
  33. <a-radio value="all">全部</a-radio>
  34. <a-radio value="ENOUGH" :disabled="isDisabled">有库存</a-radio>
  35. <a-radio value="LESS" :disabled="isDisabled">缺货</a-radio>
  36. </a-radio-group>
  37. </a-form-model-item>
  38. <!-- 销售分类打印 -->
  39. <a-form-model-item label="产品售价" prop="priceType" v-if="nowType=='SALES_BILL_TYPE'&&$hasPermissions('B_salesTypePrint_salesPrice')">
  40. <a-radio-group v-model="form.priceType">
  41. <a-radio value="SALES_BILL_TYPE_COST">打印</a-radio>
  42. <a-radio value="SALES_BILL_TYPE">不打印</a-radio>
  43. </a-radio-group>
  44. </a-form-model-item>
  45. <!-- 销售打印 -->
  46. <a-form-model-item label="产品售价" prop="priceType" v-if="nowType=='SALES_BILL'&&$hasPermissions('B_salesPrint_salesPrice')">
  47. <a-radio-group v-model="form.priceType">
  48. <a-radio value="SALES_BILL_COST">打印</a-radio>
  49. <a-radio value="SALES_BILL">不打印</a-radio>
  50. </a-radio-group>
  51. </a-form-model-item>
  52. <!-- 销售导出 -->
  53. <a-form-model-item label="产品售价" prop="priceType" v-if="nowType=='export'&&$hasPermissions('B_salesDetailExport_salesPrice')">
  54. <a-radio-group v-model="form.priceType">
  55. <a-radio :value="form.dataScope == 'ENOUGH' ? 'SALES_BILL_COST_NOT_LACK':'SALES_BILL_COST'">导出</a-radio>
  56. <a-radio :value="form.dataScope == 'ENOUGH' ? 'SALES_BILL_NOT_LACK':'SALES_BILL'">不导出</a-radio>
  57. </a-radio-group>
  58. </a-form-model-item>
  59. <!-- 销售分类打印 -->
  60. <a-form-model-item label="货位编号" prop="orderBy" v-if="nowType=='SALES_BILL_TYPE'">
  61. <a-radio-group v-model="form.orderBy">
  62. <a-radio value="sbd.STACK_PLACE_CODE ASC">打印(↑升序)</a-radio>
  63. <a-radio value="sbd.STACK_PLACE_CODE DESC">打印(↓降序)</a-radio>
  64. <a-radio value="-1">不打印</a-radio>
  65. </a-radio-group>
  66. </a-form-model-item>
  67. <!-- 平均公斤单价 -->
  68. <a-form-model-item label="平均公斤单价" prop="averagePrice" v-if="nowType=='export'&&$hasPermissions('B_salesDetail_avgprice')">
  69. <a-radio-group v-model="form.averagePrice">
  70. <a-radio :value="1">导出</a-radio>
  71. <a-radio :value="0">不导出</a-radio>
  72. </a-radio-group>
  73. </a-form-model-item>
  74. </a-form-model>
  75. <div class="btn-cont">
  76. <a-button id="sales-print-back" @click="cancel">取消</a-button>
  77. <a-button type="primary" class="button-info" id="sales-print-save" @click="handleSave()" style="margin-left: 15px;">{{ nowType=='export' ? '导出' : '打印预览' }}</a-button>
  78. <a-button v-if="nowType!='export'" type="primary" id="sales-print" @click="handleSave('print')" style="margin-left: 10px;">快捷打印</a-button>
  79. </div>
  80. </a-spin>
  81. </a-modal>
  82. </template>
  83. <script>
  84. import { salesDetailProductType } from '@/api/salesNew'
  85. export default {
  86. props: {
  87. openModal: { // 弹框显示状态
  88. type: Boolean,
  89. default: false
  90. },
  91. itemData: { // 单据详情信息
  92. type: Object,
  93. default: () => {
  94. return null
  95. }
  96. },
  97. nowType: { // 操作类型,打印、分类打印、导出
  98. type: String,
  99. default: ''
  100. }
  101. },
  102. data () {
  103. return {
  104. isShow: this.openModal, // 是否打开弹框
  105. // 打印、导出选项
  106. form: {
  107. id: 'all',
  108. dataScope: 'all',
  109. priceType: undefined,
  110. orderBy: undefined,
  111. averagePrice: undefined
  112. },
  113. // 选项校验
  114. rules: {
  115. id: [{ required: true, message: '请选择产品分类', trigger: 'change' }],
  116. dataScope: [{ required: true, message: '请选择是否缺货产品', trigger: 'change' }],
  117. priceType: [{ required: true, message: '请选择产品售价', trigger: 'change' }],
  118. orderBy: [{ required: true, message: '请选择货位编号', trigger: 'change' }],
  119. averagePrice: [{ required: true, message: '请选择平均公斤单价', trigger: 'change' }]
  120. },
  121. formItemLayout: {
  122. labelCol: { span: 6 },
  123. wrapperCol: { span: 15 }
  124. },
  125. spinning: false,
  126. typeList: [] // 产品分类
  127. }
  128. },
  129. computed: {
  130. // 弹框标题
  131. modalTit () {
  132. let title = ''
  133. if (this.nowType == 'SALES_BILL') {
  134. title = '销售打印'
  135. } else if (this.nowType == 'SALES_BILL_TYPE') {
  136. title = '销售分类打印'
  137. } else if (this.nowType == 'export') {
  138. title = '导出Excel'
  139. }
  140. return title
  141. },
  142. // 是否禁用
  143. isDisabled () {
  144. const states = ['WAIT_SUBMIT', 'WAIT_AUDIT', 'AUDIT_REJECT']
  145. return this.itemData && states.includes(this.itemData.billStatus)
  146. }
  147. },
  148. methods: {
  149. cancel () {
  150. this.$emit('close')
  151. },
  152. // 确认
  153. handleSave (isPrint) {
  154. const _this = this
  155. this.$refs.ruleForm.validate(valid => {
  156. if (valid) {
  157. // 分类打印
  158. if (_this.nowType == 'SALES_BILL_TYPE') {
  159. // 销售分类无权限不打印
  160. if (!_this.$hasPermissions('B_salesTypePrint_salesPrice')) {
  161. _this.form.priceType = 'SALES_BILL_TYPE'
  162. }
  163. const item = _this.typeList.find(item => item.id == _this.form.id)
  164. if (item) {
  165. const obj = {
  166. salesBillSn: _this.itemData.salesBillSn,
  167. productBrandSn: item.productBrandSn,
  168. productTypeSn3: item.productTypeSn3,
  169. priceType: _this.form.priceType,
  170. type: isPrint || 'preview'
  171. }
  172. // 打印货位编号
  173. if (_this.form.orderBy != '-1') {
  174. obj.orderBy = _this.form.orderBy
  175. obj.priceType = obj.priceType + '_STACK_PLACE'
  176. }
  177. _this.$emit('ok', obj)
  178. }
  179. } else if (_this.nowType == 'SALES_BILL') { // 销售打印
  180. // 销售打印无权限不打印
  181. if (!_this.$hasPermissions('B_salesPrint_salesPrice')) {
  182. _this.form.priceType = 'SALES_BILL'
  183. }
  184. const obj = {
  185. salesBillSn: _this.itemData.salesBillSn,
  186. priceType: _this.form.priceType,
  187. type: isPrint || 'preview'
  188. }
  189. _this.$emit('ok', obj)
  190. } else if (_this.nowType == 'export') { // 销售导出
  191. // 销售导出无权限不导出
  192. if (!_this.$hasPermissions('B_salesDetailExport_salesPrice')) {
  193. _this.form.priceType = _this.form.dataScope == 'ENOUGH' ? 'SALES_BILL_NOT_LACK' : 'SALES_BILL'
  194. }
  195. if (_this.form.averagePrice == '1') {
  196. _this.form.priceType += '_WEIGHT'
  197. }
  198. const obj = {
  199. salesBillSn: _this.itemData.salesBillSn,
  200. priceType: _this.form.priceType,
  201. dataScope: _this.form.dataScope == 'all' ? '' : _this.form.dataScope,
  202. type: isPrint || 'preview'
  203. }
  204. _this.$emit('ok', obj)
  205. }
  206. _this.isShow = false
  207. } else {
  208. return false
  209. }
  210. })
  211. },
  212. // 获取该销售单产品二级分类
  213. getTypeData () {
  214. this.typeList = [{ id: 'all' }]
  215. salesDetailProductType({ sn: this.itemData.salesBillSn || null }).then(res => {
  216. if (res.status == 200) {
  217. if (res.data && res.data.length > 0) {
  218. this.typeList = [...this.typeList, ...res.data]
  219. }
  220. }
  221. })
  222. }
  223. },
  224. watch: {
  225. // 父页面传过来的弹框状态
  226. openModal (newValue, oldValue) {
  227. this.isShow = newValue
  228. },
  229. // 重定义的弹框状态
  230. isShow (newValue, oldValue) {
  231. if (!newValue) {
  232. // 重置表单选项
  233. this.form = {
  234. id: 'all',
  235. dataScope: 'all',
  236. priceType: undefined,
  237. orderBy: undefined
  238. }
  239. this.$refs.ruleForm.resetFields()
  240. } else {
  241. // 如果是分类打印
  242. if (this.nowType == 'SALES_BILL_TYPE') {
  243. this.getTypeData()
  244. }
  245. }
  246. }
  247. }
  248. }
  249. </script>
  250. <style lang="less">
  251. .sales-print-type-modal{
  252. .btn-cont {
  253. text-align: center;
  254. margin: 35px 0 10px;
  255. }
  256. }
  257. </style>