index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <div class="app-container">
  3. <div class="top-taber" style="margin-top: 10px">
  4. <el-radio-group v-model="otaType" size="small" @change="handleQuery">
  5. <el-radio-button label="1">美团</el-radio-button>
  6. <el-radio-button label="2">携程</el-radio-button>
  7. </el-radio-group>
  8. </div>
  9. <el-row :gutter="10" class="mb8" style="margin-top: 30px">
  10. <el-col :span="1.5">
  11. <el-button
  12. type="primary"
  13. plain
  14. icon="el-icon-key"
  15. size="mini"
  16. @click="handleKey"
  17. v-hasPermi="['otaMr:otaMr:key']"
  18. >填写密钥</el-button>
  19. </el-col>
  20. <el-col :span="1.5">
  21. <el-button
  22. type="primary"
  23. plain
  24. icon="el-icon-plus"
  25. size="mini"
  26. @click="handleAdd"
  27. v-hasPermi="['otaMr:otaMr:add']"
  28. >添加商品</el-button>
  29. </el-col>
  30. <right-toolbar :showSearch.sync="showSearch" :search="false" @queryTable="getList"></right-toolbar>
  31. </el-row>
  32. <el-table ref="tables" v-loading="loading" :data="dataList" border>
  33. <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
  34. <el-table-column label="商品名称" align="center" prop="goodsName" />
  35. <el-table-column label="类型" align="center" prop="goodsName" />
  36. <el-table-column label="市场价" align="center" prop="otaPrice">
  37. <template slot-scope="scope">
  38. <span>¥{{ scope.row.otaPrice }}</span>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="销售价格" align="center" prop="otaPrice">
  42. <template slot-scope="scope">
  43. <span>¥{{ scope.row.otaPrice }}</span>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="结算价" align="center" prop="otaPrice">
  47. <template slot-scope="scope">
  48. <span>¥{{ scope.row.otaPrice }}</span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  52. <template slot-scope="scope">
  53. <span v-hasPermi="['otaMr:otaMr:edit']" style="display: inline-block;margin-left: 10px;">
  54. <el-button
  55. size="mini"
  56. type="text"
  57. v-if="scope.row.status != '1'"
  58. @click="handleUpdate(scope.row,scope.index)"
  59. >修改</el-button>
  60. </span>
  61. <span v-hasPermi="['otaMr:otaMr:delete']" style="display: inline-block;margin-left: 10px;">
  62. <el-button
  63. size="mini"
  64. type="text"
  65. v-if="scope.row.status != '1'"
  66. @click="handleDelete(scope.row,scope.index)"
  67. >删除</el-button>
  68. </span>
  69. </template>
  70. </el-table-column>
  71. </el-table>
  72. <pagination
  73. v-show="total>0"
  74. :total="total"
  75. :page.sync="queryParams.pageNum"
  76. :limit.sync="queryParams.pageSize"
  77. @pagination="getList"
  78. />
  79. <!-- 新增/编辑弹框 -->
  80. <add-and-edit
  81. ref="addAndEdit"
  82. :dict="dict"
  83. @getList="getList"
  84. />
  85. <!-- 编辑商品弹框 -->
  86. <data-edit
  87. ref="dataEdit"
  88. @getList="getList"
  89. :dict="dict"></data-edit>
  90. <el-dialog
  91. title="填写密钥"
  92. :visible.sync="visibleStatus"
  93. width="600px"
  94. :destroy-on-close="true"
  95. :close-on-click-modal="false"
  96. >
  97. <div class="dialog">
  98. <el-form :model="otaForm" ref="otaForm" :rules="otaRules" label-width="120px">
  99. <el-form-item label="供应商id" prop="name">
  100. <el-input
  101. v-model="otaForm.name"
  102. placeholder=""
  103. clearable
  104. style="width: 100%;"
  105. />
  106. </el-form-item>
  107. <el-form-item label="client id" prop="otaKey">
  108. <el-input
  109. v-model="otaForm.otaKey"
  110. placeholder=""
  111. clearable
  112. style="width: 100%;"
  113. />
  114. </el-form-item>
  115. <el-form-item label="client secret" prop="otaValue">
  116. <el-input
  117. v-model="otaForm.otaValue"
  118. placeholder=""
  119. clearable
  120. style="width: 100%;"
  121. />
  122. </el-form-item>
  123. </el-form>
  124. </div>
  125. <div slot="footer" class="dialog-footer">
  126. <el-button @click="visibleStatus = false">取消</el-button>
  127. <el-button
  128. type="primary"
  129. @click="submitForm"
  130. v-loading.fullscreen.lock="otaLoading"
  131. element-loading-text="提交中..."
  132. element-loading-spinner="el-icon-loading"
  133. element-loading-background="rgba(0, 0, 0, 0.8)"
  134. >
  135. <span v-if="otaLoading">提交中...</span>
  136. <span v-else>保存</span>
  137. </el-button>
  138. </div>
  139. </el-dialog>
  140. </div>
  141. </template>
  142. <script>
  143. import { pageList, deleteById, getOtaConfig, otaSave } from '@/api/otaMr/otaMr'
  144. import addAndEdit from "./dialog/addAndEdit.vue";
  145. import dataEdit from "./dialog/dataEdit.vue";
  146. export default {
  147. name: "agreement",
  148. dicts: ['agreement_type'],
  149. components: { addAndEdit, dataEdit },
  150. data() {
  151. return {
  152. // 遮罩层
  153. loading: true,
  154. otaLoading: false,
  155. // 选中数组
  156. ids: [],
  157. // 非单个禁用
  158. single: true,
  159. // 非多个禁用
  160. multiple: true,
  161. // 显示搜索条件
  162. showSearch: true,
  163. // 总条数
  164. total: 0,
  165. // 用户表格数据
  166. dataList: null,
  167. // 弹出层标题
  168. title: "",
  169. otaType: '1',
  170. // 是否显示弹出层
  171. open: false,
  172. // 日期范围
  173. dateRange: [],
  174. // 查询参数
  175. queryParams: {
  176. pageNum: 1,
  177. pageSize: 10,
  178. ota: '1'
  179. },
  180. visibleStatus: false,
  181. newObj: {},
  182. visibleType: '',
  183. otaForm: {},
  184. otaRules: {
  185. name: [{ required: true, message: "请输入供应商id", trigger: ["change","blur"] }],
  186. otaKey: [{ required: true, message: "请输入client id", trigger: ["change","blur"] }],
  187. otaValue: [{ required: true, message: "请输入client secret", trigger: ["change","blur"] }]
  188. },
  189. };
  190. },
  191. created() {
  192. this.getList();
  193. },
  194. methods: {
  195. /** 查询列表 */
  196. getList() {
  197. this.loading = true;
  198. this.queryParams.ota = this.otaType
  199. pageList(this.addDateRange(this.queryParams, this.dateRange))
  200. .then(response => {
  201. this.dataList = response.data.rows;
  202. this.total = response.data.total;
  203. this.loading = false;
  204. }
  205. );
  206. },
  207. // 取消按钮
  208. cancel() {
  209. this.open = false;
  210. },
  211. /** 搜索按钮操作 */
  212. handleQuery() {
  213. this.queryParams.pageNum = 1;
  214. this.getList();
  215. },
  216. /** 重置按钮操作 */
  217. resetQuery() {
  218. this.dateRange = [];
  219. this.dataList = [];
  220. this.queryParams.pageNum = 1;
  221. this.handleQuery();
  222. },
  223. /** 新增按钮操作 */
  224. handleAdd() {
  225. this.$refs["addAndEdit"].openDialog("新增数据", this.queryParams);
  226. },
  227. /** 修改按钮操作 */
  228. handleUpdate(row) {
  229. this.$refs["dataEdit"].openDialog("修改数据", row);
  230. },
  231. /** 删除按钮操作 */
  232. handleDelete(row) {
  233. this.$modal.confirm('是否确认删除商品名称为"' + row.goodsName + '"的数据项?').then(function() {
  234. return deleteById(row.id);
  235. }).then(() => {
  236. this.getList();
  237. this.$modal.msgSuccess("删除成功");
  238. }).catch(() => {});
  239. },
  240. /** 查看按钮操作 */
  241. handleKey(obj, type) {
  242. this.visibleStatus = true
  243. this.visibleType = type;
  244. this.otaForm = {};
  245. this.getOtaConfigApi();
  246. },
  247. /** 查询列表 */
  248. getOtaConfigApi() {
  249. getOtaConfig({ota: this.otaType})
  250. .then(response => {
  251. let dataList = response.data;
  252. dataList.forEach(item => {
  253. this.$set(this.otaForm, item.otaKey, item.otaValue);
  254. })
  255. });
  256. },
  257. /**
  258. * 保存
  259. * @date 2023-11-22
  260. * @returns {any}
  261. */
  262. submitForm() {
  263. this.$refs["otaForm"].validate(async (valid) => {
  264. if (valid) {
  265. try {
  266. let postList = [];
  267. for (const key in this.otaForm) {
  268. postList.push({
  269. ota: this.otaType,
  270. otaKey: key,
  271. otaValue: this.otaForm[key]
  272. })
  273. }
  274. this.otaLoading = true;
  275. const { code } = await otaSave(postList);
  276. if (code === 200) {
  277. this.$message.success("操作成功!");
  278. this.getList();
  279. this.visibleStatus = false;
  280. }
  281. } catch (error) {
  282. } finally {
  283. this.otaLoading = false;
  284. }
  285. }
  286. });
  287. },
  288. }
  289. };
  290. </script>