edit.html 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <el-card shadow="never" style="border: 0;">
  3. <el-form-item label="客户名称">
  4. <el-select v-model="value" placeholder="请选择" @change="changeCustomer" disabled >
  5. <el-option
  6. v-for="item in customerList"
  7. :key="item.value"
  8. :label="item.label"
  9. :value="item.value">
  10. </el-option>
  11. </el-select>
  12. </el-form-item>
  13. <el-form ref="form" :model="form" label-width="80px" border stripe>
  14. <el-form-item label="品种">
  15. <el-checkbox-group v-model="form.nameValue">
  16. <el-checkbox :label="item.label" :value="JSON.stringify(item)" v-for="(item, index) in options"
  17. :key="index" @change="changeType">
  18. </el-checkbox>
  19. </el-checkbox-group>
  20. </el-form-item>
  21. <el-form-item label="规格">
  22. <el-table :data="tableData" style="border: 1px solid rgb(235, 235, 235); border-radius: 6px">
  23. <el-table-column prop="name" label="规格" width="200">
  24. </el-table-column>
  25. <el-table-column prop="price" label="发货价格" align="center">
  26. <template #default="{row}">
  27. <el-input v-model="row.price" placeholder="发货价格"></el-input>
  28. </template>
  29. </el-table-column>
  30. <el-table-column label="操作" width="120" header-align="right">
  31. <template #default="scope">
  32. <el-button @click.native.prevent="deleteRow(scope.$index, tableData)" type="text"
  33. size="small">
  34. 移除
  35. </el-button>
  36. </template>
  37. </el-table-column>
  38. </el-table>
  39. </el-form-item>
  40. <el-form-item>
  41. <el-button type="primary" @click="onSubmit">立即创建</el-button>
  42. <el-button>取消</el-button>
  43. </el-form-item>
  44. </el-form>
  45. </el-card>
  46. </template>
  47. <script>
  48. import form from "@components/Form.js";
  49. var typeList = [], boxList = [], customerList = [], customer = 0;
  50. export default {
  51. components: { 'YunForm': form },
  52. data() {
  53. return {
  54. row: Yunqi.data.row,
  55. tableData: Yunqi.data.row.specs,
  56. value: Yunqi.data.row.customer_id,
  57. form: {
  58. nameValue: Yunqi.data.row.variety,
  59. },
  60. options: typeList,//品种
  61. customerList: customerList, //客户列表
  62. }
  63. },
  64. methods: {
  65. changeType: function (data, row) {
  66. //获取规格
  67. let obj = JSON.parse(row.target.value);
  68. //品种去除
  69. let idx = boxList.findIndex(item => item.value == obj.value);
  70. if (idx != -1) {
  71. boxList.splice(idx, 1)
  72. }else{
  73. boxList.push({ label: obj.label, value: obj.value });
  74. }
  75. Yunqi.ajax.get('shop/customer_spec/get_box', { type_id: obj.value }, false, false, true).then(res => {
  76. //编辑数据
  77. if (res.length > 0) {
  78. for (var key in Object(res)) {
  79. let index = this.tableData.findIndex(item => item.value == res[key]['id']);
  80. if (index != -1 ) {
  81. this.tableData.splice(index, 1)
  82. }else {
  83. this.tableData.push({ name: res[key]['title'], value: res[key]['id'], price: res[key]['price'], type_id:obj.value, type_name: obj.label });
  84. }
  85. }
  86. }
  87. });
  88. },
  89. onSubmit() {
  90. //获取规格
  91. if (this.tableData == "" || boxList.length == 0 ) return;
  92. Yunqi.ajax.post('shop/customer_spec/edit', {ids: Yunqi.data.row.id, type_list: boxList, type_box: this.tableData }, false, false, true).then(res => {
  93. if (res.code == 200) {
  94. this.$message.success(__('设置成功'));
  95. Yunqi.api.closelayer(Yunqi.app.window.id, true);
  96. } else {
  97. Yunqi.alert(__('请填写发货价格'), __('温馨提示'), { type: 'error' });
  98. }
  99. });
  100. },
  101. deleteRow(index, rows) {
  102. rows.splice(index, 1);
  103. }
  104. },
  105. onLoad: function () {
  106. for (let index = 0; index < this.form.nameValue.length; index++) {
  107. this.form.nameValue[index] = JSON.stringify(this.form.nameValue[index]);
  108. }
  109. let type = Yunqi.data.fieldList;
  110. //全部品种
  111. for (var key in Object(type)) {
  112. typeList.push({ label: type[key], value: key });
  113. }
  114. //全部客户
  115. let customer = Yunqi.data.customerList;
  116. for (var key in Object(customer)) {
  117. customerList.push({ label: customer[key], value: key });
  118. }
  119. //品种
  120. for (var key in Object(Yunqi.data.row.variety)) {
  121. boxList[key] = JSON.parse(Yunqi.data.row.variety[key]);
  122. }
  123. },
  124. }
  125. </script>
  126. <style>
  127. </style>