offlineModal.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <a-modal
  3. centered
  4. class="productInfoOffline-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="提示"
  8. v-model="isShow"
  9. @cancle="isShow=false"
  10. :width="800">
  11. <p v-if="loadData.length==1" style="font-weight: bold;margin-left: 20px;">确认要下线吗?</p>
  12. <p v-else style="font-weight: bold;margin-left: 20px;">已选有效数据{{ loadData.length }}条,确认要批量下线吗?</p>
  13. <a-spin :spinning="spinning" tip="Loading...">
  14. <a-form-model
  15. id="productInfoEdit-form"
  16. ref="ruleForm"
  17. :model="form"
  18. :rules="rules"
  19. :label-col="formItemLayout.labelCol"
  20. :wrapper-col="formItemLayout.wrapperCol">
  21. <a-form-model-item label="下线选项" prop="offlineReasonType">
  22. <v-select
  23. code="OFFLINE_REASON_TYPE"
  24. id="productInfoOffline-offlineReasonType"
  25. v-model="form.offlineReasonType"
  26. allowClear
  27. placeholder="请选择下线选项"
  28. ></v-select>
  29. </a-form-model-item>
  30. <a-form-model-item label="通用编码" :required="form.offlineReasonType=='通用'">
  31. <!-- 列表 -->
  32. <a-table
  33. class="sTable"
  34. ref="table"
  35. size="small"
  36. :rowKey="(record) => record.productSn"
  37. :columns="columns"
  38. :dataSource="loadData"
  39. :pagination="false"
  40. bordered>
  41. <!-- 通用编码 -->
  42. <template slot="commonProductList" slot-scope="text, record" >
  43. <productCodeList ref="productCodeList" mode="multiple" @change="e => productCodeChange(e, record)" />
  44. </template>
  45. </a-table>
  46. </a-form-model-item>
  47. <a-form-model-item label="下线备注" prop="offlineRemark">
  48. <a-textarea
  49. id="productInfoOffline-offlineRemark"
  50. :maxLength="60"
  51. v-model="form.offlineRemark"
  52. placeholder="请输入下线备注(最多60个字符)"
  53. allowClear />
  54. </a-form-model-item>
  55. </a-form-model>
  56. <div class="btn-cont">
  57. <a-button type="primary" id="productInfoOffline-submit" @click="handleSubmit">确定</a-button>
  58. <a-button id="productInfoOffline-cancel" @click="isShow = false" style="margin-left: 100px;">取消</a-button>
  59. </div>
  60. </a-spin>
  61. </a-modal>
  62. </template>
  63. <script>
  64. import { VSelect } from '@/components'
  65. import productCodeList from '@/views/common/productCodeList.vue'
  66. import { productOffline } from '@/api/product'
  67. export default {
  68. name: 'ProductInfoDetailModal',
  69. components: { VSelect, productCodeList },
  70. props: {
  71. openModal: { // 弹框显示状态
  72. type: Boolean,
  73. default: false
  74. },
  75. offlineProductList: {
  76. type: Array,
  77. default: () => {
  78. return []
  79. }
  80. }
  81. },
  82. data () {
  83. return {
  84. isShow: this.openModal, // 是否打开弹框
  85. spinning: false,
  86. formItemLayout: {
  87. labelCol: { span: 3 },
  88. wrapperCol: { span: 21 }
  89. },
  90. form: {
  91. offlineReasonType: undefined,
  92. offlineRemark: ''
  93. },
  94. rules: {
  95. offlineReasonType: [
  96. { required: true, message: '请选择下线选项', trigger: 'change' }
  97. ]
  98. },
  99. columns: [
  100. { title: '产品编码', dataIndex: 'code', width: 220, align: 'center', customRender: function (text) { return text || '--' } },
  101. { title: '通用编码', scopedSlots: { customRender: 'commonProductList' }, align: 'center' }
  102. ],
  103. loadData: []
  104. }
  105. },
  106. methods: {
  107. productCodeChange (val, row) {
  108. console.log(val)
  109. row.commonProductList = []
  110. if (val.length > 0) {
  111. val.map(item => {
  112. row.commonProductList.push({ code: item.row && item.row.code ? item.row.code : undefined, productSn: item.key || undefined })
  113. })
  114. }
  115. },
  116. // 确定 下线
  117. handleSubmit () {
  118. const _this = this
  119. if (_this.form.offlineReasonType == '通用') {
  120. const arr = []
  121. this.loadData.map((item, index) => {
  122. if (item.commonProductList.length < 1) {
  123. arr.push(index + 1)
  124. }
  125. })
  126. if (arr.length > 0) {
  127. this.$message.warning('请将通用编码填写完整后再提交!')
  128. return
  129. }
  130. }
  131. this.$refs.ruleForm.validate(valid => {
  132. if (valid) {
  133. const params = JSON.parse(JSON.stringify(_this.form))
  134. params.offlineProductList = _this.loadData
  135. console.log(params)
  136. return
  137. _this.spinning = true
  138. productOffline(params).then(res => {
  139. if (res.status == 200) {
  140. _this.$message.success(res.message)
  141. setTimeout(() => {
  142. _this.$emit('ok')
  143. _this.isShow = false
  144. _this.spinning = false
  145. }, 1000)
  146. } else {
  147. _this.spinning = false
  148. }
  149. })
  150. } else {
  151. console.log('error submit!!')
  152. return false
  153. }
  154. })
  155. }
  156. },
  157. watch: {
  158. // 父页面传过来的弹框状态
  159. openModal (newValue, oldValue) {
  160. this.isShow = newValue
  161. },
  162. // 重定义的弹框状态
  163. isShow (newValue, oldValue) {
  164. if (!newValue) {
  165. this.$emit('close')
  166. this.loadData = []
  167. this.form.offlineReasonType = undefined
  168. this.form.offlineRemark = ''
  169. }
  170. },
  171. offlineProductList: {
  172. handler (newValue, oldValue) {
  173. if (this.isShow && newValue) {
  174. this.loadData = JSON.parse(JSON.stringify(newValue))
  175. }
  176. },
  177. deep: true
  178. }
  179. }
  180. }
  181. </script>
  182. <style lang="less">
  183. .productInfoOffline-modal{
  184. .ant-modal-body {
  185. padding: 40px 40px 24px;
  186. }
  187. .btn-cont {
  188. text-align: center;
  189. margin: 35px 0 10px;
  190. }
  191. }
  192. </style>