add-purchase-task.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <script>
  2. import { add } from "@/api/business/purchase/purchase-contract";
  3. import { arr2obj } from "@/utils/data-transform";
  4. import {
  5. initDicts,
  6. initRules,
  7. initParams,
  8. initComponents,
  9. } from "@/utils/init";
  10. import { initColumns } from "./config/add";
  11. export default {
  12. name: "AddPurchaseTaskDrawer",
  13. // components: initComponents(initColumns()),
  14. dicts: initDicts(initColumns()),
  15. data() {
  16. return {
  17. visible: false,
  18. columns: initColumns(),
  19. rules: initRules(initColumns()),
  20. params: initParams(initColumns()),
  21. currentComponent: { name: "", title: "", value: "", row: {} },
  22. };
  23. },
  24. computed: {},
  25. watch: {},
  26. methods: {
  27. setVisible(prop) {
  28. this.visible = prop;
  29. },
  30. //
  31. openAsyncInputDialog(prop, type) {
  32. try {
  33. const {
  34. key,
  35. title,
  36. config: { componentName },
  37. } = prop;
  38. this.currentComponent.row = prop;
  39. this.currentComponent.title = title;
  40. this.currentComponent.name = componentName;
  41. if (type === "change") {
  42. this.currentComponent.value = this.params[key];
  43. }
  44. if (type === "click") {
  45. this.currentComponent.value = "";
  46. }
  47. this.$nextTick(() => {
  48. const { setVisible } = this.$refs[componentName];
  49. setVisible(true);
  50. });
  51. } catch (err) {
  52. this.$notify.error({ title: "error", message: err });
  53. } finally {
  54. }
  55. },
  56. updateParams(prop) {
  57. const {
  58. config: { dataMapping },
  59. } = this.currentComponent.row;
  60. for (let key in dataMapping) {
  61. this.params[key] = prop[dataMapping[key]];
  62. }
  63. },
  64. },
  65. created() {
  66. console.log(this.params);
  67. },
  68. mounted() {},
  69. destroyed() {},
  70. };
  71. </script>
  72. <template>
  73. <el-drawer
  74. direction="btt"
  75. size="100%"
  76. :with-header="false"
  77. :visible.sync="visible"
  78. @open="beforeOpen"
  79. >
  80. <el-card
  81. :body-style="{
  82. padding: '20px',
  83. display: 'flex',
  84. 'flex-wrap': 'wrap',
  85. }"
  86. style="margin: 10px"
  87. >
  88. <div
  89. slot="header"
  90. style="
  91. display: flex;
  92. justify-content: space-between;
  93. align-items: center;
  94. "
  95. >
  96. <h3>新增</h3>
  97. <div style="text-align: right">
  98. <el-button size="mini" @click="cancel">取消</el-button>
  99. <el-button size="mini" type="danger" @click="sava">保存</el-button>
  100. <el-button size="mini" type="info" @click="submitSava">
  101. 保存并新增
  102. </el-button>
  103. </div>
  104. </div>
  105. <component
  106. v-if="currentComponent.name"
  107. :is="currentComponent.name"
  108. :ref="currentComponent.name"
  109. :title="currentComponent.title"
  110. :value="currentComponent.value"
  111. @confirm="updateParams"
  112. ></component>
  113. <el-row>
  114. <el-form
  115. size="mini"
  116. label-position="right"
  117. label-width="135px"
  118. :model="params"
  119. :rules="rules"
  120. >
  121. <el-col
  122. v-for="(column, index) in columns"
  123. :key="index"
  124. :span="column.span || 6"
  125. >
  126. <el-form-item :prop="column.key" :label="column.title">
  127. <el-input
  128. v-if="column.type === 'Input'"
  129. v-model="params[column.key]"
  130. :placeholder="column.placeholder"
  131. :clearable="column.clearable"
  132. :disabled="column.disabled"
  133. style="width: 100%"
  134. ></el-input>
  135. <el-input
  136. v-if="column.type === 'InputDialog'"
  137. v-model="params[column.key]"
  138. :placeholder="column.placeholder"
  139. :clearable="column.clearable"
  140. :disabled="column.disabled"
  141. style="width: 100%"
  142. @blur="openAsyncInputDialog(column, 'change')"
  143. @change="openAsyncInputDialog(column, 'change')"
  144. >
  145. <template #suffix>
  146. <el-icon
  147. class="el-icon-s-operation"
  148. style="cursor: pointer"
  149. @click.native.stop="openAsyncInputDialog(column, 'click')"
  150. ></el-icon>
  151. </template>
  152. </el-input>
  153. <el-input
  154. v-if="column.type === 'Textarea'"
  155. v-model="params[column.key]"
  156. type="textarea"
  157. :placeholder="column.placeholder"
  158. :clearable="column.clearable"
  159. :disabled="column.disabled"
  160. style="width: 100%"
  161. ></el-input>
  162. <el-input-number
  163. v-if="column.type === 'InputNumber'"
  164. v-model="params[column.key]"
  165. :controls-position="
  166. column.config && column.config.controlsPosition
  167. "
  168. :placeholder="column.placeholder"
  169. :clearable="column.clearable"
  170. :disabled="column.disabled"
  171. style="width: 100%"
  172. ></el-input-number>
  173. <el-select
  174. v-if="column.type === 'Select'"
  175. v-model="params[column.key]"
  176. :placeholder="column.placeholder"
  177. :clearable="column.clearable"
  178. :disabled="column.disabled"
  179. style="width: 100%"
  180. >
  181. <el-option
  182. v-for="item in dict.type[column.config.optionsName]"
  183. :key="item.value"
  184. :label="item.label"
  185. :value="item.value"
  186. >
  187. </el-option>
  188. </el-select>
  189. <el-select
  190. v-if="column.type === 'TagSelect'"
  191. v-model="params[column.key]"
  192. multiple
  193. clearable
  194. collapse-tags
  195. :placeholder="column.placeholder"
  196. :clearable="column.clearable"
  197. :disabled="column.disabled"
  198. style="width: 100%"
  199. >
  200. <template #prefix>
  201. <el-icon
  202. class="el-icon-s-operation"
  203. style="cursor: pointer"
  204. @click.stop="$message.info(234)"
  205. ></el-icon>
  206. </template>
  207. <el-option
  208. v-for="item in options"
  209. :key="item.value"
  210. :label="item.label"
  211. :value="item.value"
  212. >
  213. </el-option>
  214. </el-select>
  215. <el-date-picker
  216. v-if="column.type === 'DatePicker'"
  217. v-model="params[column.key]"
  218. :type="column.config.type"
  219. :placeholder="column.placeholder"
  220. :clearable="column.clearable"
  221. :disabled="column.disabled"
  222. :picker-options="column.pickerOptions"
  223. style="width: 100%"
  224. >
  225. </el-date-picker>
  226. <el-upload
  227. v-if="column.type === 'Upload'"
  228. :file-list="params[column.key]"
  229. :disabled="column.disabled"
  230. drag
  231. action="https://jsonplaceholder.typicode.com/posts/"
  232. multiple
  233. >
  234. <i class="el-icon-upload"></i>
  235. <div class="el-upload__text">
  236. 将文件拖到此处,或<em>点击上传</em>
  237. </div>
  238. <div class="el-upload__tip" slot="tip">
  239. 只能上传jpg/png文件,且不超过500kb
  240. </div>
  241. </el-upload>
  242. </el-form-item>
  243. </el-col>
  244. </el-form>
  245. </el-row>
  246. </el-card>
  247. </el-drawer>
  248. </template>