printModal.vue 10 KB

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