add-purchase-contract.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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-something";
  10. import { initColumns } from "./config/add";
  11. export default {
  12. name: "AddPurchaseContractDrawer",
  13. components: initComponents(initColumns()),
  14. dicts: initDicts(initColumns()),
  15. data() {
  16. return {
  17. visible: true,
  18. columns: initColumns(),
  19. rules: initRules(initColumns()),
  20. params: initParams(initColumns()),
  21. tabColumns: initTabColumns(),
  22. tabName: "first",
  23. tabTableDatas: {
  24. first: [],
  25. second: [],
  26. third: [],
  27. fourth: [],
  28. fifth: [],
  29. },
  30. currentComponent: { name: "", title: "", value: "", row: {} },
  31. };
  32. },
  33. computed: {},
  34. watch: {},
  35. methods: {
  36. beforeOpen() {
  37. const { deptName, nickName, orgName } = this.$store.state.user;
  38. this.params.puOrg = orgName;
  39. this.params.buyer = nickName;
  40. this.params.puDept = deptName;
  41. },
  42. setVisible(prop) {
  43. this.visible = prop;
  44. },
  45. addTableRow() {},
  46. cancel() {
  47. this.setVisible(false);
  48. this.params = arr2obj(this.columns, "key", "value");
  49. },
  50. sava() {
  51. this.setVisible(false);
  52. },
  53. async submitSava() {
  54. console.log(this.params);
  55. return;
  56. try {
  57. const res = await add(this.params);
  58. console.log("res", res);
  59. } catch (err) {
  60. this.$notify.error({ title: "error", message: err });
  61. } finally {
  62. this.setVisible(false);
  63. }
  64. },
  65. //
  66. openAsyncInputDialog(prop, type) {
  67. try {
  68. const {
  69. key,
  70. title,
  71. config: { componentName },
  72. } = prop;
  73. this.currentComponent.row = prop;
  74. this.currentComponent.title = title;
  75. this.currentComponent.name = componentName;
  76. if (type === "change") {
  77. this.currentComponent.value = this.params[key];
  78. }
  79. if (type === "click") {
  80. this.currentComponent.value = "";
  81. }
  82. this.$nextTick(() => {
  83. const { setVisible } = this.$refs[componentName];
  84. setVisible(true);
  85. });
  86. } catch (err) {
  87. this.$notify.error({ title: "error", message: err });
  88. } finally {
  89. }
  90. },
  91. updateParams(prop) {
  92. const {
  93. config: { dataMapping },
  94. } = this.currentComponent.row;
  95. for (let key in dataMapping) {
  96. this.params[key] = prop[dataMapping[key]];
  97. }
  98. },
  99. },
  100. created() {
  101. // console.log("this,", initComponents(initColumns()));
  102. },
  103. mounted() {},
  104. destroyed() {},
  105. };
  106. </script>
  107. <template>
  108. <el-drawer
  109. direction="btt"
  110. size="100%"
  111. :with-header="false"
  112. :visible.sync="visible"
  113. @open="beforeOpen"
  114. >
  115. <el-card
  116. :body-style="{
  117. padding: '20px',
  118. display: 'flex',
  119. 'flex-wrap': 'wrap',
  120. }"
  121. style="margin: 10px"
  122. >
  123. <div
  124. slot="header"
  125. style="
  126. display: flex;
  127. justify-content: space-between;
  128. align-items: center;
  129. "
  130. >
  131. <h3>新增</h3>
  132. <div style="text-align: right">
  133. <el-button size="mini" @click="cancel">取消</el-button>
  134. <el-button size="mini" type="danger" @click="sava">保存</el-button>
  135. <el-button size="mini" type="info" @click="submitSava">
  136. 保存并新增
  137. </el-button>
  138. </div>
  139. </div>
  140. <component
  141. v-if="currentComponent.name"
  142. :is="currentComponent.name"
  143. :ref="currentComponent.name"
  144. :title="currentComponent.title"
  145. :value="currentComponent.value"
  146. @confirm="updateParams"
  147. ></component>
  148. <el-row>
  149. <el-form
  150. size="mini"
  151. label-position="right"
  152. label-width="135px"
  153. :model="params"
  154. :rules="rules"
  155. >
  156. <el-col
  157. v-for="(column, index) in columns"
  158. :key="index"
  159. :span="column.span || 6"
  160. >
  161. <el-form-item :prop="column.key" :label="column.title">
  162. <el-input
  163. v-if="column.type === 'Input'"
  164. v-model="params[column.key]"
  165. :placeholder="column.placeholder"
  166. :clearable="column.clearable"
  167. :disabled="column.disabled"
  168. style="width: 100%"
  169. ></el-input>
  170. <el-input
  171. v-if="column.type === 'InputDialog'"
  172. v-model="params[column.key]"
  173. :placeholder="column.placeholder"
  174. :clearable="column.clearable"
  175. :disabled="column.disabled"
  176. style="width: 100%"
  177. @blur="openAsyncInputDialog(column, 'change')"
  178. @change="openAsyncInputDialog(column, 'change')"
  179. >
  180. <template #suffix>
  181. <el-icon
  182. class="el-icon-s-operation"
  183. style="cursor: pointer"
  184. @click.native.stop="openAsyncInputDialog(column, 'click')"
  185. ></el-icon>
  186. </template>
  187. </el-input>
  188. <el-input
  189. v-if="column.type === 'Textarea'"
  190. v-model="params[column.key]"
  191. type="textarea"
  192. :placeholder="column.placeholder"
  193. :clearable="column.clearable"
  194. :disabled="column.disabled"
  195. style="width: 100%"
  196. ></el-input>
  197. <el-input-number
  198. v-if="column.type === 'InputNumber'"
  199. v-model="params[column.key]"
  200. :controls-position="column.config.controlsPosition"
  201. :placeholder="column.placeholder"
  202. :clearable="column.clearable"
  203. :disabled="column.disabled"
  204. style="width: 100%"
  205. ></el-input-number>
  206. <el-select
  207. v-if="column.type === 'Select'"
  208. v-model="params[column.key]"
  209. :placeholder="column.placeholder"
  210. :clearable="column.clearable"
  211. :disabled="column.disabled"
  212. style="width: 100%"
  213. >
  214. <el-option
  215. v-for="item in dict.type[column.config.optionsName]"
  216. :key="item.value"
  217. :label="item.label"
  218. :value="item.value"
  219. >
  220. </el-option>
  221. </el-select>
  222. <el-select
  223. v-if="column.type === 'TagSelect'"
  224. v-model="params[column.key]"
  225. multiple
  226. clearable
  227. collapse-tags
  228. :placeholder="column.placeholder"
  229. :clearable="column.clearable"
  230. :disabled="column.disabled"
  231. style="width: 100%"
  232. >
  233. <template #prefix>
  234. <el-icon
  235. class="el-icon-s-operation"
  236. style="cursor: pointer"
  237. @click.stop="$message.info(234)"
  238. ></el-icon>
  239. </template>
  240. <el-option
  241. v-for="item in options"
  242. :key="item.value"
  243. :label="item.label"
  244. :value="item.value"
  245. >
  246. </el-option>
  247. </el-select>
  248. <el-date-picker
  249. v-if="column.type === 'DatePicker'"
  250. v-model="params[column.key]"
  251. :type="column.config.type"
  252. :placeholder="column.placeholder"
  253. :clearable="column.clearable"
  254. :disabled="column.disabled"
  255. :picker-options="column.pickerOptions"
  256. style="width: 100%"
  257. >
  258. </el-date-picker>
  259. <el-upload
  260. v-if="column.type === 'Upload'"
  261. :file-list="params[column.key]"
  262. :disabled="column.disabled"
  263. drag
  264. action="https://jsonplaceholder.typicode.com/posts/"
  265. multiple
  266. >
  267. <i class="el-icon-upload"></i>
  268. <div class="el-upload__text">
  269. 将文件拖到此处,或<em>点击上传</em>
  270. </div>
  271. <div class="el-upload__tip" slot="tip">
  272. 只能上传jpg/png文件,且不超过500kb
  273. </div>
  274. </el-upload>
  275. </el-form-item>
  276. </el-col>
  277. </el-form>
  278. </el-row>
  279. </el-card>
  280. <el-card
  281. :body-style="{
  282. padding: '20px',
  283. display: 'flex',
  284. 'flex-wrap': 'wrap',
  285. position: 'relative',
  286. }"
  287. style="margin: 10px"
  288. >
  289. <el-tabs v-model="tabName" @tab-click="handleClick" style="width: 100%">
  290. <el-tab-pane
  291. v-for="(column, index) in tabColumns"
  292. :key="index"
  293. :label="column.title"
  294. :name="column.key"
  295. >
  296. <el-table :data="tabTableDatas[column.key]" style="width: 100%">
  297. <el-table-column
  298. v-for="(cColumn, cIndex) in column.tableColumns"
  299. :key="cIndex"
  300. :prop="cColumn.key"
  301. :label="cColumn.title"
  302. :width="cColumn.width"
  303. >
  304. </el-table-column>
  305. </el-table>
  306. </el-tab-pane>
  307. </el-tabs>
  308. <el-row style="position: absolute; top: 20px; right: 20px">
  309. <el-button size="mini" @click="addTableRow">增行</el-button>
  310. </el-row>
  311. </el-card>
  312. </el-drawer>
  313. </template>