BatchSetInfoModal.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div ref="container">
  3. <a-modal
  4. :title="title"
  5. :width="1000"
  6. :visible="visible"
  7. :confirm-loading="confirmLoading"
  8. :getContainer="() => $refs.container"
  9. :maskStyle="{ top: '93px', left: '154px' }"
  10. :wrapClassName="wrapClassNameInfo()"
  11. :mask="isDesktop()"
  12. :maskClosable="false"
  13. @ok="handleOk"
  14. @cancel="handleCancel"
  15. cancelText="取消"
  16. okText="保存"
  17. style="top: 20%; height: 45%"
  18. >
  19. <a-spin :spinning="confirmLoading">
  20. <a-form :form="form">
  21. <a-row class="form-row" :gutter="24">
  22. <a-col :md="8" :sm="24">
  23. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="颜色">
  24. <a-input placeholder="请输入颜色" v-decorator.trim="['color']" />
  25. </a-form-item>
  26. </a-col>
  27. <a-col :md="8" :sm="24">
  28. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="基础重量">
  29. <a-input-number style="width: 100%" placeholder="请输入基础重量(kg)" v-decorator.trim="['weight']" />
  30. </a-form-item>
  31. </a-col>
  32. <a-col :md="8" :sm="24">
  33. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="保质期">
  34. <a-input-number style="width: 100%" placeholder="请输入保质期(天)" v-decorator.trim="['expiryNum']" />
  35. </a-form-item>
  36. </a-col>
  37. <a-col :md="8" :sm="24">
  38. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="类别">
  39. <a-tree-select
  40. style="width: 100%"
  41. :dropdownStyle="{ maxHeight: '200px', overflow: 'auto' }"
  42. allow-clear
  43. :treeData="categoryTree"
  44. v-decorator="['categoryId']"
  45. placeholder="请选择类别"
  46. >
  47. </a-tree-select>
  48. </a-form-item>
  49. </a-col>
  50. <a-col :md="8" :sm="24">
  51. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="序列号">
  52. <a-select placeholder="有无序列号" v-decorator="['enableSerialNumber']">
  53. <a-select-option value="1">有</a-select-option>
  54. <a-select-option value="0">无</a-select-option>
  55. </a-select>
  56. </a-form-item>
  57. </a-col>
  58. <a-col :md="8" :sm="24">
  59. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="批号">
  60. <a-select placeholder="有无批号" v-decorator="['enableBatchNumber']">
  61. <a-select-option value="1">有</a-select-option>
  62. <a-select-option value="0">无</a-select-option>
  63. </a-select>
  64. </a-form-item>
  65. </a-col>
  66. <a-col :md="8" :sm="24">
  67. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="备注">
  68. <a-textarea :rows="1" placeholder="请输入备注" v-decorator="['remark']" style="margin-top: 8px" />
  69. </a-form-item>
  70. </a-col>
  71. </a-row>
  72. </a-form>
  73. </a-spin>
  74. </a-modal>
  75. </div>
  76. </template>
  77. <script>
  78. import { queryMaterialCategoryTreeList, batchUpdateMaterial } from '@/api/api'
  79. import { mixinDevice } from '@/utils/mixin'
  80. export default {
  81. name: 'BatchSetInfoModal',
  82. mixins: [mixinDevice],
  83. data() {
  84. return {
  85. title: '批量编辑',
  86. visible: false,
  87. categoryTree: [],
  88. materialIds: '',
  89. model: {},
  90. labelCol: {
  91. xs: { span: 24 },
  92. sm: { span: 5 },
  93. },
  94. wrapperCol: {
  95. xs: { span: 24 },
  96. sm: { span: 16 },
  97. },
  98. confirmLoading: false,
  99. form: this.$form.createForm(this),
  100. }
  101. },
  102. created() {},
  103. methods: {
  104. loadTreeData() {
  105. let that = this
  106. let params = {}
  107. params.id = ''
  108. queryMaterialCategoryTreeList(params).then((res) => {
  109. if (res) {
  110. that.categoryTree = []
  111. for (let i = 0; i < res.length; i++) {
  112. let temp = res[i]
  113. that.categoryTree.push(temp)
  114. }
  115. }
  116. })
  117. },
  118. edit(ids) {
  119. this.materialIds = ids
  120. this.form.resetFields()
  121. this.model = Object.assign({}, '')
  122. this.loadTreeData()
  123. this.visible = true
  124. },
  125. close() {
  126. this.$emit('close')
  127. this.visible = false
  128. },
  129. handleOk() {
  130. const that = this
  131. // 触发表单验证
  132. this.form.validateFields((err, values) => {
  133. if (!err) {
  134. let formData = Object.assign(this.model, values)
  135. if (JSON.stringify(formData) === '{}') {
  136. that.$message.warning('抱歉,请输入要批量编辑的内容!')
  137. return
  138. }
  139. if (formData.enableSerialNumber === '1' && formData.enableBatchNumber === '1') {
  140. that.$message.warning('抱歉,序列号和批号只能选择一项!')
  141. return
  142. }
  143. let idList = that.materialIds ? that.materialIds.split(',') : []
  144. that.$confirm({
  145. title: '确认操作',
  146. content: '是否操作选中的' + idList.length + '条数据?',
  147. onOk: function () {
  148. that.confirmLoading = true
  149. let paramObj = {
  150. ids: that.materialIds,
  151. material: JSON.stringify(formData),
  152. }
  153. batchUpdateMaterial(paramObj)
  154. .then((res) => {
  155. if (res.code === 200) {
  156. that.$emit('ok')
  157. } else {
  158. that.$message.warning(res.data.message)
  159. }
  160. })
  161. .finally(() => {
  162. that.confirmLoading = false
  163. that.close()
  164. })
  165. },
  166. })
  167. }
  168. })
  169. },
  170. handleCancel() {
  171. this.close()
  172. },
  173. },
  174. }
  175. </script>
  176. <style scoped></style>