detail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <template>
  2. <div>
  3. <Toptitle
  4. :title="
  5. type == 1
  6. ? '超标价格方案新增'
  7. : type == 2
  8. ? '超标价格方案编辑'
  9. : '超标价格方案详情'
  10. "
  11. >
  12. <slot name="titleButton">
  13. <Button @click="goBack" type="primary" ghost style="margin-right:10px;"
  14. >返回</Button
  15. >
  16. <Button
  17. @click="postData"
  18. type="primary"
  19. v-show="!isChecked"
  20. style="margin-right:10px;"
  21. >保存</Button
  22. >
  23. </slot>
  24. </Toptitle>
  25. <div class="top_search">
  26. <Form :model="formData" :label-width="100" class="top_search_form">
  27. <FormItem label="ID:">
  28. <Input
  29. type="text"
  30. size="small"
  31. disabled
  32. v-if="type != 3"
  33. v-model="formData.id"
  34. placeholder="自动生成"
  35. style="width: 200px"
  36. />
  37. <span v-else>{{ formData.id }}</span>
  38. </FormItem>
  39. <FormItem label="方案名称:">
  40. <Input
  41. type="text"
  42. size="small"
  43. v-if="type != 3"
  44. v-model="formData.title"
  45. placeholder="请输入方案名称"
  46. style="width: 200px"
  47. />
  48. <span v-else>{{ formData.title }}</span>
  49. </FormItem>
  50. </Form>
  51. </div>
  52. <div class="addBtn">
  53. <Button @click="handleRuleAdd()" v-show="!isChecked" type="primary"
  54. >新增规则</Button
  55. >
  56. </div>
  57. <Table :columns="tableColumns" max-height="600" :data="tableData" border>
  58. <template slot="productSet" slot-scope="{ index }">
  59. <!-- <Select v-model="tableData[index].basic_product_id"
  60. :disabled="isChecked"
  61. @on-change="changeProduct(tableData[index],index)">
  62. <Option v-for="item of cascader_list"
  63. :key="item.id"
  64. :value="item.id"
  65. :label="item.title"></Option>
  66. </Select> -->
  67. <el-cascader
  68. v-if="type != 3"
  69. v-model="tableData[index].basic_product_id"
  70. size="small"
  71. :show-all-levels="false"
  72. :options="cascader_list"
  73. :props="{
  74. expandTrigger: 'hover',
  75. children: 'child',
  76. value: 'id',
  77. label: 'title',
  78. emitPath: false,
  79. }"
  80. @change="changeProduct(tableData[index], index)"
  81. ></el-cascader>
  82. <span v-else>{{ tableData[index].product_type_title }}</span>
  83. </template>
  84. <template slot="partsSet" slot-scope="{ index }">
  85. <Select v-model="tableData[index].part_id" v-if="type != 3">
  86. <!-- @on-change="changeProduct(tableData[index],index)" -->
  87. <Option
  88. v-for="item of tableData[index].partsList"
  89. :key="item.id"
  90. :value="item.id"
  91. :label="item.title"
  92. ></Option>
  93. </Select>
  94. <span v-else>{{ tableData[index].part_title }}</span>
  95. </template>
  96. <template slot="typeSet" slot-scope="{ index }">
  97. <Select v-model="tableData[index].type" v-if="type != 3">
  98. <!-- @on-change="changeProduct(tableData[index],index)" -->
  99. <Option label="高" :value="1"></Option>
  100. <Option label="宽" :value="2"></Option>
  101. <Option label="厚" :value="3"></Option>
  102. </Select>
  103. <span v-else>{{
  104. tableData[index].type == 1
  105. ? "高"
  106. : tableData[index].type == 2
  107. ? "宽"
  108. : "厚"
  109. }}</span>
  110. </template>
  111. <template slot="priceSet" slot-scope="{ index }">
  112. <Input
  113. @on-focus="openKey(index)"
  114. v-if="type != 3"
  115. clearable
  116. placeholder="请输入公式"
  117. v-model="tableData[index].formula"
  118. />
  119. <span v-else>{{ tableData[index].formula }}</span>
  120. </template>
  121. <template slot="set" slot-scope="{ index }">
  122. <a
  123. style="margin:0 5px"
  124. v-show="!isChecked"
  125. @click="handleSet(tableData[index], index, 4)"
  126. >删除</a
  127. >
  128. </template>
  129. </Table>
  130. <Modal
  131. v-model="keyModal"
  132. :width="1250"
  133. :mask-closable="false"
  134. :closable="false"
  135. >
  136. <div>
  137. <KeyBoard
  138. :rightData="measureList"
  139. @cancel="cancelKey"
  140. @success="successKey"
  141. class="key-co"
  142. />
  143. </div>
  144. <div slot="footer"></div>
  145. </Modal>
  146. </div>
  147. </template>
  148. <script>
  149. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  150. // 例如:import 《组件名称》 from '《组件路径》';
  151. import KeyBoard from "../../../components/keyboard/index";
  152. export default {
  153. name: "",
  154. components: { KeyBoard },
  155. props: {},
  156. // import引入的组件需要注入到对象中才能使用
  157. data() {
  158. // 这里存放数据
  159. return {
  160. type: this.$route.query.type || null,
  161. id: this.$route.query.id || null,
  162. isChecked: this.$route.query.type == 3,
  163. loading: false,
  164. tableData: [],
  165. page_index: 1,
  166. total: 0,
  167. page_size: 10,
  168. formData: {},
  169. keyModal: false,
  170. tableColumns: [
  171. {
  172. title: "产品分类",
  173. key: "basic_product_id",
  174. align: "center",
  175. minWidth: 140,
  176. slot: "productSet",
  177. },
  178. {
  179. title: "部件",
  180. key: "part_id",
  181. align: "center",
  182. minWidth: 140,
  183. slot: "partsSet",
  184. },
  185. {
  186. title: "测量字段",
  187. key: "type",
  188. align: "center",
  189. minWidth: 140,
  190. slot: "typeSet",
  191. },
  192. {
  193. title: "最小数值",
  194. key: "min",
  195. align: "center",
  196. minWidth: 160,
  197. render: (h, params) => {
  198. const { row, index } = params;
  199. const currencyRow = this.tableData[index];
  200. return this.type != 3
  201. ? h("Input", {
  202. props: {
  203. placeholder: "默认为0",
  204. value: currencyRow.min,
  205. disabled: this.isChecked,
  206. },
  207. on: {
  208. "on-change": (e) => {
  209. const val = e.target.value * 1;
  210. currencyRow.min = val;
  211. // this.tableData.splice(index, 1, currencyRow);
  212. },
  213. },
  214. })
  215. : h("span", {}, currencyRow.min);
  216. },
  217. },
  218. {
  219. title: "最大数值",
  220. key: "max",
  221. align: "center",
  222. minWidth: 160,
  223. render: (h, params) => {
  224. const { row, index } = params;
  225. const currencyRow = this.tableData[index];
  226. return this.type != 3
  227. ? h("Input", {
  228. props: {
  229. placeholder: "默认为99999",
  230. value: currencyRow.max,
  231. disabled: this.isChecked,
  232. },
  233. on: {
  234. "on-change": (e) => {
  235. const val = e.target.value * 1;
  236. currencyRow.max = val;
  237. // this.tableData.splice(index, 1, currencyRow);
  238. },
  239. },
  240. })
  241. : h("span", {}, currencyRow.max);
  242. },
  243. },
  244. {
  245. title: "超标价格",
  246. key: "formula",
  247. align: "center",
  248. slot: "priceSet",
  249. minWidth: 140,
  250. },
  251. { title: "操作", key: "", align: "center", slot: "set", width: 100 },
  252. ],
  253. partsList: [],
  254. measureList: [],
  255. attrindex: null,
  256. cascader_list: [],
  257. };
  258. },
  259. // 生命周期 - 创建完成(可以访问当前this实例)
  260. created() {
  261. // 获取产品分类
  262. this.axios
  263. .get("/api/basics_product_index")
  264. .then((res) => {
  265. this.cascader_list = res.data.data;
  266. })
  267. .catch((err) => {
  268. console.error(err);
  269. });
  270. },
  271. // 生命周期 - 挂载完成(可以访问DOM元素)
  272. mounted() {
  273. this.init();
  274. },
  275. methods: {
  276. init() {
  277. this.id &&
  278. this.axios
  279. .get("/api/overdraft_detail", { params: { id: this.id } })
  280. .then((res) => {
  281. this.tableData = res.data.list;
  282. this.formData = res.data.detail;
  283. if (this.type != 3) {
  284. this.tableData.forEach((element, index) => {
  285. element.partsList = [];
  286. this.axios
  287. .get("/api/get_part_by_basic_product", {
  288. params: { basic_product_id: element.basic_product_id },
  289. })
  290. .then((res) => {
  291. element.partsList = res.data;
  292. this.tableData.splice(index, 1, element);
  293. // this.$forceUpdate()
  294. })
  295. .catch((err) => {
  296. console.error(err);
  297. });
  298. element.basic_product_id &&
  299. this.axios("/api/basics_product_list", {
  300. params: { id: element.basic_product_id },
  301. }).then((res) => {
  302. if (res.code == 200) {
  303. const { data } = res;
  304. const result = data.filter(
  305. (rows) => rows.id == element.basic_product_id
  306. );
  307. // this.productFiled = data;
  308. this.measureList = result[0].measure;
  309. }
  310. });
  311. });
  312. }
  313. })
  314. .catch((err) => {
  315. console.error(err);
  316. });
  317. },
  318. goBack() {
  319. this.$router.go(-1);
  320. },
  321. handleSet(row, index, type) {
  322. this.tableData.splice(index, 1);
  323. },
  324. postData() {
  325. this.axios({
  326. method: "post",
  327. url: "/api/overdraft_edit",
  328. data: {
  329. ...this.formData,
  330. detail: this.tableData,
  331. },
  332. }).then((res) => {
  333. if (res.code == 200) {
  334. this.$Message.success(res.msg);
  335. this.goBack();
  336. }
  337. });
  338. },
  339. handleRuleAdd() {
  340. const obj = { min: null, max: null, formula: null };
  341. this.tableData.push(obj);
  342. },
  343. changeProduct(row, index) {
  344. row.basic_product_id &&
  345. this.axios
  346. .get("/api/get_part_by_basic_product", {
  347. params: { basic_product_id: row.basic_product_id },
  348. })
  349. .then((res) => {
  350. row.partsList = res.data;
  351. row.part_id = "";
  352. this.tableData.splice(index, 1, row);
  353. })
  354. .catch((err) => {
  355. console.error(err);
  356. });
  357. row.basic_product_id &&
  358. this.axios("/api/basics_product_list", {
  359. params: { id: row.basic_product_id },
  360. }).then((res) => {
  361. if (res.code == 200) {
  362. const { data } = res;
  363. const result = data.filter(
  364. (rows) => rows.id == row.basic_product_id
  365. );
  366. // this.productFiled = data;
  367. this.measureList = result[0].measure;
  368. }
  369. });
  370. },
  371. openKey(row) {
  372. this.keyModal = true;
  373. this.attrindex = row;
  374. },
  375. successKey(str) {
  376. this.tableData[this.attrindex].formula = str;
  377. this.keyModal = false;
  378. this.tableData.splice(this.attrindex, 1, this.tableData[this.attrindex]);
  379. },
  380. cancelKey() {
  381. this.keyModal = false;
  382. },
  383. },
  384. // 监听属性 类似于data概念
  385. computed: {},
  386. // 监控data中的数据变化
  387. watch: {},
  388. beforeCreate() {}, // 生命周期 - 创建之前
  389. beforeMount() {}, // 生命周期 - 挂载之前
  390. beforeUpdate() {}, // 生命周期 - 更新之前
  391. updated() {}, // 生命周期 - 更新之后
  392. beforeDestroy() {}, // 生命周期 - 销毁之前
  393. destroyed() {}, // 生命周期 - 销毁完成
  394. activated() {}, // 如果页面有keep-alive缓存功能,这个函数会触发
  395. };
  396. </script>
  397. <style lang="scss" scoped>
  398. .top_search {
  399. padding: 20px 0;
  400. width: 100%;
  401. .top_search_form {
  402. // width: 800px;
  403. // display: flex;
  404. // justify-content: space-around;
  405. /deep/ .ivu-form-item {
  406. display: inline-block;
  407. width: 300px;
  408. }
  409. }
  410. }
  411. .addBtn {
  412. display: flex;
  413. justify-content: flex-end;
  414. padding: 10px 0;
  415. }
  416. /deep/ .ivu-table-wrapper {
  417. overflow: visible;
  418. }
  419. /deep/.ivu-form-item-content {
  420. span {
  421. vertical-align: middle;
  422. }
  423. }
  424. </style>