index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. methods: {
  60. //
  61. async open(prop) {
  62. this.visible = await this.fetchItem(prop);
  63. },
  64. //
  65. hide() {
  66. this.visible = false;
  67. },
  68. //
  69. async fetchItem(prop) {
  70. try {
  71. // try
  72. this.loading = true;
  73. const { code, data } = await FIRSTDIRECT(prop);
  74. if (code === 200) {
  75. this.data = data.map((item) => ({
  76. ...item,
  77. orderPriceVos: item.orderPriceVos.map((cItem) => ({
  78. ...item,
  79. customerName:'',
  80. customer:'',
  81. ...cItem,
  82. purchaseQuantity: item.orderPriceVos.length === 1 ? (item.puQty - item.executeQty) : undefined
  83. })),
  84. }));
  85. this.showData = _.cloneDeep(this.data);
  86. console.log(this.data,'this.data');
  87. return true;
  88. } else {
  89. return false;
  90. }
  91. } catch (err) {
  92. // catch
  93. console.error(err);
  94. } finally {
  95. // finally
  96. this.loading = false;
  97. }
  98. },
  99. //
  100. async submit(prop) {
  101. const params = prop
  102. .map((item) => ({
  103. ...item,
  104. orderPriceVos: item.orderPriceVos.filter(
  105. (citem) => citem.purchaseQuantity
  106. ),
  107. }))
  108. .filter((item) => item.orderPriceVos.length);
  109. console.log(params,'params');
  110. try {
  111. // try
  112. const { msg, code } = await ADD(params);
  113. if (code === 200) {
  114. this.hide();
  115. this.$emit("success");
  116. this.$notify.success({ title: msg, duration: 3000 });
  117. }
  118. } catch (err) {
  119. // catch
  120. } finally {
  121. // finally
  122. }
  123. },
  124. hide(){
  125. this.visible = false;
  126. },
  127. supplierChange(value){
  128. console.log(value,'value');
  129. },
  130. // 建议值
  131. querySearch(queryString, cb){
  132. let results = this.restaurants;
  133. results = queryString
  134. ? results.filter(this.createFilter(queryString))
  135. : results;
  136. //cb是回调函数,返回筛选出的结果数据到输入框下面的输入列表
  137. cb(results);
  138. },
  139. createFilter(queryString) {
  140. return (item) => {
  141. return item.value.toUpperCase().match(queryString.toUpperCase());
  142. };
  143. },
  144. handleSelect(prop){
  145. console.log(prop,'prop');
  146. this.showData = this.data.map(item => {
  147. return {
  148. ...item,
  149. orderPriceVos:item.orderPriceVos.filter(order => order.supplier === prop.id),
  150. }
  151. })
  152. },
  153. handleClear(){
  154. this.showData = _.cloneDeep(this.data);
  155. },
  156. // 对象数组去重
  157. uniqueFunc(arr, uniId){
  158. const res = new Map();
  159. return arr.filter((item) => !res.has(item[uniId]) && res.set(item[uniId], 1));
  160. },
  161. },
  162. created() {},
  163. mounted() {},
  164. destroyed() {},
  165. };
  166. </script>
  167. <template>
  168. <el-button
  169. v-bind="$attrs"
  170. v-on="$listeners"
  171. :disabled="disabled"
  172. @click="open(selectData)"
  173. >
  174. {{ title }}
  175. <el-drawer
  176. :show-close="false"
  177. :size="width"
  178. :title="title"
  179. :visible.sync="visible"
  180. append-to-body
  181. >
  182. <template slot="title">
  183. <span>{{ title }}</span>
  184. <el-button
  185. type="primary"
  186. :size="$attrs.size"
  187. :loading="loading"
  188. @click="submit(data)"
  189. >确 认</el-button
  190. >
  191. <el-button
  192. :size="$attrs.size"
  193. :loading="loading"
  194. @click="hide"
  195. >取 消</el-button
  196. >
  197. </template>
  198. <!-- <el-row style="padding: 0 16px;">
  199. <el-col>
  200. <el-autocomplete
  201. class="inline-input"
  202. :size="size"
  203. v-model="supplier"
  204. clearable
  205. :fetch-suggestions="querySearch"
  206. placeholder="请输入供应商"
  207. @select="handleSelect"
  208. @clear="handleClear"
  209. ></el-autocomplete>
  210. </el-col>
  211. </el-row> -->
  212. <div v-for="(item, index) in data" :key="index" class="m-4">
  213. <template v-if="item.orderPriceVos.length">
  214. <el-descriptions>
  215. <template slot="title" >
  216. <template>
  217. <span style="margin-right: 10px">{{ item.materialName }}</span>
  218. <span style="color: tomato">{{ item.puQty }}</span>
  219. (<span style="color: tomato">{{
  220. item.puQty - (item.executeQty || 0)
  221. }}</span
  222. >) <span> {{ item.puUnitName }}</span>
  223. </template>
  224. </template>
  225. <el-descriptions-item
  226. v-for="(basic,bIndex) in basicColumns"
  227. :key="bIndex"
  228. :label="basic.item.title"
  229. >{{ item[basic.item.key] }}
  230. </el-descriptions-item>
  231. <el-descriptions-item
  232. label="需求数量"
  233. >{{ item.puQty - (item.executeQty || 0) }}
  234. </el-descriptions-item>
  235. </el-descriptions>
  236. <el-super-table
  237. v-model="item.orderPriceVos"
  238. :columns="tableColumns"
  239. :size="$attrs.size"
  240. :dict="dict"
  241. >
  242. <!-- showSummary -->
  243. <template slot="purchaseQuantity" slot-scope="scope">
  244. <component
  245. v-bind="scope.attr"
  246. v-model="scope.row[scope.item.key]"
  247. :size="$attrs.size"
  248. :max="scope.attr.max(scope.row)"
  249. >
  250. </component>
  251. </template>
  252. </el-super-table>
  253. </template>
  254. </div>
  255. </el-drawer>
  256. </el-button>
  257. </template>
  258. <style scoped></style>