index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <script>
  2. import { TableColumns ,BasicColumns} from "./column";
  3. import { initDicts } from "@/utils/init.js";
  4. import { FIRSTDIRECT, ADD } from "@/api/business/purchase/task";
  5. export default {
  6. name: "FirstDirectPurchaseDrawer",
  7. dicts: [...initDicts(TableColumns)],
  8. props: {
  9. selectData: {
  10. type: [Array],
  11. require: true,
  12. },
  13. },
  14. components: {
  15. ElSuperTable: () => import("@/components/super-table/index.vue"),
  16. ElDictTag: () => import("@/components/DictTag/index.vue"),
  17. ElComputedInputV2: () => import("@/components/computed-input-v2/index.vue"),
  18. },
  19. data() {
  20. return {
  21. title: "订单生成",
  22. width: "100%",
  23. column: 1,
  24. visible: false,
  25. loading: false,
  26. tableColumns: TableColumns,
  27. basicColumns:BasicColumns,
  28. data: [],
  29. showData:[],
  30. supplier:'',
  31. size:'mini',
  32. };
  33. },
  34. computed: {
  35. disabled: {
  36. get() {
  37. return !this.selectData.length;
  38. },
  39. set() {},
  40. },
  41. restaurants:{
  42. get(){
  43. let allSupplier = [];
  44. this.data.forEach(item =>{
  45. let orderPriceVos = item.orderPriceVos.map(order => ({
  46. value:order.supplierName,
  47. id:order.supplier
  48. }))
  49. allSupplier.push(...orderPriceVos);
  50. })
  51. allSupplier = this.uniqueFunc(allSupplier,'id');
  52. console.log(allSupplier,'allSupplier');
  53. return allSupplier;
  54. },
  55. set(){},
  56. }
  57. },
  58. watch: {
  59. },
  60. methods: {
  61. //
  62. async open(prop) {
  63. this.visible = await this.fetchItem(prop);
  64. this.supplier = '';
  65. },
  66. //
  67. hide() {
  68. this.visible = false;
  69. },
  70. //
  71. async fetchItem(prop) {
  72. try {
  73. // try
  74. this.loading = true;
  75. const { code, data } = await FIRSTDIRECT(prop);
  76. if (code === 200) {
  77. this.data = data.map((item) => ({
  78. ...item,
  79. orderPriceVos: item.orderPriceVos.map((cItem) => ({
  80. ...item,
  81. customerName:'',
  82. customer:'',
  83. ...cItem,
  84. purchaseQuantity: item.orderPriceVos.length === 1 ? (item.puQty - item.executeQty) : undefined
  85. })),
  86. }));
  87. console.log(this.data,'this.data');
  88. this.showData = _.cloneDeep(this.data);
  89. return true;
  90. } else {
  91. return false;
  92. }
  93. } catch (err) {
  94. // catch
  95. console.error(err);
  96. } finally {
  97. // finally
  98. this.loading = false;
  99. }
  100. },
  101. //
  102. async submit(prop) {
  103. const params = prop
  104. .map((item) => ({
  105. ...item,
  106. orderPriceVos: item.orderPriceVos.filter(
  107. (citem) => citem.purchaseQuantity
  108. ),
  109. }))
  110. .filter((item) => item.orderPriceVos.length);
  111. console.log(params,'params');
  112. try {
  113. this.loading = true;
  114. // try
  115. const { msg, code } = await ADD(params);
  116. if (code === 200) {
  117. this.hide();
  118. this.$emit("success");
  119. this.$notify.success({ title: msg, duration: 3000 });
  120. }
  121. } catch (err) {
  122. // catch
  123. } finally {
  124. // finally
  125. this.loading = false;
  126. }
  127. },
  128. hide(){
  129. this.visible = false;
  130. },
  131. supplierChange(value){
  132. console.log(value,'value');
  133. },
  134. // 建议值
  135. querySearch(queryString, cb){
  136. let results = this.restaurants;
  137. results = queryString
  138. ? results.filter(this.createFilter(queryString))
  139. : results;
  140. //cb是回调函数,返回筛选出的结果数据到输入框下面的输入列表
  141. cb(results);
  142. },
  143. createFilter(queryString) {
  144. return (item) => {
  145. return item.value.toUpperCase().match(queryString.toUpperCase());
  146. };
  147. },
  148. handleSelect(prop){
  149. console.log(this.data,'handleSelect');
  150. // this.tableColumns = this.tableColumns.map(({ item, attr }) =>{
  151. // if(item['key'] === 'supplierName'){
  152. // item.filter = [prop.value];
  153. // }
  154. // return {
  155. // item: {...item},
  156. // attr: {...attr},
  157. // }
  158. // })
  159. // this.$refs.superTable.forEach(item =>{
  160. // let { onFilter, onFilters } = item;
  161. // let supplierFilter = {
  162. // item:{
  163. // key: 'supplierName',
  164. // title: '供应商',
  165. // filterabled:true,
  166. // },
  167. // attr: {}
  168. // }
  169. // onFilters(supplierFilter);
  170. // onFilter();
  171. // })
  172. this.showData = this.data.map(item => {
  173. return {
  174. ...item,
  175. orderPriceVos:item.orderPriceVos.filter(order => order.supplier === prop.id),
  176. }
  177. })
  178. },
  179. handleClear(){
  180. this.showData = _.cloneDeep(this.data);
  181. },
  182. // 对象数组去重
  183. uniqueFunc(arr, uniId){
  184. const res = new Map();
  185. return arr.filter((item) => !res.has(item[uniId]) && res.set(item[uniId], 1));
  186. },
  187. changeQuantity(prop,value){
  188. this.data = this.data.map(item =>{
  189. if(item.id === prop.id){
  190. item.orderPriceVos = item.orderPriceVos.map(order =>{
  191. if(order.id === value.id){
  192. return value;
  193. }
  194. return order;
  195. })
  196. // item.orderPriceVos.forEach(order =>{
  197. // if(order.id === value.id){
  198. // let change = prop.orderPriceVos.filter(order => order.id === value.id);
  199. // order = {...change};
  200. // }
  201. // })
  202. }
  203. return item;
  204. })
  205. },
  206. changeDatePlan(prop,value){
  207. this.data = this.data.map(item =>{
  208. if(item.id === prop.id){
  209. item.orderPriceVos = item.orderPriceVos.map(order =>{
  210. if(order.id === value.id){
  211. return value;
  212. }
  213. return order;
  214. })
  215. }
  216. return item;
  217. })
  218. },
  219. changeNote(prop,value){
  220. this.data = this.data.map(item =>{
  221. if(item.id === prop.id){
  222. item.orderPriceVos = item.orderPriceVos.map(order =>{
  223. if(order.id === value.id){
  224. return value;
  225. }
  226. return order;
  227. })
  228. }
  229. return item;
  230. })
  231. },
  232. },
  233. created() {},
  234. mounted() {},
  235. updated() {
  236. // this.$refs.superTable && this.$refs.superTable[0].doLayout();
  237. },
  238. destroyed() {},
  239. };
  240. </script>
  241. <template>
  242. <el-button
  243. v-bind="$attrs"
  244. v-on="$listeners"
  245. :disabled="disabled"
  246. @click="open(selectData)"
  247. >
  248. {{ title }}
  249. <el-drawer
  250. :show-close="false"
  251. :size="width"
  252. :title="title"
  253. v-loading="loading"
  254. :visible.sync="visible"
  255. append-to-body
  256. >
  257. <template slot="title">
  258. <span>{{ title }}</span>
  259. <el-button
  260. type="primary"
  261. :size="$attrs.size"
  262. @click="submit(data)"
  263. v-loading="loading"
  264. >确 认</el-button
  265. >
  266. <el-button
  267. :size="$attrs.size"
  268. @click="hide"
  269. v-loading="loading"
  270. >取 消</el-button
  271. >
  272. </template>
  273. <el-row style="padding: 0 16px;">
  274. <el-col>
  275. <el-autocomplete
  276. class="inline-input"
  277. :size="size"
  278. v-model="supplier"
  279. clearable
  280. :fetch-suggestions="querySearch"
  281. placeholder="请输入供应商"
  282. @select="handleSelect"
  283. @clear="handleClear"
  284. ></el-autocomplete>
  285. </el-col>
  286. </el-row>
  287. <div v-for="(item, index) in showData" :key="index" class="m-4">
  288. <template v-if="item.orderPriceVos.length">
  289. <el-descriptions :column="4">
  290. <template slot="title" >
  291. <template>
  292. <span style="margin-right: 10px">{{ item.materialName }}</span>
  293. <span style="color: tomato">{{ item.puQty }}</span>
  294. (<span style="color: tomato">{{
  295. item.puQty - (item.executeQty || 0)
  296. }}</span
  297. >) <span> {{ item.puUnitName }}</span>
  298. </template>
  299. </template>
  300. <el-descriptions-item
  301. v-for="(basic,bIndex) in basicColumns"
  302. :key="bIndex"
  303. :label="basic.item.title"
  304. >{{ item[basic.item.key] }}
  305. </el-descriptions-item>
  306. <el-descriptions-item
  307. label="需求数量"
  308. >{{ item.puQty - (item.executeQty || 0) }}
  309. </el-descriptions-item>
  310. </el-descriptions>
  311. <el-super-table
  312. v-if="visible"
  313. ref="superTable"
  314. v-model="item.orderPriceVos"
  315. :columns="tableColumns"
  316. :size="$attrs.size"
  317. :dict="dict"
  318. showSummary
  319. >
  320. <!-- showSummary -->
  321. <template slot="purchaseQuantity" slot-scope="scope">
  322. <component
  323. v-bind="scope.attr"
  324. v-model="scope.row[scope.item.key]"
  325. :size="$attrs.size"
  326. :max="scope.attr.max(scope.row)"
  327. @change="changeQuantity(item,scope.row)"
  328. >
  329. </component>
  330. </template>
  331. <template slot="arrivalDatePlan" slot-scope="scope">
  332. <component
  333. v-bind="scope.attr"
  334. v-model="scope.row[scope.item.key]"
  335. :size="$attrs.size"
  336. @change="changeDatePlan"
  337. >
  338. </component>
  339. </template>
  340. <template slot="note" slot-scope="scope">
  341. <component
  342. v-bind="scope.attr"
  343. v-model="scope.row[scope.item.key]"
  344. :size="$attrs.size"
  345. @change="changeNote"
  346. >
  347. </component>
  348. </template>
  349. </el-super-table>
  350. </template>
  351. </div>
  352. </el-drawer>
  353. </el-button>
  354. </template>
  355. <style scoped></style>